diff --git a/tests/drivers/at/main.c b/tests/drivers/at/main.c index e424ac8b78cd1..4e3ccacc45e67 100644 --- a/tests/drivers/at/main.c +++ b/tests/drivers/at/main.c @@ -33,6 +33,8 @@ static at_dev_t at_dev; static char buf[256]; static char resp[1024]; +static bool initialized; +static bool is_power_on; static int init(int argc, char **argv) { @@ -64,6 +66,8 @@ static int init(int argc, char **argv) return 1; } + initialized = true; + return res; } @@ -74,6 +78,18 @@ static int send(int argc, char **argv) return 1; } + if (initialized == false) { + puts("Error: AT device not initialized.\n"); + puts("Execute init function first.\n"); + return 1; + } + + if (is_power_on == false) { + puts("Error: AT device not power on.\n"); + puts("Execute power_on function first.\n"); + return 1; + } + ssize_t len; if ((len = at_send_cmd_get_resp(&at_dev, argv[1], resp, sizeof(resp), 10 * US_PER_SEC)) < 0) { puts("Error"); @@ -92,6 +108,18 @@ static int send_ok(int argc, char **argv) return 1; } + if (initialized == false) { + puts("Error: AT device not initialized.\n"); + puts("Execute init function first.\n"); + return 1; + } + + if (is_power_on == false) { + puts("Error: AT device not power on.\n"); + puts("Execute power_on function first.\n"); + return 1; + } + if (at_send_cmd_wait_ok(&at_dev, argv[1], 10 * US_PER_SEC) < 0) { puts("Error"); return 1; @@ -109,6 +137,18 @@ static int send_lines(int argc, char **argv) return 1; } + if (initialized == false) { + puts("Error: AT device not initialized.\n"); + puts("Execute init function first.\n"); + return 1; + } + + if (is_power_on == false) { + puts("Error: AT device not power on.\n"); + puts("Execute power_on function first.\n"); + return 1; + } + ssize_t len; if ((len = at_send_cmd_get_lines(&at_dev, argv[1], resp, sizeof(resp), true, 10 * US_PER_SEC)) < 0) { puts("Error"); @@ -129,6 +169,18 @@ static int send_recv_bytes(int argc, char **argv) return 1; } + if (initialized == false) { + puts("Error: AT device not initialized.\n"); + puts("Execute init function first.\n"); + return 1; + } + + if (is_power_on == false) { + puts("Error: AT device not power on.\n"); + puts("Execute power_on function first.\n"); + return 1; + } + sprintf(buffer, "%s%s", argv[1], CONFIG_AT_SEND_EOL); at_send_bytes(&at_dev, buffer, strlen(buffer)); @@ -151,6 +203,18 @@ static int send_recv_bytes_until_string(int argc, char **argv) return 1; } + if (initialized == false) { + puts("Error: AT device not initialized.\n"); + puts("Execute init function first.\n"); + return 1; + } + + if (is_power_on == false) { + puts("Error: AT device not power on.\n"); + puts("Execute power_on function first.\n"); + return 1; + } + sprintf(buffer, "%s%s", argv[1], CONFIG_AT_SEND_EOL); at_send_bytes(&at_dev, buffer, strlen(buffer)); memset(buffer, 0, sizeof(buffer)); @@ -183,6 +247,7 @@ static int power_on(int argc, char **argv) (void)argv; at_dev_poweron(&at_dev); + is_power_on = true; puts("Powered on"); @@ -195,6 +260,7 @@ static int power_off(int argc, char **argv) (void)argv; at_dev_poweroff(&at_dev); + is_power_on = false; puts("Powered off"); @@ -370,6 +436,9 @@ int main(void) { puts("AT command test app"); + initialized = false; + is_power_on = false; + /* run the shell */ char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);