Skip to content

Commit d3338c7

Browse files
committed
Upgrade to Zephyr v3.6 and zcbor v0.8.1
1 parent 0389f4a commit d3338c7

File tree

7 files changed

+38
-29
lines changed

7 files changed

+38
-29
lines changed

src/thingset_bin.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
#include <stdio.h>
1818
#include <string.h>
1919

20+
static void bin_decoder_init(struct thingset_context *ts, const uint8_t *payload,
21+
size_t payload_len)
22+
{
23+
zcbor_new_decode_state(ts->decoder, ZCBOR_ARRAY_SIZE(ts->decoder), payload, payload_len, 1,
24+
NULL, 0);
25+
26+
/* required to accept incoming data which does not use the most compact encoding */
27+
ts->decoder->constant_state->enforce_canonical = false;
28+
}
29+
2030
static int bin_serialize_map_start(struct thingset_context *ts)
2131
{
2232
return zcbor_map_start_encode(ts->encoder, UINT8_MAX) ? 0 : -THINGSET_ERR_RESPONSE_TOO_LARGE;
@@ -113,7 +123,7 @@ static int bin_serialize_simple_value(zcbor_state_t *encoder, union thingset_dat
113123
break;
114124
#if CONFIG_THINGSET_DECFRAC_TYPE_SUPPORT
115125
case THINGSET_TYPE_DECFRAC:
116-
success = zcbor_tag_encode(encoder, ZCBOR_TAG_DECFRAC_ARR);
126+
success = zcbor_tag_put(encoder, ZCBOR_TAG_DECFRAC_ARR);
117127
success = success && zcbor_list_start_encode(encoder, 2);
118128
success = success && zcbor_int32_put(encoder, -detail); /* exponent */
119129
success = success && zcbor_int32_put(encoder, *data.decfrac); /* mantissa */
@@ -124,7 +134,7 @@ static int bin_serialize_simple_value(zcbor_state_t *encoder, union thingset_dat
124134
success = zcbor_bool_put(encoder, *data.b);
125135
break;
126136
case THINGSET_TYPE_STRING:
127-
success = zcbor_tstr_put_term(encoder, data.str);
137+
success = zcbor_tstr_put_term(encoder, data.str, detail);
128138
break;
129139
#if CONFIG_THINGSET_BYTES_TYPE_SUPPORT
130140
case THINGSET_TYPE_BYTES:
@@ -171,17 +181,17 @@ static int bin_serialize_metadata(struct thingset_context *ts,
171181
return err;
172182
}
173183

174-
const char *name = "name";
175-
if (!zcbor_tstr_put_term(ts->encoder, name)) {
184+
const char name[] = "name";
185+
if (!zcbor_tstr_put_lit(ts->encoder, name)) {
176186
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
177187
}
178188

179-
if (!zcbor_tstr_put_term(ts->encoder, object->name)) {
189+
if (!zcbor_tstr_encode_ptr(ts->encoder, object->name, strlen(object->name))) {
180190
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
181191
}
182192

183-
const char *type = "type";
184-
if (!zcbor_tstr_put_term(ts->encoder, type)) {
193+
const char type[] = "type";
194+
if (!zcbor_tstr_put_lit(ts->encoder, type)) {
185195
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
186196
}
187197

@@ -236,7 +246,8 @@ static int bin_serialize_value(struct thingset_context *ts,
236246
success = zcbor_list_start_encode(ts->encoder, UINT8_MAX);
237247
for (unsigned int i = 0; i < ts->num_objects; i++) {
238248
if (ts->data_objects[i].parent_id == object->id) {
239-
zcbor_tstr_put_term(ts->encoder, ts->data_objects[i].name);
249+
zcbor_tstr_encode_ptr(ts->encoder, ts->data_objects[i].name,
250+
strlen(ts->data_objects[i].name));
240251
}
241252
}
242253
success = success && zcbor_list_end_encode(ts->encoder, UINT8_MAX);
@@ -295,7 +306,7 @@ static int bin_serialize_key(struct thingset_context *ts, const struct thingset_
295306
}
296307
}
297308
else {
298-
if (zcbor_tstr_put_term(ts->encoder, object->name) == false) {
309+
if (zcbor_tstr_encode_ptr(ts->encoder, object->name, strlen(object->name)) == false) {
299310
return -THINGSET_ERR_RESPONSE_TOO_LARGE;
300311
}
301312
}
@@ -362,8 +373,7 @@ static int bin_parse_endpoint(struct thingset_context *ts)
362373
ts->msg_payload = ts->decoder->payload;
363374

364375
/* re-initialize decoder for payload parsing */
365-
zcbor_new_decode_state(ts->decoder, ZCBOR_ARRAY_SIZE(ts->decoder), ts->msg_payload,
366-
ts->msg_len - (ts->msg_payload - ts->msg), 1);
376+
bin_decoder_init(ts, ts->msg_payload, ts->msg_len - (ts->msg_payload - ts->msg));
367377

368378
return 0;
369379
}
@@ -471,8 +481,7 @@ static int bin_serialize_report_header(struct thingset_context *ts, const char *
471481

472482
static void bin_deserialize_payload_reset(struct thingset_context *ts)
473483
{
474-
zcbor_new_decode_state(ts->decoder, ZCBOR_ARRAY_SIZE(ts->decoder), ts->msg_payload,
475-
ts->msg_len - (ts->msg_payload - ts->msg), 1);
484+
bin_decoder_init(ts, ts->msg_payload, ts->msg_len - (ts->msg_payload - ts->msg));
476485
}
477486

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

799-
zcbor_new_decode_state(ts->decoder, ZCBOR_ARRAY_SIZE(ts->decoder), ts->msg + 1, ts->msg_len - 1,
800-
1);
808+
bin_decoder_init(ts, ts->msg + 1, ts->msg_len - 1);
801809

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

823833
uint32_t id;
824834
size_t successfully_parsed_bytes = 0;

src/thingset_txt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ static int json_serialize_simple_value(char *buf, size_t size, union thingset_da
142142
break;
143143
}
144144
else {
145-
pos = snprintf(buf, size, "%.*f,", detail, *data.f32);
145+
/* explicit double-conversion required to please compiler */
146+
pos = snprintf(buf, size, "%.*f,", detail, (double)*data.f32);
146147
break;
147148
}
148149
#if CONFIG_THINGSET_DECFRAC_TYPE_SUPPORT

tests/cpp/prj.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ CONFIG_THINGSET_DECFRAC_TYPE_SUPPORT=y
99
CONFIG_THINGSET_BYTES_TYPE_SUPPORT=y
1010

1111
CONFIG_ZTEST=y
12-
CONFIG_ZTEST_NEW_API=y
1312
CONFIG_ZTEST_SUMMARY=n
1413

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

1817
# enable click-able absolute paths in assert messages
19-
#CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
18+
CONFIG_BUILD_OUTPUT_STRIP_PATHS=n

tests/protocol/prj.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ CONFIG_THINGSET_JSON_STRING_ESCAPING=y
1111
CONFIG_THINGSET_METADATA_ENDPOINT=y
1212

1313
CONFIG_ZTEST=y
14-
CONFIG_ZTEST_NEW_API=y
1514
CONFIG_ZTEST_SUMMARY=n
1615

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

2019
# enable click-able absolute paths in assert messages
21-
#CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
20+
CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
2221

2322
CONFIG_COVERAGE=y
2423

tests/report/prj.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ CONFIG_THINGSET_REPORT_RECORD_SERIALIZATION=y
1313
CONFIG_THINGSET_BINARY_MAX_DEPTH=8
1414

1515
CONFIG_ZTEST=y
16-
CONFIG_ZTEST_NEW_API=y
1716
CONFIG_ZTEST_SUMMARY=n
1817

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

2221
# enable click-able absolute paths in assert messages
23-
#CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
22+
CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
2423

2524
CONFIG_COVERAGE=y

tests/serde/prj.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ CONFIG_THINGSET_DECFRAC_TYPE_SUPPORT=y
99
CONFIG_THINGSET_BYTES_TYPE_SUPPORT=y
1010

1111
CONFIG_ZTEST=y
12-
CONFIG_ZTEST_NEW_API=y
1312
CONFIG_ZTEST_SUMMARY=n
1413

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

1817
# enable click-able absolute paths in assert messages
19-
#CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
18+
CONFIG_BUILD_OUTPUT_STRIP_PATHS=n
2019

2120
#CONFIG_ZCBOR_VERBOSE=y

west.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ manifest:
44
remotes:
55
- name: zephyrproject-rtos
66
url-base: https://github.com/zephyrproject-rtos
7+
- name: NordicSemiconductor
8+
url-base: https://github.com/NordicSemiconductor
79

810
projects:
911
- name: zephyr
1012
remote: zephyrproject-rtos
11-
revision: v3.3-branch
13+
revision: v3.6-branch
1214
import:
1315
name-allowlist:
1416
- edtt
15-
- zcbor
17+
# Use Nordic repo to pull in https://github.com/NordicSemiconductor/zcbor/pull/407
1618
- name: zcbor
17-
remote: zephyrproject-rtos
18-
revision: 67fd8bb88d3136738661fa8bb5f9989103f4599e
19+
remote: NordicSemiconductor
20+
revision: 16648fb060d857f164635ca4e8eaa716d906d244
1921
path: modules/lib/zcbor

0 commit comments

Comments
 (0)