# HG changeset patch # User Mychaela Falconia # Date 1477534418 0 # Node ID bbc41034f14ccce65420ee23043e513d9cae7ab4 # Parent 84920d3d97c68e0f6237cb1d6cd5a080b5adb74c fc-shell: added support for AT commands in one-shot mode diff -r 84920d3d97c6 -r bbc41034f14c rvinterf/asyncshell/at.c --- a/rvinterf/asyncshell/at.c Thu Oct 27 00:18:49 2016 +0000 +++ b/rvinterf/asyncshell/at.c Thu Oct 27 02:13:38 2016 +0000 @@ -3,15 +3,22 @@ */ #include +#include #include #include #include #include #include +#include #include "pktmux.h" #include "limits.h" #include "exitcodes.h" +extern u_char rvi_msg[]; +extern int rvi_msg_len; +extern int oneshot_nowait; +extern int sock; + send_string_to_ati(str) char *str; { @@ -44,3 +51,59 @@ ati_rx_control(1); send_string_to_ati(arg); } + +oneshot_at_command(cmd) + char *cmd; +{ + fd_set fds; + int rc; + + if (!oneshot_nowait) { + init(); /* to catch the response properly */ + ati_rx_control(1); + } + rc = send_string_to_ati(cmd); + if (rc) + exit(rc); + if (oneshot_nowait) + exit(0); + /* wait for response */ + for (;;) { + FD_ZERO(&fds); + FD_SET(sock, &fds); + rc = select(sock+1, &fds, 0, 0, 0); + if (rc < 0) { + if (errno == EINTR) + continue; + perror("select"); + exit(ERROR_UNIX); + } + if (FD_ISSET(sock, &fds)) + handle_rvinterf_input(); + } +} + +cmd_str_oneshot(argc, argv) + char **argv; +{ + return oneshot_at_command(argv[1]); +} + +void +oneshot_at_check_response() +{ + if (rvi_msg_len == 4 && !strncmp(rvi_msg + 2, "OK", 2)) + exit(0); + if (rvi_msg_len == 4 && !strncmp(rvi_msg + 2, "> ", 2)) + exit(0); + if (rvi_msg_len == 7 && !strncmp(rvi_msg + 2, "ERROR", 5)) + exit(ERROR_TARGET); + if (rvi_msg_len == 6 && !strncmp(rvi_msg + 2, "BUSY", 4)) + exit(ERROR_TARGET); + if (rvi_msg_len == 12 && !strncmp(rvi_msg + 2, "NO CARRIER", 10)) + exit(ERROR_TARGET); + if (rvi_msg_len >= 12 && !strncmp(rvi_msg + 2, "+CME ERROR", 10)) + exit(ERROR_TARGET); + if (rvi_msg_len >= 12 && !strncmp(rvi_msg + 2, "+CMS ERROR", 10)) + exit(ERROR_TARGET); +} diff -r 84920d3d97c6 -r bbc41034f14c rvinterf/asyncshell/main.c --- a/rvinterf/asyncshell/main.c Thu Oct 27 00:18:49 2016 +0000 +++ b/rvinterf/asyncshell/main.c Thu Oct 27 02:13:38 2016 +0000 @@ -12,6 +12,7 @@ char *socket_pathname = "/tmp/rvinterf_socket"; char *rvinterf_ttyport; int ttyhacks, dflag; +int oneshot_mode, oneshot_nowait; int sock; @@ -25,7 +26,7 @@ int c, sopt = 0; fd_set fds; - while ((c = getopt(argc, argv, "B:dl:p:s:w:")) != EOF) + while ((c = getopt(argc, argv, "B:dl:np:s:w:")) != EOF) switch (c) { case 'B': rvinterf_Bopt = optarg; @@ -36,6 +37,9 @@ case 'l': rvinterf_lopt = optarg; continue; + case 'n': + oneshot_nowait++; + continue; case 'p': rvinterf_ttyport = optarg; continue; @@ -69,8 +73,10 @@ connect_local_socket(); } - if (argv[optind]) + if (argv[optind]) { + oneshot_mode = 1; return oneshot_command(argc - optind, argv + optind); + } ttyhacks = isatty(0) && !dflag; init(); diff -r 84920d3d97c6 -r bbc41034f14c rvinterf/asyncshell/oneshot.c --- a/rvinterf/asyncshell/oneshot.c Thu Oct 27 00:18:49 2016 +0000 +++ b/rvinterf/asyncshell/oneshot.c Thu Oct 27 02:13:38 2016 +0000 @@ -12,6 +12,7 @@ extern int cmd_poweroff(); extern int cmd_send_oneshot(); extern int cmd_sp_oneshot(); +extern int cmd_str_oneshot(); extern int cmd_tchdl_oneshot(); extern int cmd_tgtreset(); @@ -24,6 +25,7 @@ {"poweroff", 0, 0, cmd_poweroff}, {"send", 1, MAX_PKT_TO_TARGET, cmd_send_oneshot}, {"sp", 2, 2, cmd_sp_oneshot}, + {"str", 1, 1, cmd_str_oneshot}, {"tch-dl", 1, 1, cmd_tchdl_oneshot}, {"tgtreset", 0, 0, cmd_tgtreset}, {0, 0, 0, 0} @@ -34,6 +36,14 @@ { struct cmdtab *tp; + if (!strncmp(argv[0], "AT", 2) || !strncmp(argv[0], "at", 2)) { + if (argc != 1) { + fprintf(stderr, + "error: AT command must be a single argument\n"); + exit(ERROR_USAGE); + } + return oneshot_at_command(argv[0]); + } for (tp = cmdtab; tp->cmd; tp++) if (!strcmp(tp->cmd, argv[0])) break; diff -r 84920d3d97c6 -r bbc41034f14c rvinterf/asyncshell/pktsort.c --- a/rvinterf/asyncshell/pktsort.c Thu Oct 27 00:18:49 2016 +0000 +++ b/rvinterf/asyncshell/pktsort.c Thu Oct 27 02:13:38 2016 +0000 @@ -15,6 +15,7 @@ extern u_char rvi_msg[]; extern int rvi_msg_len; +extern int oneshot_mode; static void process_rvt() @@ -57,6 +58,8 @@ strcpy(buf, "ATI: "); safe_print_trace(rvi_msg + 2, rvi_msg_len - 2, buf + 5); async_msg_output(buf); + if (oneshot_mode) + oneshot_at_check_response(); } void