From ca0c49ec482f624b40c98e090bb1f8fd123ae915 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 10 Mar 2021 10:48:17 +0100 Subject: [PATCH] sink sender --- src/main/CMakeLists.txt | 1 + src/main/app_main.c | 3 +++ src/main/counter.c | 7 +++++++ src/main/sinkSender.c | 33 +++++++++++++++++++++++++++++++++ src/main/sinkSender.h | 9 +++++++++ 5 files changed, 53 insertions(+) create mode 100644 src/main/sinkSender.c create mode 100644 src/main/sinkSender.h diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index 86ffcd8..918e51f 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -4,4 +4,5 @@ idf_component_register(SRCS "app_main.c" "counter.c" "timesync.c" "sha256.c" + "sinkSender.c" INCLUDE_DIRS ".") diff --git a/src/main/app_main.c b/src/main/app_main.c index 78707d7..c4cb854 100644 --- a/src/main/app_main.c +++ b/src/main/app_main.c @@ -16,6 +16,7 @@ #include "gpio.h" #include "counter.h" #include "timesync.h" +#include "sinkSender.h" @@ -45,6 +46,8 @@ void app_main(void) networkInit(isGpioForceProv()); timesyncInit(); + sinksenderInit(); + /* Start main application now */ while (1) { vTaskDelay(1000 / portTICK_PERIOD_MS); diff --git a/src/main/counter.c b/src/main/counter.c index a40f21d..522abb2 100644 --- a/src/main/counter.c +++ b/src/main/counter.c @@ -20,6 +20,7 @@ static const uint32_t COUNTER_FREQUENCY = 1e6; static xQueueHandle zeroCrossingQueue = NULL; static const uint64_t QUEUE_MARKER = UINT64_MAX; +xQueueHandle minuteBufferQueue = NULL; static t_minuteBuffer minuteBuffer; static uint32_t secondOfMinute; @@ -61,6 +62,9 @@ static void counterZeroCrossingAveragerTask(void *arg) { if (settled) { ESP_LOGI(TAG, "handing over to sender"); + if (minuteBufferQueue) { + xQueueSend(minuteBufferQueue, &minuteBuffer, portMAX_DELAY); + } // sinkSenderSendMinute(); } else { ESP_LOGI(TAG, "now it is settled"); @@ -97,6 +101,8 @@ void IRAM_ATTR counterZeroCrossingISR(void *arg) { } void counterInit() { + ESP_LOGI(TAG, "Initializing counter"); + timer_config_t config = { .divider = 80, .counter_dir = TIMER_COUNT_UP, @@ -109,6 +115,7 @@ void counterInit() { timer_start(TIMER_GROUP_0, 0); zeroCrossingQueue = xQueueCreate(20, sizeof(uint64_t)); + minuteBufferQueue = xQueueCreate(5, sizeof(t_minuteBuffer)); settled = false; secondOfMinute = 0; diff --git a/src/main/sinkSender.c b/src/main/sinkSender.c new file mode 100644 index 0000000..876e1be --- /dev/null +++ b/src/main/sinkSender.c @@ -0,0 +1,33 @@ +#include "sinksender.h" +#include "sinkStruct.h" + +#include +#include + + +#include +#include +#include +#include + +static const char *TAG = "ss"; + + +extern xQueueHandle minuteBufferQueue; + +static void sinksenderExecTask(void *arg) { + while (1) { + if (minuteBufferQueue) { + static t_minuteBuffer minuteBuffer; + if (xQueueReceive(minuteBufferQueue, &minuteBuffer, portMAX_DELAY) == pdPASS) { + ESP_LOGI(TAG, "Got a buffer from queue"); + } + } + } +} + +void sinksenderInit() { + ESP_LOGI(TAG, "Initializing sink sender"); + + xTaskCreate(sinksenderExec, "sinksender_exec_task", 4096, NULL, 5, NULL); +} diff --git a/src/main/sinkSender.h b/src/main/sinkSender.h new file mode 100644 index 0000000..03fe3ea --- /dev/null +++ b/src/main/sinkSender.h @@ -0,0 +1,9 @@ +#ifndef _SINKSENDER_H_ +#define _SINKSENDER_H_ + + +void sinksenderInit(); + + + +#endif // _SINKSENDER_H_ \ No newline at end of file