Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/drivers/at: add check if device is initialized before sending command #20140

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions tests/drivers/at/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static at_dev_t at_dev;
static char buf[256];
static char resp[1024];
static char rp_buf[256];
static bool initialized = false;
static bool is_power_on = false;

static int init(int argc, char **argv)
{
Expand Down Expand Up @@ -72,6 +74,8 @@ static int init(int argc, char **argv)
return 1;
}

initialized = true;

return res;
}

Expand All @@ -82,6 +86,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 @@ -100,6 +116,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 @@ -117,6 +145,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),
10 * US_PER_SEC)) < 0) {
Expand All @@ -138,6 +178,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 @@ -160,6 +212,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 @@ -192,6 +256,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 @@ -204,6 +269,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
Loading