-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTelemetry.h
86 lines (63 loc) · 1.95 KB
/
Telemetry.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef Telemetry_h
#define Telemetry_h
// Pure base class for data received by the telemetry module
class ITelemetry_ReceiveTarget
{
public:
virtual void startReception() = 0;
virtual void receiveTerm(int _index, const char *_value) = 0;
virtual void receiveChecksumCorrect() = 0;
virtual void receiveChecksumError() = 0;
};
// Largest distance between commas and such
#define CTelemetry_TERMSIZE (16)
// The telemetry module
class CTelemetry
{
protected:
// State machine states
typedef enum
{
TParser_S_WaitingForStart = 0, // Waiting for $
TParser_S_ParsingTerms, // Processing comma-separated terms
TParser_S_ProcessingChecksum // Checking the checksum term
} CTelemetry_Parser_StateE;
// Stuff for processing commands from the house
ICommunicationInterface *m_commInterface;
ITelemetry_ReceiveTarget *m_receiveTarget;
// Current state machine state
CTelemetry_Parser_StateE m_state;
// Location to accumulate data as the parse
// progresses. Mostly for the stuff between
// commas
char m_receiveTerm[CTelemetry_TERMSIZE];
int m_receiveTermOffset;
int m_receiveTermNumber;
// Running checksum
unsigned char m_receiveChecksum;
// Parser processing
void parseChar(unsigned char _c);
void addReceiveTermChar(unsigned char _c);
void processTerm(); // Returns true when valid and recognized sentence is complete
unsigned char from_hex(unsigned char _a);
void reset();
// Members for sending data
int m_transmitTermNumber;
int m_transmitChecksum;
public:
CTelemetry();
virtual ~CTelemetry();
void setInterfaces(ICommunicationInterface *_commInterface,
ITelemetry_ReceiveTarget *_receiveTarget);
void tick();
void parse(const unsigned char *_buf, unsigned int _bufLen);
// Interface for sending data
void transmissionStart();
void sendTerm(const char *_value);
void sendTerm(int _value);
void sendTerm(unsigned int _value);
void sendTerm(bool _value);
void sendTerm(double _value);
void transmissionEnd();
};
#endif