5
5
*/
6
6
7
7
#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>
12
8
#include <sb_fota.h>
13
9
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
-
94
10
static int app_cmd_clock (const struct shell * shell , size_t argc , char * * argv )
95
11
{
96
12
ARG_UNUSED (argc );
97
13
98
14
int err ;
15
+
99
16
err = sb_fota_clock_set (argv [1 ]);
100
17
if (err ) {
101
18
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)
105
22
return 0 ;
106
23
}
107
24
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
-
275
25
SHELL_STATIC_SUBCMD_SET_CREATE (
276
- app_cmds , SHELL_CMD_ARG ( ver , NULL , "Firmware version." , app_cmd_ver , 1 , 0 ),
26
+ app_cmds ,
277
27
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> " ,
282
32
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
+ );
291
34
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