diff --git a/release/Makefile b/release/Makefile index 3d0ad24..73a02c7 100644 --- a/release/Makefile +++ b/release/Makefile @@ -7,7 +7,7 @@ $(info ZIP $(ZIP)) IMAGES=\ release/httpd.user1.bin \ release/httpd.user2.bin \ -release/Parallax-ESP-v010.ota \ +release/Parallax-ESP.ota \ release/blank.bin \ release/esp_init_data_default.bin @@ -28,7 +28,7 @@ build: $(MAKE) -C .. STA_SSID= STA_PASS= clean $(MAKE) -C .. STA_SSID= STA_PASS= -staged-files: release release/release-notes.txt release/tests release/samples $(IMAGES) +staged-files: release release/release-notes.txt $(IMAGES) $(CP) flash-all.sh update-fw.sh clear.sh clear-ffs.sh release release/release-notes.txt: release-notes.txt @@ -40,7 +40,7 @@ release/boot_v1.%.bin: $(SDK)/bin/boot_v1.%.bin patch release/%: ../build/% $(CP) $< $@ -release/Parallax-ESP-v010.ota: ../build/httpd.ota +release/Parallax-ESP.ota: ../build/httpd.ota $(CP) $< $@ release/blank.bin: $(SDK)/bin/blank.bin @@ -52,20 +52,6 @@ release/esp_init_data_default.bin: $(SDK)/bin/esp_init_data_default.bin release: mkdir -p release -release/tests: - mkdir -p release/tests - cp ../tests/*.[ch] release/tests - cp ../tests/*.html release/tests - cp ../tests/*.side release/tests - cp ../tests/Makefile release/tests - -release/samples: - mkdir -p release/samples - cp ../samples/*.[ch] release/samples - cp ../samples/*.html release/samples - cp ../samples/*.side release/samples - cp ../samples/Makefile release/samples - patch: patch.c cc -o $@ $< diff --git a/samples/Makefile b/samples/Makefile deleted file mode 100644 index 063ea81..0000000 --- a/samples/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -$(info HOME $(HOME)) - -TARGET=robot.elf - -all: robot.elf blink.elf - -CFLAGS=-mcmm -Os -Wall -m32bit-doubles -I $(HOME)/simple/include -L $(HOME)/simple/lib - -%.elf: %.c cmd.o - propeller-elf-gcc $(CFLAGS) -o $@ $< cmd.o -lsimple-cmm -lm - -%.o: %.c - propeller-elf-gcc -c $(CFLAGS) -o $@ $< - -run: $(TARGET) - proploader $< -t - -clean: - rm -f *.o *.elf diff --git a/samples/blink.c b/samples/blink.c deleted file mode 100644 index a14931f..0000000 --- a/samples/blink.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "simpletools.h" -#include "cmd.h" - -fdserial *debug; - -// uncomment this to use wifi pins other than 31/30 -//#define SEPARATE_WIFI_PINS - -#ifdef SEPARATE_WIFI_PINS -#define WIFI_RX 9 -#define WIFI_TX 8 -#else -#define WIFI_RX 31 -#define WIFI_TX 30 -#endif - -// uncomment this to use debug pins other than 31/30 -//#define SEPARATE_DEBUG_PINS - -#ifdef SEPARATE_DEBUG_PINS -#define DEBUG_RX 9 -#define DEBUG_TX 8 -#else -#define DEBUG_RX 31 -#define DEBUG_TX 30 -#endif - -int main(void) -{ - int blink = 0; - wifi *esp; - - // Close default same-cog terminal - simpleterm_close(); - - esp = wifi_open(WIFI_RX, WIFI_TX); -#ifdef SEPARATE_DEBUG_PINS - debug = fdserial_open(DEBUG_RX, DEBUG_TX, 0, 115200); -#else - debug = esp->port; -#endif - - pause(500); - - int value; - wifi_getInteger(esp, "pin-gpio15", &value); - dprint(debug, "value = %d\n", value); - - for (;;) { - waitcnt(CNT + CLKFREQ/2); - wifi_setInteger(esp, "pin-gpio15", blink); - blink = !blink; - } - - return 0; -} diff --git a/samples/cmd.c b/samples/cmd.c deleted file mode 100644 index 63dfaf8..0000000 --- a/samples/cmd.c +++ /dev/null @@ -1,412 +0,0 @@ -#include "simpletools.h" -#include "fdserial.h" -#include "cmd.h" - -// this is needed until vsprint gets added to Simple Libraries -//#define vsprint(buf, fmt, args) _intsprnt((fmt), (args), (buf)) -#define vsprint(buf, fmt, args) vsprintf((buf), (fmt), (args)) - -static int checkForEvent(wifi *dev, char *buf, int maxSize); -static void request(wifi *dev, const char *fmt, ...); -static void requestPayload(wifi *dev, const char *buf, int len); -static int getResponse(wifi *dev, char *buf, int maxSize); -static int parseResponse(wifi *dev, const char *fmt, ...); -static int parseBuffer(const char *buf, const char *fmt, ...); -static int parseBuffer1(const char *buf, const char *fmt, va_list ap); - -wifi *wifi_open(int wifi_rx, int wifi_tx) -{ - wifi *dev; - if (!(dev = (wifi *)malloc(sizeof(wifi)))) - return NULL; - if (wifi_init(dev, wifi_rx, wifi_tx) != 0) { - free(dev); - return NULL; - } - return dev; -} - -int wifi_init(wifi *dev, int wifi_rx, int wifi_tx) -{ - // initialize the wifi device structure - memset(dev, 0, sizeof(wifi)); - dev->messageState = WIFI_STATE_START; - - // set to open collector instead of driven - if (!(dev->port = fdserial_open(wifi_rx, wifi_tx, 0b0100, 115200))) - return -1; - - // generate a BREAK to enter CMD command mode - pause(10); - low(wifi_tx); - pause(1); - input(wifi_tx); - pause(1); - - return 0; -} - -int wifi_getInteger(wifi *dev, const char *name, int *pValue) -{ - char result; - request(dev, "CHECK:%s", name); - if (parseResponse(dev, CMD_PREFIX "=^c,^i\r", &result, pValue) != 0 || result != 'S') - return -1; - return 0; -} - -int wifi_setInteger(wifi *dev, const char *name, int value) -{ - char result; - int arg; - request(dev, "SET:%s,%d", name, value); - if (parseResponse(dev, CMD_PREFIX "=^c,^i\r", &result, &arg) != 0 || result != 'S') - return -1; - return 0; -} - -int wifi_listen(wifi *dev, char *protocol, const char *path, int *pHandle) -{ - char result; - int arg; - request(dev, "LISTEN:%s,%s", protocol, path); - if (parseResponse(dev, CMD_PREFIX "=^c,^d\r", &result, &arg) != 0 || result != 'S') - return -1; - *pHandle = arg; - return 0; -} - -int wifi_path(wifi *dev, int handle, char *path, int maxSize) -{ - char result; - request(dev, "PATH:%d", handle); - if (parseResponse(dev, CMD_PREFIX "=^c,^s\r", &result, path, maxSize) != 0 || result != 'S') - return -1; - return 0; -} - -int wifi_arg(wifi *dev, int handle, const char *name, char *buf, int maxSize) -{ - char result; - request(dev, "ARG:%d,%s", handle, name); - if (parseResponse(dev, CMD_PREFIX "=^c,^s\r", &result, buf, maxSize) != 0 || result != 'S') - return -1; - return 0; -} - -int wifi_checkForEvent(wifi *dev, char *pType, int *pHandle, int *pListener) -{ - char buf[128]; - - if (checkForEvent(dev, buf, sizeof(buf)) <= 0) - return 0; - - if (parseBuffer(buf, CMD_PREFIX "!^c,^i,^i\r", pType, pHandle, pListener) != 0) - return -1; - - return 1; -} - -static int checkForMessage(wifi *dev, int type, char *buf, int maxSize) -{ - int ch, newTail, i, j; - - while ((ch = fdserial_rxCheck(dev->port)) != -1) { - switch (dev->messageState) { - case WIFI_STATE_START: - if (ch == CMD_START) { - dev->messageStart = dev->messageTail; - newTail = (dev->messageTail + 1) % sizeof(dev->messageBuffer); - if (newTail != dev->messageHead) { - dev->messageBuffer[dev->messageTail] = ch; - dev->messageTail = newTail; - } - else { - dbg("MSG: queue overflow\n"); - return -1; - } - dev->messageState = WIFI_STATE_DATA; - } - else { - // out of band data - return -1; - } - break; - case WIFI_STATE_DATA: - newTail = (dev->messageTail + 1) % sizeof(dev->messageBuffer); - if (newTail != dev->messageHead) { - dev->messageBuffer[dev->messageTail] = ch; - dev->messageTail = newTail; - } - else { - dbg("MSG: queue overflow\n"); - return -1; - } - if (ch == '\r') { -#if 0 - { char tmp[128]; - i = dev->messageStart; - j = 0; - while (i != dev->messageTail) { - if (j < sizeof(tmp) - 1) - tmp[j++] = dev->messageBuffer[i]; - i = (i + 1) % sizeof(dev->messageBuffer); - } - tmp[j] = '\0'; - dbg("Got: %s\n", &tmp[1]); - } -#endif - dev->messageState = WIFI_STATE_START; - i = (dev->messageStart + 1) % sizeof(dev->messageBuffer); - if (dev->messageBuffer[i] == type) { - i = dev->messageStart; - j = 0; - while (i != dev->messageTail) { - if (j < maxSize - 1) - buf[j++] = dev->messageBuffer[i]; - i = (i + 1) % sizeof(dev->messageBuffer); - } - buf[j] = '\0'; - dev->messageTail = dev->messageStart; - return j; - } - } - break; - default: - dbg("MSG: internal error\n"); - return -1; - } - } - - return 0; -} - -static int getResponse(wifi *dev, char *buf, int maxSize) -{ - int ret; - while ((ret = checkForMessage(dev, '=', buf, maxSize)) <= 0) - ; - return ret; -} - -static int checkForEvent(wifi *dev, char *buf, int maxSize) -{ - if (dev->messageHead != dev->messageTail) { - int i = dev->messageHead; - int j = 0; - int ch; - while (i != dev->messageTail) { - ch = dev->messageBuffer[i]; - if (j < maxSize - 1) - buf[j++] = ch; - i = (i + 1) % sizeof(dev->messageBuffer); - if (ch == '\r') { - dev->messageHead = i; - buf[j] = '\0'; - dbg("Got *QUEUED* event: %s\n", &buf[1]); - return j; - } - } - } - return checkForMessage(dev, '!', buf, maxSize); -} - -static void request(wifi *dev, const char *fmt, ...) -{ - char buf[100], *p = buf; - - va_list ap; - va_start(ap, fmt); - vsprint(buf, fmt, ap); - va_end(ap); - - fdserial_txChar(dev->port, CMD_START); - while (*p != '\0') - fdserial_txChar(dev->port, *p++); - fdserial_txChar(dev->port, '\r'); -} - -static void requestPayload(wifi *dev, const char *buf, int len) -{ - while (--len >= 0) - fdserial_txChar(dev->port, *buf++); -} - -#define CHUNK_SIZE 8 - -int wifi_reply(wifi *dev, int chan, int code, const char *payload) -{ - int payloadLength = (payload ? strlen(payload) : 0); - char result; - int count; - - if (payloadLength == 0) { -dbg("REPLY %d, %d\n", chan, code); - request(dev, "REPLY:%d,%d", chan, code); - } - - else { - int remaining = payloadLength; - while (remaining > 0) { - if ((count = remaining) > CHUNK_SIZE) - count = CHUNK_SIZE; - if (remaining == payloadLength) { -dbg("REPLY %d, %d, %d, %d\n", chan, code, payloadLength, count); - request(dev, "REPLY:%d,%d,%d,%d", chan, code, payloadLength, count); - requestPayload(dev, payload, count); - } - else { -dbg("SEND %d, %d\n", chan, count); - request(dev, "SEND:%d,%d", chan, count); - requestPayload(dev, payload, count); - } - payload += count; - remaining -= count; - if (remaining > 0) { - parseResponse(dev, CMD_PREFIX "=^c,^d\r", &result, &count); -dbg(" ret %c %d\n", result, count); - if (result != 'S') { -dbg(" failed with %d\n", count); - return count; - } - } - } - } - - parseResponse(dev, CMD_PREFIX "=^c,^d\r", &result, &count); -dbg(" final ret %c %d\n", result, count); - - return payloadLength; -} - -static int parseResponse(wifi *dev, const char *fmt, ...) -{ - char buf[128]; - va_list ap; - int ret; - - if (getResponse(dev, buf, sizeof(buf)) <= 0) - return -1; - - va_start(ap, fmt); - ret = parseBuffer1(buf, fmt, ap); - va_end(ap); - - return ret; -} - -static void wifi_collectPayload(wifi *dev, char *buf, int bufSize, int count) -{ - while (--count >= 0) { - int ch = fdserial_rxChar(dev->port); - if (bufSize > 0) { - *buf++ = ch; - --bufSize; - } - } -} - -typedef struct { - const char *p; - int savedChar; -} State; - -static int nextchar(State *state) -{ - int ch; - if ((ch = state->savedChar) != EOF) - state->savedChar = EOF; - else - ch = *state->p ? *state->p++ : EOF; - return ch; -} - -static void ungetchar(State *state, int ch) -{ - state->savedChar = ch; -} - -static int parseBuffer(const char *buf, const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = parseBuffer1(buf, fmt, ap); - va_end(ap); - - return ret; -} - -static int parseBuffer1(const char *buf, const char *fmt, va_list ap) -{ - State state = { .p = buf, .savedChar = EOF }; - const char *p = fmt; - int ch, rch; - - while ((ch = *p++) != '\0') { - - rch = nextchar(&state); - - if (ch == '^') { - switch (*p++) { - case 'c': - if (rch == EOF) - return -1; - *va_arg(ap, char *) = rch; - break; - case 'i': - { - int value = 0; - int sign = 1; - if (rch == EOF) - return -1; - if (rch == '-') { - if ((rch = nextchar(&state)) == EOF) - return -1; - sign = -1; - } - if (!isdigit(rch)) - return -1; - do { - value = value * 10 + rch - '0'; - } while ((rch = nextchar(&state)) != EOF && isdigit(rch)); - *va_arg(ap, int *) = value * sign; - ungetchar(&state, rch); - } - break; - case 's': - { - int term = *p; - char *buf = va_arg(ap, char *); - int len = va_arg(ap, int); - while (rch != EOF && rch != term) { - if (len > 1) { - *buf++ = rch; - --len; - } - rch = nextchar(&state); - } - *buf = '\0'; - ungetchar(&state, rch); - } - break; - case '^': - if (rch != '^') - return -1; - break; - case '\0': - // fall through - default: - return -1; - } - } - - else { - if (rch != ch) - return -1; - } - } - - return 0; -} diff --git a/samples/cmd.h b/samples/cmd.h deleted file mode 100644 index 4c6cc19..0000000 --- a/samples/cmd.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef __CMD_H__ -#define __CMD_H__ - -#include -#include "simpletools.h" -#include "fdserial.h" - -extern fdserial *debug; - -#define dbg(args...) dprint(debug, args) - -#define CMD_PREFIX "\xFE" -#define CMD_START 0xFE - -enum { - CMD_TKN_START = 0xFE, - CMD_TKN_INT8 = 0xFD, - CMD_TKN_UINT8 = 0xFC, - CMD_TKN_INT16 = 0xFB, - CMD_TKN_UINT16 = 0xFA, - CMD_TKN_INT32 = 0xF9, - CMD_TKN_UINT32 = 0xF8, - - CMD_TKN_HTTP = 0xF7, - CMD_TKN_WS = 0xF6, - CMD_TKN_TCP = 0xF5, - CMD_TKN_STA = 0xF4, - CMD_TKN_AP = 0xF3, - CMD_TKN_STA_AP = 0xF2, - - // gap for more tokens - - CMD_TKN_JOIN = 0xEF, - CMD_TKN_CHECK = 0xEE, - CMD_TKN_SET = 0xED, - CMD_TKN_POLL = 0xEC, - CMD_TKN_PATH = 0xEB, - CMD_TKN_SEND = 0xEA, - CMD_TKN_RECV = 0xE9, - CMD_TKN_CLOSE = 0xE8, - CMD_TKN_LISTEN = 0xE7, - CMD_TKN_ARG = 0xE6, - CMD_TKN_REPLY = 0xE5, - CMD_TKN_CONNECT = 0xE4, - - CMD_MIN_TOKEN = 0x80 -}; - -#define WIFI_QUEUE_MAX 1024 - -typedef enum { - WIFI_STATE_START, - WIFI_STATE_DATA -} wifi_state; - -typedef struct wifi wifi; -typedef struct wifi_listener wifi_listener; -typedef struct wifi_request wifi_request; - -struct wifi { - fdserial *port; - wifi_state messageState; - char messageBuffer[WIFI_QUEUE_MAX]; - int messageHead; - int messageTail; - int messageStart; - wifi_listener *listeners; -}; - -struct wifi_listener { - wifi *dev; - int handle; - int (*doRequest)(wifi *wifi, wifi_request *request); - wifi_request *requests; -}; - -struct wifi_request { - wifi_listener *listener; - int handle; - void (*doDisconnect)(wifi_request *request); - int (*doSent)(wifi_request *request, int count); - int (*doError)(wifi_request *request, int err); -}; - -wifi *wifi_open(int wifi_rx, int wifi_tx); -int wifi_init(wifi *dev, int wifi_rx, int wifi_tx); -int wifi_getInteger(wifi *dev, const char *name, int *pValue); -int wifi_setInteger(wifi *dev, const char *name, int value); -int wifi_listen(wifi *dev, char *protocol, const char *path, int *pHandle); -int wifi_path(wifi *dev, int handle, char *path, int maxSize); -int wifi_arg(wifi *dev, int handle, const char *name, char *buf, int maxSize); -int wifi_reply(wifi *dev, int chan, int code, const char *payload); -int wifi_checkForEvent(wifi *dev, char *pType, int *pHandle, int *pListener); - -#endif diff --git a/samples/robot.c b/samples/robot.c deleted file mode 100644 index 41f3d98..0000000 --- a/samples/robot.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - Robot test program -*/ - -#include "simpletools.h" -#include "abdrive.h" -#include "ping.h" -#include "cmd.h" - -// uncomment this to use wifi pins other than 31/30 -//#define SEPARATE_WIFI_PINS - -#ifdef SEPARATE_WIFI_PINS -#define WIFI_RX 9 -#define WIFI_TX 8 -#else -#define WIFI_RX 31 -#define WIFI_TX 30 -#endif - -// uncomment this to use debug pins other than 31/30 -//#define SEPARATE_DEBUG_PINS - -#ifdef SEPARATE_DEBUG_PINS -#define DEBUG_RX 9 -#define DEBUG_TX 8 -#else -#define DEBUG_RX 31 -#define DEBUG_TX 30 -#endif - -#define PING_PIN 10 - -#define DEBUG - -fdserial *debug; - -int wheelLeft; -int wheelRight; - -void init_robot(void); -int process_robot_command(int whichWay); -void set_robot_speed(int left, int right); - -#define LONG_REPLY "This is a very long reply that should be broken into multiple chunks to test REPLY followed by SEND.\r\n" - -void handleEvent(wifi *esp, char type, char handle, int arg); - -int main(void) -{ - int listenHandle; - wifi *esp; - - // Close default same-cog terminal - simpleterm_close(); - - esp = wifi_open(WIFI_RX, WIFI_TX); -#ifdef SEPARATE_DEBUG_PINS - debug = fdserial_open(DEBUG_RX, DEBUG_TX, 0, 115200); -#else - debug = esp->port; -#endif - - dbg("\n\nRobot Firmware 2.0\n"); - - init_robot(); - - wifi_setInteger(esp, "cmd-events", 1); - wifi_listen(esp, "HTTP", "/robot*", &listenHandle); - - for (;;) { - int handle, arg; - char type; - - if (wifi_checkForEvent(esp, &type, &handle, &arg) > 0) { - dbg("Got event %c: handle %d, arg %d\n", type, handle, arg); - handleEvent(esp, type, handle, arg); - } - } - - return 0; -} - -void handleEvent(wifi *esp, char type, char handle, int arg) -{ - char url[128], buf[128]; - - switch (type) { - case 'P': - wifi_path(esp, handle, url, sizeof(url)); - dbg("%d: path '%s'\n", handle, url); - if (strcmp(url, "/robot") == 0) { - wifi_arg(esp, handle, "gto", buf, sizeof(buf)); - dbg("gto='%s'\n", buf); - if (process_robot_command(buf[0]) != 0) - dbg("Unknown robot command: '%c'\n", buf[0]); - wifi_reply(esp, handle, 200, ""); - } - else { - dbg("Unknown POST URL\n"); - wifi_reply(esp, handle, 404, "unknown"); - } - break; - case 'G': - wifi_path(esp, handle, url, sizeof(url)); - dbg("%d: path '%s'\n", handle, url); - if (strcmp(url, "/robot-ping") == 0) { - sprinti(buf, "%d", ping_cm(PING_PIN)); - wifi_reply(esp, handle, 200, buf); - } - else if (strcmp(url, "/robot-test") == 0) { - wifi_reply(esp, handle, 200, LONG_REPLY); - } - else { - dbg("Unknown GET URL\n"); - wifi_reply(esp, handle, 404, "unknown"); - } - break; - case 'S': - dbg("%d: send complete\n", handle); - break; - case 'X': - dbg("%d: disconnected\n", handle); - break; - case 'E': - dbg("%d: connection failed: %d\n", handle, arg); - break; - default: - dbg("unknown event: '%c' 0x%02x\n", type, type); - break; - } -} - -void init_robot(void) -{ - wheelLeft = wheelRight = 0; - high(26); - set_robot_speed(wheelLeft, wheelRight); -} - -int process_robot_command(int whichWay) -{ - toggle(26); - - switch (whichWay) { - - case 'F': // forward - #ifdef DEBUG - dbg("Forward\n"); - #endif - if (wheelLeft > wheelRight) - wheelRight = wheelLeft; - else if (wheelLeft < wheelRight) - wheelLeft = wheelRight; - else { - wheelLeft = wheelLeft + 32; - wheelRight = wheelRight + 32; - } - break; - - case 'R': // right - #ifdef DEBUG - dbg("Right\n"); - #endif - wheelLeft = wheelLeft + 16; - wheelRight = wheelRight - 16; - break; - - case 'L': // left - #ifdef DEBUG - dbg("Left\n"); - #endif - wheelLeft = wheelLeft - 16; - wheelRight = wheelRight + 16; - break; - - case 'B': // reverse - #ifdef DEBUG - dbg("Reverse\n"); - #endif - if(wheelLeft < wheelRight) - wheelRight = wheelLeft; - else if (wheelLeft > wheelRight) - wheelLeft = wheelRight; - else { - wheelLeft = wheelLeft - 32; - wheelRight = wheelRight - 32; - } - break; - - case 'S': // stop - #ifdef DEBUG - dbg("Stop\n"); - #endif - wheelLeft = 0; - wheelRight = 0; - break; - - default: // unknown request - return -1; - } - - if (wheelLeft > 128) wheelLeft = 128; - if (wheelLeft < -128) wheelLeft = -128; - if (wheelRight > 128) wheelRight = 128; - if (wheelRight < -128) wheelRight = -128; - - set_robot_speed(wheelLeft, wheelRight); - - return 0; -} - -void set_robot_speed(int left, int right) -{ - #ifdef DEBUG - dbg("L %d, R %d\n", wheelLeft, wheelRight); - #endif - - wheelLeft = left; - wheelRight = right; - drive_speed(wheelLeft, wheelRight); -} diff --git a/samples/robot.html b/samples/robot.html deleted file mode 100644 index a4820db..0000000 --- a/samples/robot.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - -
- - Hi! I'm ActivityBot :) -
- Forward
- LeftStopRight
- Reverse - -

