JM9 XRCU Board 0.2.0a
Libraries API Reference
Loading...
Searching...
No Matches
Serial_packer.h
Go to the documentation of this file.
1
8
9#ifndef SERIAL_PACKER_H
10#define SERIAL_PACKER_H
11
12#include <Arduino.h>
13#include <HardwareSerial.h>
14
15// JM9 UART packet:
16// start-byte
17// length-byte (sum of amount of cmd/reg-byte and data-bytes)
18// cmd/reg-byte (optional, may be treated as the first data byte)
19// data-bytes (variable length)
20// xor-byte (xor of start-byte and length-byte and cmd/reg-byte and data-bytes)
21//
22// reject entire packet if xor-byte is not matched
23
32 private:
36 HardwareSerial &uart;
37
41 const uint8_t start_byte;
42
46 uint8_t xor_byte;
47
52 void send_byte (const uint8_t data);
53
54 public:
55
62 Serial_packer (HardwareSerial &init_uart, const uint8_t init_start_byte);
63
71 bool send (const uint8_t * const tx_buf, const uint8_t tx_buf_len);
72
79};
80
81#endif // #ifndef SERIAL_PACKER_H
Definition HardwareSerial.h:99
bool send(const uint8_t *const tx_buf, const uint8_t tx_buf_len)
Creates and sends a packet.
HardwareSerial & get_uart()
Gets the UART object to send the packets to.
Serial_packer(HardwareSerial &init_uart, const uint8_t init_start_byte)
Creates a packer.