wifidmm/src/wifidmm.c

56 lines
1.5 KiB
C

#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <espressif/esp_common.h>
#include <esp/uart.h>
#include <FreeRTOS.h>
#include <task.h>
#include "common.h"
#include "network.h"
#include "httpd.h"
/* This task continuosly listen for incoming data
* on the UART line, parses the packets and feeds
* the meter readings to the network shipping task
* discarding invalid packets
*/
void SerialDataCollectionTask(void *p) {
char c;
char buffer[50];
int bufpos = 0;
for (;;) {
if (read(0, (void *)&c, 1)) {
printf("%02x", c);
if (bufpos < sizeof(buffer) / sizeof(buffer[0]) - 1)
buffer[bufpos++] = c;
if (c == '\n') {
buffer[bufpos] = '\0';
/* TODO: Send the frame to the shipping task */
bufpos = 0;
printf("Measurement: %s\n", buffer);
}
}
}
}
/* This task sends parsed measurements to the network */
void MeasurementShippingTask(void *p) {
for (;;)
vTaskDelay(TIME_MS(5000));
}
void user_init(void) {
uart_set_baud(0, 115200);
printf("SDK version:%s\n", sdk_system_get_sdk_version());
xTaskCreate(NetworkConnectionTask, "NetworkConnection", 512, NULL, 1, NULL);
xTaskCreate(SerialDataCollectionTask, "SerialDataCollection", 512, NULL, 2, NULL);
xTaskCreate(MeasurementShippingTask, "MeasurementShipping", 512, NULL, 1, NULL);
xTaskCreate(httpd_task, "httpd", 512, NULL, 1, NULL);
}
/* vim: set et ai ts=4 sw=4: */