aboutsummaryrefslogtreecommitdiff
path: root/stm32f091/server.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-10-27 15:37:35 +0200
committerlonkaars <loek@pipeframe.xyz>2022-10-27 15:37:35 +0200
commit94e31069df88c3d5e50b4160705c2b7aa27e152b (patch)
treefac20382f2055fc47fdee182b0b12d3dc564a888 /stm32f091/server.c
parent4dbb57fe63d3c59893d1a670fecdde7ea20c9a4a (diff)
WIP server parser
Diffstat (limited to 'stm32f091/server.c')
-rw-r--r--stm32f091/server.c74
1 files changed, 68 insertions, 6 deletions
diff --git a/stm32f091/server.c b/stm32f091/server.c
index de6ea50..aa2ff8b 100644
--- a/stm32f091/server.c
+++ b/stm32f091/server.c
@@ -3,15 +3,77 @@
#include <stdlib.h>
#include <string.h>
+#include "esp8266.h"
#include "server.h"
+#include "setup.h"
+#include "consts.h"
+static ws_s_server_parser g_ws_server_parser = {
+ .counter = 0,
+ .last_response = WS_SERVER_RC_NONE,
+ .mode = WS_SERVER_LM_IDLE,
+};
+
+// TODO: next_few_bytes_are assumes that the complete search string is in the
+// buffer, so won't work for buffer cutoffs
+#define next_few_bytes_are(code) (i + sizeof(code) - 1 < size && strncmp((char*)&data[i], code, sizeof(code) - 1) == 0)
void ws_server_req_incoming(uint8_t* data, size_t size) {
- // TODO: server req incoming implementation
- //
- // example +IPD command:
- // +IPD,0,15:last-records 5\n
- //
- // TODO: protocol req response parser -> (ws_esp8622_at_send(data, channel) ?)
+#ifdef WS_DBG_PRINT_ESP_OVER_USART2
+ uint8_t red[] = { 0x1b, 0x5b, 0x33, 0x31, 0x6d };
+ HAL_UART_Transmit(&huart2, red, sizeof(red), 100);
+ HAL_UART_Transmit(&huart2, data, size, 100);
+#endif
+
+ for (unsigned int i = 0; i < size; i++) {
+ uint8_t byte = data[i];
+
+ switch (g_ws_server_parser.mode) {
+ case WS_SERVER_LM_CMD_ECHO: {
+ if (byte == '\n') g_ws_server_parser.mode = WS_SERVER_LM_STATUS_CODE;
+ break;
+ }
+ case WS_SERVER_LM_STATUS_CODE: {
+ bool code_got = false;
+ if (next_few_bytes_are("OK")) {
+ code_got = true;
+ g_ws_server_parser.last_response = WS_SERVER_RC_OK;
+ } else if (next_few_bytes_are("ERROR")) {
+ code_got = true;
+ g_ws_server_parser.last_response = WS_SERVER_RC_ERR;
+ } else if (next_few_bytes_are("busy p...")) {
+ code_got = true;
+ g_ws_server_parser.last_response = WS_SERVER_RC_BUSY;
+ }
+ if (code_got) g_ws_server_parser.mode = WS_SERVER_LM_IDLE;
+ break;
+ }
+ case WS_SERVER_LM_IDLE: {
+ if (next_few_bytes_are("+IPD")) {
+ i += 3; // skip I, P, and D
+ g_ws_server_parser.mode = WS_SERVER_LM_IPD_LISTENING;
+ }
+ break;
+ }
+ case WS_SERVER_LM_IPD_LISTENING: {
+ // +IPD,0,15:last-records 5\n
+ break;
+ }
+ default: {}
+ }
+ }
return;
}
+
+void ws_server_send(uint8_t* data, size_t size) {
+ g_ws_server_parser.mode = WS_SERVER_LM_CMD_ECHO;
+ ws_esp8266_send(data, size);
+ while (g_ws_server_parser.mode != WS_SERVER_LM_IDLE) {};
+}
+
+void ws_server_req_respond(unsigned int channel, uint8_t* data, size_t size) {
+ uint8_t Tx_close[]="AT+CIPCLOSE=0\r\n";
+ uint8_t Tx_send[]="AT+CIPSEND=0,LEN:";
+ return;
+}
+