updated readme
This commit is contained in:
parent
ae2a092fab
commit
929f4042e0
18
README.md
18
README.md
@ -38,25 +38,21 @@ SimpleSerialProtocol has a very simple API so it should be very easy to implemen
|
|||||||
The protocol works as following, each packet has 3 seperate stages.
|
The protocol works as following, each packet has 3 seperate stages.
|
||||||
|
|
||||||
### ID
|
### ID
|
||||||
This could be the device or service you want to reach.
|
ID of packet (device)
|
||||||
|
|
||||||
### Command
|
### Type
|
||||||
This is the command you want to send to the device or service.
|
Type of packet (action)
|
||||||
|
|
||||||
### Data
|
### Data
|
||||||
This is the data you want to send to the device or service.
|
Data of packet (data)
|
||||||
|
|
||||||
Of course you could change the use of any of these values to fit your needs.
|
Of course you could change the use of any of these values to fit your needs.
|
||||||
A complete packet would look like this:
|
A complete packet would look like this:
|
||||||
|
|
||||||
```
|
```
|
||||||
<ID_HERE:COMMAND_HERE:DATA_HERE>
|
ID - TYPE - DATA
|
||||||
```
|
```
|
||||||
|
|
||||||
As you can see the packet starts and ends with ``< - >`` characters and the stages are seperated with `` : `` characters.
|
|
||||||
|
|
||||||
`This means you can't use any of these characters as data in the packets!!`
|
|
||||||
|
|
||||||
Include SSP and define a new device.
|
Include SSP and define a new device.
|
||||||
```c++
|
```c++
|
||||||
#include <SimpleSerialProtocol.h>
|
#include <SimpleSerialProtocol.h>
|
||||||
@ -80,7 +76,7 @@ Now create a method (with a packet parameter) which will be called when a packet
|
|||||||
void onPacket(Packet packet) {
|
void onPacket(Packet packet) {
|
||||||
Serial.println("Received Packet!");
|
Serial.println("Received Packet!");
|
||||||
Serial.println(packet.id);
|
Serial.println(packet.id);
|
||||||
Serial.println(packet.command);
|
Serial.println(packet.type);
|
||||||
Serial.println(packet.data);
|
Serial.println(packet.data);
|
||||||
Serial.println("----------------");
|
Serial.println("----------------");
|
||||||
}
|
}
|
||||||
@ -92,7 +88,7 @@ void loop() {
|
|||||||
```
|
```
|
||||||
To send packets you can use the ``sendPacket`` method.
|
To send packets you can use the ``sendPacket`` method.
|
||||||
```c++
|
```c++
|
||||||
deviceOne.sendPacket("IDPacket", "Commandhere", "testtest");
|
deviceOne.sendPacket("IDPacket", "Typehere", "testtest");
|
||||||
```
|
```
|
||||||
## Contributing
|
## Contributing
|
||||||
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
|
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
|
||||||
|
@ -8,12 +8,12 @@ SimpleSerialProtocol deviceOne;
|
|||||||
void onPacket(Packet packet) {
|
void onPacket(Packet packet) {
|
||||||
Serial.println("Received Packet!");
|
Serial.println("Received Packet!");
|
||||||
Serial.println(packet.id);
|
Serial.println(packet.id);
|
||||||
Serial.println(packet.command);
|
Serial.println(packet.type);
|
||||||
Serial.println(packet.data);
|
Serial.println(packet.data);
|
||||||
Serial.println("----------------");
|
Serial.println("----------------");
|
||||||
|
|
||||||
// To send a packet
|
// To send a packet
|
||||||
deviceOne.sendPacket("IDPacket", "Commandhere", "testtest");
|
deviceOne.sendPacket("IDPacket", "TypeHere", "testtest");
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@ -25,8 +25,5 @@ void loop() {
|
|||||||
// Call receive packets function (looping) to handle incoming serial packets.
|
// Call receive packets function (looping) to handle incoming serial packets.
|
||||||
// If a complete packet has been received it will call the callback function (onPacket).
|
// If a complete packet has been received it will call the callback function (onPacket).
|
||||||
deviceOne.receivePackets(onPacket);
|
deviceOne.receivePackets(onPacket);
|
||||||
|
|
||||||
// Small delay to not over overwork CPU.
|
|
||||||
delay(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user