aboutsummaryrefslogtreecommitdiff
path: root/stm32f091
diff options
context:
space:
mode:
Diffstat (limited to 'stm32f091')
-rw-r--r--stm32f091/consts.h2
-rw-r--r--stm32f091/protocol.c4
-rw-r--r--stm32f091/server.c24
-rw-r--r--stm32f091/setup.c6
4 files changed, 8 insertions, 28 deletions
diff --git a/stm32f091/consts.h b/stm32f091/consts.h
index 6d5b8d2..2a09508 100644
--- a/stm32f091/consts.h
+++ b/stm32f091/consts.h
@@ -9,6 +9,8 @@
#define WS_DMA_RX_BUFFER_SIZE 100
#define WS_DMA_TX_BUFFER_SIZE 1024
+#define WS_BACKLOG_SIZE (24 * 60)
+
#define WS_PINOUT_I2C_SDA_PIN GPIO_PIN_9
#define WS_PINOUT_I2C_SDA_PORT GPIOB
#define WS_PINOUT_I2C_SCL_PIN GPIO_PIN_8
diff --git a/stm32f091/protocol.c b/stm32f091/protocol.c
index f4be08f..405ceb8 100644
--- a/stm32f091/protocol.c
+++ b/stm32f091/protocol.c
@@ -7,7 +7,7 @@
#include "esp8266.h"
void ws_protocol_res_last_records(ws_s_protocol_parsed_req_cmd* parsed_cmd, ws_s_protocol_res* response, bool send) {
- static int record_amount = 0;
+ static unsigned int record_amount = 0;
static unsigned int record_offset = 0;
const char* response_header = "id,temperature,humidity,atmospheric_pressure\n";
const unsigned int response_line_len = strlen("xxxx,xx,xx,xx\n");
@@ -21,7 +21,7 @@ void ws_protocol_res_last_records(ws_s_protocol_parsed_req_cmd* parsed_cmd, ws_s
if (sscanf(parsed_cmd->argv[2], "%x", &record_offset) < 1) response->success = WS_PROTOCOL_CMD_RETURN_ERROR;
else {
record_amount = WS_MIN(record_amount + record_offset, ws_backlog_get_record_count());
- record_amount = WS_MAX(0, record_amount - record_offset);
+ record_amount = WS_MAX(0, (int) record_amount - (int) record_offset);
response->msg->bytes = strlen(response_header) + response_line_len * record_amount;
}
} else {
diff --git a/stm32f091/server.c b/stm32f091/server.c
index d69ef1e..1d4a469 100644
--- a/stm32f091/server.c
+++ b/stm32f091/server.c
@@ -162,9 +162,8 @@ 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_head], (char*) data, size); // append string
+ size_t limited_size = WS_MIN(size, g_ws_esp8266_dma_tx_buffer_head - g_ws_esp8266_dma_tx_buffer_tail);
+ strncpy((char*) &g_ws_esp8266_dma_tx_buffer[g_ws_esp8266_dma_tx_buffer_head], (char*) data, limited_size); // append string
g_ws_esp8266_dma_tx_buffer_head += size; // shift head
}
@@ -201,24 +200,5 @@ void ws_server_buffer_send_chunk() {
if (g_ws_esp8266_dma_tx_buffer_head == g_ws_esp8266_dma_tx_buffer_tail) {
g_ws_esp8266_dma_tx_buffer_head = g_ws_esp8266_dma_tx_buffer_tail = 0;
}
-
-// #ifdef WS_DBG_PRINT_ESP_OVER_USART2
-// 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_head, 100);
-// #endif
-//
-// HAL_UART_Transmit(&huart1, g_ws_esp8266_dma_tx_buffer, g_ws_esp8266_dma_tx_buffer_head, 100);
-// g_ws_esp8266_dma_tx_buffer_head = 0;
-//
-// HAL_UART_Transmit(&huart1, (uint8_t*) "+++", 3, 100);
}
-// 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);
- g_ws_server_parser.mode = WS_SERVER_LM_CMD_ECHO;
- ws_esp8266_send((uint8_t*) cmd, len);
- while (!__HAL_DMA_GET_FLAG(&hdma_usart1_tx, DMA_FLAG_TC2));
- free(cmd);
-}
diff --git a/stm32f091/setup.c b/stm32f091/setup.c
index ef00a29..658e1bb 100644
--- a/stm32f091/setup.c
+++ b/stm32f091/setup.c
@@ -92,9 +92,7 @@ void ws_io_setup() {
.Pull = GPIO_NOPULL
});
- // TODO: remove debug size
- ws_backlog_alloc(24 * 60);
- // ws_backlog_alloc(10);
+ ws_backlog_alloc(WS_BACKLOG_SIZE);
#ifdef WS_DBG_PRINT_ESP_OVER_USART2
ws_dbg_set_usart2_tty_color(WS_DBG_TTY_COLOR_DBGMSG);
@@ -184,7 +182,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) {
__HAL_RCC_GPIOB_CLK_ENABLE();
HAL_GPIO_Init(GPIOB, &(GPIO_InitTypeDef) {
- .Pin = GPIO_PIN_8|GPIO_PIN_9, //TODO: use #defines in setup.h
+ .Pin = WS_PINOUT_I2C_SCL_PIN | WS_PINOUT_I2C_SDA_PIN,
.Mode = GPIO_MODE_AF_OD,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_HIGH,