updated readme!
This commit is contained in:
96
README.md
96
README.md
@@ -4,26 +4,98 @@ SSP is a easy-to-use serial protocol system for arduino type devices.
|
||||
|
||||
## Installation
|
||||
|
||||
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install foobar.
|
||||
### Using Arduino IDE
|
||||
|
||||
Download repository as ZIP and import it using the IDE.
|
||||
|
||||
### Using PlatformIO (Recommended)
|
||||
|
||||
Add the following dependency to your ``platform.ini`` file under ``lib_deps``.
|
||||
|
||||
```ini
|
||||
; SSP
|
||||
https://git.aterve.com/Frozenverse/SimpleSerialProtocol.git
|
||||
```
|
||||
|
||||
``platform.ini`` should look something like this:
|
||||
|
||||
```ini
|
||||
[env:megaatmega2560]
|
||||
platform = atmelavr
|
||||
board = megaatmega2560
|
||||
framework = arduino
|
||||
|
||||
lib_deps =
|
||||
; SSP
|
||||
https://git.aterve.com/Frozenverse/SimpleSerialProtocol.git
|
||||
|
||||
```bash
|
||||
pip install foobar
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```python
|
||||
import foobar
|
||||
SimpleSerialProtocol has a very simple API so it should be very easy to implement it. Look at ``ssp.ino`` in the examples folder for a complete example.
|
||||
|
||||
foobar.pluralize('word') # returns 'words'
|
||||
foobar.pluralize('goose') # returns 'geese'
|
||||
foobar.singularize('phenomena') # returns 'phenomenon'
|
||||
The protocol works as following, each packet has 3 seperate stages.
|
||||
|
||||
### ID
|
||||
This could be the device or service you want to reach.
|
||||
|
||||
### Command
|
||||
This is the command you want to send to the device or service.
|
||||
|
||||
### Data
|
||||
This is the data you want to send to the device or service.
|
||||
|
||||
Of course you could change the use of any of these values to fit your needs.
|
||||
A complete packet would look like this:
|
||||
|
||||
```
|
||||
<ID_HERE:COMMAND_HERE:DATA_HERE>
|
||||
```
|
||||
|
||||
## Contributing
|
||||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
||||
As you can see the packet starts and ends with ``< - >`` characters and the stages are seperated with `` : `` characters.
|
||||
|
||||
Please make sure to update tests as appropriate.
|
||||
`This means you can't use any of these characters as data in the packets!!`
|
||||
|
||||
Include SSP and define a new device.
|
||||
```C++
|
||||
#include <SimpleSerialProtocol.h>
|
||||
|
||||
// Define new device
|
||||
SimpleSerialProtocol device;
|
||||
```
|
||||
|
||||
Initialize the serial device and connection.
|
||||
First parameter is the serial channel. For example; the mega 2560 has 4 serial channels (RX0/TX0 through RX3/TX3)
|
||||
Second parameter is the baud rate.
|
||||
```C++
|
||||
void setup() {
|
||||
// Initialize serial device on index 0 with a baud rate of 115200
|
||||
device.init(0, 115200);
|
||||
}
|
||||
```
|
||||
|
||||
Now create a method (with a packet parameter) which will be called when a packet is received. In the main loop call ``receivePackets`` with the callback function as parameter regularly. (more times the better)
|
||||
```C++
|
||||
void onPacket(Packet packet) {
|
||||
Serial.println("Received Packet!");
|
||||
Serial.println(packet.id);
|
||||
Serial.println(packet.command);
|
||||
Serial.println(packet.data);
|
||||
Serial.println("----------------");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
device.receivePackets(onPacket);
|
||||
delay(1);
|
||||
}
|
||||
```
|
||||
To send packets you can use the ``sendPacket`` method.
|
||||
```C++
|
||||
deviceOne.sendPacket("IDPacket", "Commandhere", "testtest");
|
||||
```
|
||||
## Contributing
|
||||
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
|
||||
|
||||
## License
|
||||
[MIT](https://choosealicense.com/licenses/mit/)
|
||||
[MIT](https://www.gnu.org/licenses/gpl-3.0.en.html)
|
Reference in New Issue
Block a user