-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nrf_rpc: Add command to obtain version of remote.
Commit adds command to pbtain the remote ncs commit sha version. Signed-off-by: Przemyslaw Bida <[email protected]>
- Loading branch information
Showing
30 changed files
with
582 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.. _nrf_rpc_dev_info: | ||
|
||
nRF RPC device information | ||
########################## | ||
|
||
.. contents:: | ||
:local: | ||
:depth: 2 | ||
|
||
This library allows you to obtain the device information functions of the :ref:`nrfxlib:nrf_rpc` on a remote server. | ||
|
||
Configuration | ||
************* | ||
|
||
Use the :kconfig:option:`CONFIG_NRF_RPC_DEV_INFO` Kconfig option to enable this library. | ||
To enable it for the client, use the :kconfig:option:`CONFIG_NRF_RPC_DEV_INFO_CLIENT` Kconfig option and respectively, | ||
:kconfig:option:`CONFIG_NRF_RPC_DEV_INFO_SERVER` for the server. | ||
|
||
API documentation | ||
***************** | ||
|
||
| Header file: :file:`include/nrf_rpc/nrf_rpc_dev_info.h` | ||
.. doxygengroup:: nrf_rpc_dev_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#ifndef UTILS_NRF_RPC_UTILS_H_ | ||
#define UTILS_NRF_RPC_UTILS_H_ | ||
|
||
/** | ||
* @defgroup nrf_rpc_dev_info nRF RPC device information. | ||
* @{ | ||
* @brief nRF RPC device information functions. | ||
* | ||
*/ | ||
|
||
/** @brief Get version of remote server the RPC client is connected to. | ||
* | ||
* @retval version of the remote on success. | ||
* @retval NULL on failure. | ||
*/ | ||
const char *nrf_rpc_get_ncs_commit_sha(void); | ||
|
||
/** | ||
* @} | ||
*/ | ||
|
||
#endif /* UTILS_NRF_RPC_UTILS_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
samples/nrf_rpc/protocols_serialization/client/src/dev_info_shell.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <zephyr/shell/shell.h> | ||
#include <nrf_rpc/nrf_rpc_dev_info.h> | ||
|
||
static int remote_version_cmd(const struct shell *sh, size_t argc, char *argv[]) | ||
{ | ||
const char *version = nrf_rpc_get_ncs_commit_sha(); | ||
|
||
shell_print(sh, "Remote version: %s", version); | ||
|
||
return 0; | ||
} | ||
|
||
SHELL_STATIC_SUBCMD_SET_CREATE(util_cmds, | ||
SHELL_CMD_ARG(remote_version, NULL, "Get server version", | ||
remote_version_cmd, 1, 0), | ||
SHELL_SUBCMD_SET_END); | ||
|
||
SHELL_CMD_ARG_REGISTER(rpc, &util_cmds, "nRF RPC utility commands", NULL, 1, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
add_subdirectory(common) | ||
|
||
add_subdirectory_ifdef(CONFIG_NRF_RPC_DEV_INFO_CLIENT client) | ||
add_subdirectory_ifdef(CONFIG_NRF_RPC_DEV_INFO_SERVER server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
menuconfig NRF_RPC_DEV_INFO | ||
bool "nRF RPC device information functionalities" | ||
depends on NRF_RPC | ||
depends on NRF_RPC_CBOR | ||
help | ||
nRF RPC device information functionalities | ||
|
||
if NRF_RPC_DEV_INFO | ||
|
||
choice NRF_RPC_DEV_INFO_ROLE_CHOICE | ||
prompt "nRF RPC device information role selection" | ||
default NRF_RPC_DEV_INFO_CLIENT | ||
help | ||
nRF RPC device information role selection | ||
|
||
config NRF_RPC_DEV_INFO_SERVER | ||
bool "nRF RPC device information server role" | ||
help | ||
Enable nRF RPC device information server role. | ||
|
||
config NRF_RPC_DEV_INFO_CLIENT | ||
bool "nRF RPC device information client role" | ||
help | ||
Enable nRF RPC device information client role. | ||
|
||
endchoice | ||
|
||
config DEV_INFO_RPC_INITIALIZE_NRF_RPC | ||
bool "Automatically initialize nRF RPC library" | ||
help | ||
Initialize nRF RPC library during the system startup. Disabling this | ||
option allow user to initialize it in a different way. | ||
|
||
endif # NRF_RPC_DEV_INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
zephyr_library() | ||
|
||
zephyr_library_sources( | ||
dev_info_client.c | ||
) | ||
|
||
zephyr_library_include_directories( | ||
${CMAKE_CURRENT_SOURCE_DIR}/../common | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include "zephyr/sys/util.h" | ||
#include <nrf_rpc/nrf_rpc_serialize.h> | ||
#include <nrf_rpc_cbor.h> | ||
|
||
#include <ncs_commit.h> | ||
#include <dev_info_rpc_ids.h> | ||
|
||
NRF_RPC_GROUP_DECLARE(dev_info_group); | ||
|
||
static char version[16]; | ||
|
||
const char *nrf_rpc_get_ncs_commit_sha(void) | ||
{ | ||
struct nrf_rpc_cbor_ctx ctx; | ||
size_t size = ARRAY_SIZE(version); | ||
|
||
memset(version, 0, ARRAY_SIZE(version)); | ||
|
||
NRF_RPC_CBOR_ALLOC(&dev_info_group, ctx, 0); | ||
|
||
nrf_rpc_cbor_cmd_rsp_no_err(&dev_info_group, DEV_INFO_RPC_GET_VERSION, &ctx); | ||
|
||
nrf_rpc_decode_str(&ctx, version, size); | ||
|
||
if (!nrf_rpc_decoding_done_and_check(&dev_info_group, &ctx)) { | ||
nrf_rpc_err(-EBADMSG, NRF_RPC_ERR_SRC_RECV, &dev_info_group, | ||
DEV_INFO_RPC_GET_VERSION, NRF_RPC_PACKET_TYPE_RSP); | ||
return NULL; | ||
} | ||
|
||
return version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
zephyr_library() | ||
|
||
zephyr_library_sources( | ||
dev_info_rpc.c | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#if CONFIG_NRF_RPC_IPC_SERVICE | ||
#include <nrf_rpc/nrf_rpc_ipc.h> | ||
#elif CONFIG_NRF_RPC_UART_TRANSPORT | ||
#include <nrf_rpc/nrf_rpc_uart.h> | ||
#elif CONFIG_MOCK_NRF_RPC_TRANSPORT | ||
#include <mock_nrf_rpc_transport.h> | ||
#endif | ||
#include <nrf_rpc_cbor.h> | ||
|
||
#include <zephyr/device.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
#ifdef CONFIG_NRF_RPC_IPC_SERVICE | ||
NRF_RPC_IPC_TRANSPORT(dev_info_rpc_tr, DEVICE_DT_GET(DT_NODELABEL(ipc0)), "dev_info_rpc_ept"); | ||
#elif defined(CONFIG_NRF_RPC_UART_TRANSPORT) | ||
#define dev_info_rpc_tr NRF_RPC_UART_TRANSPORT(DT_CHOSEN(nordic_rpc_uart)) | ||
#elif defined(CONFIG_MOCK_NRF_RPC_TRANSPORT) | ||
#define dev_info_rpc_tr mock_nrf_rpc_tr | ||
#endif | ||
NRF_RPC_GROUP_DEFINE(dev_info_group, "dev_info", &dev_info_rpc_tr, NULL, NULL, NULL); | ||
LOG_MODULE_REGISTER(dev_info_rpc, LOG_LEVEL_DBG); | ||
|
||
#ifdef CONFIG_DEV_INFO_RPC_INITIALIZE_NRF_RPC | ||
static void err_handler(const struct nrf_rpc_err_report *report) | ||
{ | ||
LOG_ERR("nRF RPC error %d ocurred. See nRF RPC logs for more details", report->code); | ||
k_oops(); | ||
} | ||
|
||
static int serialization_init(void) | ||
{ | ||
int err; | ||
|
||
err = nrf_rpc_init(err_handler); | ||
if (err) { | ||
return -EINVAL; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
SYS_INIT(serialization_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY); | ||
#endif /* CONFIG_DEV_INFO_RPC_INITIALIZE_NRF_RPC */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#ifndef DEV_INFO_RPC_IDS_H_ | ||
#define DEV_INFO_RPC_IDS_H_ | ||
|
||
/** @brief Command IDs accepted by the device information over RPC server. | ||
*/ | ||
enum ot_rpc_cmd_server { | ||
DEV_INFO_RPC_GET_VERSION = 0, | ||
}; | ||
|
||
#endif /* DEV_INFO_RPC_IDS_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
zephyr_library() | ||
|
||
zephyr_library_sources( | ||
dev_info_server.c | ||
) | ||
|
||
zephyr_library_include_directories( | ||
${CMAKE_CURRENT_SOURCE_DIR}/../common | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <nrf_rpc/nrf_rpc_serialize.h> | ||
#include <nrf_rpc_cbor.h> | ||
|
||
#include <ncs_commit.h> | ||
#include <dev_info_rpc_ids.h> | ||
|
||
NRF_RPC_GROUP_DECLARE(dev_info_group); | ||
|
||
static void get_server_version(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx, | ||
void *handler_data) | ||
{ | ||
struct nrf_rpc_cbor_ctx rsp_ctx; | ||
size_t cbor_buffer_size = 0; | ||
|
||
if (!nrf_rpc_decoding_done_and_check(group, ctx)) { | ||
nrf_rpc_err(-EBADMSG, NRF_RPC_ERR_SRC_RECV, group, DEV_INFO_RPC_GET_VERSION, | ||
NRF_RPC_PACKET_TYPE_CMD); | ||
return; | ||
} | ||
|
||
cbor_buffer_size += 2 + strlen(NCS_COMMIT_STRING); | ||
|
||
NRF_RPC_CBOR_ALLOC(group, rsp_ctx, cbor_buffer_size); | ||
|
||
nrf_rpc_encode_str(&rsp_ctx, NCS_COMMIT_STRING, strlen(NCS_COMMIT_STRING)); | ||
nrf_rpc_cbor_rsp_no_err(group, &rsp_ctx); | ||
} | ||
|
||
NRF_RPC_CBOR_CMD_DECODER(dev_info_group, get_server_version, DEV_INFO_RPC_GET_VERSION, | ||
get_server_version, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.