-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
189 lines (157 loc) · 4.89 KB
/
test.c
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <stdio.h>
#include "sensor.h"
#include "stdint.h"
#include <stdlib.h>
#include "unused.h"
#include "configfile.h"
#include "sensor_db.h"
#include <assert.h>
#include "webcmd.h"
#include <string.h>
int main(int argc, char* argv[])
{
webmsg commandToSend;
bool hasReceivedCommand;
bool bOk = webcmd_init("fifo_test");
if (!bOk)
{
fprintf(stderr, "unable to open fifo_test\n");
}
while (1)
{
hasReceivedCommand = webcmd_checkMsg(&commandToSend);
if (hasReceivedCommand)
{
//send command to xb device.
fprintf(stdout, "Command received from web serveur (%x,%x,%x,%x,%x,%x,%x,%x):%d:%d\n",
commandToSend.zbAddress[0], commandToSend.zbAddress[1], commandToSend.zbAddress[2],
commandToSend.zbAddress[3], commandToSend.zbAddress[4], commandToSend.zbAddress[5],
commandToSend.zbAddress[6], commandToSend.zbAddress[7],
commandToSend.sensor_id, commandToSend.command);
/*uint32_t size;
size = sensor_build_command(&commandToSend, zbPayload, MAX_SIZE_FRAME);
if (size != 0)
{
zigbee_protocol_sendData(zigbee,
&commandToSend.zbAddress,
ZIGBEE_UNKNOWN_16B_ADDR,
zbPayload,
size);
}
else
{
fprintf(stdout, "can't send data 'sensor_build_command' returns 0\n");
}*/
}
else
{
fprintf(stdout, "not received\n");
}
usleep(500000);
}
return EXIT_SUCCESS;
}
#if 0
const uint8_t payload1[] = {0x0, 0x8, 0x3, 0x1, 0x3, 0x16, 0x2d, 0x2, 0x3, 0x1d, 0xf0, 0x3, 0x0, 0x1, 0xd3};
const uint8_t payload2[] = {0x0, 0x5, 0x3, 0x1, 0x3, 0x17, 0x95, 0x2, 0x3, 0x13, 0x7b, 0x3, 0x3, 0x1, 0xcf};
int main (int argc, char* argv[])
{
UNUSED(argc);
UNUSED(argv);
zigbee_decodedFrame frame;
frame.receivedPacket.receiver64bAddr[0] = 0x0;
frame.receivedPacket.receiver64bAddr[1] = 0x13;
frame.receivedPacket.receiver64bAddr[2] = 0xa2;
frame.receivedPacket.receiver64bAddr[3] = 0x0;
frame.receivedPacket.receiver64bAddr[4] = 0x40;
frame.receivedPacket.receiver64bAddr[5] = 0xbd;
frame.receivedPacket.receiver64bAddr[6] = 0x47;
frame.receivedPacket.receiver64bAddr[7] = 0x18;
frame.receivedPacket.payloadSize = 15;
frame.receivedPacket.payload = (uint8_t*) payload1;
frame.type = ZIGBEE_RECEIVE_PACKET;
sensor_readAndProvideSensorData(&frame, "./post_data.rb");
frame.receivedPacket.payloadSize = 15;
frame.receivedPacket.payload = (uint8_t*) payload2;
frame.type = ZIGBEE_RECEIVE_PACKET;
sensor_readAndProvideSensorData(&frame, "./post_data.rb");
if (argc >= 2)
{
configfile_read(argv[1]);
fprintf(stdout, "script = %s\n", config_scriptName);
fprintf(stdout, "pandID = (%d)\n", config_nbPanID);
for (uint32_t i = 0; i < config_nbPanID; i++)
{
fprintf(stdout, "%d = 0x%x\n", i, config_panID[i]);
}
}
zigbee_64bDestAddr addr;
addr[0] = 0;
addr[1] = 1;
addr[2] = 2;
addr[3] = 3;
addr[4] = 4;
addr[5] = 5;
addr[6] = 6;
addr[7] = 7;
bool isRetry;
isRetry = sensor_db_update(&addr, 0);
fprintf(stdout, "isRetry = %d\n", isRetry);
assert(isRetry == false);
isRetry = sensor_db_update(&addr, 0);
fprintf(stdout, "isRetry = %d\n", isRetry);
assert(isRetry == true);
isRetry = sensor_db_update(&addr, 1);
fprintf(stdout, "isRetry = %d\n", isRetry);
assert(isRetry == false);
zigbee_64bDestAddr addr2;
addr2[0] = 0;
addr2[1] = 10;
addr2[2] = 20;
addr2[3] = 30;
addr2[4] = 40;
addr2[5] = 55;
addr2[6] = 60;
addr2[7] = 70;
isRetry = sensor_db_update(&addr, 0);
fprintf(stdout, "isRetry = %d\n", isRetry);
assert(isRetry == false);
isRetry = sensor_db_update(&addr2, 0);
fprintf(stdout, "isRetry = %d\n", isRetry);
assert(isRetry == false);
isRetry = sensor_db_update(&addr, 10);
fprintf(stdout, "isRetry = %d\n", isRetry);
assert(isRetry == false);
isRetry = sensor_db_update(&addr2, 0);
fprintf(stdout, "isRetry = %d\n", isRetry);
assert(isRetry == true);
isRetry = sensor_db_update(&addr, 10);
fprintf(stdout, "isRetry = %d\n", isRetry);
assert(isRetry == true);
isRetry = sensor_db_update(&addr2, 255);
fprintf(stdout, "isRetry = %d\n", isRetry);
assert(isRetry == false);
bool bCorrectlyDecoded;
char message[255];
webmsg msg;
const char* pMsg = "xb@00:13:a2:00:40:d9:68:9c;3;ECO\nxb@00:13:a2:00:40:d9:68:9d;3;CONFORT\n";
zigbee_64bDestAddr zbAddr;
zbAddr[0] = 0;
zbAddr[1] = 0x13;
zbAddr[2] = 0xa2;
zbAddr[3] = 0;
zbAddr[4] = 0x40;
zbAddr[5] = 0xd9;
zbAddr[6] = 0x68;
zbAddr[7] = 0x9c;
strcpy(message, pMsg);
bCorrectlyDecoded = webcmd_decodeFrame(message, sizeof(pMsg), &msg);
assert(bCorrectlyDecoded == true);
assert(msg.command == ECO);
assert(msg.sensor_id == 3);
for (uint32_t i = 0; i < ZIGBEE_MAX_MAC_ADDRESS_NUMBER; i++)
{
assert(msg.zbAddress[i] == zbAddr[i]);
}
}
#endif