-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathVeDirectFrameHandler.h
61 lines (46 loc) · 2.29 KB
/
VeDirectFrameHandler.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* frameHandler.h
*
* Arduino library to read from Victron devices using VE.Direct protocol.
* Derived from Victron framehandler reference implementation.
*
* 2020.05.05 - 0.2 - initial release
* 2021.02.23 - 0.3 - change frameLen to 22 per VE.Direct Protocol version 3.30
*
*/
#ifndef FRAMEHANDLER_H_
#define FRAMEHANDLER_H_
const byte frameLen = 22; // VE.Direct Protocol: max frame size is 18
const byte nameLen = 9; // VE.Direct Protocol: max name size is 9 including /0
const byte valueLen = 33; // VE.Direct Protocol: max value size is 33 including /0
const byte buffLen = 40; // Maximum number of lines possible from the device. Current protocol shows this to be the BMV700 at 33 lines.
class VeDirectFrameHandler {
public:
VeDirectFrameHandler();
void rxData(uint8_t inbyte); // byte of serial data to be passed by the application
char veName[buffLen][nameLen] = { }; // public buffer for received names
char veValue[buffLen][valueLen] = { }; // public buffer for received values
int frameIndex; // which line of the frame are we on
int veEnd; // current size (end) of the public buffer
private:
//bool mStop; // not sure what Victron uses this for, not using
enum States { // state machine
IDLE,
RECORD_BEGIN,
RECORD_NAME,
RECORD_VALUE,
CHECKSUM,
RECORD_HEX
};
int mState; // current state
uint8_t mChecksum; // checksum value
char * mTextPointer; // pointer to the private buffer we're writing to, name or value
char mName[9]; // buffer for the field name
char mValue[33]; // buffer for the field value
char tempName[frameLen][nameLen]; // private buffer for received names
char tempValue[frameLen][valueLen]; // private buffer for received values
void textRxEvent(char *, char *);
void frameEndEvent(bool);
void logE(char *, char *);
bool hexRxEvent(uint8_t);
};
#endif // FRAMEHANDLER_H_