Skip to content

Commit 1167257

Browse files
kacperradoszewskinordic-hani
authored andcommitted
NCSDK-31749: trim down the sample shell
Removed some shell commands from the sample application, including ping and data send functionality (as they were somewhat unreliable and arbitrary), AT shell (this already exists in the NCS and is now enabled in the project configuration) and PSM and EDRX setting (these can be done directly via AT commands). Signed-off-by: Kacper Radoszewski <kacper.radoszewski@nordicsemi.no>
1 parent 3ff6d3c commit 1167257

File tree

4 files changed

+17
-266
lines changed

4 files changed

+17
-266
lines changed

doc/links.txt

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145

146146
.. ### Source: github.com
147147

148+
.. _`sdk-nrf`: https://github.com/nrfconnect/sdk-nrf
148149
.. _`sdk-nrfxlib`: https://github.com/nrfconnect/sdk-nrfxlib
149150
.. _`nRF Cloud JSON protocol schemas`: https://github.com/nRFCloud/application-protocols
150151
.. _`nRF Cloud Utils`: https://github.com/nRFCloud/utils

doc/sample.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ After programming the sample and all prerequisites to the development kit, test
9090

9191
<inf> sb_fota: Next update check in 14 days, 09:20:10
9292

93-
#. Use ``sb_fota_clock_set()`` to set the modem time to trick the update to happen (Or simply wait ~14 days).
93+
#. Use ``sb_fota_clock_set()`` to set the modem time to trick the update to happen (or simply wait ~14 days).
9494

9595
For example, if ``AT+CCLK`` returns ``25/03/04,01:30:40+04``, then use the ``app clock`` shell command to set the clock::
9696

@@ -126,6 +126,10 @@ This sample uses the following `sdk-nrfxlib`_ library:
126126

127127
* `Modem library <nrfxlib_nrf_modem_>`_
128128

129+
It uses the following `sdk-nrf`_ library:
130+
131+
* `AT shell`
132+
129133
It uses the following |addon|.
130134

131135
* SoftBank FOTA library

sample/prj.conf

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ CONFIG_MPU_ALLOW_FLASH_WRITE=y
4949
# HTTP Client
5050
CONFIG_HTTP_CLIENT=y
5151

52+
# AT Shell
53+
CONFIG_AT_SHELL=y
54+
5255
# JSON Parser
5356
CONFIG_JSON_LIBRARY=y
5457

sample/src/shell.c

+8-265
Original file line numberDiff line numberDiff line change
@@ -5,97 +5,14 @@
55
*/
66

77
#include <zephyr/shell/shell.h>
8-
#include <nrf_modem_at.h>
9-
#include <zephyr/net/socket.h>
10-
#include <modem/lte_lc.h>
11-
#include <modem/modem_info.h>
128
#include <sb_fota.h>
139

