Skip to content

Commit ee503e4

Browse files
aentingermattiabertorello
authored andcommitted
Bugfix - All numeric data types are excepted for BaseTime and Time
1 parent 20c1f43 commit ee503e4

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

ArduinoCloudThing.cpp

+32-8
Original file line numberDiff line numberDiff line change
@@ -296,21 +296,33 @@ ArduinoCloudThing::MapParserState ArduinoCloudThing::handle_BaseName(CborValue *
296296
ArduinoCloudThing::MapParserState ArduinoCloudThing::handle_BaseTime(CborValue * value_iter, MapData * map_data) {
297297
MapParserState next_state = MapParserState::Error;
298298

299+
if(cbor_value_is_integer(value_iter)) {
300+
int val = 0;
301+
if(cbor_value_get_int(value_iter, &val) == CborNoError) {
302+
map_data->base_time.set(static_cast<double>(val));
303+
}
304+
}
305+
299306
if(cbor_value_is_double(value_iter)) {
300307
double val = 0.0;
301308
if(cbor_value_get_double(value_iter, &val) == CborNoError) {
302309
map_data->base_time.set(val);
303310
}
304311
}
305312

306-
if(cbor_value_is_integer(value_iter)) {
307-
int val = 0;
308-
if(cbor_value_get_int(value_iter, &val) == CborNoError) {
313+
if(cbor_value_is_float(value_iter)) {
314+
float val = 0.0;
315+
if(cbor_value_get_float(value_iter, &val) == CborNoError) {
309316
map_data->base_time.set(static_cast<double>(val));
310317
}
311318
}
312319

313-
/* TODO: Check for half float / float */
320+
if(cbor_value_is_half_float(value_iter)) {
321+
uint16_t val = 0;
322+
if(cbor_value_get_half_float(value_iter, &val) == CborNoError) {
323+
map_data->base_time.set(static_cast<double>(convertCborHalfFloatToDouble(val)));
324+
}
325+
}
314326

315327
if(cbor_value_advance(value_iter) == CborNoError) {
316328
next_state = MapParserState::MapKey;
@@ -403,21 +415,33 @@ ArduinoCloudThing::MapParserState ArduinoCloudThing::handle_BooleanValue(CborVal
403415
ArduinoCloudThing::MapParserState ArduinoCloudThing::handle_Time(CborValue * value_iter, MapData * map_data) {
404416
MapParserState next_state = MapParserState::Error;
405417

418+
if(cbor_value_is_integer(value_iter)) {
419+
int val = 0;
420+
if(cbor_value_get_int(value_iter, &val) == CborNoError) {
421+
map_data->time.set(static_cast<double>(val));
422+
}
423+
}
424+
406425
if(cbor_value_is_double(value_iter)) {
407426
double val = 0.0;
408427
if(cbor_value_get_double(value_iter, &val) == CborNoError) {
409428
map_data->time.set(val);
410429
}
411430
}
412431

413-
if(cbor_value_is_integer(value_iter)) {
414-
int val = 0;
415-
if(cbor_value_get_int(value_iter, &val) == CborNoError) {
432+
if(cbor_value_is_float(value_iter)) {
433+
float val = 0.0;
434+
if(cbor_value_get_float(value_iter, &val) == CborNoError) {
416435
map_data->time.set(static_cast<double>(val));
417436
}
418437
}
419438

420-
/* TODO: Check for half float / float */
439+
if(cbor_value_is_half_float(value_iter)) {
440+
uint16_t val = 0;
441+
if(cbor_value_get_half_float(value_iter, &val) == CborNoError) {
442+
map_data->time.set(static_cast<double>(convertCborHalfFloatToDouble(val)));
443+
}
444+
}
421445

422446
if(cbor_value_advance(value_iter) == CborNoError) {
423447
next_state = MapParserState::MapKey;

0 commit comments

Comments
 (0)