- PING))) Distance:
-

(waiting)
-

-
-
- - diff --git a/samples/robot.side b/samples/robot.side deleted file mode 100644 index 1e835e9..0000000 --- a/samples/robot.side +++ /dev/null @@ -1,10 +0,0 @@ -robot.c -cmd.c ->compiler=C ->memtype=cmm main ram compact ->optimize=-Os ->-m32bit-doubles ->-fno-exceptions ->defs::-std=c99 ->-lm ->BOARD::ACTIVITYBOARD diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index a1e24a2..0000000 --- a/tests/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -$(info HOME $(HOME)) - -TARGET=robot.elf - -all: robot.elf blink.elf robot-ws.elf tcp-test.elf ifttt.elf test.elf - -CFLAGS=-mcmm -Os -Wall -m32bit-doubles -I $(HOME)/simple/include -L $(HOME)/simple/lib - -%.elf: %.c cmd.o - propeller-elf-gcc $(CFLAGS) -o $@ $< cmd.o -lsimple-cmm -lm - -%.o: %.c - propeller-elf-gcc -c $(CFLAGS) -o $@ $< - -run: $(TARGET) - proploader $< -t - -clean: - rm -f *.o *.elf diff --git a/tests/blink.c b/tests/blink.c deleted file mode 100644 index 948f62a..0000000 --- a/tests/blink.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "simpletools.h" -#include "cmd.h" - -// uncomment this if the wifi module is on pins other than 31/30 -//#define SEPARATE_WIFI_PINS - -#ifdef SEPARATE_WIFI_PINS -#define WIFI_RX 9 -#define WIFI_TX 8 -#else -#define WIFI_RX 31 -#define WIFI_TX 30 -#endif - -int main(void) -{ - int blink = 0; - - cmd_init(WIFI_RX, WIFI_TX, 31, 30); - - pause(500); - - int value; - request("CHECK:pin-gpio15"); - waitFor(CMD_START "=S,^i\r", &value); - dprint(debug, "value = %d\n", value); - - for (;;) { - waitcnt(CNT + CLKFREQ/2); - request("SET:pin-gpio15,%d", blink); - waitFor(CMD_START "=S,0\r"); - blink = !blink; - } - - return 0; -} diff --git a/tests/blink.side b/tests/blink.side deleted file mode 100644 index 8dcbc53..0000000 --- a/tests/blink.side +++ /dev/null @@ -1,10 +0,0 @@ -blink.c -cmd.c ->compiler=C ->memtype=cmm main ram compact ->optimize=-Os ->-m32bit-doubles ->-fno-exceptions ->defs::-std=c99 ->-lm ->BOARD::ACTIVITYBOARD diff --git a/tests/cmd.c b/tests/cmd.c deleted file mode 100644 index 69b0dc8..0000000 --- a/tests/cmd.c +++ /dev/null @@ -1,255 +0,0 @@ -#include "simpletools.h" -#include "fdserial.h" -#include "cmd.h" - -fdserial *wifi; -fdserial *debug; - -void cmd_init(int wifi_rx, int wifi_tx, int debug_rx, int debug_tx) -{ - // Close default same-cog terminal - simpleterm_close(); - - // Set to open collector instead of driven - wifi = fdserial_open(wifi_rx, wifi_tx, 0b0100, 115200); - - // Generate a BREAK to enter CMD command mode - pause(10); - low(wifi_tx); - pause(1); - input(wifi_tx); - pause(1); - - if (debug_tx != -1 && wifi_tx != debug_tx) - debug = fdserial_open(debug_rx, debug_tx, 0, 115200); - else - debug = wifi; -} - -void request(char *fmt, ...) -{ - char buf[100], *p = buf; - - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - - fdserial_txChar(wifi, CMD_START_BYTE); - while (*p != '\0') - fdserial_txChar(wifi, *p++); - fdserial_txChar(wifi, CMD_END_BYTE); -} - -void requestPayload(char *buf, int len) -{ - while (--len >= 0) - fdserial_txChar(wifi, *buf++); -} - -#define CHUNK_SIZE 8 - -static int reply1(int chan, int code, char *payload) -{ - int payloadLength = (payload ? strlen(payload) : 0); - char result; - int count; - - if (payloadLength == 0) { -dprint(debug, "REPLY %d, %d\n", chan, code); - request("REPLY:%d,%d", chan, code); - } - - else { - int remaining = payloadLength; - while (remaining > 0) { - if ((count = remaining) > CHUNK_SIZE) - count = CHUNK_SIZE; - if (remaining == payloadLength) { -dprint(debug, "REPLY %d, %d, %d, %d\n", chan, code, payloadLength, count); - request("REPLY:%d,%d,%d,%d", chan, code, payloadLength, count); - requestPayload(payload, count); - } - else { -dprint(debug, "SEND %d, %d\n", chan, count); - request("SEND:%d,%d", chan, count); - requestPayload(payload, count); - } - payload += count; - remaining -= count; - if (remaining > 0) { - waitFor(CMD_START "=^c,^d\r", &result, &count); -dprint(debug, " ret %c %d\n", result, count); - if (result != 'S') { -dprint(debug, " failed with %d\n", count); - return count; - } - } - } - } - - waitFor(CMD_START "=^c,^d\r", &result, &count); -dprint(debug, " final ret %c %d\n", result, count); - - return payloadLength; -} - -int reply(int chan, int code, char *payload) -{ - int ret = reply1(chan, code, payload); - dprint(debug, "ret: %d\n", ret); - return ret; -} - -typedef struct { - int savedChar; -} State; - -static int nextchar(State *state) -{ - int ch; - if ((ch = state->savedChar) != EOF) - state->savedChar = EOF; - else - ch = fdserial_rxChar(wifi); - return ch; -} - -static void ungetchar(State *state, int ch) -{ - state->savedChar = ch; -} - -int waitFor(char *fmt, ...) -{ - State state = { .savedChar = EOF }; - int ch, rch, len, i; - char *p = fmt; - char buf[100]; - int ret = -1; - - len = 0; - while (*p != '\0' && *p != '^') { - ++len; - ++p; - } - - if (len > sizeof(buf)) - return -1; - - for (i = 0; i < len; ++i) { - if ((rch = nextchar(&state)) == EOF) - return -1; - buf[i] = rch; - } - - while (strncmp(fmt, buf, len) != 0) { - memcpy(buf, &buf[1], len - 1); - if ((rch = nextchar(&state)) == EOF) - return -1; - buf[len - 1] = rch; - } - - va_list ap; - va_start(ap, fmt); - - while ((ch = *p++) != '\0') { - - rch = nextchar(&state); - - if (ch == '^') { - switch (*p++) { - case 'c': - if (rch == EOF) - goto done; - *va_arg(ap, char *) = rch; - break; - case 'i': - { - int value = 0; - int sign = 1; - if (rch == EOF) - goto done; - if (rch == '-') { - if ((rch = nextchar(&state)) == EOF) - goto done; - sign = -1; - } - if (!isdigit(rch)) - goto done; - do { - value = value * 10 + rch - '0'; - } while ((rch = nextchar(&state)) != EOF && isdigit(rch)); - *va_arg(ap, int *) = value * sign; - ungetchar(&state, rch); - } - break; - case 's': - { - int term = *p; - char *buf = va_arg(ap, char *); - int len = va_arg(ap, int); - while (rch != EOF && rch != term) { - if (len > 1) { - *buf++ = rch; - --len; - } - rch = nextchar(&state); - } - *buf = '\0'; - ungetchar(&state, rch); - } - break; - case '^': - if (rch != '^') - goto done; - break; - case '\0': - // fall through - default: - goto done; - } - } - - else { - if (rch != ch) - goto done; - } - } - - ret = 0; - -done: - va_end(ap); - - return ret; -} - -void collectUntil(int term, char *buf, int size) -{ - int ch, i; - i = 0; - while ((ch = fdserial_rxChar(wifi)) != EOF && ch != term) { - if (i < size - 1) - buf[i++] = ch; - } - buf[i] = '\0'; -} - -void collectPayload(char *buf, int bufSize, int count) -{ - while (--count >= 0) { - int ch = fdserial_rxChar(wifi); - if (bufSize > 0) { - *buf++ = ch; - --bufSize; - } - } -} - -void skipUntil(int term) -{ - int ch; - while ((ch = fdserial_rxChar(wifi)) != EOF && ch != term) - ; -} diff --git a/tests/cmd.h b/tests/cmd.h deleted file mode 100644 index 83d5b0f..0000000 --- a/tests/cmd.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef __CMD_H__ -#define __CMD_H__ - -#include "fdserial.h" - -#define CMD_START_BYTE 0xFE -#define CMD_END_BYTE '\r' - -#define CMD_START "\xFE" -#define CMD_INT8 "\xFD" -#define CMD_UINT8 "\xFC" -#define CMD_INT16 "\xFB" -#define CMD_UINT16 "\xFA" -#define CMD_INT32 "\xF9" -#define CMD_UINT32 "\xF8" - -#define CMD_HTTP "\xF7" -#define CMD_WS "\xF6" -#define CMD_TCP "\xF5" -#define CMD_STA "\xF4" -#define CMD_AP "\xF3" -#define CMD_STA_AP "\xF2" - -#define CMD_JOIN "\xEF" -#define CMD_CHECK "\xEE" -#define CMD_SET "\xED" -#define CMD_POLL "\xEC" -#define CMD_PATH "\xEB" -#define CMD_SEND "\xEA" -#define CMD_RECV "\xE9" -#define CMD_CLOSE "\xE8" -#define CMD_LISTEN "\xE7" -#define CMD_ARG "\xE6" -#define CMD_REPLY "\xE5" -#define CMD_CONNECT "\xE4" - -#define CMD_END "\r" - -extern fdserial *wifi; -extern fdserial *debug; - -void cmd_init(int wifi_rx, int wifi_tx, int debug_rx, int debug_tx); -void request(char *fmt, ...); -void requestPayload(char *buf, int len); -int reply(int chan, int code, char *payload); -int waitFor(char *fmt, ...); -void collectUntil(int term, char *buf, int size); -void collectPayload(char *buf, int bufSize, int count); -void skipUntil(int term); - -#endif diff --git a/tests/ifttt.c b/tests/ifttt.c deleted file mode 100644 index a0e9f81..0000000 --- a/tests/ifttt.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - TCP test program -*/ -#include "simpletools.h" -#include "fdserial.h" -#include "cmd.h" - -//#define IfTTT_KEY "YOUR_API_KEY" -#define IfTTT_KEY "csY3T4PPMydBKXuaDVi72j" - -// uncomment this if the wifi module is on pins other than 31/30 -//#define SEPARATE_WIFI_PINS - -#ifdef SEPARATE_WIFI_PINS -#define WIFI_RX 9 -#define WIFI_TX 8 -#else -#define WIFI_RX 31 -#define WIFI_TX 30 -#endif - -int main(void) -{ - char buf[1000]; - int type, handle; - - cmd_init(WIFI_RX, WIFI_TX, 31, 30); - - request("CONNECT:maker.ifttt.com,80"); - waitFor(CMD_START "=^c,^i\r", &type, &handle); - dprint(debug, "Connect returned '%c,%d'\n", type, handle); - - if (type == 'S') { - dprint(debug, "Connected on handle %d\n", handle); - -#define REQ "\ -POST /trigger/post_tweet/with/key/" IfTTT_KEY " HTTP/1.1\r\n\ -Host: maker.ifttt.com\r\n\ -Connection: keep-alive\r\n\ -Accept: */*\r\n\ -\r\n" - - request("SEND:%d,%d", handle, strlen(REQ)); - requestPayload(REQ, strlen(REQ)); - waitFor(CMD_START "=^s\r", buf, sizeof(buf)); - dprint(debug, "Send returned '%s'\n", buf); - - if (buf[0] == 'S') { - int retries = 10; - while (--retries >= 0) { - int count, i; - - request("RECV:%d,%d", handle, sizeof(buf)); - waitFor(CMD_START "=^c,^i\r", &type, &count); - collectPayload(buf, sizeof(buf), count); - if (count >= sizeof(buf)) - count = sizeof(buf) - 1; - buf[count] = '\0'; - dprint(debug, "Recv returned '%c,%d'\n", type, count); - for (i = 0; i < count; ++i) - dprint(debug, "%c", buf[i]); - dprint(debug, "[EOF]\n"); - - if (type == 'S') - break; - - waitcnt(CNT + CLKFREQ/4); - } - } - - request("CLOSE:%d", handle); - waitFor(CMD_START "=^s\r", buf, sizeof(buf)); - dprint(debug, "Disconnect returned '%s'\n", buf); - } - - dprint(debug, "Done!\n"); - - return 0; -} diff --git a/tests/ifttt.side b/tests/ifttt.side deleted file mode 100644 index bec3584..0000000 --- a/tests/ifttt.side +++ /dev/null @@ -1,10 +0,0 @@ -ifttt.c -cmd.c ->compiler=C ->memtype=cmm main ram compact ->optimize=-Os ->-m32bit-doubles ->-fno-exceptions ->defs::-std=c99 ->-lm ->BOARD::ACTIVITYBOARD diff --git a/tests/robot-ws.c b/tests/robot-ws.c deleted file mode 100644 index 8899cb4..0000000 --- a/tests/robot-ws.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - Robot test program -*/ -#include -#include "simpletools.h" -#include "abdrive.h" -#include "ping.h" -#include "cmd.h" - -// uncomment this if the wifi module is on pins other than 31/30 -//#define SEPARATE_WIFI_PINS - -#ifdef SEPARATE_WIFI_PINS -#define WIFI_RX 9 -#define WIFI_TX 8 -#else -#define WIFI_RX 31 -#define WIFI_TX 30 -#endif - -#define PING_PIN 10 - -#define DEBUG - -int wheelLeft; -int wheelRight; - -void init_robot(void); -int process_robot_command(int whichWay); -void set_robot_speed(int left, int right); - -int main(void) -{ - int pingHandle = 0; - int lastPingDistance = -1; - int handle; - - cmd_init(WIFI_RX, WIFI_TX, 31, 30); - - init_robot(); - - request("SET:cmd-pause-time,5"); - waitFor(CMD_START "=S,0\r"); - - request("LISTEN:WS,/ws/robot"); - waitFor(CMD_START "=S,^d\r", &handle); - - for (;;) { - char url[128], arg[128]; - int type, handle, listener, count, pingDistance; - char result; - - waitcnt(CNT + CLKFREQ/4); - - request("POLL"); - waitFor(CMD_START "=^c,^i,^i\r", &type, &handle, &listener); - if (type != 'N') - dprint(debug, "Got %c: handle %d, listener %d\n", type, handle, listener); - - switch (type) { - case 'W': - request("PATH:%d", handle); - waitFor(CMD_START "=S,^s\r", url, sizeof(url)); - dprint(debug, "%d: path '%s'\n", handle, url); - pingHandle = handle; - break; - case 'D': - request("RECV:%d,%d", handle, sizeof(arg)); - waitFor(CMD_START "=S,^i\r", &count); - collectPayload(arg, sizeof(arg), count); - dprint(debug, "%d: PAYLOAD %d\n", pingHandle, count); - if (process_robot_command(arg[0]) != 0) - dprint(debug, "Unknown robot command: '%c'\n", arg[0]); - break; - case 'S': - dprint(debug, "Send completed\n"); - break; - case 'N': - break; - default: - dprint(debug, "unknown response: 0x%02x\n", type); - break; - } - - if (pingHandle > 0) { - if ((pingDistance = ping_cm(PING_PIN)) != lastPingDistance) { - char buf[128]; - dprint(debug, "New PING))) distance: %d\n", pingDistance); - lastPingDistance = pingDistance; - sprintf(buf, "%d", pingDistance); - request("SEND:%d,%d", pingHandle, strlen(buf)); - requestPayload(buf, strlen(buf)); - waitFor(CMD_START "=^c,^i\r", &result, &count); - dprint(debug, " got %c %d\n", result, count); - } - } - } - - return 0; -} - -void init_robot(void) -{ - wheelLeft = wheelRight = 0; - high(26); - set_robot_speed(wheelLeft, wheelRight); -} - -int process_robot_command(int whichWay) -{ - toggle(26); - - switch (whichWay) { - - case 'F': // forward - #ifdef DEBUG - dprint(debug, "Forward\n"); - #endif - if (wheelLeft > wheelRight) - wheelRight = wheelLeft; - else if (wheelLeft < wheelRight) - wheelLeft = wheelRight; - else { - wheelLeft = wheelLeft + 32; - wheelRight = wheelRight + 32; - } - break; - - case 'R': // right - #ifdef DEBUG - dprint(debug, "Right\n"); - #endif - wheelLeft = wheelLeft + 16; - wheelRight = wheelRight - 16; - break; - - case 'L': // left - #ifdef DEBUG - dprint(debug, "Left\n"); - #endif - wheelLeft = wheelLeft - 16; - wheelRight = wheelRight + 16; - break; - - case 'B': // reverse - #ifdef DEBUG - dprint(debug, "Reverse\n"); - #endif - if(wheelLeft < wheelRight) - wheelRight = wheelLeft; - else if (wheelLeft > wheelRight) - wheelLeft = wheelRight; - else { - wheelLeft = wheelLeft - 32; - wheelRight = wheelRight - 32; - } - break; - - case 'S': // stop - #ifdef DEBUG - dprint(debug, "Stop\n"); - #endif - wheelLeft = 0; - wheelRight = 0; - break; - - default: // unknown request - return -1; - } - - if (wheelLeft > 128) wheelLeft = 128; - if (wheelLeft < -128) wheelLeft = -128; - if (wheelRight > 128) wheelRight = 128; - if (wheelRight < -128) wheelRight = -128; - - set_robot_speed(wheelLeft, wheelRight); - - return 0; -} - -void set_robot_speed(int left, int right) -{ - #ifdef DEBUG - dprint(debug, "L %d, R %d\n", wheelLeft, wheelRight); - #endif - - wheelLeft = left; - wheelRight = right; - drive_speed(wheelLeft, wheelRight); -} diff --git a/tests/robot-ws.html b/tests/robot-ws.html deleted file mode 100644 index fdae5a6..0000000 --- a/tests/robot-ws.html +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - -
- - Hi! I'm WebSockets ActivityBot :) -
- Forward
- LeftStopRight
- Reverse - -

