From 60eaafe29325c8757cc67ec34adebe6f61d70cc7 Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Thu, 24 Mar 2022 14:56:03 +0200 Subject: [PATCH] net: lwm2m: SenML CBOR gencode adaption Generated code needs some modifications for it to work correctly. Adds license information. Signed-off-by: Veijo Pesonen --- .../net/lib/lwm2m/lwm2m_senml_cbor_decode.c | 17 +++++++----- .../net/lib/lwm2m/lwm2m_senml_cbor_decode.h | 11 ++++---- .../net/lib/lwm2m/lwm2m_senml_cbor_encode.c | 27 ++++++++++++------- .../net/lib/lwm2m/lwm2m_senml_cbor_encode.h | 11 ++++---- subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h | 17 +++++++----- 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c index 5eed8a473d..2ce6c77577 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Generated using zcbor version 0.3.99 * https://github.com/zephyrproject-rtos/zcbor @@ -10,10 +15,7 @@ #include #include "zcbor_decode.h" #include "lwm2m_senml_cbor_decode.h" - -#if DEFAULT_MAX_QTY != 99 -#error "The type file was generated with a different default_max_qty than this file" -#endif +#include "lwm2m_senml_cbor_types.h" static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result) { @@ -155,7 +157,8 @@ static bool decode_record(zcbor_state_t *state, struct record *result) zcbor_present_decode(&((*result)._record_union_present), (zcbor_decoder_t *)decode_repeated_record_union, state, (&(*result)._record_union)) && - zcbor_multi_decode(0, 3, &(*result)._record__key_value_pair_count, + zcbor_multi_decode(0, ARRAY_SIZE(result->_record__key_value_pair), + &(*result)._record__key_value_pair_count, (zcbor_decoder_t *)decode_repeated_record__key_value_pair, state, (&(*result)._record__key_value_pair), sizeof(struct record__key_value_pair))) || @@ -174,7 +177,8 @@ static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result) bool tmp_result = (( (zcbor_list_start_decode(state) && - ((zcbor_multi_decode(1, 99, &(*result)._lwm2m_senml__record_count, + ((zcbor_multi_decode(1, ARRAY_SIZE(result->_lwm2m_senml__record), + &(*result)._lwm2m_senml__record_count, (zcbor_decoder_t *)decode_record, state, (&(*result)._lwm2m_senml__record), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && @@ -201,6 +205,7 @@ uint_fast8_t cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len, if (!ret) { uint_fast8_t ret = zcbor_pop_error(states); + return (ret == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : ret; } return ZCBOR_SUCCESS; diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h index b4d575b728..3a152feb16 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Generated using zcbor version 0.3.99 * https://github.com/zephyrproject-rtos/zcbor @@ -12,11 +17,7 @@ #include #include #include "zcbor_decode.h" -#include "lwm2m_senml_cbor_decode_types.h" - -#if DEFAULT_MAX_QTY != 99 -#error "The type file was generated with a different default_max_qty than this file" -#endif +#include "lwm2m_senml_cbor_types.h" uint_fast8_t cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len, struct lwm2m_senml *result, size_t *payload_len_out); diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c index 974715ed1e..63accd8140 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Generated using zcbor version 0.3.99 * https://github.com/zephyrproject-rtos/zcbor @@ -10,10 +15,7 @@ #include #include "zcbor_encode.h" #include "lwm2m_senml_cbor_encode.h" - -#if DEFAULT_MAX_QTY != 99 -#error "The type file was generated with a different default_max_qty than this file" -#endif +#include "lwm2m_senml_cbor_types.h" static bool encode_repeated_record_bn(zcbor_state_t *state, const struct record_bn *input) { @@ -139,7 +141,9 @@ static bool encode_record(zcbor_state_t *state, const struct record *input) { zcbor_print("%s\r\n", __func__); - bool tmp_result = (((zcbor_map_start_encode(state, 6) && + int max_keys = ARRAY_SIZE(input->_record__key_value_pair); + + bool tmp_result = (((zcbor_map_start_encode(state, max_keys) && ((zcbor_present_encode(&((*input)._record_bn_present), (zcbor_encoder_t *)encode_repeated_record_bn, state, (&(*input)._record_bn)) && @@ -150,12 +154,13 @@ static bool encode_record(zcbor_state_t *state, const struct record *input) (zcbor_encoder_t *)encode_repeated_record_union, state, (&(*input)._record_union)) && zcbor_multi_encode_minmax( - 0, 3, &(*input)._record__key_value_pair_count, + 0, max_keys, + &(*input)._record__key_value_pair_count, (zcbor_encoder_t *)encode_repeated_record__key_value_pair, state, (&(*input)._record__key_value_pair), sizeof(struct record__key_value_pair))) || (zcbor_list_map_end_force_encode(state), false)) && - zcbor_map_end_encode(state, 6)))); + zcbor_map_end_encode(state, max_keys)))); if (!tmp_result) zcbor_trace(); @@ -166,15 +171,16 @@ static bool encode_record(zcbor_state_t *state, const struct record *input) static bool encode_lwm2m_senml(zcbor_state_t *state, const struct lwm2m_senml *input) { zcbor_print("%s\r\n", __func__); + size_t max_records = ARRAY_SIZE(input->_lwm2m_senml__record); bool tmp_result = - (((zcbor_list_start_encode(state, 99) && - ((zcbor_multi_encode_minmax(1, 99, &(*input)._lwm2m_senml__record_count, + (((zcbor_list_start_encode(state, max_records) && + ((zcbor_multi_encode_minmax(1, max_records, &(*input)._lwm2m_senml__record_count, (zcbor_encoder_t *)encode_record, state, (&(*input)._lwm2m_senml__record), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && - zcbor_list_end_encode(state, 99)))); + zcbor_list_end_encode(state, max_records)))); if (!tmp_result) zcbor_trace(); @@ -197,6 +203,7 @@ uint_fast8_t cbor_encode_lwm2m_senml(uint8_t *payload, size_t payload_len, if (!ret) { uint_fast8_t ret = zcbor_pop_error(states); + return (ret == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : ret; } return ZCBOR_SUCCESS; diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h index 485180f95f..959b74608b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h @@ -1,3 +1,8 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Generated using zcbor version 0.3.99 * https://github.com/zephyrproject-rtos/zcbor @@ -12,11 +17,7 @@ #include #include #include "zcbor_encode.h" -#include "lwm2m_senml_cbor_encode_types.h" - -#if DEFAULT_MAX_QTY != 99 -#error "The type file was generated with a different default_max_qty than this file" -#endif +#include "lwm2m_senml_cbor_types.h" uint_fast8_t cbor_encode_lwm2m_senml(uint8_t *payload, size_t payload_len, const struct lwm2m_senml *input, size_t *payload_len_out); diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h index c3cb70356d..f7b7153ab3 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h @@ -1,17 +1,22 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Generated using zcbor version 0.3.99 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -#ifndef LWM2M_SENML_CBOR_DECODE_TYPES_H__ -#define LWM2M_SENML_CBOR_DECODE_TYPES_H__ +#ifndef LWM2M_SENML_CBOR_TYPES_H__ +#define LWM2M_SENML_CBOR_TYPES_H__ #include #include #include #include -#include "zcbor_decode.h" +#include "zcbor_common.h" /** Which value for --default-max-qty this file was created with. * @@ -20,7 +25,7 @@ * * See `zcbor --help` for more information about --default-max-qty */ -#define DEFAULT_MAX_QTY 99 +#define DEFAULT_MAX_QTY CONFIG_LWM2M_RW_SENML_CBOR_RECORDS struct record_bn { struct zcbor_string _record_bn; @@ -97,8 +102,8 @@ struct record { }; struct lwm2m_senml { - struct record _lwm2m_senml__record[99]; + struct record _lwm2m_senml__record[DEFAULT_MAX_QTY]; uint_fast32_t _lwm2m_senml__record_count; }; -#endif /* LWM2M_SENML_CBOR_DECODE_TYPES_H__ */ +#endif /* LWM2M_SENML_CBOR_TYPES_H__ */