mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #20140 from krzysztof-cabaj/tests-drivers-at
tests/drivers/at: add check if device is initialized before sending command
This commit is contained in:
commit
f130ebfccc
@ -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)
|
||||
{
|
||||
@ -72,6 +74,8 @@ static int init(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -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");
|
||||
@ -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;
|
||||
@ -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) {
|
||||
@ -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));
|
||||
|
||||
@ -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));
|
||||
@ -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");
|
||||
|
||||
@ -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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user