-
Notifications
You must be signed in to change notification settings - Fork 10
/
SPort.h
76 lines (68 loc) · 2.1 KB
/
SPort.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
#ifndef SPort_H
#define SPort_H
#include "Arduino.h"
#define FRSKY_RX_PACKET_SIZE 0x09
#define STATE_DATA_IDLE 0x01
#define STATE_DATA_IN_FRAME 0x02
#define STATE_DATA_XOR 0x03
#define START_STOP 0x7e
#define BYTESTUFF 0x7d
#define STUFF_MASK 0x20
#define DATA_FRAME 0x10
// FrSky new DATA IDs (2 bytes)
#define RSSI_ID 0xf101
#define ADC1_ID 0xf102
#define ADC2_ID 0xf103
#define BATT_ID 0xf104
#define SWR_ID 0xf105
#define T1_FIRST_ID 0x0400
#define T1_LAST_ID 0x040f
#define T2_FIRST_ID 0x0410
#define T2_LAST_ID 0x041f
#define RPM_FIRST_ID 0x0500
#define RPM_LAST_ID 0x050f
#define FUEL_FIRST_ID 0x0600
#define FUEL_LAST_ID 0x060f
#define ALT_FIRST_ID 0x0100
#define ALT_LAST_ID 0x010f
#define VARIO_FIRST_ID 0x0110
#define VARIO_LAST_ID 0x011f
#define ACCX_FIRST_ID 0x0700
#define ACCX_LAST_ID 0x070f
#define ACCY_FIRST_ID 0x0710
#define ACCY_LAST_ID 0x071f
#define ACCZ_FIRST_ID 0x0720
#define ACCZ_LAST_ID 0x072f
#define CURR_FIRST_ID 0x0200
#define CURR_LAST_ID 0x020f
#define VFAS_FIRST_ID 0x0210
#define VFAS_LAST_ID 0x021f
#define GPS_SPEED_FIRST_ID 0x0830
#define GPS_SPEED_LAST_ID 0x083f
#define CELLS_FIRST_ID 0x0300
#define CELLS_LAST_ID 0x030f
#define SPORT_DATA_U8(packet) (buffer[4])
#define SPORT_DATA_S32(packet) (*((int32_t *)(buffer+4)))
#define SPORT_DATA_U32(packet) (*((uint32_t *)(buffer+4)))
class SPort {
public:
SPort(HardwareSerial & serial) : _serial (serial) {}
void begin();
void begin(bool useTimer);
void process();
long getVarioSpeed();
long getVarioAltitude();
int getVfasVoltage();
int getVfasCurrent();
int getVfasConsumption();
private:
HardwareSerial & _serial;
long _varioSpeed;
long _varioAltitude;
unsigned long _altitudeOffset;
int _vfasVoltage;
int _vfasCurrent;
unsigned long _vfasConsumption;
unsigned long _uptime;
};
#endif