From 09a9d099bc58c3bd6457bf93c9183e702a5ff97a Mon Sep 17 00:00:00 2001 From: Nick Van Doorn Date: Tue, 24 Apr 2018 13:51:05 -0700 Subject: Initial commit --- .gitignore | 6 ++++++ main/Component.cdef | 11 +++++++++++ main/main.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.adef | 21 +++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 .gitignore create mode 100644 main/Component.cdef create mode 100644 main/main.c create mode 100644 setup.adef diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b94fee --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.update +_build** +.DS_Store +legato +.repo +.AppleDouble diff --git a/main/Component.cdef b/main/Component.cdef new file mode 100644 index 0000000..fb206ea --- /dev/null +++ b/main/Component.cdef @@ -0,0 +1,11 @@ +cflags: +{ + -std=c99 + -I$BRNKL_ROOT/apps/util +} + +sources: +{ + $BRNKL_ROOT/apps/util/util.c + main.c +} diff --git a/main/main.c b/main/main.c new file mode 100644 index 0000000..e36fa04 --- /dev/null +++ b/main/main.c @@ -0,0 +1,52 @@ +#include "legato.h" + +#define N_UARTS 2 +#define GPIO_START 21 +#define GPIO_END 37 +#define BUFFER_LEN 256 + +static const char* TTY_AT_PATH = "/dev/ttyAT"; + +static int configureGpio (int fd, char* buffer, bool* res) { + int resIndex = 0; + for (int i = GPIO_START; i <= GPIO_END; i++) { + int strSize = sprintf(buffer, "AT+WIOCFG=%d,16\r", i); + LE_INFO("Running AT command on GPIO %d (%s)", i, buffer); + write(fd, buffer, strSize); + int nRead = read(fd, buffer, BUFFER_LEN); + buffer[nRead + 1] = '\0'; + LE_INFO("Got %s response for GPIO %d", buffer, i); + // if the return string matches OK + // we can consider this one a success + res[resIndex++] = strcmp(buffer, "OK") == 0; + } + return resIndex; +} + +static int configureUart (int fd, char* buffer, bool* res) { + int resIndex = 0; + for (int i = 1; i <= N_UARTS; i++) { + int strSize = sprintf(buffer, "AT!MAPUART=17,%d\r", i); + LE_INFO("Running AT command on UART %d (%s)", i, buffer); + write(fd, buffer, strSize); + int nRead = read(fd, buffer, BUFFER_LEN); + buffer[nRead + 1] = '\0'; + LE_INFO("Got %s response for UART %d", buffer, i); + // if the return string matches OK + // we can consider this one a success + res[resIndex++] = strcmp(buffer, "OK") == 0; + } + return resIndex; +} + +COMPONENT_INIT { + char buffer[BUFFER_LEN]; + bool res[BUFFER_LEN]; + int serialFd = le_tty_Open(TTY_AT_PATH, O_RDWR); + le_tty_SetBaudRate(serialFd, LE_TTY_SPEED_9600); + le_tty_SetCanonical(serialFd); + int n = configureGpio(serialFd, buffer, res); + // seek to the right location in res + configureUart(serialFd, buffer, res + n); + le_tty_Close(serialFd); +} diff --git a/setup.adef b/setup.adef new file mode 100644 index 0000000..17c2052 --- /dev/null +++ b/setup.adef @@ -0,0 +1,21 @@ +version: 0.1.0 +sandboxed: false +start: manual + +executables: +{ + setup = ( main ) +} + +processes: +{ + envVars: + { + LE_LOG_LEVEL = INFO + } + + run: + { + ( setup ) + } +} -- cgit v1.2.3