modem: shell: Add info command

Add an information command that currently will only prints
GSM muxing status.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2020-03-31 17:41:08 +03:00
commit 31ec75fca3
3 changed files with 136 additions and 0 deletions

View file

@ -791,6 +791,24 @@ int uart_mux_recv(struct device *mux, struct gsm_dlci *dlci, u8_t *data,
return wrote; return wrote;
} }
void uart_mux_foreach(uart_mux_cb_t cb, void *user_data)
{
sys_snode_t *sn, *sns;
SYS_SLIST_FOR_EACH_NODE_SAFE(&uart_mux_data_devlist, sn, sns) {
struct uart_mux_dev_data *dev_data =
CONTAINER_OF(sn, struct uart_mux_dev_data, node);
if (!dev_data->in_use) {
continue;
}
cb(dev_data->real_uart->uart, dev_data->dev,
dev_data->dlci ? gsm_dlci_id(dev_data->dlci) : -1,
user_data);
}
}
#define DEFINE_UART_MUX_CFG_DATA(x, _) \ #define DEFINE_UART_MUX_CFG_DATA(x, _) \
struct uart_mux_cfg_data uart_mux_config_##x = { \ struct uart_mux_cfg_data uart_mux_config_##x = { \
}; };

View file

@ -17,9 +17,15 @@
#include <string.h> #include <string.h>
#include <device.h> #include <device.h>
#include <shell/shell.h> #include <shell/shell.h>
#include <drivers/console/uart_mux.h>
#include <sys/printk.h> #include <sys/printk.h>
struct modem_shell_user_data {
const struct shell *shell;
void *user_data;
};
#if defined(CONFIG_MODEM_CONTEXT) #if defined(CONFIG_MODEM_CONTEXT)
#include "modem_context.h" #include "modem_context.h"
#define ms_context modem_context #define ms_context modem_context
@ -127,7 +133,98 @@ static int cmd_modem_send(const struct shell *shell, size_t argc,
return 0; return 0;
} }
#if defined(CONFIG_GSM_MUX)
static void uart_mux_cb(struct device *uart, struct device *dev,
int dlci_address, void *user_data)
{
struct modem_shell_user_data *data = user_data;
const struct shell *shell = data->shell;
int *count = data->user_data;
const char *ch = "?";
if (*count == 0) {
shell_fprintf(shell, SHELL_NORMAL,
"\nReal UART\tMUX UART\tDLCI\n");
}
(*count)++;
if (dlci_address == CONFIG_GSM_MUX_DLCI_AT) {
ch = "AT";
} else if (dlci_address == CONFIG_GSM_MUX_DLCI_PPP) {
ch = "PPP";
} else if (dlci_address == 0) {
ch = "control";
}
shell_fprintf(shell, SHELL_NORMAL,
"%s\t\t%s\t\t%d (%s)\n",
uart->config->name, dev->config->name, dlci_address, ch);
}
#endif
static int cmd_modem_info(const struct shell *shell, size_t argc, char *argv[])
{
struct ms_context *mdm_ctx;
char *endptr;
int i, arg = 1;
/* info */
if (!argv[arg]) {
shell_fprintf(shell, SHELL_ERROR,
"Please enter a modem index\n");
return -EINVAL;
}
/* <index> of modem receiver */
i = (int)strtol(argv[arg], &endptr, 10);
if (*endptr != '\0') {
shell_fprintf(shell, SHELL_ERROR,
"Please enter a modem index\n");
return -EINVAL;
}
mdm_ctx = ms_context_from_id(i);
if (!mdm_ctx) {
shell_fprintf(shell, SHELL_ERROR, "Modem receiver not found!");
return 0;
}
shell_fprintf(shell, SHELL_NORMAL,
"Modem index : %d\n"
"Iface Device : %s\n"
"Manufacturer : %s\n"
"Model : %s\n"
"Revision : %s\n"
"IMEI : %s\n"
"RSSI : %d\n",
i,
UART_DEV_NAME(mdm_ctx),
mdm_ctx->data_manufacturer,
mdm_ctx->data_model,
mdm_ctx->data_revision,
mdm_ctx->data_imei,
mdm_ctx->data_rssi);
shell_fprintf(shell, SHELL_NORMAL,
"GSM 07.10 muxing : %s\n",
IS_ENABLED(CONFIG_GSM_MUX) ? "enabled" : "disabled");
#if defined(CONFIG_GSM_MUX)
struct modem_shell_user_data user_data;
int count = 0;
user_data.shell = shell;
user_data.user_data = &count;
uart_mux_foreach(uart_mux_cb, &user_data);
#endif
return 0;
}
SHELL_STATIC_SUBCMD_SET_CREATE(sub_modem, SHELL_STATIC_SUBCMD_SET_CREATE(sub_modem,
SHELL_CMD(info, NULL, "Show information for a modem", cmd_modem_info),
SHELL_CMD(list, NULL, "List registered modems", cmd_modem_list), SHELL_CMD(list, NULL, "List registered modems", cmd_modem_list),
SHELL_CMD(send, NULL, "Send an AT <command> to a registered modem " SHELL_CMD(send, NULL, "Send an AT <command> to a registered modem "
"receiver", cmd_modem_send), "receiver", cmd_modem_send),

View file

@ -104,6 +104,27 @@ __syscall struct device *uart_mux_find(int dlci_address);
*/ */
struct device *uart_mux_alloc(void); struct device *uart_mux_alloc(void);
/**
* @typedef uart_mux_cb_t
* @brief Callback used while iterating over UART muxes
*
* @param uart Pointer to UART device where the mux is running
* @param dev Pointer to UART mux device
* @param dlci_address DLCI channel id this UART is muxed
* @param user_data A valid pointer to user data or NULL
*/
typedef void (*uart_mux_cb_t)(struct device *uart, struct device *dev,
int dlci_address, void *user_data);
/**
* @brief Go through all the UART muxes and call callback
* for each of them
*
* @param cb User-supplied callback function to call
* @param user_data User specified data
*/
void uart_mux_foreach(uart_mux_cb_t cb, void *user_data);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif