Skip to content

Commit

Permalink
Upgrade to Zephyr v3.6 and zcbor v0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjaeger committed May 1, 2024
1 parent d2a610d commit b72d7ce
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 29 deletions.
42 changes: 26 additions & 16 deletions src/thingset_bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
#include <stdio.h>
#include <string.h>

static void bin_decoder_init(struct thingset_context *ts, const uint8_t *payload,
size_t payload_len)
{
zcbor_new_decode_state(ts->decoder, ZCBOR_ARRAY_SIZE(ts->decoder), payload, payload_len, 1,
NULL, 0);

/* required to accept incoming data which does not use the most compact encoding */
ts->decoder->constant_state->enforce_canonical = false;
}

static int bin_serialize_map_start(struct thingset_context *ts)
{
return zcbor_map_start_encode(ts->encoder, UINT8_MAX) ? 0 : -THINGSET_ERR_RESPONSE_TOO_LARGE;
Expand Down Expand Up @@ -113,7 +123,7 @@ static int bin_serialize_simple_value(zcbor_state_t *encoder, union thingset_dat
break;
#if CONFIG_THINGSET_DECFRAC_TYPE_SUPPORT
case THINGSET_TYPE_DECFRAC:
success = zcbor_tag_encode(encoder, ZCBOR_TAG_DECFRAC_ARR);
success = zcbor_tag_put(encoder, ZCBOR_TAG_DECFRAC_ARR);
success = success && zcbor_list_start_encode(encoder, 2);
success = success && zcbor_int32_put(encoder, -detail); /* exponent */
success = success && zcbor_int32_put(encoder, *data.decfrac); /* mantissa */
Expand All @@ -124,7 +134,7 @@ static int bin_serialize_simple_value(zcbor_state_t *encoder, union thingset_dat
success = zcbor_bool_put(encoder, *data.b);
break;
case THINGSET_TYPE_STRING:
success = zcbor_tstr_put_term(encoder, data.str);
success = zcbor_tstr_put_term(encoder, data.str, detail);
break;
#if CONFIG_THINGSET_BYTES_TYPE_SUPPORT
case THINGSET_TYPE_BYTES:
Expand Down Expand Up @@ -171,17 +181,17 @@ static int bin_serialize_metadata(struct thingset_context *ts,
return err;
}

const char *name = "name";
if (!zcbor_tstr_put_term(ts->encoder, name)) {
const char name[] = "name";
if (!zcbor_tstr_put_lit(ts->encoder, name)) {
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
}

if (!zcbor_tstr_put_term(ts->encoder, object->name)) {
if (!zcbor_tstr_encode_ptr(ts->encoder, object->name, strlen(object->name))) {
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
}

const char *type = "type";
if (!zcbor_tstr_put_term(ts->encoder, type)) {
const char type[] = "type";
if (!zcbor_tstr_put_lit(ts->encoder, type)) {
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
}

Expand Down Expand Up @@ -236,7 +246,8 @@ static int bin_serialize_value(struct thingset_context *ts,
success = zcbor_list_start_encode(ts->encoder, UINT8_MAX);
for (unsigned int i = 0; i < ts->num_objects; i++) {
if (ts->data_objects[i].parent_id == object->id) {
zcbor_tstr_put_term(ts->encoder, ts->data_objects[i].name);
zcbor_tstr_encode_ptr(ts->encoder, ts->data_objects[i].name,
strlen(ts->data_objects[i].name));
}
}
success = success && zcbor_list_end_encode(ts->encoder, UINT8_MAX);
Expand Down Expand Up @@ -295,7 +306,7 @@ static int bin_serialize_key(struct thingset_context *ts, const struct thingset_
}
}
else {
if (zcbor_tstr_put_term(ts->encoder, object->name) == false) {
if (zcbor_tstr_encode_ptr(ts->encoder, object->name, strlen(object->name)) == false) {
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
}
}
Expand Down Expand Up @@ -362,8 +373,7 @@ static int bin_parse_endpoint(struct thingset_context *ts)
ts->msg_payload = ts->decoder->payload;

/* re-initialize decoder for payload parsing */
zcbor_new_decode_state(ts->decoder, ZCBOR_ARRAY_SIZE(ts->decoder), ts->msg_payload,
ts->msg_len - (ts->msg_payload - ts->msg), 1);
bin_decoder_init(ts, ts->msg_payload, ts->msg_len - (ts->msg_payload - ts->msg));

return 0;
}
Expand Down Expand Up @@ -471,8 +481,7 @@ static int bin_serialize_report_header(struct thingset_context *ts, const char *

static void bin_deserialize_payload_reset(struct thingset_context *ts)
{
zcbor_new_decode_state(ts->decoder, ZCBOR_ARRAY_SIZE(ts->decoder), ts->msg_payload,
ts->msg_len - (ts->msg_payload - ts->msg), 1);
bin_decoder_init(ts, ts->msg_payload, ts->msg_len - (ts->msg_payload - ts->msg));
}

static int bin_deserialize_string(struct thingset_context *ts, const char **str_start,
Expand Down Expand Up @@ -796,8 +805,7 @@ inline void thingset_bin_setup(struct thingset_context *ts, size_t rsp_buf_offse
{
ts->api = &bin_api;

zcbor_new_decode_state(ts->decoder, ZCBOR_ARRAY_SIZE(ts->decoder), ts->msg + 1, ts->msg_len - 1,
1);
bin_decoder_init(ts, ts->msg + 1, ts->msg_len - 1);

zcbor_new_encode_state(ts->encoder, ZCBOR_ARRAY_SIZE(ts->encoder), ts->rsp + rsp_buf_offset,
ts->rsp_size - rsp_buf_offset, 1);
Expand All @@ -818,7 +826,9 @@ int thingset_bin_import_data_progressively(struct thingset_context *ts, uint8_t
* and subsequent cases, where we set the payload pointer back to the start of the buffer)
*/
zcbor_new_decode_state(ts->decoder, ZCBOR_ARRAY_SIZE(ts->decoder), ts->decoder->payload_mut,
size - (ts->decoder->payload - ts->msg), ts->decoder->elem_count);
size - (ts->decoder->payload - ts->msg), ts->decoder->elem_count, NULL,
0);
ts->decoder->constant_state->enforce_canonical = false;

uint32_t id;
size_t successfully_parsed_bytes = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/thingset_txt.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ static int json_serialize_simple_value(char *buf, size_t size, union thingset_da
break;
}
else {
pos = snprintf(buf, size, "%.*f,", detail, *data.f32);
/* explicit double-conversion required to please compiler */
pos = snprintf(buf, size, "%.*f,", detail, (double)*data.f32);
break;
}
#if CONFIG_THINGSET_DECFRAC_TYPE_SUPPORT
Expand Down
3 changes: 1 addition & 2 deletions tests/cpp/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ CONFIG_THINGSET_DECFRAC_TYPE_SUPPORT=y
CONFIG_THINGSET_BYTES_TYPE_SUPPORT=y

CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_ZTEST_SUMMARY=n

# enable colored output (see tc_util_user_override.h)
CONFIG_ZTEST_TC_UTIL_USER_OVERRIDE=y

# enable click-able absolute paths in assert messages
#CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
3 changes: 1 addition & 2 deletions tests/protocol/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ CONFIG_THINGSET_JSON_STRING_ESCAPING=y
CONFIG_THINGSET_METADATA_ENDPOINT=y

CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_ZTEST_SUMMARY=n

# enable colored output (see tc_util_user_override.h)
CONFIG_ZTEST_TC_UTIL_USER_OVERRIDE=y

# enable click-able absolute paths in assert messages
#CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
CONFIG_BUILD_OUTPUT_STRIP_PATHS=n

CONFIG_COVERAGE=y
3 changes: 1 addition & 2 deletions tests/report/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ CONFIG_THINGSET_REPORT_RECORD_SERIALIZATION=y
CONFIG_THINGSET_BINARY_MAX_DEPTH=8

CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_ZTEST_SUMMARY=n

# enable colored output (see tc_util_user_override.h)
CONFIG_ZTEST_TC_UTIL_USER_OVERRIDE=y

# enable click-able absolute paths in assert messages
#CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
CONFIG_BUILD_OUTPUT_STRIP_PATHS=n

CONFIG_COVERAGE=y
3 changes: 1 addition & 2 deletions tests/serde/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ CONFIG_THINGSET_DECFRAC_TYPE_SUPPORT=y
CONFIG_THINGSET_BYTES_TYPE_SUPPORT=y

CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_ZTEST_SUMMARY=n

# enable colored output (see tc_util_user_override.h)
CONFIG_ZTEST_TC_UTIL_USER_OVERRIDE=y

# enable click-able absolute paths in assert messages
#CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
CONFIG_BUILD_OUTPUT_STRIP_PATHS=n

#CONFIG_ZCBOR_VERBOSE=y
10 changes: 6 additions & 4 deletions west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ manifest:
remotes:
- name: zephyrproject-rtos
url-base: https://github.com/zephyrproject-rtos
- name: NordicSemiconductor
url-base: https://github.com/NordicSemiconductor

projects:
- name: zephyr
remote: zephyrproject-rtos
revision: v3.3-branch
revision: v3.6-branch
import:
name-allowlist:
- edtt
- zcbor
# Use Nordic repo to pull in https://github.com/NordicSemiconductor/zcbor/pull/407
- name: zcbor
remote: zephyrproject-rtos
revision: 67fd8bb88d3136738661fa8bb5f9989103f4599e
remote: NordicSemiconductor
revision: 16648fb060d857f164635ca4e8eaa716d906d244
path: modules/lib/zcbor

0 comments on commit b72d7ce

Please sign in to comment.