aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-10-30 17:31:16 +0100
committerlonkaars <loek@pipeframe.xyz>2022-10-30 17:31:16 +0100
commitfc95a016d13c1510a024888c1b87bbfe1a7f7601 (patch)
tree9b98a41d648da3e5acde0897d41cd79c11a7d1e3
parentd629902140406ac26fa65c1a7d559e6f1798206f (diff)
squash more todo's
-rw-r--r--makefile4
-rw-r--r--stm32f091/consts.h2
-rw-r--r--stm32f091/protocol.c4
-rw-r--r--stm32f091/server.c24
-rw-r--r--stm32f091/setup.c6
-rw-r--r--todo.md6
6 files changed, 13 insertions, 33 deletions
diff --git a/makefile b/makefile
index a94d2a0..31ff4bf 100644
--- a/makefile
+++ b/makefile
@@ -8,10 +8,10 @@ client_makefile:
qmake client/client.pro -o client/makefile
client: client_makefile
- make -jC client
+ make -j -C client
client_compile_commands: client_makefile
compiledb -o client/compile_commands.json make -BnC client
stm32:
- make -jC stm32f091
+ make -j -C stm32f091
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,
diff --git a/todo.md b/todo.md
index c19f3ae..150e12c 100644
--- a/todo.md
+++ b/todo.md
@@ -20,9 +20,9 @@
- [x] `sensor.c:36: return (uint8_t) humidity; //TODO: convert with range -> util.h`
- [x] `sensor.c:51: return (uint8_t) val; // TODO: convert with range`
- [x] `server.c:47:// TODO: next_few_bytes_are assumes that the complete search string is in the`
-- [ ] `server.c:146: // TODO: buffer overrun protection`
+- [x] `server.c:146: // TODO: buffer overrun protection`
- [x] `server.c:152:// TODO: refactor this`
- [x] `server.c:165:// TODO: refactor this`
- [x] `server.c:174:// TODO: refactor this`
-- [ ] `setup.c:95: // TODO: remove debug size`
-- [ ] `setup.c:187: .Pin = GPIO_PIN_8|GPIO_PIN_9, //TODO: use #defines in setup.h`
+- [x] `setup.c:95: // TODO: remove debug size`
+- [x] `setup.c:187: .Pin = GPIO_PIN_8|GPIO_PIN_9, //TODO: use #defines in setup.h`