Skip to content

Commit

Permalink
samples: lwm2m_client: Add shell commands for testing
Browse files Browse the repository at this point in the history
Add shell commands for testing functionality that
would trigger on a button press.

uart:~$ app
app - LwM2M client application commands
Subcommands:
  gnss  : Trigger GNSS search
  gfix  : Trigger Ground Fix location request

Signed-off-by: Seppo Takalo <[email protected]>
  • Loading branch information
SeppoTakalo authored and rlubos committed Jan 16, 2024
1 parent 2aaabac commit ad5c79f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions samples/cellular/lwm2m_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ zephyr_compile_definitions(PROJECT_NAME=${PROJECT_NAME})

# NORDIC SDK APP START
target_sources(app PRIVATE src/main.c)
target_sources_ifdef(CONFIG_SHELL app PRIVATE src/shell.c)
zephyr_include_directories(src)
# NORDIC SDK APP END

Expand Down
50 changes: 50 additions & 0 deletions samples/cellular/lwm2m_client/src/shell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/shell/shell.h>
#include <net/lwm2m_client_utils_location.h>
#include "location_events.h"
#include "gnss_module.h"

#define HELP_CMD "LwM2M client application commands"
#define HELP_GNSS "Trigger GNSS search"
#define HELP_GFIX "Trigger Ground Fix location request"

static int cmd_gnss(const struct shell *sh, size_t argc, char **argv)
{
#if defined(CONFIG_LWM2M_CLIENT_UTILS_LOCATION_ASSIST_AGNSS) || \
defined(CONFIG_LWM2M_CLIENT_UTILS_LOCATION_ASSIST_PGPS)
shell_print(sh, "Starting GNSS\n");
start_gnss();
return 0;
#else
shell_print(sh, "A-GNSS not enabled\n");
return -ENOEXEC;
#endif
}

static int cmd_gfix(const struct shell *sh, size_t argc, char **argv)
{
#if defined(CONFIG_LWM2M_CLIENT_UTILS_GROUND_FIX_OBJ_SUPPORT)
shell_print(sh, "Send cell location request event\n");
struct ground_fix_location_request_event *ground_fix_event =
new_ground_fix_location_request_event();

APP_EVENT_SUBMIT(ground_fix_event);
return 0;
#else
shell_print(sh, "Ground Fix not enabled\n");
return -ENOEXEC;
#endif
}

SHELL_STATIC_SUBCMD_SET_CREATE(sub_app,
SHELL_COND_CMD_ARG(CONFIG_LWM2M_CLIENT_UTILS_LOCATION_ASSISTANCE,
gnss, NULL, HELP_GNSS, cmd_gnss, 1, 0),
SHELL_COND_CMD_ARG(CONFIG_LWM2M_CLIENT_UTILS_GROUND_FIX_OBJ_SUPPORT,
gfix, NULL, HELP_GFIX, cmd_gfix, 1, 0),
SHELL_SUBCMD_SET_END);
SHELL_CMD_ARG_REGISTER(app, &sub_app, HELP_CMD, NULL, 1, 0);

0 comments on commit ad5c79f

Please sign in to comment.