14-
#define DEFAULT_DATA_SEND_INTERVAL 10
15-
16-
static int fd = -1;
17-
static struct addrinfo *addrinfo_res;
18-
static const char dummy_data[] = "01234567890123456789012345678901"
19-
"01234567890123456789012345678901"
20-
"01234567890123456789012345678901"
21-
"01234567890123456789012345678901"
22-
"01234567890123456789012345678901"
23-
"01234567890123456789012345678901"
24-
"01234567890123456789012345678901"
25-
"01234567890123456789012345678901";
26-
static char response_buf[4096];
27-
28-
int ping(const char *local, const char *remote, int count);
29-
30-
static void udp_socket_open(void)
31-
{
32-
int err;
33-
struct addrinfo hints = {
34-
.ai_family = AF_INET,
35-
.ai_socktype = SOCK_DGRAM,
36-
};
37-
38-
/* Use dummy destination address and port */
39-
err = getaddrinfo("192.168.123.45", NULL, &hints, &addrinfo_res);
40-
if (err) {
41-
printk("getaddrinfo() failed, err %d\n", errno);
42-
}
43-
44-
((struct sockaddr_in *)addrinfo_res->ai_addr)->sin_port = htons(61234);
45-
46-
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
47-
}
48-
49-
void data_send_work_handler(struct k_work *work)
50-
{
51-
sendto(fd, dummy_data, sizeof(dummy_data) - 1, 0, addrinfo_res->ai_addr,
52-
sizeof(struct sockaddr_in));
53-
}
54-
55-
K_WORK_DEFINE(data_send_work, data_send_work_handler);
56-
57-
void data_send_timer_handler(struct k_timer *dummy)
58-
{
59-
k_work_submit(&data_send_work);
60-
}
61-
62-
K_TIMER_DEFINE(data_send_timer, data_send_timer_handler, NULL);
63-
64-
#define FOTA_APP_BUILD_VERSION "1.1"
65-
static int app_cmd_ver(const struct shell *shell, size_t argc, char **argv)
66-
{
67-
ARG_UNUSED(argc);
68-
ARG_UNUSED(argv);
69-
70-
int ret = modem_info_init();
71-
72-
if (ret) {
73-
shell_error(shell, "modem_info_init() failed, %d", ret);
74-
return ret;
75-
}
76-
77-
response_buf[0] = '\0';
78-
ret = modem_info_string_get(MODEM_INFO_FW_VERSION, response_buf, sizeof(response_buf));
79-
if (ret < 0) {
80-
shell_error(shell, "modem_info_string_get() failed, %d", ret);
81-
return ret;
82-
}
83-
shell_print(shell, "App FW version:\t\t%s", FOTA_APP_BUILD_VERSION);
84-
shell_print(shell, "Modem FW version:\t%s", response_buf);
85-
#if CONFIG_LTE_NETWORK_MODE_NBIOT
86-
shell_print(shell, "System mode:\t\tCat.NB");
87-
#else
88-
shell_print(shell, "System mode:\t\tCat.M");
89-
#endif
90-
91-
return 0;
92-
}
93-
9410
static int app_cmd_clock(const struct shell *shell, size_t argc, char **argv)
9511
{
9612
ARG_UNUSED(argc);
9713

9814
int err;
15+
9916
err = sb_fota_clock_set(argv[1]);
10017
if (err) {
10118
shell_error(shell, "clock: invalid time string");
@@ -105,188 +22,14 @@ static int app_cmd_clock(const struct shell *shell, size_t argc, char **argv)
10522
return 0;
10623
}
10724

108-
static int app_cmd_at(const struct shell *shell, size_t argc, char **argv)
109-
{
110-
ARG_UNUSED(argc);
111-
112-
int err;
113-
err = nrf_modem_at_cmd(response_buf, sizeof(response_buf), "%s", argv[1]);
114-
if (err) {
115-
shell_error(shell, "ERROR");
116-
return -EINVAL;
117-
}
118-
119-
shell_print(shell, "%sOK", response_buf);
120-
121-
return 0;
122-
}
123-
124-
static int app_cmd_ping(const struct shell *shell, size_t argc, char **argv)
125-
{
126-
int err;
127-
char ipv4[16];
128-
char *tmp1, *tmp2;
129-
int count = 1;
130-
131-
err = nrf_modem_at_cmd(response_buf, sizeof(response_buf), "AT+CGPADDR");
132-
if (err) {
133-
shell_error(shell, "AT ERROR");
134-
return -EINVAL;
135-
}
136-
137-
/* parse +CGPADDR: 0,"10.145.192.136" */
138-
tmp1 = strstr(response_buf, "\"");
139-
if (tmp1 == NULL) {
140-
shell_error(shell, "AT ERROR");
141-
return -EINVAL;
142-
}
143-
tmp1++;
144-
tmp2 = strstr(tmp1, "\"");
145-
if (tmp2 == NULL) {
146-
shell_error(shell, "AT ERROR");
147-
return -EINVAL;
148-
}
149-
150-
memset(ipv4, 0x00, 16);
151-
strncpy(ipv4, (const char *)tmp1, (size_t)(tmp2 - tmp1));
152-
if (argc > 2) {
153-
count = strtoul(argv[2], NULL, 10);
154-
}
155-
ping(ipv4, argv[1], count);
156-
157-
return 0;
158-
}
159-
160-
static int app_cmd_data_start(const struct shell *shell, size_t argc, char **argv)
161-
{
162-
int period = 0;
163-
164-
if (fd < 0) {
165-
udp_socket_open();
166-
}
167-
168-
if (fd >= 0) {
169-
if (argc > 1) {
170-
period = atoi(argv[1]);
171-
}
172-
if (period < 1) {
173-
period = DEFAULT_DATA_SEND_INTERVAL;
174-
}
175-
shell_print(shell, "start: sending periodic data every %d seconds", period);
176-
k_timer_start(&data_send_timer, K_NO_WAIT, K_SECONDS(period));
177-
} else {
178-
shell_error(shell, "start: socket not open");
179-
return -EINVAL;
180-
}
181-
182-
return 0;
183-
}
184-
185-
static int app_cmd_data_stop(const struct shell *shell, size_t argc, char **argv)
186-
{
187-
ARG_UNUSED(argc);
188-
ARG_UNUSED(argv);
189-
190-
if (k_timer_remaining_get(&data_send_timer) > 0) {
191-
k_timer_stop(&data_send_timer);
192-
shell_print(shell, "stop: periodic data stopped");
193-
} else {
194-
shell_error(shell, "stop: periodic data not started");
195-
return -ENOEXEC;
196-
}
197-
198-
return 0;
199-
}
200-
201-
static int app_cmd_edrx_enable(const struct shell *shell, size_t argc, char **argv)
202-
{
203-
ARG_UNUSED(argc);
204-
ARG_UNUSED(argv);
205-
206-
int ret = lte_lc_edrx_req(true);
207-
if (ret) {
208-
shell_print(shell, "Failed to enable eDRX");
209-
}
210-
211-
return ret;
212-
}
213-
214-
static int app_cmd_edrx_disable(const struct shell *shell, size_t argc, char **argv)
215-
{
216-
ARG_UNUSED(argc);
217-
ARG_UNUSED(argv);
218-
219-
int ret = lte_lc_edrx_req(false);
220-
if (ret) {
221-
shell_print(shell, "Failed to disable eDRX");
222-
}
223-
224-
return ret;
225-
}
226-
227-
static int app_cmd_psm_enable(const struct shell *shell, size_t argc, char **argv)
228-
{
229-
ARG_UNUSED(argc);
230-
ARG_UNUSED(argv);
231-
232-
int ret = lte_lc_psm_req(true);
233-
if (ret) {
234-
shell_print(shell, "Failed to enable PSM");
235-
}
236-
237-
return ret;
238-
}
239-
240-
static int app_cmd_psm_disable(const struct shell *shell, size_t argc, char **argv)
241-
{
242-
ARG_UNUSED(argc);
243-
ARG_UNUSED(argv);
244-
245-
int ret = lte_lc_psm_req(false);
246-
if (ret) {
247-
shell_print(shell, "Failed to disable PSM");
248-
}
249-
250-
return ret;
251-
}
252-
253-
SHELL_STATIC_SUBCMD_SET_CREATE(app_data_cmds,
254-
SHELL_CMD(start, NULL,
255-
"'app data start [interval in seconds]' starts "
256-
"periodic UDP data sending. The default "
257-
"interval is 10 seconds.",
258-
app_cmd_data_start),
259-
SHELL_CMD(stop, NULL, "Stop periodic UDP data sending.",
260-
app_cmd_data_stop),
261-
SHELL_SUBCMD_SET_END);
262-
263-
SHELL_STATIC_SUBCMD_SET_CREATE(app_edrx_cmds,
264-
SHELL_CMD(enable, NULL, "'app edrx enable' enable eDRX",
265-
app_cmd_edrx_enable),
266-
SHELL_CMD(disable, NULL, "'app edrx disable' disable eDRX",
267-
app_cmd_edrx_disable),
268-
SHELL_SUBCMD_SET_END);
269-
270-
SHELL_STATIC_SUBCMD_SET_CREATE(
271-
app_psm_cmds, SHELL_CMD(enable, NULL, "'app psm enable' enable PSM", app_cmd_psm_enable),
272-
SHELL_CMD(disable, NULL, "'app psm disable' disable PSM", app_cmd_psm_disable),
273-
SHELL_SUBCMD_SET_END);
274-
27525
SHELL_STATIC_SUBCMD_SET_CREATE(
276-
app_cmds, SHELL_CMD_ARG(ver, NULL, "Firmware version.", app_cmd_ver, 1, 0),
26+
app_cmds,
27727
SHELL_CMD_ARG(clock, NULL,
278-
"'app clock <yy/MM/dd,hh:mm:ss-/+zz>' sets "
279-
"modem clock (see modem AT command "
280-
"specification for AT+CCLK for detailed "
281-
"format description)",
28+
"Set modem clock (see modem AT command specification for AT+CCLK for "
29+
"detailed format description)\n"
30+
"Usage:\n"
31+
"app clock <yy/MM/dd,hh:mm:ss-/+zz>",
28232
app_cmd_clock, 2, 0),
283-
SHELL_CMD_ARG(at, NULL, "Execute an AT command.", app_cmd_at, 2, 0),
284-
SHELL_CMD_ARG(ping, NULL, "Ping remote host by 'ping <ip> [count]'.", app_cmd_ping, 2, 1),
285-
SHELL_CMD(data, &app_data_cmds,
286-
"Send periodic UDP data over default "
287-
"APN.",
288-
NULL),
289-
SHELL_CMD(edrx, &app_edrx_cmds, "Enable or disable eDRX.", NULL),
290-
SHELL_CMD(psm, &app_psm_cmds, "Enable or disable PSM.", NULL), SHELL_SUBCMD_SET_END);
33+
);
29134

292-
SHELL_CMD_REGISTER(app, &app_cmds, "Commands for controlling the FOTA sample application", NULL);
35+
SHELL_CMD_REGISTER(app, &app_cmds, "Commands for controlling the SoftBank FOTA sample application", NULL);

0 commit comments

Comments
 (0)