diff options
Diffstat (limited to 'stm32f091/server.c')
-rw-r--r-- | stm32f091/server.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/stm32f091/server.c b/stm32f091/server.c index 8001380..1419da8 100644 --- a/stm32f091/server.c +++ b/stm32f091/server.c @@ -20,7 +20,7 @@ ws_s_server_parser g_ws_server_parser = { }; static ws_s_protocol_req_parser_state* g_ws_protocol_parsers[WS_SERVER_MAX_CHANNELS] = {0}; -static unsigned int g_ws_esp8266_dma_tx_buffer_index = 0; +static unsigned int g_ws_esp8266_dma_tx_buffer_size = 0; void ws_server_req_parse_byte(unsigned int channel, uint8_t byte, bool ignore) { if (ignore) return; @@ -126,7 +126,7 @@ void ws_server_req_incoming(uint8_t* data, size_t size) { break; } case WS_SERVER_LM_CIPSEND_LISTENING: { - if (next_few_bytes_are("SEND OK")) { + if (next_few_bytes_are("SEND OK") || next_few_bytes_are("ERROR")) { ws_server_req_respond_end(0); // g_ws_server_parser.mode = WS_SERVER_LM_IDLE; } @@ -146,23 +146,25 @@ void ws_server_send(uint8_t* data, size_t size) { void ws_server_buffer_send_append(uint8_t* data, size_t size) { // TODO: buffer overrun protection // while (!__HAL_DMA_GET_FLAG(&hdma_usart1_tx, DMA_FLAG_TC2)); // make sure buffer isn't used - strncpy((char*) &g_ws_esp8266_dma_tx_buffer[g_ws_esp8266_dma_tx_buffer_index], (char*) data, size); // append string - g_ws_esp8266_dma_tx_buffer_index += size; // shift head + strncpy((char*) &g_ws_esp8266_dma_tx_buffer[g_ws_esp8266_dma_tx_buffer_size], (char*) data, size); // append string + g_ws_esp8266_dma_tx_buffer_size += size; // shift head } +// TODO: refactor this void ws_server_buffer_send_finish() { #ifdef WS_DBG_PRINT_ESP_OVER_USART2 uint8_t green[] = { 0x1b, 0x5b, 0x33, 0x32, 0x6d }; HAL_UART_Transmit(&huart2, green, sizeof(green), 100); - HAL_UART_Transmit(&huart2, g_ws_esp8266_dma_tx_buffer, strlen((char*) g_ws_esp8266_dma_tx_buffer), 100); + 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, strlen((char*) g_ws_esp8266_dma_tx_buffer)); + 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); - g_ws_esp8266_dma_tx_buffer_index = 0; + g_ws_esp8266_dma_tx_buffer_size = 0; while (!__HAL_DMA_GET_FLAG(&hdma_usart1_tx, DMA_FLAG_TC2)); } +// TODO: refactor this void ws_server_req_respond_start(unsigned int channel, size_t size) { char* cmd = NULL; size_t len = asiprintf(&cmd, "AT+CIPSEND=%d,%d\r\n", channel, size); @@ -171,6 +173,7 @@ void ws_server_req_respond_start(unsigned int channel, size_t size) { while (!__HAL_DMA_GET_FLAG(&hdma_usart1_tx, DMA_FLAG_TC2)); } +// TODO: refactor this void ws_server_req_respond_end(unsigned int channel) { char* cmd = NULL; size_t len = asiprintf(&cmd, "AT+CIPCLOSE=%d\r\n", channel); @@ -178,4 +181,3 @@ void ws_server_req_respond_end(unsigned int channel) { ws_esp8266_send((uint8_t*) cmd, len); while (!__HAL_DMA_GET_FLAG(&hdma_usart1_tx, DMA_FLAG_TC2)); } - |