drivers: modem: add modem shell extension

Add a set of modem shell commands to support modem development.

Start with:
modem list: Lists all registered modems and related information
modem send <modem receiver index> <command>: Send command to modem

Signed-off-by: Michael Scott <mike@foundries.io>
This commit is contained in:
Michael Scott 2018-08-01 12:03:00 -08:00 committed by Jukka Rissanen
commit 8b3d4ab6b8
3 changed files with 122 additions and 0 deletions

View file

@ -1,2 +1,3 @@
zephyr_sources_ifdef(CONFIG_MODEM_RECEIVER modem_receiver.c) zephyr_sources_ifdef(CONFIG_MODEM_RECEIVER modem_receiver.c)
zephyr_sources_ifdef(CONFIG_MODEM_SHELL modem_shell.c)
zephyr_sources_ifdef(CONFIG_MODEM_WNCM14A2A wncm14a2a.c) zephyr_sources_ifdef(CONFIG_MODEM_WNCM14A2A wncm14a2a.c)

View file

@ -32,6 +32,13 @@ config MODEM_RECEIVER_MAX_CONTEXTS
Maximum number of modem receiver contexts to handle. For most Maximum number of modem receiver contexts to handle. For most
purposes this should stay at 1. purposes this should stay at 1.
config MODEM_SHELL
bool "Enable modem shell utilities"
select CONSOLE_SHELL
help
Activate shell module that provides modem utilities like
sending a command to the modem UART.
config MODEM_WNCM14A2A config MODEM_WNCM14A2A
bool "Enable Wistron LTE-M modem driver" bool "Enable Wistron LTE-M modem driver"
depends on UART_INTERRUPT_DRIVEN depends on UART_INTERRUPT_DRIVEN

114
drivers/modem/modem_shell.c Normal file
View file

@ -0,0 +1,114 @@
/** @file
* @brief Modem shell module
*
* Provide some modem shell commands that can be useful to applications.
*/
/*
* Copyright (c) 2018 Foundries.io
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <stdlib.h>
#include <string.h>
#include <device.h>
#include <shell/shell.h>
#include <misc/printk.h>
#include <drivers/modem/modem_receiver.h>
#define MODEM_SHELL_MODULE "modem"
int modem_shell_cmd_list(int argc, char *argv[])
{
struct mdm_receiver_context *mdm_ctx;
int i, count = 0;
printk("Modem receivers:\n");
for (i = 0; i < CONFIG_MODEM_RECEIVER_MAX_CONTEXTS; i++) {
mdm_ctx = mdm_receiver_context_from_id(i);
if (mdm_ctx) {
count++;
printk("%d:\tUART Name: %s\n"
"\tManufacturer: %s\n"
"\tModel: %s\n"
"\tRevision: %s\n"
"\tIMEI: %s\n"
"\tRSSI: %d\n", i,
mdm_ctx->uart_dev->config->name,
mdm_ctx->data_manufacturer,
mdm_ctx->data_model,
mdm_ctx->data_revision,
mdm_ctx->data_imei,
mdm_ctx->data_rssi);
}
}
if (!count) {
printk("None found.\n");
}
return 0;
}
int modem_shell_cmd_send(int argc, char *argv[])
{
struct mdm_receiver_context *mdm_ctx;
char *endptr;
int ret, i, arg = 1;
/* list */
if (!argv[arg]) {
printk("Please enter a modem index\n");
return -EINVAL;
}
/* <index> of modem receiver */
i = (int)strtol(argv[arg], &endptr, 10);
if (*endptr != '\0') {
printk("Please enter a modem index\n");
return -EINVAL;
}
mdm_ctx = mdm_receiver_context_from_id(i);
if (!mdm_ctx) {
printk("Modem receiver not found!");
return 0;
}
for (i = arg + 1; i < argc; i++) {
ret = mdm_receiver_send(mdm_ctx, argv[i], strlen(argv[i]));
if (ret < 0) {
printk("Error sending '%s': %d\n", argv[i], ret);
return 0;
}
if (i == argc - 1) {
ret = mdm_receiver_send(mdm_ctx, "\r\n", 2);
} else {
ret = mdm_receiver_send(mdm_ctx, " ", 1);
}
if (ret < 0) {
printk("Error sending (CRLF or space): %d\n", ret);
return 0;
}
}
return 0;
}
static struct shell_cmd modem_commands[] = {
/* Keep the commands in alphabetical order */
{ "list", modem_shell_cmd_list, "\n\tList registered modems" },
{ "send", modem_shell_cmd_send,
"\n\tSend an AT <command> to a registered modem receiver:"
"\n\tsend <index> <command>" },
{ NULL, NULL, NULL }
};
SHELL_REGISTER(MODEM_SHELL_MODULE, modem_commands);