-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathv202_protocol.h
More file actions
72 lines (60 loc) · 1.55 KB
/
v202_protocol.h
File metadata and controls
72 lines (60 loc) · 1.55 KB
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
/* v202_protocol.h -- Handle the v202 protocol.
*
* Copyright (C) 2016 execuc
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#ifndef V202_PROTOCOL_H_
#define V202_PROTOCOL_H_
#include "Arduino.h"
#include "nrf24l01p.h"
typedef struct __attribute__((__packed__)) {
uint8_t throttle;
int8_t yaw;
int8_t pitch;
int8_t roll;
int8_t trim_yaw;
int8_t trim_pitch;
int8_t trim_roll;
uint8_t flags;
uint8_t crc;
} rx_values_t;
enum rxState
{
NO_BIND = 0,
WAIT_FIRST_SYNCHRO,
BOUND,
SIGNAL_LOST
};
enum rxReturn
{
BOUND_NEW_VALUES = 0, // Bound state, frame received with new TX values
BOUND_NO_VALUES, // Bound state, no new frame received
NOT_BOUND, // Not bound, initial state
BIND_IN_PROGRESS, // Bind in progress, first frame has been received with TX id, wait no bind frame
ERROR_SIGNAL_LOST, // Signal lost
UNKNOWN // ???, not used for moment
};
class v202Protocol
{
public:
v202Protocol();
~v202Protocol();
void init(nrf24l01p *wireless);
uint8_t run(rx_values_t *rx_value );
protected:
void retrieveFrequency();
bool checkCRC();
inline bool checkTXaddr() { return ( mTxid[0] == mFrame[7] && mTxid[1] == mFrame[8] && mTxid[2] == mFrame[9]);}
nrf24l01p *mWireless;
uint8_t mTxid[3];
uint8_t mRfChannels[16];
uint8_t mRfChNum;
uint8_t mFrame[16];
uint8_t mState;
uint8_t mErrorTimeoutCode;
uint16_t mTimeout;
unsigned long mLastSignalTime;
};
#endif /* V202_PROTOCOL_H_ */