diff options
Diffstat (limited to 'stm32f091')
-rw-r--r-- | stm32f091/backlog.c | 5 | ||||
-rw-r--r-- | stm32f091/esp8266.c | 7 | ||||
-rw-r--r-- | stm32f091/main.c | 1 | ||||
-rw-r--r-- | stm32f091/makefile | 8 | ||||
-rw-r--r-- | stm32f091/protocol.c | 33 | ||||
-rw-r--r-- | stm32f091/sensor.c | 6 | ||||
-rw-r--r-- | stm32f091/server.c | 2 | ||||
-rw-r--r-- | stm32f091/util.h | 3 |
8 files changed, 54 insertions, 11 deletions
diff --git a/stm32f091/backlog.c b/stm32f091/backlog.c index 926ccad..662fc75 100644 --- a/stm32f091/backlog.c +++ b/stm32f091/backlog.c @@ -33,11 +33,6 @@ ws_s_backlog_record* ws_backlog_get_last_record(uint16_t record_offset) { return ws_backlog_get_record((g_ws_backlog_database->buffer_end - record_offset - 1) % g_ws_backlog_database->buffer_size); } -static uint16_t mod(uint16_t a, uint16_t b) { - uint16_t m = a % b; - return m < 0 ? (b < 0) ? m - b : m + b : m; -} - uint16_t ws_backlog_get_record_count() { // add buffer_size to the result of the modulo operation if it's result is negative // (only works when buffer_size is less than 2^15) diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c index 6f12191..4c5d0d2 100644 --- a/stm32f091/esp8266.c +++ b/stm32f091/esp8266.c @@ -22,7 +22,7 @@ void ws_esp8266_ATsendCommand(uint8_t* data){ } int ws_esp8266_checkOK(uint8_t *receiveData,int length){ char *ret=""; - char *ret1=""; + // char *ret1=""; HAL_UART_Transmit(&huart2, receiveData,length,1000); ret = strstr((char*)receiveData,"OK"); // ret = strstr((char*)receiveData,"change"); @@ -159,8 +159,9 @@ void ws_esp8266_serveraan(){ HAL_Delay(1000); } void ws_esp8266_serveruit(){ - int ret; - uint8_t buffer1[27]={0}; uint8_t Tx_server[]="AT+CIPSERVER=0\r\n"; + //int ret; + //uint8_t buffer1[27]={0}; + uint8_t Tx_server[]="AT+CIPSERVER=0\r\n"; // // while(ret!=1){ diff --git a/stm32f091/main.c b/stm32f091/main.c index 9235f1b..7cb0718 100644 --- a/stm32f091/main.c +++ b/stm32f091/main.c @@ -16,7 +16,6 @@ int main() { }); ws_backlog_alloc(24 * 60); - ws_sensor_read(); xTaskCreate(ws_sensor_read_task, "sensor", 128, NULL, 1, NULL); vTaskStartScheduler(); diff --git a/stm32f091/makefile b/stm32f091/makefile index 5a185de..20424c3 100644 --- a/stm32f091/makefile +++ b/stm32f091/makefile @@ -5,6 +5,8 @@ RM = rm -f TARGET = main +include ../shared/shared.mk + SHARED_FLAGS += -g SHARED_FLAGS += -DSTM32F091xC SHARED_FLAGS += -Wall @@ -74,9 +76,15 @@ $(TARGET).bin: $(TARGET).elf %.o: %.s $(CC) -c $(AFLAGS) $< -o $@ +lib/%.o: lib/%.c + $(CC) -c $(CFLAGS) -w $< -o $@ + %.o: %.c $(CC) -c $(CFLAGS) $< -o $@ +%-stm.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + $(TARGET).elf: $(OBJS) $(LD) $(LFLAGS) $^ -o $@ diff --git a/stm32f091/protocol.c b/stm32f091/protocol.c new file mode 100644 index 0000000..589ee5d --- /dev/null +++ b/stm32f091/protocol.c @@ -0,0 +1,33 @@ +#include <stdio.h> + +#include "../shared/protocol.h" +#include "backlog.h" +#include "util.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; + const char* response_header = "id,temperature,humidity,atmospheric_pressure\n"; + const size_t response_line_size = sizeof("xxxx,xx,xx,xx\n"); + + if (!send) { + response->success = WS_PROTOCOL_CMD_RETURN_OK; + if (sscanf(parsed_cmd->argv[1], "%u", &record_amount) < 1) response->success = WS_PROTOCOL_CMD_RETURN_ERROR; + record_amount = WS_MIN(record_amount, ws_backlog_get_record_count()); + response->csh = true; + response->msg = ws_bin_s_alloc(0); + response->msg->bytes = strlen(response_header) + response_line_size * record_amount; + } else { + ws_protocol_send_data(response_header, strlen(response_header)); + char line[response_line_size + 1]; // +1 for null terminator -> sprintf + for (unsigned int i = 0; i < record_amount; i++) { + ws_s_backlog_record* record = ws_backlog_get_last_record(i); + 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_size); + } + } +} + +void ws_protocol_send_data(const char* data, unsigned int length) { + //TODO: implement on esp data channels + HAL_UART_Transmit(&huart2, (uint8_t*) data, length, HAL_MAX_DELAY); +} diff --git a/stm32f091/sensor.c b/stm32f091/sensor.c index bc3cfd3..1c94e2a 100644 --- a/stm32f091/sensor.c +++ b/stm32f091/sensor.c @@ -58,6 +58,12 @@ void ws_sensor_read() { .sens_humidity = ws_sensor_humidity() }; ws_backlog_add_record(record); + + // < DEBUG PROTOCOL PARSING CODE > + // ws_s_protocol_req_parser_state* parser = ws_protocol_req_parser_alloc(); + // const char* request = "last-records 5\n"; + // ws_protocol_parse_req_bytes(parser, (char*) request, strlen(request)); + // ws_protocol_req_parser_free(parser); } void ws_sensor_read_task() { diff --git a/stm32f091/server.c b/stm32f091/server.c index e289245..4840527 100644 --- a/stm32f091/server.c +++ b/stm32f091/server.c @@ -28,7 +28,7 @@ void ws_server_demo() { uint8_t receive[24]={0}; uint8_t sendToQTData[]="gelukt"; uint8_t test[]="test"; - int ret; + //int ret; //ATsendCommand(sendToQTData); while (1) { diff --git a/stm32f091/util.h b/stm32f091/util.h index 8e3258f..92f093f 100644 --- a/stm32f091/util.h +++ b/stm32f091/util.h @@ -6,10 +6,11 @@ #include <string.h> #include "setup.h" +#include "../shared/util.h" #define ws_usb_printf(fmt, ...) { \ char temp[255]; \ - sprintf(temp, fmt, ##__VA_ARGS__); \ + snprintf(temp, 255, fmt, ##__VA_ARGS__); \ HAL_UART_Transmit(&huart2, (uint8_t*) temp, sizeof(char) * strlen(temp), HAL_MAX_DELAY); \ } |