Skip to content

Commit

Permalink
tests/drivers/at: add check if device is initialized before sending c…
Browse files Browse the repository at this point in the history
…ommand
  • Loading branch information
krzysztof-cabaj committed Dec 6, 2023
1 parent 182700f commit 619ee31
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/drivers/at/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -64,6 +66,8 @@ static int init(int argc, char **argv)
return 1;
}

initialized = true;

return res;
}

Expand All @@ -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");
Expand All @@ -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;
Expand All @@ -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) {

Check warning on line 153 in tests/drivers/at/main.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
puts("Error");
Expand All @@ -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));

Expand All @@ -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));
Expand Down Expand Up @@ -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");

Expand All @@ -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");

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 619ee31

Please sign in to comment.