Skip to content

Commit

Permalink
fix: wrong va_arg read in printf
Browse files Browse the repository at this point in the history
  • Loading branch information
darlanalves committed Feb 24, 2024
1 parent 738b6a4 commit eebc5d4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 79 deletions.
19 changes: 2 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions src/include/vm_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -143,13 +140,18 @@ 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;
paused = false;

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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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];

Expand Down
63 changes: 7 additions & 56 deletions src/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -35,92 +35,44 @@ 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);
}

checkAgain();
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);
int i = 0;

if (strncmp(data, "GET", 3) == 0)
{
TRACE("Status\n");
espconn_send(conn, (uint8 *)httpOK, strlen(httpOK));
espconn_send(conn, "Status", strlen("Status"));
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;
}

Expand Down Expand Up @@ -178,7 +130,6 @@ void onDisconnect(void *arg)

void onReconnect(void *arg, int error)
{
TRACE("Reconnected after error %d\n", error);
checkAgain();
}

Expand Down
19 changes: 19 additions & 0 deletions test-remote.sh
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit eebc5d4

Please sign in to comment.