aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-10-29 12:26:46 +0200
committerlonkaars <loek@pipeframe.xyz>2022-10-29 12:26:46 +0200
commit7b4dbb553a4d22e88bafc38163d1b2f951c40fde (patch)
treea44931ef69de0c2fac265e32d953e88213b998e0
parentc429e17061d392ea4b3f73ebcc9101db8e491d8f (diff)
add bunch of unneccesary debug stuff, fix some stuff and expect espressif esp firmware
-rw-r--r--stm32f091/esp8266.c2
-rw-r--r--stm32f091/server.c92
-rw-r--r--stm32f091/setup.c6
-rw-r--r--stm32f091/util.h31
4 files changed, 89 insertions, 42 deletions
diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c
index b896567..159b55d 100644
--- a/stm32f091/esp8266.c
+++ b/stm32f091/esp8266.c
@@ -58,7 +58,7 @@ void ws_esp8266_send(uint8_t* data, size_t size) {
g_ws_esp8266_dma_tx_buffer[limited_size] = 0x00;
#ifdef WS_DBG_PRINT_ESP_OVER_USART2
- ws_dbg_set_usart2_tty_color(2);
+ ws_dbg_set_usart2_tty_color(WS_DBG_TTY_COLOR_TX);
HAL_UART_Transmit(&huart2, g_ws_esp8266_dma_tx_buffer, strlen((char*) g_ws_esp8266_dma_tx_buffer), 100);
#endif
diff --git a/stm32f091/server.c b/stm32f091/server.c
index 46d18f0..e0c97dc 100644
--- a/stm32f091/server.c
+++ b/stm32f091/server.c
@@ -49,7 +49,7 @@ void ws_server_req_finish(unsigned int channel, bool ignore) {
#define next_few_bytes_are(code) (((i + sizeof(code) - 2) < size) && (strncmp((char*)&data[i], code, sizeof(code) - 1) == 0))
void ws_server_req_incoming(uint8_t* data, size_t size) {
#ifdef WS_DBG_PRINT_ESP_OVER_USART2
- ws_dbg_set_usart2_tty_color(1);
+ ws_dbg_set_usart2_tty_color(WS_DBG_TTY_COLOR_RX);
HAL_UART_Transmit(&huart2, data, size, 100);
#endif
@@ -64,12 +64,19 @@ void ws_server_req_incoming(uint8_t* data, size_t size) {
case WS_SERVER_LM_STATUS_CODE: {
bool code_got = false;
if (next_few_bytes_are("OK")) {
+ i += 1;
code_got = true;
g_ws_server_parser.last_response = WS_SERVER_RC_OK;
- } else if (next_few_bytes_are("ERROR") || next_few_bytes_are("FAIL")) {
+ } else if (next_few_bytes_are("ERROR")) {
+ i += 4;
+ code_got = true;
+ g_ws_server_parser.last_response = WS_SERVER_RC_ERR;
+ } else if (next_few_bytes_are("FAIL")) {
+ i += 3;
code_got = true;
g_ws_server_parser.last_response = WS_SERVER_RC_ERR;
} else if (next_few_bytes_are("busy p...")) {
+ i += 8;
code_got = true;
g_ws_server_parser.last_response = WS_SERVER_RC_BUSY;
}
@@ -80,49 +87,49 @@ void ws_server_req_incoming(uint8_t* data, size_t size) {
if (next_few_bytes_are("+IPD,")) {
i += 4; // skip I, P, D, and comma
g_ws_server_parser.mode = WS_SERVER_LM_IPD_LISTENING;
- } else if (next_few_bytes_are("> ")) {
+ } else if (next_few_bytes_are(">")) { // ">" on official espressif firmware, "> " on ai-thinker firmware
g_ws_server_parser.mode = WS_SERVER_LM_CIPSEND_LISTENING;
ws_server_buffer_send_finish();
}
break;
}
case WS_SERVER_LM_IPD_LISTENING: {
- switch (g_ws_server_parser.channel_listen_mode) {
- case WS_SERVER_CL_CHANNEL_ID: {
- if (byte == ',') {
- g_ws_server_parser.channel_listen_mode = WS_SERVER_CL_DATA_LENGTH;
- break;
- }
- g_ws_server_parser.current_channel *= 10;
- g_ws_server_parser.current_channel += byte - '0'; // ascii to int
+ switch (g_ws_server_parser.channel_listen_mode) {
+ case WS_SERVER_CL_CHANNEL_ID: {
+ if (byte == ',') {
+ g_ws_server_parser.channel_listen_mode = WS_SERVER_CL_DATA_LENGTH;
break;
}
- case WS_SERVER_CL_DATA_LENGTH: {
- if (byte == ':') {
- g_ws_server_parser.channel_listen_mode = WS_SERVER_CL_DATA_READ;
- if (g_ws_server_parser.channel_data_length > WS_PROTOCOL_CMD_BUFFER_LEN)
- g_ws_server_parser.channel_data_ignore = true;
- break;
- }
- g_ws_server_parser.channel_data_length *= 10;
- g_ws_server_parser.channel_data_length += byte - '0'; // ascii to int
+ g_ws_server_parser.current_channel *= 10;
+ g_ws_server_parser.current_channel += byte - '0'; // ascii to int
+ break;
+ }
+ case WS_SERVER_CL_DATA_LENGTH: {
+ if (byte == ':') {
+ g_ws_server_parser.channel_listen_mode = WS_SERVER_CL_DATA_READ;
+ if (g_ws_server_parser.channel_data_length > WS_PROTOCOL_CMD_BUFFER_LEN)
+ g_ws_server_parser.channel_data_ignore = true;
break;
}
- case WS_SERVER_CL_DATA_READ: {
- ws_server_req_parse_byte(g_ws_server_parser.current_channel, byte, g_ws_server_parser.channel_data_ignore);
- g_ws_server_parser.channel_data_counter++;
- if (g_ws_server_parser.channel_data_counter == g_ws_server_parser.channel_data_length) {
- g_ws_server_parser.current_channel = 0;
- g_ws_server_parser.channel_data_counter = 0;
- g_ws_server_parser.channel_data_length = 0;
- g_ws_server_parser.channel_listen_mode = WS_SERVER_CL_CHANNEL_ID;
- ws_server_req_finish(g_ws_server_parser.current_channel, g_ws_server_parser.channel_data_ignore);
- g_ws_server_parser.mode = WS_SERVER_LM_IDLE;
- }
- break;
+ g_ws_server_parser.channel_data_length *= 10;
+ g_ws_server_parser.channel_data_length += byte - '0'; // ascii to int
+ break;
+ }
+ case WS_SERVER_CL_DATA_READ: {
+ ws_server_req_parse_byte(g_ws_server_parser.current_channel, byte, g_ws_server_parser.channel_data_ignore);
+ g_ws_server_parser.channel_data_counter++;
+ if (g_ws_server_parser.channel_data_counter == g_ws_server_parser.channel_data_length) {
+ g_ws_server_parser.current_channel = 0;
+ g_ws_server_parser.channel_data_counter = 0;
+ g_ws_server_parser.channel_data_length = 0;
+ g_ws_server_parser.channel_listen_mode = WS_SERVER_CL_CHANNEL_ID;
+ ws_server_req_finish(g_ws_server_parser.current_channel, g_ws_server_parser.channel_data_ignore);
+ g_ws_server_parser.mode = WS_SERVER_LM_IDLE;
}
- default: {}
+ break;
}
+ default: {}
+ }
break;
}
case WS_SERVER_LM_CIPSEND_LISTENING: {
@@ -151,15 +158,26 @@ void ws_server_buffer_send_append(uint8_t* data, size_t size) {
// TODO: refactor this
void ws_server_buffer_send_finish() {
+ /* const int chunk_size = 16; // esp is garbage
+
+ for (unsigned int chunk = 0; chunk <= (g_ws_esp8266_dma_tx_buffer_size / chunk_size); chunk++) {
+ HAL_UART_Transmit_DMA(&huart1, &g_ws_esp8266_dma_tx_buffer[chunk_size * chunk], WS_MIN(chunk_size, g_ws_esp8266_dma_tx_buffer_size % chunk_size));
+ __HAL_UART_ENABLE_IT(&huart1, UART_IT_TXE);
+ while (!__HAL_DMA_GET_FLAG(&hdma_usart1_tx, DMA_FLAG_TC2));
+ } */
#ifdef WS_DBG_PRINT_ESP_OVER_USART2
- ws_dbg_set_usart2_tty_color(2);
+ ws_dbg_set_usart2_tty_color(WS_DBG_TTY_COLOR_TX);
HAL_UART_Transmit(&huart2, g_ws_esp8266_dma_tx_buffer, g_ws_esp8266_dma_tx_buffer_size, 100);
#endif
- HAL_UART_Transmit_DMA(&huart1, g_ws_esp8266_dma_tx_buffer, g_ws_esp8266_dma_tx_buffer_size);
- __HAL_UART_ENABLE_IT(&huart1, UART_IT_TXE);
+ HAL_UART_Transmit(&huart1, g_ws_esp8266_dma_tx_buffer, g_ws_esp8266_dma_tx_buffer_size, 100);
+ // for (unsigned j = 0; j < 10000; j++) asm("nop"); // esp garbage
+ // for (unsigned int i = 0; i < g_ws_esp8266_dma_tx_buffer_size; i++) {
+ // // send as slow as possible because the esp is garbage
+ // for (unsigned j = 0; j < 1000; j++) asm("nop"); // did i mention the esp is garbage
+ // HAL_UART_Transmit(&huart1, &g_ws_esp8266_dma_tx_buffer[i], 1, 100);
+ // }
g_ws_esp8266_dma_tx_buffer_size = 0;
- while (!__HAL_DMA_GET_FLAG(&hdma_usart1_tx, DMA_FLAG_TC2));
}
// TODO: refactor this
diff --git a/stm32f091/setup.c b/stm32f091/setup.c
index 1591649..ef00a29 100644
--- a/stm32f091/setup.c
+++ b/stm32f091/setup.c
@@ -97,18 +97,18 @@ void ws_io_setup() {
// ws_backlog_alloc(10);
#ifdef WS_DBG_PRINT_ESP_OVER_USART2
- ws_dbg_set_usart2_tty_color(7);
+ ws_dbg_set_usart2_tty_color(WS_DBG_TTY_COLOR_DBGMSG);
const char restart_str[] = "\r\n--- stm restart ---\r\n";
- HAL_UART_Transmit(&huart2, restart_str, strlen(restart_str), 100);
+ HAL_UART_Transmit(&huart2, (uint8_t*) restart_str, strlen(restart_str), 100);
#endif
+ ws_esp8266_ap_client_mode();
#ifdef WS_ESP8266_WLAN_MAC
ws_esp8266_set_mac();
#endif
#ifdef WS_ESP8266_WLAN_IP
ws_esp8266_set_ip();
#endif
- ws_esp8266_ap_client_mode();
do ws_esp8266_connect(); while (g_ws_server_parser.last_response == WS_SERVER_RC_ERR);
ws_esp8266_start_tcp_server();
}
diff --git a/stm32f091/util.h b/stm32f091/util.h
index 9f5c1ec..dde3677 100644
--- a/stm32f091/util.h
+++ b/stm32f091/util.h
@@ -8,6 +8,35 @@
#include "setup.h"
#include "../shared/util.h"
+#define WS_DBG_TTY_COLOR_BLK 0x0
+#define WS_DBG_TTY_COLOR_RED 0x1
+#define WS_DBG_TTY_COLOR_GRN 0x2
+#define WS_DBG_TTY_COLOR_YLW 0x3
+#define WS_DBG_TTY_COLOR_BLU 0x4
+#define WS_DBG_TTY_COLOR_VLT 0x5
+#define WS_DBG_TTY_COLOR_CYN 0x6
+#define WS_DBG_TTY_COLOR_WHI 0x7
+#define WS_DBG_TTY_COLOR_BR_BLK 0x8
+#define WS_DBG_TTY_COLOR_BR_RED 0x9
+#define WS_DBG_TTY_COLOR_BR_GRN 0xa
+#define WS_DBG_TTY_COLOR_BR_YLW 0xb
+#define WS_DBG_TTY_COLOR_BR_BLU 0xc
+#define WS_DBG_TTY_COLOR_BR_VLT 0xd
+#define WS_DBG_TTY_COLOR_BR_CYN 0xe
+#define WS_DBG_TTY_COLOR_BR_WHI 0xf
+
+// serial debug color scheme
+#define WS_DBG_TTY_COLOR_DBGMSG WS_DBG_TTY_COLOR_BR_BLK
+#define WS_DBG_TTY_COLOR_TX WS_DBG_TTY_COLOR_GRN
+#define WS_DBG_TTY_COLOR_RX WS_DBG_TTY_COLOR_RED
+
+// unused
+// #define WS_DBG_TTY_COLOR_CMD_ECHO WS_DBG_TTY_COLOR_BLK
+// #define WS_DBG_TTY_COLOR_STATUS_CODE WS_DBG_TTY_COLOR_YLW
+// #define WS_DBG_TTY_COLOR_IDLE WS_DBG_TTY_COLOR_VLT
+// #define WS_DBG_TTY_COLOR_IPD_LISTENING WS_DBG_TTY_COLOR_GRN
+// #define WS_DBG_TTY_COLOR_CIPSEND_LISTENING WS_DBG_TTY_COLOR_RED
+
#define ws_usb_printf(fmt, ...) { \
char temp[255]; \
snprintf(temp, 255, fmt, ##__VA_ARGS__); \
@@ -15,6 +44,6 @@
}
#define ws_dbg_set_usart2_tty_color(color) { \
- uint8_t sgr[] = { 0x1b, 0x5b, 0x33, 0x30 + color, 0x6d }; \
+ uint8_t sgr[] = { 0x1b, 0x5b, 0x33 + (color > 7 ? 6 : 0), 0x30 + (color & 0b111), 0x6d }; \
HAL_UART_Transmit(&huart2, sgr, sizeof(sgr), 100); \
}