From 0c9c00f976437d1f8b8da95d89423b90ede87d6f Mon Sep 17 00:00:00 2001
From: Alexandre Abadie <alexandre.abadie@inria.fr>
Date: Tue, 22 May 2018 15:49:26 +0200
Subject: [PATCH] tests/at: improve shell and add README

---
 tests/{at => driver_at}/Makefile |  0
 tests/driver_at/README.md        |  8 ++++++++
 tests/{at => driver_at}/main.c   | 34 ++++++++++++++++++--------------
 3 files changed, 27 insertions(+), 15 deletions(-)
 rename tests/{at => driver_at}/Makefile (100%)
 create mode 100644 tests/driver_at/README.md
 rename tests/{at => driver_at}/main.c (72%)

diff --git a/tests/at/Makefile b/tests/driver_at/Makefile
similarity index 100%
rename from tests/at/Makefile
rename to tests/driver_at/Makefile
diff --git a/tests/driver_at/README.md b/tests/driver_at/README.md
new file mode 100644
index 0000000000..0edc0e2d17
--- /dev/null
+++ b/tests/driver_at/README.md
@@ -0,0 +1,8 @@
+Expected result
+===============
+You should be presented with a RIOT shell that privides commands to
+initialize an UART and send AT commands to an AT module.
+
+Background
+==========
+Test for the AT command parser driver.
diff --git a/tests/at/main.c b/tests/driver_at/main.c
similarity index 72%
rename from tests/at/main.c
rename to tests/driver_at/main.c
index 78e7274a7b..1307287f77 100644
--- a/tests/at/main.c
+++ b/tests/driver_at/main.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2018 OTA keys S.A.
+ *               2018 Inria
  *
  * This file is subject to the terms and conditions of the GNU Lesser
  * General Public License v2.1. See the file LICENSE in the top level
@@ -14,34 +15,38 @@
  * @brief    AT module test application
  *
  * @author   Vincent Dupont <vincent@otakeys.com>
+ * @author   Alexandre Abadie <alexandre.abadie@inria.fr>
  *
  * @}
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 
 #include "at.h"
 #include "shell.h"
 #include "timex.h"
 
+#include "periph/uart.h"
+
 static at_dev_t at_dev;
 static char buf[256];
 static char resp[1024];
 
-#ifndef UART_AT
-#define UART_AT     UART_DEV(1)
-#endif
-
-#ifndef BAUDRATE_AT
-#define BAUDRATE_AT 115200
-#endif
-
 static int init(int argc, char **argv)
 {
     (void)argc;
     (void)argv;
 
-    at_dev_init(&at_dev, UART_AT, BAUDRATE_AT, buf, sizeof(buf));
+    if (argc < 3) {
+        printf("Usage: %s <uart> <baudrate>\n", argv[0]);
+        return 1;
+    }
+
+    uint8_t uart = atoi(argv[1]);
+    uint32_t baudrate = atoi(argv[2]);
+
+    at_dev_init(&at_dev, UART_DEV(uart), baudrate, buf, sizeof(buf));
 
     return 0;
 }
@@ -49,18 +54,17 @@ static int init(int argc, char **argv)
 static int send(int argc, char **argv)
 {
     if (argc < 2) {
-        puts("Please enter a command");
+        printf("Usage: %s <command>\n", argv[0]);
         return 1;
     }
 
-    if (at_send_cmd_get_resp(&at_dev, argv[1], resp, sizeof(resp), 10 * US_PER_SEC) > 0) {
-        puts("Response:");
-        puts(resp);
-    }
-    else {
+    if (at_send_cmd_get_resp(&at_dev, argv[1], resp, sizeof(resp), 10 * US_PER_SEC) < 0) {
         puts("Error");
+        return 1;
     }
 
+    printf("Response: %s\n", resp);
+
     return 0;
 }
 
-- 
GitLab