Skip to content

Commit 908afcb

Browse files
committed
Fixed leave array
1 parent bc0275b commit 908afcb

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

extras/test/src/test_command_decode.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,19 @@ SCENARIO("Test the decoding of command messages") {
111111
THEN("The decode is successful") {
112112
REQUIRE(err == MessageDecoder::DecoderState::Success);
113113
REQUIRE(msg->fields.params.length == 13);
114-
REQUIRE(msg->fields.params.last_values[0] == (uint8_t)0);
115-
REQUIRE(msg->fields.params.last_values[1] == (uint8_t)1);
116-
REQUIRE(msg->fields.params.last_values[2] == (uint8_t)2);
117-
REQUIRE(msg->fields.params.last_values[3] == (uint8_t)3);
118-
REQUIRE(msg->fields.params.last_values[4] == (uint8_t)4);
119-
REQUIRE(msg->fields.params.last_values[5] == (uint8_t)5);
120-
REQUIRE(msg->fields.params.last_values[6] == (uint8_t)6);
121-
REQUIRE(msg->fields.params.last_values[7] == (uint8_t)7);
122-
REQUIRE(msg->fields.params.last_values[8] == (uint8_t)8);
123-
REQUIRE(msg->fields.params.last_values[9] == (uint8_t)9);
114+
REQUIRE(msg->fields.params.last_values[0] == (uint8_t)0x00);
115+
REQUIRE(msg->fields.params.last_values[1] == (uint8_t)0x01);
116+
REQUIRE(msg->fields.params.last_values[2] == (uint8_t)0x02);
117+
REQUIRE(msg->fields.params.last_values[3] == (uint8_t)0x03);
118+
REQUIRE(msg->fields.params.last_values[4] == (uint8_t)0x04);
119+
REQUIRE(msg->fields.params.last_values[5] == (uint8_t)0x05);
120+
REQUIRE(msg->fields.params.last_values[6] == (uint8_t)0x06);
121+
REQUIRE(msg->fields.params.last_values[7] == (uint8_t)0x07);
122+
REQUIRE(msg->fields.params.last_values[8] == (uint8_t)0x08);
123+
REQUIRE(msg->fields.params.last_values[9] == (uint8_t)0x09);
124+
REQUIRE(msg->fields.params.last_values[10] == (uint8_t)0x10);
125+
REQUIRE(msg->fields.params.last_values[11] == (uint8_t)0x11);
126+
REQUIRE(msg->fields.params.last_values[12] == (uint8_t)0x12);
124127
REQUIRE(genericMessage->id == (uint32_t)67072);
125128
}
126129

@@ -136,16 +139,15 @@ SCENARIO("Test the decoding of command messages") {
136139
Message * genericMessage = (Message*) msg;
137140

138141
/*
139-
140-
DA 00010100 # tag(65792)
141-
84 # array(4)
142-
6C # text(12)
143-
6F74612D69642D3132333435 # "ota-id-12345"
144-
78 2F # text(47)
145-
2F73746F726167652F6F74612F37363132333837363734363132383736313233383736313233383736313233313233 # "/storage/ota/7612387674612876123876123876123123"
146-
53 # bytes(19)
142+
DA 00010100 # tag(65792)
143+
84 # array(4)
144+
6C # text(12)
145+
6F74612D69642D3132333435 # "ota-id-12345"
146+
75 # text(21)
147+
383736313233383736313233383736313233313233 # "876123876123876123123"
148+
53 # bytes(19)
147149
33303034616162323735313164623332313264 # "3004aab27511db3212d"
148-
50 # bytes(16)
150+
50 # bytes(16)
149151
6A6B6173646B6A686173646B6A687868 # "jkasdkjhasdkjhxh"
150152
151153
*/

src/ArduinoIoTCloudTCP.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,21 @@ void ArduinoIoTCloudTCP::printDebugInfo()
302302
void ArduinoIoTCloudTCP::decode(){
303303
GenericCommand * msg = new GenericCommand();
304304

305+
uint8_t const payloadl[] = {0xDA, 0x00, 0x01, 0x06, 0x00, 0x81, 0x4D, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12};
306+
307+
int payload_length = sizeof(payloadl) / sizeof(uint8_t);
308+
MessageDecoder::decode((Message*) msg, payloadl, payload_length);
309+
310+
ThingGetLastValueCmdDown * lastValueCommand = (ThingGetLastValueCmdDown*) msg;
311+
312+
DEBUG_INFO(">LV is %s", lastValueCommand->fields.params.last_values[10]);
313+
314+
delete msg;
315+
msg = new GenericCommand();
316+
305317
uint8_t const payload[] = {0xDA, 0x00, 0x01, 0x01, 0x00, 0x84, 0x6C, 0x6F, 0x74, 0x61, 0x2D, 0x69, 0x64, 0x2D, 0x31, 0x32, 0x33, 0x34, 0x35, 0x75, 0x38, 0x37, 0x36, 0x31, 0x32, 0x33, 0x38, 0x37, 0x36, 0x31, 0x32, 0x33, 0x38, 0x37, 0x36, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x53, 0x33, 0x30, 0x30, 0x34, 0x61, 0x61, 0x62, 0x32, 0x37, 0x35, 0x31, 0x31, 0x64, 0x62, 0x33, 0x32, 0x31, 0x32, 0x64, 0x50, 0x6A, 0x6B, 0x61, 0x73, 0x64, 0x6B, 0x6A, 0x68, 0x61, 0x73, 0x64, 0x6B, 0x6A, 0x68, 0x78, 0x68};
306318

307-
int payload_length = sizeof(payload) / sizeof(uint8_t);
319+
payload_length = sizeof(payload) / sizeof(uint8_t);
308320
MessageDecoder::DecoderState err1 = MessageDecoder::decode((Message*) msg, payload, payload_length);
309321

310322
DEBUG_INFO(">Message OTA id is %d", msg->command);
@@ -315,7 +327,6 @@ void ArduinoIoTCloudTCP::decode(){
315327
DEBUG_INFO(">Command status %d", static_cast<int>(err1));
316328

317329
delete msg;
318-
319330
}
320331

321332
void ArduinoIoTCloudTCP::encode(){

src/cbor/MessageDecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class MessageDecoder
6666

6767
static ArrayParserState handle_EnterArray(CborValue * main_iter, CborValue * array_iter);
6868
static ArrayParserState handle_Param(CborValue * param, Message * message);
69-
static ArrayParserState handle_LeaveArray();
69+
static ArrayParserState handle_LeaveArray(CborValue * main_iter, CborValue * array_iter);
7070

7171
static bool ifNumericConvertToDouble(CborValue * value_iter, double * numeric_val);
7272
static double convertCborHalfFloatToDouble(uint16_t const half_val);

0 commit comments

Comments
 (0)