-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArduhdlc.h
34 lines (28 loc) · 987 Bytes
/
Arduhdlc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef arduhdlc_h
#define arduhdlc_h
#include "Arduino.h"
#include <stdint.h>
#include <stdbool.h>
typedef void (*sendchar_type)(uint8_t);
typedef void (*frame_handler_type)(const uint8_t *framebuffer, uint16_t framelength);
class Arduhdlc
{
public:
Arduhdlc(sendchar_type, frame_handler_type, uint16_t max_frame_length);
void charReceiver(uint8_t data);
void sendFrame(const uint8_t *framebuffer, uint8_t frame_length);
private:
/* User must define a function, that sends a 8bit char over the chosen interface, usart, spi, i2c etc. */
sendchar_type sendchar_function;
/* User must define a function, that will process the valid received frame */
/* This function can act like a command router/dispatcher */
frame_handler_type frame_handler;
void sendchar(uint8_t data);
bool escape_character;
uint8_t *receive_frame_buffer;
uint8_t frame_position;
// 16bit CRC sum for _crc_ccitt_update
uint16_t frame_checksum;
uint16_t max_frame_length;
};
#endif