Skip to content

Commit

Permalink
Started documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed Oct 20, 2018
1 parent dfeb698 commit 9e7d89b
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 8 deletions.
75 changes: 73 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,74 @@
Device installation
===================

In this section we cover retrieval of the latest release or development version
of the code and subsequent installation for an Arduino device.

Download
--------

Latest release
~~~~~~~~~~~~~~

Navigate to the `latest release`_ and either download the ``.zip`` or the
``.tar.gz`` file.

Unpack the downloaded archive.


From source
~~~~~~~~~~~

The source is hosted on GitHub_, to install the latest development version, use
the following command.

::

git clone https://github.com/jfjlaros/simpleRPC.git


Installation
============
------------

Arduino IDE
~~~~~~~~~~~

In the Arduino IDE, a library can be added to the list of standard libraries by
clicking through the following menu options.

- Sketch
- Import Library
- Add Library

To add the library, navigate to the downloaded folder and select the subfolder
named ``simpleRPC``.

- Click OK.

Now the library can be added to any new project by clicking through the
following menu options.

- Sketch
- Import Library
- simpleRPC


Ino
~~~

Ino_ is an easy way of working with Arduino hardware from the command line.
Adding libraries is also easy, simply place the library in the ``lib``
subdirectory.


::

cd lib
git clone https://github.com/jfjlaros/simpleRPC.git


Host installation
=================

The software is distributed via PyPI_, it can be installed with ``pip``:

Expand All @@ -21,5 +90,7 @@ the following commands.
pip install .


.. _PyPI: https://pypi.org/project/arduino-simple-rpc
.. _latest release: https://github.com/jfjlaros/simpleRPC/releases/latest
.. _Ino: http://inotool.org
.. _GitHub: https://github.com/jfjlaros/simpleRPC.git
.. _PyPI: https://pypi.org/project/arduino-simple-rpc
68 changes: 68 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,71 @@
Usage
=====

Device
------

.. code:: cpp
#include <simpleRPC.h>
.. code:: cpp
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
interface();
}
.. code:: cpp
int add(int a, int b) {
return a + b;
}
.. code:: cpp
INTERFACE("Add two integers. @P:Value a. @P:Value b. @R:Sum of a and b.",
int, add, int, int)
Host
----

Library
~~~~~~~

.. code:: python
>>> from simple_rpc import Interface
>>>
>>> interface = Interface('/dev/ttyACM0')
>>> interface.add(1, 2)
3
.. code:: python
>>> help(interface.add)
Command line interface
~~~~~~~~~~~~~~~~~~~~~~

.. code::
$ simple_rpc list
Available methods:
add arg0 arg1
Add two integers.
arg0 (type int): Value a.
arg1 (type int): Value b.
returns (type int): Sum of a and b.
.. code::
$ simple_rpc call add 1 2
3
2 changes: 2 additions & 0 deletions simpleRPC/methods.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
INTERFACE("Receive a value and echo it back. @P: Value. @R:Value.",
int, ping, int)
INTERFACE("Test function. @R:The number 1.",
int, testInt, void)
INTERFACE("Test function. @R:The constant phi.",
Expand Down
7 changes: 7 additions & 0 deletions simpleRPC/simpleRPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,10 @@ void interface(void) {
}

#undef INTERFACE

/**
* Test function.
*/
int ping(int x) {
return x;
}
15 changes: 9 additions & 6 deletions simple_rpc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def _describe_parameters(method):

for index, parameter in enumerate(method['parameters']):
args.append('arg{}'.format(index))
description.append(' arg{}: {} (type {})'.format(
index, method['doc']['parameters'][index], parameter))
description.append(' arg{} (type {}): {}'.format(
index, parameter, method['doc']['parameters'][index]))

return args, description

Expand All @@ -35,12 +35,15 @@ def _describe_method(method):

args, parameter_description = _describe_parameters(method)
if (args):
description += ' {}\n\n{}'.format(
' '.join(args), '\n'.join(parameter_description))
description += ' {}'.format(' '.join(args))

description += '\n {}'.format(method['doc']['name'])
if (args):
description += '\n\n{}'.format('\n'.join(parameter_description))

if method['type']:
description += '\n\n returns: {} (type {})'.format(
method['doc']['type'], method['type'])
description += '\n\n returns (type {}): {}'.format(
method['type'], method['doc']['type'])

return description

Expand Down

0 comments on commit 9e7d89b

Please sign in to comment.