Skip to content

Commit bc0275b

Browse files
committed
Fixed test and ota logic
1 parent a15ae08 commit bc0275b

File tree

2 files changed

+16
-42
lines changed

2 files changed

+16
-42
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -300,40 +300,22 @@ void ArduinoIoTCloudTCP::printDebugInfo()
300300
}
301301

302302
void ArduinoIoTCloudTCP::decode(){
303-
GenericCommand * message = new GenericCommand();
304-
305-
uint8_t const payload[] = {0xDA, 0x00, 0x01, 0x03, 0x00, 0x81, 0x78, 0x24, 0x65, 0x34, 0x34, 0x39, 0x34, 0x64, 0x35, 0x35, 0x2D, 0x38, 0x37, 0x32, 0x61, 0x2D, 0x34, 0x66, 0x64, 0x32, 0x2D, 0x39, 0x36, 0x34, 0x36, 0x2D, 0x39, 0x32, 0x66, 0x38, 0x37, 0x39, 0x34, 0x39, 0x33, 0x39, 0x34, 0x63};
303+
GenericCommand * msg = new GenericCommand();
306304

305+
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};
306+
307307
int payload_length = sizeof(payload) / sizeof(uint8_t);
308-
MessageDecoder::DecoderState err1 = MessageDecoder::decode((Message*) message, payload, payload_length);
308+
MessageDecoder::DecoderState err1 = MessageDecoder::decode((Message*) msg, payload, payload_length);
309309

310-
DEBUG_INFO(">Message THING id is %d", message->command);
310+
DEBUG_INFO(">Message OTA id is %d", msg->command);
311311

312-
ThingGetIdCmdDown * thingCommand = (ThingGetIdCmdDown*) message;
313-
// DEBUG_INFO("Thing id is %s", thingCommand->fields.params.thing_id);
312+
OtaUpdateCmdDown * otaCommand = (OtaUpdateCmdDown*) msg;
313+
DEBUG_INFO(">URL is %s", otaCommand->fields.params.url);
314+
DEBUG_INFO(">ID is %s", otaCommand->fields.params.id);
314315
DEBUG_INFO(">Command status %d", static_cast<int>(err1));
315-
DEBUG_INFO(">Command status %d", static_cast<int>(MessageDecoder::DecoderState::Success));
316-
DEBUG_INFO(">Command status %d", static_cast<int>(MessageDecoder::DecoderState::MessageNotSupported));
317-
318-
delete message;
319316

320-
/*
321-
uint8_t const payloadLV[] = {0xDA, 0x00, 0x01, 0x06, 0x00, 0x81, 0x4D, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12};
322-
payload_length = sizeof(payloadLV) / sizeof(uint8_t);
323-
MessageDecoder::DecoderState err = MessageDecoder::decode((Message*) message, payloadLV, payload_length);
324-
325-
DEBUG_INFO("Message LV id is %d", message->command);
326-
DEBUG_INFO("Command status %d", static_cast<int>(err));
327-
DEBUG_INFO("Command status %d", static_cast<int>(MessageDecoder::DecoderState::Success));
328-
ThingGetLastValueCmdDown * lv = (ThingGetLastValueCmdDown*) message;
329-
DEBUG_INFO("LV payload (size: %d)", lv->fields.params.length);
330-
for (int i = 0; i < lv->fields.params.length; i++) {
331-
DEBUG_INFO("%02X", lv->fields.params.last_values[i]);
332-
}
317+
delete msg;
333318

334-
delete lv->fields.params.last_values;
335-
delete lv;
336-
*/
337319
}
338320

339321
void ArduinoIoTCloudTCP::encode(){

src/cbor/MessageDecoder.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ MessageDecoder::ArrayParserState MessageDecoder::decodeThingGetIdCmdDown(CborVal
130130
ThingGetIdCmdDown * thingCommand = (ThingGetIdCmdDown *) message;
131131

132132
// Message is composed of a single parameter, a string (thing_id)
133-
if (copyCBORStringToArray(param, thingCommand->fields.params.thing_id, sizeof(thingCommand->fields.params.thing_id))) {
134-
return ArrayParserState::LeaveArray;
135-
} else {
133+
if (!copyCBORStringToArray(param, thingCommand->fields.params.thing_id, sizeof(thingCommand->fields.params.thing_id))) {
136134
return ArrayParserState::Error;
137135
}
136+
137+
return ArrayParserState::LeaveArray;
138138
}
139139

140140
MessageDecoder::ArrayParserState MessageDecoder::decodeTimezoneCommandDown(CborValue * param, Message * message) {
@@ -182,39 +182,31 @@ MessageDecoder::ArrayParserState MessageDecoder::decodeOtaUpdateCmdDown(CborValu
182182
OtaUpdateCmdDown * ota = (OtaUpdateCmdDown *) message;
183183

184184
// Message is composed 4 parameters: id, url, initialSha, finalSha
185-
if (copyCBORStringToArray(param, ota->fields.params.id, sizeof(ota->fields.params.id))) {
186-
return ArrayParserState::LeaveArray;
187-
} else {
185+
if (!copyCBORStringToArray(param, ota->fields.params.id, sizeof(ota->fields.params.id))) {
188186
return ArrayParserState::Error;
189187
}
190188

191189
if (cbor_value_advance(param) != CborNoError) {
192190
return ArrayParserState::Error;
193191
}
194192

195-
if (copyCBORStringToArray(param, ota->fields.params.url, sizeof(ota->fields.params.url))) {
196-
return ArrayParserState::LeaveArray;
197-
} else {
193+
if (!copyCBORStringToArray(param, ota->fields.params.url, sizeof(ota->fields.params.url))) {
198194
return ArrayParserState::Error;
199195
}
200196

201197
if (cbor_value_advance(param) != CborNoError) {
202198
return ArrayParserState::Error;
203199
}
204200

205-
if (copyCBORByteToArray(param, ota->fields.params.initialSha256, sizeof(ota->fields.params.initialSha256))) {
206-
return ArrayParserState::LeaveArray;
207-
} else {
201+
if (!copyCBORByteToArray(param, ota->fields.params.initialSha256, sizeof(ota->fields.params.initialSha256))) {
208202
return ArrayParserState::Error;
209203
}
210204

211205
if (cbor_value_advance(param) != CborNoError) {
212206
return ArrayParserState::Error;
213207
}
214208

215-
if (copyCBORByteToArray(param, ota->fields.params.finalSha256, sizeof(ota->fields.params.finalSha256))) {
216-
return ArrayParserState::LeaveArray;
217-
} else {
209+
if (!copyCBORByteToArray(param, ota->fields.params.finalSha256, sizeof(ota->fields.params.finalSha256))) {
218210
return ArrayParserState::Error;
219211
}
220212

0 commit comments

Comments
 (0)