From 66f90cc011e8276108a3d8b4996291999d9770cd Mon Sep 17 00:00:00 2001 From: Darlan Alves Date: Sat, 24 Feb 2024 14:09:38 +0100 Subject: [PATCH] fix: wrong va_arg read in printf --- .github/workflows/main.yml | 19 ++---------- src/include/vm_types.hpp | 12 ++++---- src/index.cpp | 62 ++++---------------------------------- test-remote.sh | 19 ++++++++++++ 4 files changed, 33 insertions(+), 79 deletions(-) create mode 100644 test-remote.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ab5d246..e837ed2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -70,20 +70,5 @@ jobs: - name: Upload to ESP flash run: | set -e - curl -sS -X POST ${{ secrets.ESP_LIVE_URL }}/prepare - echo Upload - - ls firmware/ - - for i in $(ls firmware/ -1 | grep '0x'); do - curl -sS ${{ secrets.ESP_LIVE_URL }}/upload/$i --data-binary @firmware/$i; - done - - echo Flash - curl -sS -X POST ${{ secrets.ESP_LIVE_URL }}/flash - echo Reset - curl -sS -X POST ${{ secrets.ESP_LIVE_URL }}/reset - sleep 5 - echo Reconnect - curl -sS -X POST ${{ secrets.ESP_LIVE_URL }}/connect - echo Completed + export ESP_LIVE_URL="${{ secrets.ESP_LIVE_URL }}" + sh test-remote.sh \ No newline at end of file diff --git a/src/include/vm_types.hpp b/src/include/vm_types.hpp index b53fc77..cce9791 100644 --- a/src/include/vm_types.hpp +++ b/src/include/vm_types.hpp @@ -12,9 +12,6 @@ #define vt_signedInteger 6 #define vt_string 7 -static char *printBuffer = (char *)malloc(MAX_PRINT_BUFFER); -static int printBufferCursor = 0; - typedef unsigned char byte; typedef unsigned char *byteref; typedef unsigned int uint; @@ -143,6 +140,9 @@ class Program int callStack[MAX_STACK_SIZE]; int callStackPointer = MAX_STACK_SIZE - 1; + char printBuffer[MAX_PRINT_BUFFER]; + int printBufferCursor = 0; + void reset() { counter = 0; @@ -150,6 +150,8 @@ class Program os_memset(&interruptHandlers, 0, NUMBER_OF_PINS * sizeof(uint)); os_memset(&callStack, 0, MAX_STACK_SIZE * sizeof(int)); + os_memset(&printBuffer, 0, MAX_PRINT_BUFFER); + printBufferCursor = 0; } int callStackPush(int value) @@ -187,7 +189,7 @@ class Program { onSend(printBuffer, printBufferCursor); printBufferCursor = 0; - os_memset(printBuffer, 0, MAX_PRINT_BUFFER); + os_memset(&printBuffer, 0, MAX_PRINT_BUFFER); } void putchar(char c) @@ -217,8 +219,6 @@ class Program void printf(const char *format, va_list args) { - - char *s = va_arg(args, char *); char *p = (char *)format; char number[8]; diff --git a/src/index.cpp b/src/index.cpp index 1d4afba..81964a0 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -21,7 +21,7 @@ static Program program; static os_timer_t wifiTimer; static struct espconn *conn; -static const char *httpOK = "HTTP/1.1 200 OK\r\n\r\n\r\n"; +static const char *httpOK = "HTTP/1.1 200 OK\r\n\r\n"; static const char *httpNotOK = "HTTP/1.1 400 Bad payload\r\n\r\n"; static const char separator[4] = {0x0d, 0x0a, 0x0d, 0x0a}; @@ -35,22 +35,14 @@ void checkConnection(void *arg) { if (!wifi.isConnected()) { - TRACE("wifi off\n"); if (ESPCONN_CLOSE != conn->state) { espconn_disconnect(conn); } uint8 status = wifi_station_get_connect_status(); - if (status == STATION_WRONG_PASSWORD) - { - TRACE("wrong password\n"); - return; - } - if (status != STATION_CONNECTING) { - TRACE("connect to '%s'/'%s'\n", WIFI_SSID, WIFI_PASSWORD); wifi.connectTo(WIFI_SSID, WIFI_PASSWORD); } @@ -58,57 +50,15 @@ void checkConnection(void *arg) return; } + // todo will kill active connections if (conn->state != ESPCONN_LISTEN) { - TRACE("not started: %d\n", conn->state); espconn_accept(conn); - checkAgain(); - return; - } - - switch (conn->state) - { - case ESPCONN_NONE: - TRACE("Not started\n"); - break; - - case ESPCONN_WAIT: - TRACE("Waiting\n"); - break; - - case ESPCONN_LISTEN: - TRACE("Listening on %d\n", conn->proto.tcp->local_port); - break; - - case ESPCONN_CONNECT: - TRACE("Connecting\n"); - break; - - case ESPCONN_CLOSE: - TRACE("Closed\n"); - break; - - case ESPCONN_WRITE: - case ESPCONN_READ: - TRACE("Buffered\n"); - break; } - if (conn->state != ESPCONN_LISTEN) - { - checkAgain(); - } + checkAgain(); } -// void printBuffer(char *data, unsigned short length) -// { -// int i = 0; -// while (i < length) -// { -// TRACE("%02x ", data[i++]); -// } -// } - void onReceive(void *arg, char *data, unsigned short length) { TRACE("Received %d bytes\n", length); @@ -116,11 +66,12 @@ void onReceive(void *arg, char *data, unsigned short length) if (strncmp(data, "GET", 3) == 0) { - TRACE("Status\n"); espconn_send(conn, (uint8 *)httpOK, strlen(httpOK)); + espconn_regist_time(conn, 7199, 1); + espconn_tcp_set_max_con_allow(conn, 4); + program.flush(); // vm_systemInformation(&program); // vm_dump(&program); - // espconn_disconnect(conn); return; } @@ -178,7 +129,6 @@ void onDisconnect(void *arg) void onReconnect(void *arg, int error) { - TRACE("Reconnected after error %d\n", error); checkAgain(); } diff --git a/test-remote.sh b/test-remote.sh new file mode 100644 index 0000000..d4399b2 --- /dev/null +++ b/test-remote.sh @@ -0,0 +1,19 @@ +curl -sS -X POST $ESP_LIVE_URL/prepare +echo Upload +ls firmware/ + +for i in $(ls -1 firmware | grep '0x'); do + curl -sS $ESP_LIVE_URL/upload/$i --data-binary @firmware/$i; +done + +echo Flash +curl -sS -X POST $ESP_LIVE_URL/flash + +echo Reset +curl -sS -X POST $ESP_LIVE_URL/reset +sleep 5 + +echo Reconnect +curl -sS -X POST $ESP_LIVE_URL/connect + +echo Done. \ No newline at end of file