- PING))) Distance:
-

(waiting)
-

-
-
-
- - diff --git a/tests/robot-ws.side b/tests/robot-ws.side deleted file mode 100644 index f994e54..0000000 --- a/tests/robot-ws.side +++ /dev/null @@ -1,10 +0,0 @@ -robot-ws.c -cmd.c ->compiler=C ->memtype=cmm main ram compact ->optimize=-Os ->-m32bit-doubles ->-fno-exceptions ->defs::-std=c99 ->-lm ->BOARD::ACTIVITYBOARD diff --git a/tests/robot.c b/tests/robot.c deleted file mode 100644 index aa169c9..0000000 --- a/tests/robot.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - Robot test program -*/ -#include "simpletools.h" -#include "abdrive.h" -#include "ping.h" -#include "cmd.h" - -// uncomment this if the wifi module is on pins other than 31/30 -//#define SEPARATE_WIFI_PINS - -#ifdef SEPARATE_WIFI_PINS -#define WIFI_RX 9 -#define WIFI_TX 8 -#else -#define WIFI_RX 31 -#define WIFI_TX 30 -#endif - -#define PING_PIN 10 - -#define DEBUG - -int wheelLeft; -int wheelRight; - -void init_robot(void); -int process_robot_command(int whichWay); -void set_robot_speed(int left, int right); - -#define LONG_REPLY "This is a very long reply that should be broken into multiple chunks to test REPLY followed by SEND.\r\n" - -int main(void) -{ - int listenHandle; - - cmd_init(WIFI_RX, WIFI_TX, 31, 30); - - init_robot(); - -// request("SET:cmd-pause-time,5"); - request(CMD_SET "cmd-pause-time,5" CMD_END); - waitFor(CMD_START "=S,0\r"); - - request("LISTEN:HTTP,/robot*"); - waitFor(CMD_START "=S,^d\r", &listenHandle); - - for (;;) { - char url[128], arg[128]; - int type, handle, listener; - - waitcnt(CNT + CLKFREQ/4); - - request("POLL"); - waitFor(CMD_START "=^c,^i,^i\r", &type, &handle, &listener); - if (type != 'N') - dprint(debug, "Got %c: handle %d, listener %d\n", type, handle, listener); - - switch (type) { - case 'P': - request("PATH:%d", handle); - waitFor(CMD_START "=S,^s\r", url, sizeof(url)); - dprint(debug, "%d: path '%s'\n", handle, url); - if (strcmp(url, "/robot") == 0) { - request("ARG:%d,gto", handle); - waitFor(CMD_START "=S,^s\r", arg, sizeof(arg)); - dprint(debug, "gto='%s'\n", arg); - if (process_robot_command(arg[0]) != 0) - dprint(debug, "Unknown robot command: '%c'\n", arg[0]); - reply(handle, 200, ""); - } - else { - dprint(debug, "Unknown POST URL\n"); - reply(handle, 404, "unknown"); - } - break; - case 'G': - request("PATH:%d", handle); - waitFor(CMD_START "=S,^s\r", url, sizeof(url)); - dprint(debug, "%d: path '%s'\n", handle, url); - if (strcmp(url, "/robot-ping") == 0) { - sprintf(arg, "%d", ping_cm(PING_PIN)); - reply(handle, 200, arg); - } - else if (strcmp(url, "/robot-test") == 0) { - reply(handle, 200, LONG_REPLY); - } - else { - dprint(debug, "Unknown GET URL\n"); - reply(handle, 404, "unknown"); - } - break; - case 'S': - dprint(debug, "Send completed\n"); - break; - case 'N': - break; - default: - dprint(debug, "unknown response: '%c' 0x%02x\n", type, type); - break; - } - } - - return 0; -} - -void init_robot(void) -{ - wheelLeft = wheelRight = 0; - high(26); - set_robot_speed(wheelLeft, wheelRight); -} - -int process_robot_command(int whichWay) -{ - toggle(26); - - switch (whichWay) { - - case 'F': // forward - #ifdef DEBUG - dprint(debug, "Forward\n"); - #endif - if (wheelLeft > wheelRight) - wheelRight = wheelLeft; - else if (wheelLeft < wheelRight) - wheelLeft = wheelRight; - else { - wheelLeft = wheelLeft + 32; - wheelRight = wheelRight + 32; - } - break; - - case 'R': // right - #ifdef DEBUG - dprint(debug, "Right\n"); - #endif - wheelLeft = wheelLeft + 16; - wheelRight = wheelRight - 16; - break; - - case 'L': // left - #ifdef DEBUG - dprint(debug, "Left\n"); - #endif - wheelLeft = wheelLeft - 16; - wheelRight = wheelRight + 16; - break; - - case 'B': // reverse - #ifdef DEBUG - dprint(debug, "Reverse\n"); - #endif - if(wheelLeft < wheelRight) - wheelRight = wheelLeft; - else if (wheelLeft > wheelRight) - wheelLeft = wheelRight; - else { - wheelLeft = wheelLeft - 32; - wheelRight = wheelRight - 32; - } - break; - - case 'S': // stop - #ifdef DEBUG - dprint(debug, "Stop\n"); - #endif - wheelLeft = 0; - wheelRight = 0; - break; - - default: // unknown request - return -1; - } - - if (wheelLeft > 128) wheelLeft = 128; - if (wheelLeft < -128) wheelLeft = -128; - if (wheelRight > 128) wheelRight = 128; - if (wheelRight < -128) wheelRight = -128; - - set_robot_speed(wheelLeft, wheelRight); - - return 0; -} - -void set_robot_speed(int left, int right) -{ - #ifdef DEBUG - dprint(debug, "L %d, R %d\n", wheelLeft, wheelRight); - #endif - - wheelLeft = left; - wheelRight = right; - drive_speed(wheelLeft, wheelRight); -} diff --git a/tests/robot.html b/tests/robot.html deleted file mode 100644 index a4820db..0000000 --- a/tests/robot.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - -
- - Hi! I'm ActivityBot :) -
- Forward
- LeftStopRight
- Reverse - -

