diff options
Diffstat (limited to 'stm32f091/server.h')
-rw-r--r-- | stm32f091/server.h | 90 |
1 files changed, 80 insertions, 10 deletions
diff --git a/stm32f091/server.h b/stm32f091/server.h index e134079..07c49d9 100644 --- a/stm32f091/server.h +++ b/stm32f091/server.h @@ -2,11 +2,53 @@ #include <stdlib.h> #include <stdint.h> +#include <stdbool.h> -// void ws_server_demo(); -// -// /** FreeRTOS task that listens for incoming requests from the esp */ -// void ws_server_listen_task(); +typedef enum { + WS_SERVER_LM_CMD_ECHO, /** @brief listen for echo of sent command */ + WS_SERVER_LM_STATUS_CODE, /** @brief listen for busy, ERROR or OK */ + WS_SERVER_LM_IDLE, /** @brief listen for incoming +IPD commands */ + WS_SERVER_LM_IPD_LISTENING, /** @brief +IPD received, now reading data */ + WS_SERVER_LM_CIPSEND_LISTENING, /** @brief AT+CIPSEND sent, now reading data */ +} ws_e_server_listen_mode; + +typedef enum { + WS_SERVER_CL_CHANNEL_ID, /** @brief listen channel id */ + WS_SERVER_CL_DATA_LENGTH, /** @brief listen for data byte length */ + WS_SERVER_CL_DATA_READ, /** @brief listen for data and pipe to ws_protocol_parse_req_byte */ +} ws_e_channel_listen_mode; + +typedef enum { + WS_SERVER_RC_NONE = -1, + WS_SERVER_RC_BUSY, + WS_SERVER_RC_ERR, + WS_SERVER_RC_OK, +} ws_e_server_response_code; + +typedef struct { + uint8_t s_ok; /** @brief status code OK */ + uint8_t s_error; /** @brief status code OK */ + uint8_t s_fail; /** @brief status code OK */ + uint8_t s_busy; /** @brief status code OK */ + uint8_t i_ipd; /** @brief idle +IPD, */ + uint8_t i_prompt; /** @brief idle > */ + uint8_t l_send_ok; /** @brief ipd listen SEND OK */ + uint8_t l_error; /** @brief ipd listen ERROR */ +} ws_s_server_parser_response_counter; + +typedef struct { + ws_e_server_listen_mode mode; + ws_e_server_response_code last_response; + unsigned int current_channel; + unsigned int channel_data_length; + unsigned int channel_data_counter; + ws_e_channel_listen_mode channel_listen_mode; + bool channel_data_ignore; + ws_s_server_parser_response_counter rc; +} ws_s_server_parser; + +/** @brief global server parser struct */ +extern ws_s_server_parser g_ws_server_parser; /** * @brief +IPD incoming request handler @@ -20,10 +62,38 @@ */ 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 +// /** @brief send AT response header for incoming request on specific channel */ +// void ws_server_req_respond_start(unsigned int channel); +// /** @brief send AT tcp close on specific channel */ +// void ws_server_req_respond_end(unsigned int channel); + +/** @brief send data to esp, waiting until server returns to idle mode */ +void ws_server_send(uint8_t* data, size_t size); + +/** + * @brief parse byte from channel + * + * automatically creates parser struct and passes data onto protocol parser + * functions + * + * @param channel request channel + * @param byte data byte + * @param ignore ignore mode + */ +void ws_server_req_parse_byte(unsigned int channel, uint8_t byte, bool ignore); + +/** + * @brief close connection + * + * deallocates any parser struct that were automatically created in + * ws_server_req_parse_byte + * + * @param channel request channel + * @param ignore ignore mode + */ +void ws_server_req_finish(unsigned int channel, bool ignore); + +void ws_server_buffer_send_append(uint8_t* data, size_t size); +void ws_server_buffer_request_chunk_send(); +void ws_server_buffer_send_chunk(); |