diff --git a/.gitignore b/.gitignore index a1bead5..69648d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.vscode -build \ No newline at end of file +build +.cache diff --git a/ground-station.py b/ground-station.py index 781c3de..a4b8933 100644 --- a/ground-station.py +++ b/ground-station.py @@ -183,9 +183,9 @@ async def new_client(clientId, ws): """handler for every new client connection""" client = { "id": clientId, "boat": None, "ws": ws, "state": "active" } if client['id'] == ADMIN_ID: - print("new client connected: admin") + print("INFO: new client connected: admin") else: - print("new client connected: " + client['id']) + print("INFO: new client connected: " + client['id']) for clie in Clients: if clie['id'] == client['id']: if client['state'] == "kicked": @@ -197,7 +197,7 @@ async def new_client(clientId, ws): async def new_boat(boatId, name, ws): """handler for every new boat connection""" boat = { "id": boatId, "name": name, "ws": ws, "state": BOAT_STATE_AVAILABLE, "lastMsg": 0, "log": [] } - print("new boat connected: " + boatId) + print("INFO: new boat connected: " + boatId) for i, bo in enumerate(Boats): if bo['id'] == boat['id']: bo['state'] = BOAT_STATE_TERMINATED @@ -210,6 +210,7 @@ async def run(ws, path): """hadeler for every new websocket connection""" client = None try: + print("INFO: new connection") async for msg in ws: for message in msg.split("\n"): if len(message) == 0: @@ -218,7 +219,6 @@ async def run(ws, path): if len(message) == 3 and message[1] == "4675": client = await new_client(message[0], ws) if client is not None: - try: async for msg in ws: for message in msg.split("\n"): @@ -235,7 +235,7 @@ async def run(ws, path): elif (len(message) == 3 and message[1] == "3440"): client = await new_boat(message[0], message[2], ws) if client is not None: - try: + try: async for msg in ws: for message in msg.split("\n"): if len(message) == 0: diff --git a/rx_esp32/.gitignore b/rx_esp32/.gitignore index 037978d..3c5adf3 100644 --- a/rx_esp32/.gitignore +++ b/rx_esp32/.gitignore @@ -10,3 +10,4 @@ build /sdkconfig /dependencies.lock /src/config.h +*.old diff --git a/rx_esp32/src/adc.c b/rx_esp32/src/adc.c index beb9ddb..55abfe8 100644 --- a/rx_esp32/src/adc.c +++ b/rx_esp32/src/adc.c @@ -29,7 +29,7 @@ void adc_init() adc_continuous_new_handle(&adc_config, &adc_handle); adc_continuous_config_t dig_cfg = { - .sample_freq_hz = 100 * 6, + .sample_freq_hz = 611, //100 * 6, .conv_mode = ADC_CONV_SINGLE_UNIT_1, .format = ADC_DIGI_OUTPUT_FORMAT_TYPE2, }; diff --git a/rx_esp32/src/main.c b/rx_esp32/src/main.c index 022f1c4..cd57db0 100644 --- a/rx_esp32/src/main.c +++ b/rx_esp32/src/main.c @@ -14,12 +14,12 @@ #include "utils.h" #include "commands.h" #include "wifi.h" -#include "led.h" #include "servos.h" #include "logger.h" #include "ws.h" #if TARGET == TARGET_TX -#include "adc.h" +#include "led.h" +// #include "adc.h" #endif bool volatile running = true; @@ -91,7 +91,7 @@ CLI_charOutFn charOut_ws[3] = { &charOut_ws0, &charOut_ws1, &charOut_ws2 -} +}; #endif void app_main() { @@ -117,7 +117,7 @@ void app_main() { wifiInit(); #if TARGET == TARGET_TX - adc_init(); + // adc_init(); #endif running = true; @@ -162,8 +162,10 @@ void app_main() { { #if TARGET == TARGET_TX led_setRGB(0, 20, 0); -#endif + MainState = STATE_WIFI_CONNECTED; +#elif TARGET == TARGET_RX MainState = STATE_WS_CONNECTING; +#endif LOG_I("main: connected to ap SSID '%s'", WIFI_SSID); } else if ((bits & WIFI_FAIL_BIT) != 0) @@ -178,7 +180,7 @@ void app_main() { else if (bits != 0) { #if TARGET == TARGET_TX - led_setRGB(2, 0, 0); + led_setRGB(20, 0, 0); #endif // MainState = STATE_WIFI_CONNECTING; LOG_C("main: UNEXPECTED EVENT (bits: 0x%04x)", bits); @@ -190,8 +192,9 @@ void app_main() { switch (WSStates[WS_conn_proc]) { case STATE_WS_CONNECTING: - ws_client[WS_conn_proc] = ws_connect(WS_URL); + ws_client[WS_conn_proc] = ws_connect(WS_URL, BoatId + WS_conn_proc, WS_DEV_CODE_CLIENT); WSStates[WS_conn_proc] = STATE_WS_WAIT_CONNECTION; + LOG_I("main: websocket %d: connecting", WS_conn_proc); break; case STATE_WS_WAIT_CONNECTION: if (ws_client[WS_conn_proc]->connected) @@ -199,6 +202,7 @@ void app_main() { cli_ws_client[WS_conn_proc] = CLI_init((CLI_charOutFn)&charOut_ws[WS_conn_proc], cmdList); cli_ws_client[WS_conn_proc].echo = false; MainState = STATE_IDEL; + LOG_I("main: websocket %d: connected", WS_conn_proc); } break; @@ -217,16 +221,21 @@ void app_main() { ws_sendData(ws_client[WS_conn_proc]); break; } + // WS_conn_proc++; + // if (WS_conn_proc >= 3) + // { + // WS_conn_proc = 0; + // } - ADC_Data_t data; - if (adc_read(&data)) - { - LOG_D("ADC_DATA: %d, %d, %d, %d, %d, %d", data.value[0], data.value[1], data.value[2], data.value[3], data.value[4], data.value[5]); - } + // ADC_Data_t data; + // if (adc_read(&data)) + // { + // LOG_D("ADC_DATA: %d, %d, %d, %d, %d, %d", data.value[0], data.value[1], data.value[2], data.value[3], data.value[4], data.value[5]); + // } break; #elif TARGET == TARGET_RX case STATE_WS_CONNECTING: - ws_client = ws_connect(WS_URL); + ws_client = ws_connect(WS_URL, BoatId, WS_DEV_CODE_BOAT); MainState = STATE_WS_WAIT_CONNECTION; break; case STATE_WS_WAIT_CONNECTION: diff --git a/rx_esp32/src/ws.c b/rx_esp32/src/ws.c index 76f4c3d..367b02b 100644 --- a/rx_esp32/src/ws.c +++ b/rx_esp32/src/ws.c @@ -19,8 +19,8 @@ static void ws_event_handler(void* handler_args, esp_event_base_t base, int32_t client->connected = true; char str[100]; - snprintf(&str[0], 100, "%04d;3440;" BOAT_NAME "\n", BoatId); - esp_websocket_client_send_text(client->handle, &str[0], strlen(str), 1000); + snprintf(&str[0], 100, "%04u;%04u;" BOAT_NAME "\n", client->id, client->dev_code); + esp_websocket_client_send_text(client->handle, &str[0], strlen(str), 1000); break; case WEBSOCKET_EVENT_DISCONNECTED: @@ -111,9 +111,11 @@ static void ws_event_handler(void* handler_args, esp_event_base_t base, int32_t } } -ws_client_t ws_connect(char *url) +ws_client_t ws_connect(char *url, uint16_t id, uint16_t dev_code) { ws_client_t client = malloc(sizeof(ws_client_data_t)); + client->id = id; + client->dev_code = dev_code; client->rxBuffer_rp = 0; client->rxBuffer_wp = 0; client->txBuffer_wp = 0; diff --git a/rx_esp32/src/ws.h b/rx_esp32/src/ws.h index a3504c1..5b6d8a3 100644 --- a/rx_esp32/src/ws.h +++ b/rx_esp32/src/ws.h @@ -7,6 +7,9 @@ #include "config.h" +#define WS_DEV_CODE_BOAT 3440 +#define WS_DEV_CODE_CLIENT 4675 + typedef struct { esp_websocket_client_handle_t handle; int connected; @@ -15,10 +18,12 @@ typedef struct { uint16_t rxBuffer_rp; unsigned char txBuffer[WS_TX_BUFFER_LEN]; uint16_t txBuffer_wp; + uint16_t id; + uint16_t dev_code; } ws_client_data_t; typedef ws_client_data_t* ws_client_t; -ws_client_t ws_connect(char *url); +ws_client_t ws_connect(char *url, uint16_t id, uint16_t dev_code); int ws_getchar(ws_client_t client); void ws_putchar(ws_client_t client, char c); void ws_sendData(ws_client_t client);