18
18
**************************************************************************************/
19
19
20
20
SCENARIO (" Test the encoding of command messages" ) {
21
+ /* ***********************************************************************************/
22
+
23
+ WHEN (" Encode the OtaBeginUp message" )
24
+ {
25
+ OtaBeginUp * command = new OtaBeginUp ();
26
+ uint8_t sha[SHA256_SIZE] = {0x01 , 0x02 , 0x03 , 0x04 };
27
+ memcpy (command->fields .params .sha , sha, SHA256_SIZE);
28
+
29
+ Message * message = new Message ();
30
+ message->id = CommandID::DeviceBeginCmdUpId;
31
+
32
+ uint8_t buffer[256 ];
33
+ int bytes_encoded = 0 ;
34
+
35
+ CborError err = MessageEncoder::encode (message, buffer, sizeof (buffer), bytes_encoded);
36
+
37
+ // Test the encoding is
38
+ // DA 00010700 # tag(67328)
39
+ // 81 # array(1)
40
+ // 44 # bytes(4)
41
+ // 01020304 # "\u0001\u0002\u0003\u0004"
42
+ THEN (" The encoding is successful" ) {
43
+ REQUIRE (err == CborNoError);
44
+ REQUIRE (bytes_encoded == 7 );
45
+ REQUIRE (buffer[0 ] == 0xDA );
46
+ REQUIRE (buffer[1 ] == 0x00 );
47
+ REQUIRE (buffer[2 ] == 0x01 );
48
+ REQUIRE (buffer[3 ] == 0x07 );
49
+ REQUIRE (buffer[4 ] == 0x81 );
50
+ REQUIRE (buffer[5 ] == 0x44 );
51
+ REQUIRE (buffer[6 ] == 0x01 );
52
+ REQUIRE (buffer[7 ] == 0x02 );
53
+ REQUIRE (buffer[8 ] == 0x03 );
54
+ REQUIRE (buffer[9 ] == 0x04 );
55
+ }
56
+
57
+ delete message;
58
+ }
59
+
60
+
21
61
/* ***********************************************************************************/
22
62
23
63
WHEN (" Encode the ThingGetIdCmdUp message" )
@@ -90,14 +130,10 @@ SCENARIO("Test the encoding of command messages") {
90
130
delete message;
91
131
}
92
132
93
- /* ***********************************************************************************/
133
+ /* ***********************************************************************************/
94
134
95
- WHEN (" Encode the DeviceBeginCmdUp message" )
135
+ WHEN (" Encode the DeviceBeginCmdUpId message" )
96
136
{
97
- DeviceBeginCmdUp * command = new DeviceBeginCmdUp ();
98
- uint8_t sha[SHA256_SIZE] = {0x01 , 0x02 , 0x03 , 0x04 };
99
- memcpy (command->fields .params .sha , sha, SHA256_SIZE);
100
-
101
137
Message * message = new Message ();
102
138
message->id = CommandID::DeviceBeginCmdUpId;
103
139
@@ -107,25 +143,44 @@ SCENARIO("Test the encoding of command messages") {
107
143
CborError err = MessageEncoder::encode (message, buffer, sizeof (buffer), bytes_encoded);
108
144
109
145
// Test the encoding is
110
- // DA 00010700 # tag(67328)
111
- // 81 # array(1)
112
- // 44 # bytes(4)
113
- // 01020304 # "\u0001\u0002\u0003\u0004"
146
+ // DA 00010700 # tag(67328)
147
+ // 80 # array(0)
114
148
THEN (" The encoding is successful" ) {
115
149
REQUIRE (err == CborNoError);
116
- REQUIRE (bytes_encoded == 7 );
150
+ REQUIRE (bytes_encoded == 4 );
117
151
REQUIRE (buffer[0 ] == 0xDA );
118
152
REQUIRE (buffer[1 ] == 0x00 );
119
153
REQUIRE (buffer[2 ] == 0x01 );
120
154
REQUIRE (buffer[3 ] == 0x07 );
121
- REQUIRE (buffer[4 ] == 0x81 );
122
- REQUIRE (buffer[5 ] == 0x44 );
123
- REQUIRE (buffer[6 ] == 0x01 );
124
- REQUIRE (buffer[7 ] == 0x02 );
125
- REQUIRE (buffer[8 ] == 0x03 );
126
- REQUIRE (buffer[9 ] == 0x04 );
155
+ REQUIRE (buffer[4 ] == 0x80 );
127
156
}
157
+ delete message;
158
+ }
128
159
160
+ /* ***********************************************************************************/
161
+
162
+ WHEN (" Encode the OtaUpdateCmdDown message" )
163
+ {
164
+ Message * message = new Message ();
165
+ message->id = CommandID::OtaUpdateCmdDownId;
166
+
167
+ uint8_t buffer[256 ];
168
+ int bytes_encoded = 0 ;
169
+
170
+ CborError err = MessageEncoder::encode (message, buffer, sizeof (buffer), bytes_encoded);
171
+
172
+ // Test the encoding is
173
+ // DA 00010600 # tag(65792)
174
+ // 80 # array(0)
175
+ THEN (" The encoding is successful" ) {
176
+ REQUIRE (err == CborNoError);
177
+ REQUIRE (bytes_encoded == 4 );
178
+ REQUIRE (buffer[0 ] == 0xDA );
179
+ REQUIRE (buffer[1 ] == 0x00 );
180
+ REQUIRE (buffer[2 ] == 0x01 );
181
+ REQUIRE (buffer[3 ] == 0x06 );
182
+ REQUIRE (buffer[4 ] == 0x80 );
183
+ }
129
184
delete message;
130
185
}
131
186
@@ -183,4 +238,31 @@ SCENARIO("Test the encoding of command messages") {
183
238
delete message;
184
239
}
185
240
241
+ /* ***********************************************************************************/
242
+
243
+ WHEN (" Encode the TimezoneCommandUpId message" )
244
+ {
245
+ Message * message = new Message ();
246
+ message->id = CommandID::TimezoneCommandUpId;
247
+
248
+ uint8_t buffer[256 ];
249
+ int bytes_encoded = 0 ;
250
+
251
+ CborError err = MessageEncoder::encode (message, buffer, sizeof (buffer), bytes_encoded);
252
+
253
+ // Test the encoding is
254
+ // DA 00010800 # tag(67584)
255
+ // 80 # array(0)
256
+ THEN (" The encoding is successful" ) {
257
+ REQUIRE (err == CborNoError);
258
+ REQUIRE (bytes_encoded == 4 );
259
+ REQUIRE (buffer[0 ] == 0xDA );
260
+ REQUIRE (buffer[1 ] == 0x00 );
261
+ REQUIRE (buffer[2 ] == 0x01 );
262
+ REQUIRE (buffer[3 ] == 0x08 );
263
+ REQUIRE (buffer[4 ] == 0x80 );
264
+ }
265
+ delete message;
266
+ }
267
+
186
268
}
0 commit comments