2021-05-05 23:00:55 +02:00
2021-05-01 20:24:28 +02:00
2021-05-05 23:00:55 +02:00
2021-05-05 23:00:55 +02:00
2021-03-30 00:42:31 +02:00
2021-05-01 20:24:28 +02:00

Simple Serial Protocol (SSP)

SSP is a easy-to-use serial protocol system for arduino type devices.

Installation

Using Arduino IDE

Download repository as ZIP and import it using the IDE.

Add the following dependency to your platform.ini file under lib_deps.

; SSP
https://git.aterve.com/Frozenverse/SimpleSerialProtocol.git

platform.ini should look something like this:

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino

lib_deps =
  ; SSP
  https://git.aterve.com/Frozenverse/SimpleSerialProtocol.git

Usage

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.

The protocol works as following, each packet has 3 seperate stages.

ID

ID of packet (device)

Type

Type of packet (action)

Data

Data of packet (data)

Of course you could change the use of any of these values to fit your needs. A complete packet would look like this:

ID - TYPE - DATA

Include SSP and define a new device.

#include <SimpleSerialProtocol.h>

// Define new device
SimpleSerialProtocol device;

Initialize the serial device and connection. First parameter is a serial object. For example; the mega 2560 has 4 serial channels (RX0/TX0 through RX3/TX3) so Serial, Serial1, Serial2 ... etc. Second parameter is the baud rate.

void setup() {
    // Initialize serial device on index 0 with a baud rate of 115200
    device.init(Serial, 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)

void onPacket(Packet packet) {
  Serial.println("Received Packet!");
  Serial.println(packet.id);
  Serial.println(packet.type);
  Serial.println(packet.data);
  Serial.println("----------------");
}

void loop() {
  device.receivePackets(onPacket);
  delay(1);
}

To send packets you can use the sendPacket method.

deviceOne.sendPacket("IDPacket", "Typehere", "testtest");

Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Description
Simple Serial Protocol (SSP) for arduino devices.
Readme 50 KiB
Languages
C++ 88.3%
C 11.7%