diff --git a/samples/sid_dut/src/sid_thread.c b/samples/sid_dut/src/sid_thread.c index 75dfbb9ba0..6f2186510a 100644 --- a/samples/sid_dut/src/sid_thread.c +++ b/samples/sid_dut/src/sid_thread.c @@ -6,6 +6,7 @@ #include "sid_error.h" #include +#include #include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #if defined(CONFIG_SIDEWALK_SUBGHZ) #include @@ -31,6 +31,23 @@ #include #endif +#include +#include +#include + +#undef JSON_RAW_PRINT +#define JSON_MESSAGE_CAPACITY 512 +char JSON_MESSAGE[JSON_MESSAGE_CAPACITY + 1] = { 0 }; +size_t JSON_CHARS_WRITTEN = 0; +#define JSON_PREPARE memset(JSON_MESSAGE, 0, JSON_MESSAGE_CAPACITY) + +#define JSON_SEND \ + LOG_RAW("%s", JSON_MESSAGE); \ + JSON_CHARS_WRITTEN = 0 +#define JSON_RAW_PRINT(format, ...) \ + JSON_RAW_PRINTER_STRING(JSON_MESSAGE, JSON_CHARS_WRITTEN, JSON_MESSAGE_CAPACITY, \ + format __VA_OPT__(, ) __VA_ARGS__) + #if !FIXED_PARTITION_EXISTS(mfg_storage) #error "Flash partition is not defined for the Sidewalk manufacturing storage!!" #endif @@ -94,83 +111,35 @@ static void on_sidewalk_event(bool in_isr, void *context) k_work_submit_to_queue(&sidewalk_dut_work_q, &ctx->sidewalk_event_work); } -#define sid_msg_type_str(val) \ - ((char *[]){ "SID_MSG_TYPE_GET", "SID_MSG_TYPE_SET", "SID_MSG_TYPE_NOTIFY", \ - "SID_MSG_TYPE_RESPONSE" }[(val)]) -#define sid_link_mode_str(val) \ - (val) == SID_LINK_MODE_CLOUD ? "SID_LINK_MODE_CLOUD" : \ - (val) == SID_LINK_MODE_MOBILE ? "SID_LINK_MODE_MOBILE" : \ - "SID_LINK_MODE_INVALID" - -void sid_msg_desc_to_JSON(const struct shell *shell, const char *caller, - const struct sid_msg_desc *msg_desc) -{ - // clang-format off - JSON_DICT(caller, true, { - JSON_VAL_DICT("sid_msg_desc", - { - JSON_VAL("link_type", msg_desc->link_type, JSON_NEXT); - JSON_VAL("type", msg_desc->type, JSON_NEXT); - JSON_VAL_STR("type_str", sid_msg_type_str(msg_desc->type), JSON_NEXT); - JSON_VAL("link_mode", msg_desc->link_mode, JSON_NEXT); - JSON_VAL_STR("link_mode_str", (sid_link_mode_str(msg_desc->link_mode)), JSON_NEXT); - JSON_VAL("id", msg_desc->id, JSON_NEXT); - JSON_VAL_DICT("msg_desc_attr", - { - JSON_VAL_DICT("rx_attr", - { - JSON_VAL_STR("is_msg_ack", msg_desc->msg_desc_attr.rx_attr.is_msg_ack? "true": "false", JSON_NEXT); - JSON_VAL_STR("is_msg_duplicate", msg_desc->msg_desc_attr.rx_attr.is_msg_duplicate? "true": "false", JSON_NEXT); - JSON_VAL_STR("ack_requested", msg_desc->msg_desc_attr.rx_attr.ack_requested? "true": "false", JSON_NEXT); - JSON_VAL("rssi", msg_desc->msg_desc_attr.rx_attr.rssi, JSON_NEXT); - JSON_VAL("snr", msg_desc->msg_desc_attr.rx_attr.snr, JSON_LAST); - } - , JSON_NEXT); - JSON_VAL_DICT("tx_attr", - { - JSON_VAL_STR("request_ack", msg_desc->msg_desc_attr.tx_attr.request_ack? "True": "False", JSON_NEXT); - JSON_VAL("num_retries", msg_desc->msg_desc_attr.tx_attr.num_retries, JSON_NEXT); - JSON_VAL("ttl_in_seconds", msg_desc->msg_desc_attr.tx_attr.ttl_in_seconds, JSON_LAST); - } - , JSON_LAST); - } - , JSON_LAST); - } - , JSON_LAST); - }); - // clang-format on -} - static void on_sidewalk_msg_received(const struct sid_msg_desc *msg_desc, const struct sid_msg *msg, void *context) { - struct app_context *ctx = (struct app_context *)context; - if (ctx->shell) { - sid_msg_desc_to_JSON(ctx->shell, "on_msg_received", msg_desc); - } - + JSON_PREPARE; + JSON_DICT("on_msg_received", true, + { JSON_VAL_sid_msg_desc("sid_msg_desc", msg_desc, true, JSON_LAST); }); + JSON_SEND; LOG_DBG("Sidewalk -> App"); LOG_HEXDUMP_INF(msg->data, msg->size, ""); } static void on_sidewalk_msg_sent(const struct sid_msg_desc *msg_desc, void *context) { - struct app_context *ctx = (struct app_context *)context; - if (ctx->shell) { - sid_msg_desc_to_JSON(ctx->shell, "on_msg_sent", msg_desc); - } - + JSON_PREPARE; + JSON_DICT("on_msg_sent", true, + { JSON_VAL_sid_msg_desc("sid_msg_desc", msg_desc, false, JSON_LAST); }); + JSON_SEND; LOG_DBG("Sidewalk -> App"); } static void on_sidewalk_send_error(sid_error_t error, const struct sid_msg_desc *msg_desc, void *context) { - struct app_context *ctx = (struct app_context *)context; - if (ctx->shell) { - sid_msg_desc_to_JSON(ctx->shell, "on_send_error", msg_desc); - } - + JSON_PREPARE; + JSON_DICT("on_send_error", true, { + JSON_VAL_sid_error_t("error", error, JSON_NEXT); + JSON_VAL_sid_msg_desc("sid_msg_desc", msg_desc, false, JSON_LAST); + }); + JSON_SEND; LOG_DBG("Sidewalk -> App: error %d", error); } diff --git a/samples/template_ble/src/sidewalk_callbacks.c b/samples/template_ble/src/sidewalk_callbacks.c index 24ec690df3..83f85c3ce1 100644 --- a/samples/template_ble/src/sidewalk_callbacks.c +++ b/samples/template_ble/src/sidewalk_callbacks.c @@ -23,6 +23,11 @@ static const uint8_t *status_name[] = { "ready", "not ready", "Error", "secure c static const uint8_t *link_mode_idx_name[] = { "ble", "fsk", "lora" }; +#include +#include +#undef JSON_RAW_PRINT +#define JSON_RAW_PRINT(format, ...) LOG_RAW(format __VA_OPT__(, ) __VA_ARGS__) + static void on_sidewalk_event(bool in_isr, void *context) { LOG_DBG("on event, from %s, context %p", in_isr ? "ISR" : "App", context); @@ -40,6 +45,8 @@ static void on_sidewalk_msg_received(const struct sid_msg_desc *msg_desc, const LOG_DBG("received message(type: %d, link_mode: %d, id: %u size %u)", (int)msg_desc->type, (int)msg_desc->link_mode, msg_desc->id, msg->size); LOG_HEXDUMP_INF((uint8_t *)msg->data, msg->size, "Message data: "); + JSON_DICT("on_msg_received", true, + { JSON_VAL_sid_msg_desc("sid_msg_desc", msg_desc, true, JSON_LAST); }); } static void on_sidewalk_msg_sent(const struct sid_msg_desc *msg_desc, void *context) @@ -49,6 +56,8 @@ static void on_sidewalk_msg_sent(const struct sid_msg_desc *msg_desc, void *cont CLI_register_message_send(); #endif LOG_INF("sent message(type: %d, id: %u)", (int)msg_desc->type, msg_desc->id); + JSON_DICT("on_msg_sent", true, + { JSON_VAL_sid_msg_desc("sid_msg_desc", msg_desc, false, JSON_LAST); }); } static void on_sidewalk_send_error(sid_error_t error, const struct sid_msg_desc *msg_desc, @@ -60,6 +69,11 @@ static void on_sidewalk_send_error(sid_error_t error, const struct sid_msg_desc #endif LOG_ERR("failed to send message(type: %d, id: %u), err:%d", (int)msg_desc->type, msg_desc->id, (int)error); + + JSON_DICT("on_send_error", true, { + JSON_VAL_sid_error_t("error", error, JSON_NEXT); + JSON_VAL_sid_msg_desc("sid_msg_desc", msg_desc, false, JSON_LAST); + }); } static void on_sidewalk_status_changed(const struct sid_status *status, void *context) diff --git a/samples/template_subghz/src/sidewalk_callbacks.c b/samples/template_subghz/src/sidewalk_callbacks.c index 12866d1172..208d3cc90c 100644 --- a/samples/template_subghz/src/sidewalk_callbacks.c +++ b/samples/template_subghz/src/sidewalk_callbacks.c @@ -23,6 +23,11 @@ static const uint8_t *status_name[] = { "ready", "not ready", "Error", "secure c static const uint8_t *link_mode_idx_name[] = { "ble", "fsk", "lora" }; +#include +#include +#undef JSON_RAW_PRINT +#define JSON_RAW_PRINT(format, ...) LOG_RAW(format __VA_OPT__(, ) __VA_ARGS__) + static void on_sidewalk_event(bool in_isr, void *context) { LOG_DBG("on event, from %s, context %p", in_isr ? "ISR" : "App", context); @@ -40,6 +45,8 @@ static void on_sidewalk_msg_received(const struct sid_msg_desc *msg_desc, const LOG_DBG("received message(type: %d, link_mode: %d, id: %u size %u)", (int)msg_desc->type, (int)msg_desc->link_mode, msg_desc->id, msg->size); LOG_HEXDUMP_INF((uint8_t *)msg->data, msg->size, "Message data: "); + JSON_DICT("on_msg_received", true, + { JSON_VAL_sid_msg_desc("sid_msg_desc", msg_desc, true, JSON_LAST); }); } static void on_sidewalk_msg_sent(const struct sid_msg_desc *msg_desc, void *context) @@ -49,6 +56,8 @@ static void on_sidewalk_msg_sent(const struct sid_msg_desc *msg_desc, void *cont CLI_register_message_send(); #endif LOG_INF("sent message(type: %d, id: %u)", (int)msg_desc->type, msg_desc->id); + JSON_DICT("on_msg_sent", true, + { JSON_VAL_sid_msg_desc("sid_msg_desc", msg_desc, false, JSON_LAST); }); } static void on_sidewalk_send_error(sid_error_t error, const struct sid_msg_desc *msg_desc, @@ -60,6 +69,10 @@ static void on_sidewalk_send_error(sid_error_t error, const struct sid_msg_desc #endif LOG_ERR("failed to send message(type: %d, id: %u), err:%d", (int)msg_desc->type, msg_desc->id, (int)error); + JSON_DICT("on_send_error", true, { + JSON_VAL_sid_error_t("error", error, JSON_NEXT); + JSON_VAL_sid_msg_desc("sid_msg_desc", msg_desc, false, JSON_LAST); + }); } static void on_sidewalk_status_changed(const struct sid_status *status, void *context) diff --git a/utils/include/json_printer.h b/utils/include/json_printer.h index 8f2ea10c48..44f8c7205c 100644 --- a/utils/include/json_printer.h +++ b/utils/include/json_printer.h @@ -6,10 +6,48 @@ #include -// Redefine this macro before use to redirect json output -#define JSON_RAW_PRINT(format, ...) \ +/* Redefine this macro before use to redirect json output */ +#define JSON_RAW_PRINT(format, ...) JSON_RAW_PRINTER_SHELL(shell, format __VA_OPT__(, ) __VA_ARGS__) + +/** + * @brief Implementation of JSON_RAW_PRINT that sends the messages to shell + * @arg shell pointer to shell object + */ +#define JSON_RAW_PRINTER_SHELL(shell, format, ...) \ shell_fprintf(shell, SHELL_NORMAL, format __VA_OPT__(, ) __VA_ARGS__) +/** + * @brief Implementation of JSON_RAW_PRINT that sends the messages to log + * + */ +#define JSON_RAW_PRINTER_LOG(format, ...) LOG_RAW(format __VA_OPT__(, ) __VA_ARGS__) + +/** + * @brief Implementation of JSON_RAW_PRINT that sends the messages to memory buffer + * @arg out memory buffer + * @arg chars_written variable that stores the count of written characters + * @arg capacity size of the out buffer + * + */ +#define JSON_RAW_PRINTER_STRING(out, chars_written, capacity, format, ...) \ + { \ + do { \ + int printed_chars = \ + snprintf(out + chars_written, capacity - chars_written, \ + format __VA_OPT__(, ) __VA_ARGS__); \ + if (printed_chars < 0) { \ + LOG_ERR("Failed to add message to JSON string"); \ + } else { \ + chars_written += printed_chars; \ + } \ + } while (0); \ + } + +/** + * @brief handler for printing JSON values, uses JSON_RAW_PRINT to redirect message + * @arg indent if set to true, the JSON will be printed in multiline mode with indentation of 1 tab + * + */ #define JSON_PRINT(indent, format, ...) \ { \ if (JSON_INDENT) { \ @@ -22,17 +60,51 @@ } \ } +/** + * @brief value of comma_or_empty argument in JSON_VAL_* macros that signals that this is the last value in array or dict + * + */ #define JSON_LAST "" +/** + * @brief value of comma_or_empty argument in JSON_VAL_* macros that signals that this is not the last value in array or dict + * + */ #define JSON_NEXT ", " -#define JSON_END "\n" -#define JSON_DICT(name, in_line, content) \ +/** + * @brief Create JSON starting from root dictionary element + * @arg name the key to the dictionary + * @arg in_line print JSON in single line or multiline (true = single line /false = multi line) + * + * example output: + ``` + JSON_DICT("test", true, JSON_VAL_INT("v1", 3, JSON_LAST)) + ``` + * {"test": {"v1": 3}} + */ +#define JSON_DICT(name, in_line, ...) \ { \ int indent = 0; \ bool JSON_INDENT = (in_line == false); \ - JSON_VAL_DICT(name, content, JSON_END); \ + JSON_PRINT(indent, "{"); \ + JSON_VAL_DICT(name, JSON_LAST, { __VA_ARGS__ }); \ + JSON_PRINT(indent, "}\n"); \ } +/** + * @brief Add N string elements to dictionary from arrays with key and values + * @arg key_array array with names of the string values + * @arg val_array array with values, must have the same size as key_array + * @arg array_size number of elements in key_array/val_array + * + * example output: + ``` + char* key_arr[2] = {"var1", "var2"}; + char* val_arr[2] = {"value1", "value2"}; + JSON_DICT("example", false, JSON_VAL_STR_ENUMERATE(key_arr, val_arr, 2, JSON_LAST)) + ``` + * {"example": {"var1": "value1", "var2": "value2"}} + */ #define JSON_VAL_STR_ENUMERATE(key_array, val_array, array_size, comma_or_empty) \ { \ for (int i = 0; i < array_size - 1; i++) { \ @@ -42,20 +114,91 @@ comma_or_empty); \ } -#define JSON_VAL(key, val, comma_or_empty) \ +/** + * @brief Add INT value to the dict or array + * + * example output: + ``` + JSON_DICT("test", true, JSON_VAL_INT("v1", 3, JSON_LAST)) + ``` + * {"test": {"v1": 3}} + */ +#define JSON_VAL_INT(key, val, comma_or_empty) \ { \ - JSON_PRINT(indent, "\"%s\": %d" comma_or_empty, (char *)key, val); \ + JSON_PRINT(indent, "\"%s\": %ld" comma_or_empty, (char *)key, (long int)val); \ } + +/** + * @brief Add FLOAT value to the dict or array + * + * example output: + ``` + JSON_DICT("test", true, JSON_VAL_FLOAT("v1", 3.14, JSON_LAST)) + ``` + * {"test": {"v1": 3.14}} + */ +#define JSON_VAL_FLOAT(key, val, comma_or_empty) \ + { \ + JSON_PRINT(indent, "\"%s\": %f" comma_or_empty, (char *)key, val); \ + } + +/** + * @brief Add DOUBLE value to the dict or array + * + * example output: + ``` + JSON_DICT("test", true, JSON_VAL_DOUBLE("v1", 3.14, JSON_LAST)) + ``` + * {"test": {"v1": 3.14}} + */ +#define JSON_VAL_DOUBLE(key, val, comma_or_empty) \ + { \ + JSON_PRINT(indent, "\"%s\": %lf" comma_or_empty, (char *)key, val); \ + } + +/** + * @brief Add BOOL value to the dict or array + * + * example output: + ``` + JSON_DICT("test", true, JSON_VAL_BOOL("v1", 23, JSON_LAST)) + ``` + * {"test": {"v1": true}} + */ +#define JSON_VAL_BOOL(key, val, comma_or_empty) \ + { \ + JSON_PRINT(indent, "\"%s\": %s" comma_or_empty, (char *)key, \ + val ? "true" : "false"); \ + } + +/** + * @brief Add STR value to the dict or array + * + * example output: + ``` + JSON_DICT("test", true, JSON_VAL_STR("v1", "message", JSON_LAST)) + ``` + * {"test": {"v1": "message"}} + */ #define JSON_VAL_STR(key, str, comma_or_empty) \ { \ JSON_PRINT(indent, "\"%s\": \"%s\"" comma_or_empty, (char *)key, (char *)str); \ } -#define JSON_VAL_DICT(key, content, comma_or_empty) \ +/** + * @brief Add DICT object to the dict or array + * + * example output: + ``` + JSON_DICT("test", true, JSON_VAL_DICT("obj", JSON_LAST, JSON_VAL_STR("v1", "message", JSON_LAST))) + ``` + * {"test": {"obj":{"v1": "message"}}} + */ +#define JSON_VAL_DICT(key, comma_or_empty, ...) \ { \ JSON_PRINT(indent, "\"%s\": {", (char *)key); \ indent++; \ - { content }; \ + { __VA_ARGS__ }; \ indent--; \ JSON_PRINT(indent, "}" comma_or_empty); \ } diff --git a/utils/include/sidTypes2Json.h b/utils/include/sidTypes2Json.h new file mode 100644 index 0000000000..649bbaf3d6 --- /dev/null +++ b/utils/include/sidTypes2Json.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ +#include + +#define JSON_VAL_sid_msg_desc(name, msg_desc, msg_desc_attr_rx, comma_or_empty) \ + JSON_VAL_DICT(name, comma_or_empty, { \ + JSON_VAL_INT("link_type", msg_desc->link_type, JSON_NEXT); \ + JSON_VAL_INT("type", msg_desc->type, JSON_NEXT); \ + JSON_VAL_STR("type_str", SID_MSG_TYPE_STR(msg_desc->type), JSON_NEXT); \ + JSON_VAL_INT("link_mode", msg_desc->link_mode, JSON_NEXT); \ + JSON_VAL_STR("link_mode_str", (SID_LINK_MODE_STR(msg_desc->link_mode)), \ + JSON_NEXT); \ + JSON_VAL_INT("id", msg_desc->id, JSON_NEXT); \ + JSON_VAL_DICT("msg_desc_attr", JSON_LAST, { \ + if (msg_desc_attr_rx) { \ + JSON_VAL_DICT("rx_attr", JSON_LAST, { \ + JSON_VAL_BOOL("is_msg_ack", \ + msg_desc->msg_desc_attr.rx_attr.is_msg_ack, \ + JSON_NEXT); \ + JSON_VAL_BOOL( \ + "is_msg_duplicate", \ + msg_desc->msg_desc_attr.rx_attr.is_msg_duplicate, \ + JSON_NEXT); \ + JSON_VAL_BOOL( \ + "ack_requested", \ + msg_desc->msg_desc_attr.rx_attr.ack_requested, \ + JSON_NEXT); \ + JSON_VAL_INT("rssi", msg_desc->msg_desc_attr.rx_attr.rssi, \ + JSON_NEXT); \ + JSON_VAL_INT("snr", msg_desc->msg_desc_attr.rx_attr.snr, \ + JSON_LAST); \ + }); \ + } else { \ + JSON_VAL_DICT("tx_attr", JSON_LAST, { \ + JSON_VAL_BOOL("request_ack", \ + msg_desc->msg_desc_attr.tx_attr.request_ack, \ + JSON_NEXT); \ + JSON_VAL_INT("num_retries", \ + msg_desc->msg_desc_attr.tx_attr.num_retries, \ + JSON_NEXT); \ + JSON_VAL_INT( \ + "ttl_in_seconds", \ + msg_desc->msg_desc_attr.tx_attr.ttl_in_seconds, \ + JSON_LAST); \ + }); \ + } \ + }); \ + }) + +#define JSON_VAL_sid_error_t(name, error, comma_or_empty) \ + JSON_VAL_DICT(name, comma_or_empty, { \ + JSON_VAL_INT("value", error, JSON_NEXT); \ + JSON_VAL_STR("str", SID_ERROR_T_STR(error), JSON_LAST); \ + }); diff --git a/utils/include/sidTypes2str.h b/utils/include/sidTypes2str.h new file mode 100644 index 0000000000..92ee2a019f --- /dev/null +++ b/utils/include/sidTypes2str.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#define SID_ERROR_T_STR(err) \ + (((-(err)) > -(SID_ERROR_INVALID_STATE)) || ((-(err)) < 0)) ? \ + "UNKNOWN" : \ + ((char *[]){ \ + "SID_ERROR_NONE", \ + "SID_ERROR_GENERIC", \ + "SID_ERROR_TIMEOUT", \ + "SID_ERROR_OUT_OF_RESOURCES", \ + "SID_ERROR_OOM", \ + "SID_ERROR_OUT_OF_HANDLES", \ + "SID_ERROR_NOSUPPORT", \ + "SID_ERROR_NO_PERMISSION", \ + "SID_ERROR_NOT_FOUND", \ + "SID_ERROR_NULL_POINTER", \ + "SID_ERROR_PARAM_OUT_OF_RANGE", \ + "SID_ERROR_INVALID_ARGS", \ + "SID_ERROR_INCOMPATIBLE_PARAMS", \ + "SID_ERROR_IO_ERROR", \ + "SID_ERROR_TRY_AGAIN", \ + "SID_ERROR_BUSY", \ + "SID_ERROR_DEAD_LOCK", \ + "SID_ERROR_DATA_TYPE_OVERFLOW", \ + "SID_ERROR_BUFFER_OVERFLOW", \ + "SID_ERROR_IN_PROGRESS", \ + "SID_ERROR_CANCELED", \ + "SID_ERROR_OWNER_DEAD", \ + "SID_ERROR_UNRECOVERABLE", \ + "SID_ERROR_PORT_INVALID", \ + "SID_ERROR_PORT_NOT_OPEN", \ + "SID_ERROR_UNINITIALIZED", \ + "SID_ERROR_ALREADY_INITIALIZED", \ + "SID_ERROR_ALREADY_EXISTS", \ + "SID_ERROR_BELOW_THRESHOLD", \ + "SID_ERROR_STOPPED", \ + "SID_ERROR_STORAGE_READ_FAIL", \ + "SID_ERROR_STORAGE_WRITE_FAIL", \ + "SID_ERROR_STORAGE_ERASE_FAIL", \ + "SID_ERROR_STORAGE_FULL", \ + "SID_ERROR_AUTHENTICATION_FAIL", \ + "SID_ERROR_ENCRYPTION_FAIL", \ + "SID_ERROR_DECRYPTION_FAIL", \ + "SID_ERROR_ID_OBFUSCATION_FAIL", \ + "SID_ERROR_NO_ROUTE_AVAILABLE", \ + "SID_ERROR_INVALID_RESPONSE", \ + "SID_ERROR_INVALID_STATE", \ + }[(-(err))]) + +#define SID_MSG_TYPE_STR(val) \ + ((char *[]){ "SID_MSG_TYPE_GET", "SID_MSG_TYPE_SET", "SID_MSG_TYPE_NOTIFY", \ + "SID_MSG_TYPE_RESPONSE" }[(val)]) + +#define SID_LINK_MODE_STR(val) \ + (val) == SID_LINK_MODE_CLOUD ? "SID_LINK_MODE_CLOUD" : \ + (val) == SID_LINK_MODE_MOBILE ? "SID_LINK_MODE_MOBILE" : \ + (val) == SID_LINK_MODE_INVALID ? "SID_LINK_MODE_INVALID" : \ + "UNKNOWN" diff --git a/utils/src/shell.c b/utils/src/shell.c index caec8dc8d9..5ab30f8bcb 100644 --- a/utils/src/shell.c +++ b/utils/src/shell.c @@ -355,34 +355,28 @@ static int cmd_report(const struct shell *shell, size_t argc, char **argv) JSON_DICT("SIDEWALK_CLI", in_line, { JSON_VAL_STR("state", state, JSON_NEXT); - JSON_VAL("registered", - (CLI_status->detail.registration_status == SID_STATUS_REGISTERED), - JSON_NEXT); - JSON_VAL("time_synced", - (CLI_status->detail.time_sync_status == SID_STATUS_TIME_SYNCED), - JSON_NEXT); - JSON_VAL("link_up", (CLI_status->detail.link_status_mask), JSON_NEXT); - JSON_VAL_DICT( - "link_modes", - { - JSON_VAL( - "ble", - CLI_status->detail.supported_link_modes[SID_LINK_TYPE_1_IDX], - JSON_NEXT); - JSON_VAL( - "fsk", - CLI_status->detail.supported_link_modes[SID_LINK_TYPE_2_IDX], - JSON_NEXT); - JSON_VAL( - "lora", - CLI_status->detail.supported_link_modes[SID_LINK_TYPE_3_IDX], - JSON_LAST); - }, - JSON_NEXT); - JSON_VAL("tx_successfull", sidewalk_messages.tx_successfull, JSON_NEXT); - JSON_VAL("tx_failed", sidewalk_messages.tx_failed, JSON_NEXT); - JSON_VAL("rx_successfull", sidewalk_messages.rx_successfull, JSON_NEXT); - JSON_VAL("response_id", sidewalk_messages.resp_id, JSON_LAST); + JSON_VAL_INT("registered", + (CLI_status->detail.registration_status == SID_STATUS_REGISTERED), + JSON_NEXT); + JSON_VAL_INT("time_synced", + (CLI_status->detail.time_sync_status == SID_STATUS_TIME_SYNCED), + JSON_NEXT); + JSON_VAL_INT("link_up", (CLI_status->detail.link_status_mask), JSON_NEXT); + JSON_VAL_DICT("link_modes", JSON_NEXT, { + JSON_VAL_INT("ble", + CLI_status->detail.supported_link_modes[SID_LINK_TYPE_1_IDX], + JSON_NEXT); + JSON_VAL_INT("fsk", + CLI_status->detail.supported_link_modes[SID_LINK_TYPE_2_IDX], + JSON_NEXT); + JSON_VAL_INT("lora", + CLI_status->detail.supported_link_modes[SID_LINK_TYPE_3_IDX], + JSON_LAST); + }); + JSON_VAL_INT("tx_successfull", sidewalk_messages.tx_successfull, JSON_NEXT); + JSON_VAL_INT("tx_failed", sidewalk_messages.tx_failed, JSON_NEXT); + JSON_VAL_INT("rx_successfull", sidewalk_messages.rx_successfull, JSON_NEXT); + JSON_VAL_INT("response_id", sidewalk_messages.resp_id, JSON_LAST); }); return CMD_RETURN_OK; } @@ -394,14 +388,11 @@ void cmd_print_version(const struct shell *shell, size_t argc, char **argv) JSON_DICT("COMPONENTS_VERSION", in_line, { JSON_VAL_STR("sidewalk_fork_point", sidewalk_version_common_commit, JSON_NEXT); JSON_VAL_STR("build_time", build_time_stamp, JSON_NEXT); - JSON_VAL_DICT( - "modules", - { - JSON_VAL_STR_ENUMERATE(sidewalk_version_component_name, - sidewalk_version_component, - sidewalk_version_component_count, JSON_LAST); - }, - JSON_LAST); + JSON_VAL_DICT("modules", JSON_LAST, { + JSON_VAL_STR_ENUMERATE(sidewalk_version_component_name, + sidewalk_version_component, + sidewalk_version_component_count, JSON_LAST); + }); }); }