Arduino KVComm  master
Key-Value pair communication library for Arduino
SLIP-Receive-CRC.ino

SLIP-Receive-CRC

Receives SLIP packages with a CRC checksum over Serial.

Boards:
AVR, AVR USB, Nano Every, Nano 33, Due, Teensy 3.x, ESP8266, ESP32
See also
SLIP-Send-CRC.ino

Written by PieterP, 2020-02-06
https://github.com/tttapa/Arduino-KVComm

#include <KVComm.h>
#include <boost/crc.hpp>
// The CRC settings to use, must be the same as the sender.
using CRC = boost::crc_optimal<16, 0x1021, 0xFFFF, 0, false, false>;
// Buffer for saving the incoming packets
uint8_t slipbuffer[256];
// The actual SLIP Stream: it sends and receives packets, adds framing
// bytes, and computes a checksum using the CRC specified above.
Serial, // stream
CRC(), // sender CRC
slipbuffer, // parser
CRC(), // parser CRC
};
void setup() {
Serial.begin(115200);
}
void loop() {
size_t packetSize = slip.readPacket();
if (packetSize > 0) {
Serial.print("Received packet: ");
Serial.write(slipbuffer, packetSize);
Serial.println();
Serial.println(slip.wasTruncated() ? "Size: Truncated"
: "Size: OK");
Serial.println(slip.checksum() != 0 ? "Checksum: Mismatch"
: "Checksum: OK");
Serial.println();
}
}
KVComm.h
SLIPStreamCRC::readPacket
size_t readPacket()
Receives a packet into the read buffer.
Definition: SLIPStream.ipp:30
SLIPStreamCRC::checksum
checksum_t checksum() const
Get the checksum of the previous packet.
Definition: SLIPStream.hpp:125
SLIPStreamCRC::wasTruncated
bool wasTruncated() const
Check if the previous packet was truncated.
Definition: SLIPStream.hpp:117
SLIPStreamCRC
Class that implements SLIP, a simple packet framing protocol, and that uses cyclic redundancy checks ...
Definition: SLIPStream.hpp:84
SLIPStream.hpp