-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprotocol.h
157 lines (147 loc) · 5.07 KB
/
protocol.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/** @file rf_protocol.h
*
* @author Wassim FILALI
*
* @compiler GCC for STM32
*
*
* $Date: 29.10.2016 - creation
* $Date: 08.10.2017 - takeover for the stm32 with mbed
* $Date: 18.11.2017 - Change to Mesh Protocol 2.0 (separate control and pid)
* $Revision: 3
*
*/
#include "mbed.h"
namespace rf
{
namespace ind
{
uint8_t const size = 0;
uint8_t const control = 1;
uint8_t const pid = 2;
uint8_t const source = 3;
uint8_t const dest = 4;
uint8_t const bcst_payload = 4;
uint8_t const p2p_payload = 5;
}
namespace ctr
{
//bit 7
uint8_t const Broadcast = 0x80;
uint8_t const Peer2Peer = 0x00;
//bit 6
uint8_t const Msg_Ack = 0x40;
uint8_t const ReqResp = 0x00;
//bit 5
uint8_t const Message = 0x20;
uint8_t const Acknowledge = 0x00;
//bit 5
uint8_t const Request = 0x20;
uint8_t const Response = 0x00;
//bit 4
uint8_t const Send_Ack = 0x10;
uint8_t const No_Ack = 0x00;
//bits 3-0
uint8_t const ttl_mask = 0x0F;
uint8_t const ttl_clear = 0xF0;
}
namespace pid
{
uint8_t const exec_cmd = 0xEC;
uint8_t const test = 0xE5;
uint8_t const ping = 0x01;
uint8_t const request_pid = 0x02;
//uint8_t const chan_switch = 0x03;//deprecated use exec_cmd
uint8_t const reset = 0x04;
uint8_t const alive = 0x05;
uint8_t const button = 0x06;
uint8_t const light = 0x07;//light MAX44009 2 Bytes [MSB][4LSb]
uint8_t const temperature = 0x08;//int32_t x 100
uint8_t const heat = 0x09;//is temperature heating order
uint8_t const bme280 = 0x0A;
uint8_t const rgb = 0x0B;
uint8_t const magnet = 0x0C;
uint8_t const dimmer = 0x0D;//action of changing light intensity
uint8_t const light_rgb = 0x0E;//sensing light in luminance and colors 4x(16-bit / channel)
uint8_t const gesture = 0x0F;//APDS gesture sensor
uint8_t const proximity = 0x10;//APDS proximity sensor
uint8_t const humidity = 0x11;//int32_t x 100
uint8_t const pressure = 0x12;//int32_t x 100
uint8_t const acceleration = 0x13;//x3 int16_t (x,y,z)
uint8_t const light_n = 0x14;//light sensing 16-bit [MSB][LSB]
uint8_t const battery = 0x15;//battery in milivots 16 bits [MSB][LSB]
//test_rf_resp is not using req resp, because the both request and response
// needs to be acknowledged so considered as messages
uint8_t const test_rf_resp = 0x30;
}
namespace exec_cmd
{
//RF
uint8_t const nop = 0x00;
uint8_t const status = 0x01;
uint8_t const standby = 0x02;
uint8_t const listen = 0x03;
//uint8_t const channel = 0x04;//deprecated
uint8_t const txadd = 0x05;
uint8_t const rxadd = 0x06;
uint8_t const readreg = 0x07;
uint8_t const writereg = 0x08;
uint8_t const set_channel = 0x09;
uint8_t const get_channel = 0x0A;
//Mesh
uint8_t const send = 0x20;
uint8_t const set_mode = 0x21;
uint8_t const get_mode = 0x22;
//Functions
uint8_t const set_rx = 0x30;
uint8_t const test_rf = 0x31;
uint8_t const set_retries = 0x32;
uint8_t const set_ack_delay = 0x33;
}
namespace mode
{
uint8_t const power_down = 0x01;
uint8_t const standby = 0x02;
uint8_t const tx_tdby2 = 0x03;
uint8_t const rx = 0x04;
}
namespace set_rx
{
uint8_t const sniff = 0x00;
uint8_t const bcast = 0x01;
uint8_t const msg = 0x02;
uint8_t const resp = 0x03;
}
namespace gest
{
uint8_t const none = 0x00;
uint8_t const left = 0x01;
uint8_t const right = 0x02;
uint8_t const up = 0x03;
uint8_t const down = 0x04;
uint8_t const near = 0x05;
uint8_t const far = 0x06;
uint8_t const all = 0x07;
}
}
class Proto
{
public:
Proto(Serial *ps);
void print_light_rgb(uint8_t *rxPayload);
void fill_light_paylod(uint16_t light,uint8_t *rxPayload);
void print_light(uint8_t *rxPayload);
void print_light_uint32(uint8_t *rxPayload);
void print_new_light(uint8_t *rxPayload);
void print_magnet(uint8_t *rxPayload);
void print_battery(uint8_t *rxPayload);
void print_bme280(uint8_t *rxPayload);
void print_bme280_values(uint8_t nodeid,uint8_t *rxPayload);
int32_t get_int32(uint8_t *rxPayload);
uint32_t get_uint32(uint8_t *rxPayload);
void print_acceleration(uint8_t *rxPayload);
void print_accell(uint8_t *data);
void printf_f2(int32_t val);
public:
Serial *pser;
};