@@ -35,8 +35,10 @@ SCENARIO("Test the encoding of command messages") {
35
35
Encoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
36
36
37
37
uint8_t expected_result[] = {
38
- 0xda , 0x00 , 0x01 , 0x00 , 0x00 , 0x81 , 0x58 , 0x20 , 0x01 , 0x02 , 0x03 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 ,
39
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
38
+ 0xda , 0x00 , 0x01 , 0x00 , 0x00 , 0x81 , 0x58 , 0x20 ,
39
+ 0x01 , 0x02 , 0x03 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 ,
40
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
41
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
40
42
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
41
43
};
42
44
@@ -70,7 +72,8 @@ SCENARIO("Test the encoding of command messages") {
70
72
Encoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
71
73
72
74
uint8_t expected_result[] = {
73
- 0xda , 0x00 , 0x01 , 0x03 , 0x00 , 0x81 , 0x68 , 0x74 , 0x68 , 0x69 , 0x6e , 0x67 , 0x5f , 0x69 , 0x64
75
+ 0xda , 0x00 , 0x01 , 0x03 , 0x00 , 0x81 , 0x68 , 0x74 ,
76
+ 0x68 , 0x69 , 0x6e , 0x67 , 0x5f , 0x69 , 0x64
74
77
};
75
78
76
79
// Test the encoding is
@@ -130,7 +133,8 @@ SCENARIO("Test the encoding of command messages") {
130
133
Encoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
131
134
132
135
uint8_t expected_result[] = {
133
- 0xda , 0x00 , 0x01 , 0x07 , 0x00 , 0x81 , 0x65 , 0x32 , 0x2e , 0x30 , 0x2e , 0x30
136
+ 0xda , 0x00 , 0x01 , 0x07 , 0x00 , 0x81 , 0x65 , 0x32 ,
137
+ 0x2e , 0x30 , 0x2e , 0x30
134
138
};
135
139
136
140
// Test the encoding is
@@ -167,8 +171,10 @@ SCENARIO("Test the encoding of command messages") {
167
171
Encoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
168
172
169
173
uint8_t expected_result[] = {
170
- 0xda , 0x00 , 0x01 , 0x02 , 0x00 , 0x84 , 0x50 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
171
- 0x08 , 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f , 0xe1 , 0x20 , 0x18 , 0x64
174
+ 0xda , 0x00 , 0x01 , 0x02 , 0x00 , 0x84 , 0x50 , 0x00 ,
175
+ 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 ,
176
+ 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f , 0xe1 ,
177
+ 0x20 , 0x18 , 0x64
172
178
};
173
179
174
180
// Test the encoding is
@@ -212,4 +218,105 @@ SCENARIO("Test the encoding of command messages") {
212
218
REQUIRE (memcmp (buffer, expected_result, sizeof (expected_result)) == 0 );
213
219
}
214
220
}
221
+
222
+ /* ***************************************************************************/
223
+
224
+ WHEN (" Encode the ThingUpdateCmdId message" )
225
+ {
226
+ ThingUpdateCmd command;
227
+ command.c .id = CommandId::ThingUpdateCmdId;
228
+
229
+ String thing_id = " e4494d55-872a-4fd2-9646-92f87949394c" ;
230
+ strcpy (command.params .thing_id , thing_id.c_str ());
231
+
232
+ uint8_t buffer[512 ];
233
+ size_t bytes_encoded = sizeof (buffer);
234
+
235
+ CBORMessageEncoder encoder;
236
+ Encoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
237
+
238
+ THEN (" The encoding is unsuccessful - ThingUpdateCmdId is not supported" ) {
239
+ REQUIRE (err == Encoder::Status::Error);
240
+ }
241
+ }
242
+
243
+ /* ***************************************************************************/
244
+
245
+ WHEN (" Encode the SetTimezoneCommand message" )
246
+ {
247
+ TimezoneCommandDown command;
248
+ command.c .id = CommandId::TimezoneCommandDownId;
249
+
250
+ command.params .offset = 1708963873 ;
251
+ command.params .until = 2024579473 ;
252
+
253
+ uint8_t buffer[512 ];
254
+ size_t bytes_encoded = sizeof (buffer);
255
+
256
+ CBORMessageEncoder encoder;
257
+ Encoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
258
+
259
+ THEN (" The encoding is unsuccessful - SetTimezoneCommand is not supported" ) {
260
+ REQUIRE (err == Encoder::Status::Error);
261
+ }
262
+ }
263
+
264
+ /* ***************************************************************************/
265
+
266
+ WHEN (" Encode the LastValuesUpdateCmd message" )
267
+ {
268
+ LastValuesUpdateCmd command;
269
+ command.c .id = CommandId::LastValuesUpdateCmdId;
270
+
271
+ command.params .length = 13 ;
272
+ uint8_t last_values[13 ] = {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
273
+ 0x08 , 0x09 , 0x10 , 0x11 , 0x12 };
274
+ command.params .last_values = last_values;
275
+
276
+ uint8_t buffer[512 ];
277
+ size_t bytes_encoded = sizeof (buffer);
278
+
279
+ CBORMessageEncoder encoder;
280
+ Encoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
281
+
282
+ THEN (" The encoding is unsuccessful - LastValuesUpdateCmd is not supported" ) {
283
+ REQUIRE (err == Encoder::Status::Error);
284
+ }
285
+ }
286
+
287
+ /* ***************************************************************************/
288
+
289
+ WHEN (" Encode the OtaUpdateCmdDown message" )
290
+ {
291
+ OtaUpdateCmdDown command;
292
+ command.c .id = CommandId::OtaUpdateCmdDownId;
293
+
294
+ uint8_t buffer[512 ];
295
+ size_t bytes_encoded = sizeof (buffer);
296
+
297
+ CBORMessageEncoder encoder;
298
+ Encoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
299
+
300
+ THEN (" The encoding is unsuccessful - OtaUpdateCmdDown is not supported" ) {
301
+ REQUIRE (err == Encoder::Status::Error);
302
+ }
303
+ }
304
+
305
+ /* ***************************************************************************/
306
+
307
+ WHEN (" Encode a message with unknown command Id" )
308
+ {
309
+ OtaUpdateCmdDown command;
310
+ command.c .id = CommandId::UnknownCmdId;
311
+
312
+ uint8_t buffer[512 ];
313
+ size_t bytes_encoded = sizeof (buffer);
314
+
315
+ CBORMessageEncoder encoder;
316
+ Encoder::Status err = encoder.encode ((Message*)&command, buffer, bytes_encoded);
317
+
318
+ THEN (" The encoding is unsuccessful - OtaUpdateCmdDown is not supported" ) {
319
+ REQUIRE (err == Encoder::Status::Error);
320
+ }
321
+ }
215
322
}
0 commit comments