-
Notifications
You must be signed in to change notification settings - Fork 0
/
TelemetryReader.h
56 lines (40 loc) · 1.31 KB
/
TelemetryReader.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
#ifndef H_TELEMETRY_READER
#define H_TELEMETRY_READER
#include <Arduino.h>
#include <SoftwareSerial.h>
//#include <AltSoftSerial.h>
#include <stdint.h>
#include <BoundedQueue.h>
#include "TelemetryData.h"
#define TELEM_SERIAL Serial1
/*
* Note that the documentation might be wrong. It appears like the bytes sent from my
* updated d8r-II plus are only 10 bytes long as opposed to the 11 bytes in the documentation.
*
* See section 4.1 Frame format in the Two-way system protocol where a change from 10 to 11 bytes
* is documented
*/
class TelemetryReader
{
public:
TelemetryReader();
void update();
uint8_t getDataValue(TelemetryData::DataIndex dataType);
private:
//Read a single byte from the serial feed.
void readByte();
void decodeFrame();
void parseRCStatus();
//Return true if the current frame looks valid
//This assumes that the startByte has been popped off
bool isValidFrame();
//Static constants
static const uint8_t FRAME_LENGTH = 10;
static const uint8_t FRAME_EDGE_BYTE = 0x7E;
static const uint8_t RC_STATUS_HEADER = 0xFE;
//Private members
//The current frame needs to be stored because the tx/rx seem to spit out data as it arrives.
BoundedQueue<uint8_t> currentFrame;
uint8_t dataValues[TelemetryData::enum_size];
};
#endif