aboutsummaryrefslogtreecommitdiff
path: root/stm32f091/protocol.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-10-29 18:26:21 +0200
committerlonkaars <loek@pipeframe.xyz>2022-10-29 18:26:21 +0200
commit06376c3cfefdb01f8f4884c1b853edc16c89d1c8 (patch)
tree541f279e2ebf6898f52420f9eeb422fe9d7eb786 /stm32f091/protocol.c
parent9e9ea9d07ed2a176d6f6e83b5b100da22d8fca50 (diff)
parent7022c6fbdbdee82339fbe161df169d97235471f0 (diff)
Merge branch 'protocol' into dev
Diffstat (limited to 'stm32f091/protocol.c')
-rw-r--r--stm32f091/protocol.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/stm32f091/protocol.c b/stm32f091/protocol.c
index ca46b3b..f4be08f 100644
--- a/stm32f091/protocol.c
+++ b/stm32f091/protocol.c
@@ -7,7 +7,8 @@
#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 unsigned int record_amount = 0;
+ static 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");
@@ -16,9 +17,11 @@ void ws_protocol_res_last_records(ws_s_protocol_parsed_req_cmd* parsed_cmd, ws_s
response->csh = true;
response->msg = ws_bin_s_alloc(0);
response->msg->bytes = 0;
- if (sscanf(parsed_cmd->argv[1], "%u", &record_amount) < 1) response->success = WS_PROTOCOL_CMD_RETURN_ERROR;
+ if (sscanf(parsed_cmd->argv[1], "%x", &record_amount) < 1) response->success = WS_PROTOCOL_CMD_RETURN_ERROR;
+ if (sscanf(parsed_cmd->argv[2], "%x", &record_offset) < 1) response->success = WS_PROTOCOL_CMD_RETURN_ERROR;
else {
- record_amount = WS_MIN(record_amount, ws_backlog_get_record_count());
+ record_amount = WS_MIN(record_amount + record_offset, ws_backlog_get_record_count());
+ record_amount = WS_MAX(0, record_amount - record_offset);
response->msg->bytes = strlen(response_header) + response_line_len * record_amount;
}
} else {
@@ -26,7 +29,7 @@ void ws_protocol_res_last_records(ws_s_protocol_parsed_req_cmd* parsed_cmd, ws_s
ws_protocol_send_data(response_header, strlen(response_header));
char line[response_line_len + 1]; // + 1 for string terminator
for (unsigned int i = 0; i < record_amount; i++) {
- ws_s_backlog_record* record = ws_backlog_get_last_record(i);
+ ws_s_backlog_record* record = ws_backlog_get_last_record(i + record_offset);
sprintf(line, "%04x,%02x,%02x,%02x\n", record->id, record->sens_temperature, record->sens_humidity, record->sens_atm_pressure);
ws_protocol_send_data(line, response_line_len);
}