Skip to content

Commit

Permalink
nrf_rpc: Add command to obtain version of remote.
Browse files Browse the repository at this point in the history
Commit adds command to pbtain the remote ncs commit sha version.

Signed-off-by: Przemyslaw Bida <[email protected]>
  • Loading branch information
Przemyslaw Bida authored and rlubos committed Dec 4, 2024
1 parent b7a0d83 commit 93c10ee
Show file tree
Hide file tree
Showing 30 changed files with 582 additions and 2 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@
/tests/subsys/nfc/rpc/ @nrfconnect/ncs-protocols-serialization
/tests/subsys/nrf_compress/ @nordicjm
/tests/subsys/nrf_profiler/ @nrfconnect/ncs-si-bluebagel
/tests/subsys/nrf_rpc/ @nrfconnect/ncs-protocols-serialization
/tests/subsys/partition_manager/region/ @nordicjm @tejlmand
/tests/subsys/partition_manager/static_pm_file/ @nordicjm @tejlmand
/tests/subsys/pcd/ @nrfconnect/ncs-pluto
Expand Down
24 changes: 24 additions & 0 deletions doc/nrf/libraries/nrf_rpc/nrf_rpc_dev_info.rst
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
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ Libraries for NFC
nRF RPC libraries
-----------------

|no_changes_yet_note|
* Added the :ref:`nrf_rpc_dev_info` library for obtaining information about a device connected through the :ref:`nrfxlib:nrf_rpc`.

Other libraries
---------------
Expand Down
28 changes: 28 additions & 0 deletions include/nrf_rpc/nrf_rpc_dev_info.h
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_ */
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_RPC src/ot_shell.c)
zephyr_library_sources_ifdef(CONFIG_MPSL_CX_SOFTWARE src/coex_shell.c)
zephyr_library_sources_ifdef(CONFIG_LOG_FORWARDER_RPC src/log_rpc_shell.c)
zephyr_library_sources_ifdef(CONFIG_NFC_RPC src/nfc_shell.c)
zephyr_library_sources_ifdef(CONFIG_NRF_RPC_DEV_INFO src/dev_info_shell.c)
# NORDIC SDK APP START
2 changes: 2 additions & 0 deletions samples/nrf_rpc/protocols_serialization/client/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ CONFIG_LOG_BUFFER_SIZE=4096
CONFIG_LOG_FUNC_NAME_PREFIX_DBG=n
CONFIG_LOG_BACKEND_RTT=n
CONFIG_SHELL_LOG_BACKEND=y

CONFIG_NRF_RPC_DEV_INFO=y
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);
3 changes: 3 additions & 0 deletions samples/nrf_rpc/protocols_serialization/server/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ CONFIG_NRF_RPC_UART_RELIABLE=y

CONFIG_UART_LINE_CTRL=y
CONFIG_UART_INTERRUPT_DRIVEN=y

CONFIG_NRF_RPC_DEV_INFO=y
CONFIG_NRF_RPC_DEV_INFO_SERVER=y
2 changes: 2 additions & 0 deletions subsys/nrf_rpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ zephyr_library_sources_ifdef(CONFIG_NRF_RPC_SERIALIZE_API nrf_rpc_serialize.c)
zephyr_library_sources_ifdef(CONFIG_NRF_RPC_CALLBACK_PROXY nrf_rpc_cbkproxy.c)

zephyr_library_sources_ifdef(CONFIG_NRF_RPC_UART_TRANSPORT nrf_rpc_uart.c)

add_subdirectory_ifdef(CONFIG_NRF_RPC_DEV_INFO dev_info)
2 changes: 2 additions & 0 deletions subsys/nrf_rpc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

endif # NRF_RPC_CBOR

rsource "dev_info/Kconfig"

endif # NRF_RPC

endmenu
10 changes: 10 additions & 0 deletions subsys/nrf_rpc/dev_info/CMakeLists.txt
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)
40 changes: 40 additions & 0 deletions subsys/nrf_rpc/dev_info/Kconfig
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
15 changes: 15 additions & 0 deletions subsys/nrf_rpc/dev_info/client/CMakeLists.txt
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
)
38 changes: 38 additions & 0 deletions subsys/nrf_rpc/dev_info/client/dev_info_client.c
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;
}
11 changes: 11 additions & 0 deletions subsys/nrf_rpc/dev_info/common/CMakeLists.txt
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
)
49 changes: 49 additions & 0 deletions subsys/nrf_rpc/dev_info/common/dev_info_rpc.c
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 */
16 changes: 16 additions & 0 deletions subsys/nrf_rpc/dev_info/common/dev_info_rpc_ids.h
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_ */
15 changes: 15 additions & 0 deletions subsys/nrf_rpc/dev_info/server/CMakeLists.txt
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
)
36 changes: 36 additions & 0 deletions subsys/nrf_rpc/dev_info/server/dev_info_server.c
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);
2 changes: 1 addition & 1 deletion subsys/nrf_rpc/include/nrf_rpc_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <nrf_rpc_errno.h>

/**
* @defgroup nrf_rpc_os_zephyr nRF PRC OS abstraction for Zephyr.
* @defgroup nrf_rpc_os_zephyr nRF RPC OS abstraction for Zephyr.
* @{
* @brief nRF PRC OS abstraction for Zephyr.
*
Expand Down
Loading

0 comments on commit 93c10ee

Please sign in to comment.