sink sender

This commit is contained in:
2021-03-10 10:48:17 +01:00
parent 0f02861043
commit ca0c49ec48
5 changed files with 53 additions and 0 deletions

View File

@ -4,4 +4,5 @@ idf_component_register(SRCS "app_main.c"
"counter.c"
"timesync.c"
"sha256.c"
"sinkSender.c"
INCLUDE_DIRS ".")

View File

@ -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);

View File

@ -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;

33
src/main/sinkSender.c Normal file
View File

@ -0,0 +1,33 @@
#include "sinksender.h"
#include "sinkStruct.h"
#include <stdint.h>
#include <stdbool.h>
#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/queue.h>
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);
}

9
src/main/sinkSender.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef _SINKSENDER_H_
#define _SINKSENDER_H_
void sinksenderInit();
#endif // _SINKSENDER_H_