51 lines
1002 B
C++
51 lines
1002 B
C++
#ifndef UBUS_H
|
|
#define UBUS_H
|
|
|
|
#include <ArduinoRS485.h>
|
|
#include <util/crc16.h>
|
|
|
|
extern unsigned long _hdlc_start;
|
|
|
|
#define HDLC_START 0x7E
|
|
#define HDLC_ESC 0x7D
|
|
#define HDLC_BUF_SIZE 32
|
|
#define CRC16_CCITT_INIT_VAL 0xFFFF
|
|
|
|
class UBus: public RS485Class {
|
|
public:
|
|
enum MessageType : uint8_t {
|
|
SYS_StatusPoll = 0x00,
|
|
SYS_Identify = 0x01,
|
|
SYS_SupportedCommands = 0x02,
|
|
|
|
GPIO_Write = 0x10,
|
|
GPIO_Read = 0x11,
|
|
GPIO_WS2812 = 0x12,
|
|
|
|
PERI_NFC = 0x20,
|
|
};
|
|
|
|
uint8_t addr = 0;
|
|
uint32_t identify_ts = 0;
|
|
|
|
bool escape = false;
|
|
|
|
uint8_t buf_pos = 0;
|
|
uint8_t buffer[HDLC_BUF_SIZE];
|
|
uint16_t checksum = CRC16_CCITT_INIT_VAL;
|
|
|
|
UBus(): RS485Class(Serial, 1, 3, 2) { }
|
|
|
|
void begin();
|
|
|
|
void sendByte(uint8_t b);
|
|
void send(uint8_t msg_type, uint8_t* buf, size_t size);
|
|
void sendResponse(uint8_t msg_type, uint8_t* buf, size_t size);
|
|
|
|
void handleRequest();
|
|
|
|
void poll();
|
|
void parse(uint8_t c);
|
|
};
|
|
#endif
|