how to use CBOR decoding with ncs/zephyr

Hallo Nordic

i am working with nrf52832 and 840, with ncs v2.3.0 (working on updating to v2.5.0)

i want to pass a cbor file which holds some data from cloud to edg device, the adg device is the nrf52 that works with ncs.

i want to be able to decode the cbor file by value, not as a whole struct (in order to maintain flexibility in the data fields in the file).

1. is there some example for using zcbor or some other cbor library embedded in ncs ?

2. is it possible to decode a cbor file value by value and not as a whole struct ? (if so how can this be done, or what is the existing API for that ? )

hope to read from you soon 

best regards

Ziv

Parents
  • Hi,

    1. zcbor is part of nRF Connect SDK (thorugh Zephyr) and is used in e.g. the Bluetooth: Central SMP Client sample.

    2. For what is possible with zcbor, please refer to the zcbor documentation.

    Regards,
    Terje

  • hi Tesc

    well i have done this code which works in general, i can parse according to balue and if some value is missing i will that number of decoded vals are less then i expect

    the problem is that i always get and error from zcbor_map_decode_bulk(),

    it fails to close the map if i get it right, i get rc = 1 (false) 

    i think it fails on this line in ncs

    return zcbor_map_end_decode(zsd) ? 0 : -EBADMSG;
    any idea why ? 
    i see it decodes the values right but return an error for not ending the map
    also i don't realy understand the issue with the zcbor_state_t array, why do i need several elements of it, if i put less then 3 i get an error and no decoding happens ???
    hope to read you soon
    best regards
    Ziv
Reply
  • hi Tesc

    well i have done this code which works in general, i can parse according to balue and if some value is missing i will that number of decoded vals are less then i expect

    the problem is that i always get and error from zcbor_map_decode_bulk(),

    it fails to close the map if i get it right, i get rc = 1 (false) 

    i think it fails on this line in ncs

    return zcbor_map_end_decode(zsd) ? 0 : -EBADMSG;
    any idea why ? 
    i see it decodes the values right but return an error for not ending the map
    also i don't realy understand the issue with the zcbor_state_t array, why do i need several elements of it, if i put less then 3 i get an error and no decoding happens ???
    hope to read you soon
    best regards
    Ziv
Children