2018-08-02 04:03:00 +08:00
|
|
|
/** @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
|
|
|
|
*/
|
|
|
|
|
2018-10-20 06:15:44 +08:00
|
|
|
#define LOG_MODULE_NAME modem_shell
|
|
|
|
|
2018-08-02 04:03:00 +08:00
|
|
|
#include <zephyr.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <device.h>
|
2018-10-20 06:15:44 +08:00
|
|
|
#include <shell/shell.h>
|
2018-08-02 04:03:00 +08:00
|
|
|
|
|
|
|
#include <misc/printk.h>
|
|
|
|
|
|
|
|
#include <drivers/modem/modem_receiver.h>
|
|
|
|
|
2018-10-20 06:15:44 +08:00
|
|
|
static int cmd_modem_list(const struct shell *shell, size_t argc,
|
|
|
|
char *argv[])
|
2018-08-02 04:03:00 +08:00
|
|
|
{
|
|
|
|
struct mdm_receiver_context *mdm_ctx;
|
|
|
|
int i, count = 0;
|
|
|
|
|
2018-10-20 06:15:44 +08:00
|
|
|
shell_fprintf(shell, SHELL_NORMAL, "Modem receivers:\n");
|
2018-08-02 04:03:00 +08:00
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_MODEM_RECEIVER_MAX_CONTEXTS; i++) {
|
|
|
|
mdm_ctx = mdm_receiver_context_from_id(i);
|
|
|
|
if (mdm_ctx) {
|
|
|
|
count++;
|
2018-10-20 06:15:44 +08:00
|
|
|
shell_fprintf(shell, SHELL_NORMAL,
|
|
|
|
"%d:\tUART Name: %s\n"
|
2018-08-02 04:03:00 +08:00
|
|
|
"\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) {
|
2018-10-20 06:15:44 +08:00
|
|
|
shell_fprintf(shell, SHELL_NORMAL, "None found.\n");
|
2018-08-02 04:03:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-20 06:15:44 +08:00
|
|
|
static int cmd_modem_send(const struct shell *shell, size_t argc,
|
|
|
|
char *argv[])
|
2018-08-02 04:03:00 +08:00
|
|
|
{
|
|
|
|
struct mdm_receiver_context *mdm_ctx;
|
|
|
|
char *endptr;
|
|
|
|
int ret, i, arg = 1;
|
|
|
|
|
|
|
|
/* list */
|
|
|
|
if (!argv[arg]) {
|
2018-10-20 06:15:44 +08:00
|
|
|
shell_fprintf(shell, SHELL_ERROR,
|
|
|
|
"Please enter a modem index\n");
|
2018-08-02 04:03:00 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* <index> of modem receiver */
|
|
|
|
i = (int)strtol(argv[arg], &endptr, 10);
|
|
|
|
if (*endptr != '\0') {
|
2018-10-20 06:15:44 +08:00
|
|
|
shell_fprintf(shell, SHELL_ERROR,
|
|
|
|
"Please enter a modem index\n");
|
2018-08-02 04:03:00 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mdm_ctx = mdm_receiver_context_from_id(i);
|
|
|
|
if (!mdm_ctx) {
|
2018-10-20 06:15:44 +08:00
|
|
|
shell_fprintf(shell, SHELL_ERROR, "Modem receiver not found!");
|
2018-08-02 04:03:00 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = arg + 1; i < argc; i++) {
|
|
|
|
ret = mdm_receiver_send(mdm_ctx, argv[i], strlen(argv[i]));
|
|
|
|
if (ret < 0) {
|
2018-10-20 06:15:44 +08:00
|
|
|
shell_fprintf(shell, SHELL_ERROR,
|
|
|
|
"Error sending '%s': %d\n", argv[i], ret);
|
2018-08-02 04:03:00 +08:00
|
|
|
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) {
|
2018-10-20 06:15:44 +08:00
|
|
|
shell_fprintf(shell, SHELL_ERROR,
|
|
|
|
"Error sending (CRLF or space): %d\n",
|
|
|
|
ret);
|
2018-08-02 04:03:00 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-20 06:15:44 +08:00
|
|
|
SHELL_CREATE_STATIC_SUBCMD_SET(sub_modem) {
|
|
|
|
/* Alphabetically sorted. */
|
|
|
|
SHELL_CMD(list, NULL, "List registered modems", cmd_modem_list),
|
|
|
|
SHELL_CMD(send, NULL, "Send an AT <command> to a registered modem "
|
|
|
|
"receiver", cmd_modem_send),
|
|
|
|
SHELL_SUBCMD_SET_END /* Array terminated. */
|
2018-08-02 04:03:00 +08:00
|
|
|
};
|
|
|
|
|
2018-10-20 06:15:44 +08:00
|
|
|
SHELL_CMD_REGISTER(modem, &sub_modem, "Modem commands", NULL);
|