#include <Arduhdlc.h>
#define MAX_HDLC_FRAME_LENGTH 32
void send_character(uint8_t data);
void hdlc_command_router(const uint8_t *framebuffer, uint16_t framelength);
Arduhdlc hdlc(&send_character, &hdlc_command_router, MAX_HDLC_FRAME_LENGTH);
char framebuffer[MAX_HDLC_FRAME_LENGTH];
void send_character(uint8_t data) {
Serial.print((char) data);
}
void hdlc_command_router(const uint8_t *framebuffer, uint16_t framelength) {
// Do somethin here with the data in buffer
return;
}
void setup() {
Serial.begin(57600);
}
void loop() {
framebuffer[0] = 'T';
framebuffer[1] = 's';
framebuffer[2] = 't';
hdlc.frameDecode(framebuffer, 3);
delay(500);
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char) Serial.read();
hdlc.charReceiver(inChar);
}
}
If lib expects string: Not every bytearray can be decoded to a string, like example above. 0xbe can't be decoded