- PING))) Distance:
-

(waiting)
-

-
-
- - diff --git a/tests/robot.pbas b/tests/robot.pbas deleted file mode 100644 index a2a9551..0000000 --- a/tests/robot.pbas +++ /dev/null @@ -1,200 +0,0 @@ -' {$STAMP BS2} -' {$PBASIC 2.5} - -opIdx VAR Nib - -status VAR Byte -op VAR Byte -chan VAR Byte -string VAR Byte(12) -path VAR string -dist VAR Word -btn VAR Byte -speedLeft VAR Word -speedRight VAR Word -chars VAR Byte -flags VAR Nib - -GOSUB Setup - -DO - GOSUB Poll_for_Op - IF op = "P" THEN - GOSUB Process_gto_Post - DEBUG "btn = ", btn, CR - SELECT btn - CASE "F" - speedLeft = speedLeft + 20 - speedRight = speedRight + 20 - CASE "B" - speedLeft = speedLeft - 20 - speedRight = speedRight - 20 - CASE "L" - speedLeft = speedLeft - 20 - speedRight = speedRight + 20 - CASE "R" - speedLeft = speedLeft + 20 - speedRight = speedRight - 20 - CASE "S" - speedLeft = 0 - speedRight = 0 - ENDSELECT - - ' Keep it postive! - speedLeft = speedLeft + 1000 - speedLeft = speedLeft MIN 900 MAX 1100 - speedLeft = speedLeft - 1000 - - speedRight = speedRight + 1000 - speedRight = speedRight MIN 900 MAX 1100 - speedRight = speedRight - 1000 - - ELSEIF op = "G" THEN - GOSUB Reply_to_ping_GET - ENDIF - PAUSE 500 - PULSOUT 15, 750 + speedLeft - PULSOUT 13, 750 - speedRight - -LOOP - -Ping: - PULSOUT 9, 1 - PULSIN 9, 1, dist - dist = dist / 26 - RETURN - -Setup: - RetPt0: - opIdx = 0 - - HIGH 2 - PAUSE 10 - LOW 2 - PAUSE 10 - HIGH 2 - PAUSE 1 - - status = "N" - - DO - DEBUG $FE, "SET,cmd-pause-time,0", CR - SEROUT 2, 188, [$FE, "SET:cmd-pause-time,5", CR] - 'Success reply: þ=S,0 - 'SERIN 4, 188, 250, Timeout, [STR path\12\CR] - 'DEBUG "str = ", STR path, CR - - 'Working code - SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), status, SKIP 1, op] - DEBUG "status = ", status, ", op = ", op, CR - - 'Do we want any of these to work? - 'SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), status, SKIP(1), op, WAIT(CR)] - 'SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), status, WAIT(","), op, WAIT(CR)] - 'DEBUG "status = ", status, ", op = ", op, CR - PAUSE 20 - LOOP UNTIL status = "S" - 'POST /wifi/setmode.cgi?mode=mode - - status = "N" - - DO - DEBUG $FE, $FE, "SET:wifi-mode,3", CR - SEROUT 2, 188, [$FE, "SET:wifi-mode,3", CR] - SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), status, SKIP 1, op] - DEBUG "status = ", status, ", op = ", op, CR - PAUSE 20 - LOOP UNTIL status = "S" - - status = "N" - - DO - DEBUG $FE, "LISTEN,0,/robot*", CR - SEROUT 2, 188, [$FE, "LISTEN:0,/robot*", CR] - SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), status, SKIP 1, op] - DEBUG "status = ", status, ", op = ", op, CR - 'SERIN 4, 188, 250, Timeout, [STR path\12\CR] - 'DEBUG "str = ", STR path, CR - PAUSE 20 - LOOP UNTIL status = "S" - - RETURN - -Poll_for_Op: - 'op = "N" - RetPt1: - opIdx = 1 - DEBUG $FE, "POLL", CR - 'þPOLL - 'str = þ=P,1,5 - 'IF flags = 1 THEN - ' SEROUT 2, 188, [$FE, "POLL", CR] - ' SERIN 4, 188, 250, Timeout, [STR path\12\CR] - ' DEBUG "WARNING flags = 1", CR - ' DEBUG "str = ", STR path, CR - ' flags = 0 - 'ELSE - SEROUT 2, 188, [$FE, "POLL", CR] - SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), op, - SKIP(1), chan, - SKIP(1), chars] - DEBUG "op = ", op, ", chan = ", chan, ", chars = ", chars, CR - flags = 1 - 'ENDIF - - - IF op = "G" OR op = "P" THEN - SEROUT 2, 188, [$FE, "PATH:", chan, CR] - 'SERIN 4, 188, 250, Timeout, [STR path\12\CR] - 'DEBUG "str = ", STR path, CR - SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), status, - SKIP(1), STR path\12\CR] - DEBUG "success = ", status, ", path = ", STR path, CR - ENDIF - - 'SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), op, - ' SKIP(1), chan, - ' SKIP(1), chars] - ' - - 'SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), success, - ' SKIP(1), chan, - ' SKIP(1), STR path\12\CR] - 'debug "op = ", op, ", chan = ", chan, ", path = ", STR string, CR - RETURN - -Process_gto_POST: - RetPt2: - opIdx = 2 - IF(path(1) = "r" AND path(7) <> "p") THEN - SEROUT 2, 188, [$FE, "POSTARG:", chan, ",gto", CR] - SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), STR path\12\CR] - IF(path(2) <> 0) THEN btn = path(2) ELSE btn = 0 - 'debug "gto string1: ", STR string, CR - SEROUT 2, 188, [$FE, "REPLY:", chan, ",200,", "2", CR, "OK"] - 'SEROUT 2, 188, ["OK"] - SERIN 4, 188, 250, Timeout, [WAIT($FE, "="), STR path\12\CR] - 'debug "gto string3: ", STR string, CR - ENDIF - RETURN - -Reply_to_ping_GET: - RetPt3: - opIdx = 3 - IF(path(1) = "r" AND path(7) = "p") THEN - GOSUB Ping - SEROUT 2, 188, [$FE,"REPLY:", chan, ",200,", "3", CR] - SEROUT 2, 188, [DEC3 dist] - SERIN 4, 188, 250, Timeout, [STR path\12\CR] - 'debug "Ping reply string A: ", STR string, CR - ENDIF - RETURN - -Timeout: - DEBUG "Timeout occurred during operation ", DEC opIdx, CR - - 'IF opIdx = 2 THEN flags = 1 - - - ON opIdx GOTO RetPt0, RetPt1, RetPt2, RetPt3 - diff --git a/tests/robot.side b/tests/robot.side deleted file mode 100644 index 1e835e9..0000000 --- a/tests/robot.side +++ /dev/null @@ -1,10 +0,0 @@ -robot.c -cmd.c ->compiler=C ->memtype=cmm main ram compact ->optimize=-Os ->-m32bit-doubles ->-fno-exceptions ->defs::-std=c99 ->-lm ->BOARD::ACTIVITYBOARD diff --git a/tests/setup-wee.sh b/tests/setup-wee.sh deleted file mode 100755 index 3c9d850..0000000 --- a/tests/setup-wee.sh +++ /dev/null @@ -1,3 +0,0 @@ -curl -XPOST $1/wx/setting?name=reset-pin\&value=15 -#curl -XPOST $1/wx/setting?name=rx-pullup\&value=1 -curl -XPOST $1/wx/save-settings diff --git a/tests/tcp-test.c b/tests/tcp-test.c deleted file mode 100644 index bbaee10..0000000 --- a/tests/tcp-test.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - TCP test program -*/ -#include "simpletools.h" -#include "fdserial.h" -#include "cmd.h" - -// uncomment this if the wifi module is on pins other than 31/30 -//#define SEPARATE_WIFI_PINS - -#ifdef SEPARATE_WIFI_PINS -#define WIFI_RX 9 -#define WIFI_TX 8 -#else -#define WIFI_RX 31 -#define WIFI_TX 30 -#endif - -int main(void) -{ - char buf[1000]; - int type, handle; - - cmd_init(WIFI_RX, WIFI_TX, 31, 30); - - for (;;) { - - request("CONNECT:www-eng-x.llnl.gov,80"); - waitFor(CMD_START "=^c,^i\r", &type, &handle); - dprint(debug, "Connect returned '%c,%d'\n", type, handle); - - if (type == 'S') { - dprint(debug, "Connected on handle %d\n", handle); - -#define REQ "\ -GET /documents/a_document.txt HTTP/1.1\r\n\ -Host: www-eng-x.llnl.gov\r\n\ -\r\n" - - request("SEND:%d,%d", handle, strlen(REQ)); - requestPayload(REQ, strlen(REQ)); - waitFor(CMD_START "=^s\r", buf, sizeof(buf)); - dprint(debug, "Send returned '%s'\n", buf); - - if (buf[0] == 'S') { - int retries = 10; - while (--retries >= 0) { - int count, i; - - request("RECV:%d,%d", handle, sizeof(buf)); - waitFor(CMD_START "=^c,^i\r", &type, &count); - collectPayload(buf, sizeof(buf), count); - dprint(debug, "Recv returned '%c,%d'\n", type, count); - if (count >= sizeof(buf)) - count = sizeof(buf) - 1; - buf[count] = '\0'; - for (i = 0; i < count; ++i) - dprint(debug, "%c", buf[i]); - dprint(debug, "[EOF]\n"); - - if (type == 'S') - break; - - waitcnt(CNT + CLKFREQ/4); - } - } - - request("CLOSE:%d", handle); - waitFor(CMD_START "=^s\r", buf, sizeof(buf)); - dprint(debug, "Close returned '%s'\n", buf); - } - - waitcnt(CNT + CLKFREQ/4); - } - - dprint(debug, "Done!\n"); - - return 0; -} diff --git a/tests/tcp-test.side b/tests/tcp-test.side deleted file mode 100644 index 968e136..0000000 --- a/tests/tcp-test.side +++ /dev/null @@ -1,10 +0,0 @@ -tcp-test.c -cmd.c ->compiler=C ->memtype=cmm main ram compact ->optimize=-Os ->-m32bit-doubles ->-fno-exceptions ->defs::-std=c99 ->-lm ->BOARD::ACTIVITYBOARD diff --git a/tests/test.c b/tests/test.c deleted file mode 100644 index ed810b0..0000000 --- a/tests/test.c +++ /dev/null @@ -1,57 +0,0 @@ -#include "simpletools.h" -#include "cmd.h" - -// uncomment this if the wifi module is on pins other than 31/30 -//#define SEPARATE_WIFI_PINS - -#ifdef SEPARATE_WIFI_PINS -#define WIFI_RX 9 -#define WIFI_TX 8 -#else -#define WIFI_RX 31 -#define WIFI_TX 30 -#endif - -int main(void) -{ - int handle1, handle2, handle3, err, tries; - char result1, result2, result3; - char *cmd = CMD_LISTEN CMD_HTTP "/this\r"; - - cmd_init(WIFI_RX, WIFI_TX, 31, 30); - - tries = 3; - while (--tries >= 0) { - - request(cmd); - //request("LISTEN:HTTP,/this"); - waitFor(CMD_START "=^c,^i\r", &result1, &handle1); - dprint(debug, "'LISTEN:HTTP,/this' returned %c, %d\n", result1, handle1); - - request("LISTEN:HTTP,/that"); - waitFor(CMD_START "=^c,^i\r", &result2, &handle2); - dprint(debug, "'LISTEN:HTTP,/that' returned %c, %d\n", result2, handle2); - - request("LISTEN:HTTP,/trouble"); - waitFor(CMD_START "=^c,^i\r", &result3, &handle3); - dprint(debug, "'LISTEN:HTTP,/trouble' returned %c, %d\n", result3, handle3); - - if (result1 == 'S') { - request("CLOSE:%d", handle1); - waitFor(CMD_START "=^c,^i\r", &result1, &err); - dprint(debug, "'CLOSE:%d' returned %c, %d\n", handle1, result1, err); - } - - if (result2 == 'S') { - request("CLOSE:%d", handle2); - waitFor(CMD_START "=^c,^i\r", &result2, &err); - dprint(debug, "'CLOSE:%d' returned %c, %d\n", handle2, result2, err); - } - - if (result3 == 'S') { - dprint(debug, "Didn't expect to have to close handle3\n"); - } - } - - return 0; -} diff --git a/tests/test.side b/tests/test.side deleted file mode 100644 index cdc99b2..0000000 --- a/tests/test.side +++ /dev/null @@ -1,10 +0,0 @@ -test.c -cmd.c ->compiler=C ->memtype=cmm main ram compact ->optimize=-Os ->-m32bit-doubles ->-fno-exceptions ->defs::-std=c99 ->-lm ->BOARD::ACTIVITYBOARD