-
Notifications
You must be signed in to change notification settings - Fork 1
/
protocol.h
141 lines (90 loc) · 2.2 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
#ifndef PROTOCOL_H_
#define PROTOCOL_H_
#include "stdio.h"
#define COLLECTION_CYCLE_TIMEOUT 60
#define CONFIG_FILE (0x8010)
#define CONFIG_REC_KEY (0x7010)
#define PACKET_TYPE_UPLINK_EVENT_HEADER_0 0x04
#define PACKET_TYPE_UPLINK_SENSOR_DATA_HEADER_0 0x06
#define PACKET_TYPE_DOWNLINK_ACK_HEADER_0 0x00
#define PACKET_TYPE_DOWNLINK_SETUP_DATA_HEADER_0 0x03
#define CHIP_MANUFACTURER_NORDIC 0x01
#define CHIP_IDENTIFIER_NRF52832 0x01
#define COMMUNICATION_TYPE_BLE_CONNECTION_1M 0x01
#define EVENT_TYPE_POWER_OFF 0x00
#define EVENT_TYPE_POWER_ON 0x01
#define EVENT_TYPE_RUN_TIME_EVENT 0x02
#define PRODUCT_ID_AA_MB_03 0x03
#define NODE_EVENT_PACKET_SIZE 14
#define NODE_DATA_PACKET_SIZE 21
typedef union {
struct {
uint8_t DEVICE_ROLE :1;
uint8_t PACKET_TYPE :3;
uint8_t CHIP_MANUFACTURER :4;
} bits;
uint8_t value;
} packet_header_0_t;
typedef union {
struct {
uint8_t CHIP_IDENTIFIER :5;
uint8_t COMMUNICATION_TYPE :3;
} bits;
uint8_t value;
} packet_header_1_t;
typedef union {
struct {
uint8_t EVENT_TYPE :2;
uint8_t UNKNOWN_RESET :1;
uint8_t COMMUNICATION_TIMEOUT_RESET :1;
uint8_t SENSOR_ERROR_RESET :1;
uint8_t MAIN_LOOP_STUCK_RESET :1;
uint8_t WDT_RESET :1;
uint8_t SETUP_COMMAND_RESET :1;
} bits;
uint8_t value;
} packet_event_0_t;
typedef union {
struct {
uint8_t BME280_ERROR :1;
uint8_t HDC1080_ERROR :1;
uint8_t VCNL4040_ERROR :1;
uint8_t RESERVED_0 :1;
uint8_t RESERVED_1 :1;
uint8_t RESERVED_2 :1;
uint8_t RESERVED_3 :1;
uint8_t RESERVED_4 :1;
} bits;
uint8_t value;
} packet_event_1_t;
typedef union {
struct {
uint16_t PRODUCT_ID :14;
uint16_t DEVICE_TYPE :1;
uint16_t PRODUCT_TYPE :1;
} bits;
uint16_t value;
} product_id_t;
typedef union {
struct {
uint8_t header_0;
uint8_t header_1;
uint8_t mac_address[8];
uint8_t product_id[2];
uint8_t event_value_0;
uint8_t event_value_1;
} Event_Packet;
struct {
uint8_t header_0;
uint8_t header_1;
uint8_t mac_address[8];
uint8_t packet_info;
uint8_t battery_value;
uint8_t temperature[2];
uint8_t pressure[4];
uint8_t humidity;
uint8_t ambient_light[2];
} Data_Packet;
uint8_t buffer[21];
} node_packet_data_t;
#endif /* PROTOCOL_H_ */