123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #include <stdio.h>
- #include "sw_fifo_1.h"
- #include "sw_fifo_2.h"
- #include "app.h"
- #include "led_blink.h"
- #include "main.h"
- #include "queue.h"
- #include "temp1.h"
- #include "temp2.h"
- #include "temp3.h"
- #include "nexa.h"
- #include "stm32f4xx_hal.h"
- #include "stm32f4xx_hal_gpio.h"
- #include "wifi.h"
- #include "receiver.h"
- #include "interrupts.h"
- int receiverEnabled = 0;
- unsigned long startLogging=0; // Keep the time for next lo gevent
- int startLoggingState=0; // 0=Not active, 1=Wait for next event, 2=Sample-state
- int noLogsSent=0; // Number of logs that have been sent
- int startLoggingPos=0;
- int stopLoggingPos=0;
- int loggingReady=0;
- // This receiver task is called every 1mS, with a rather low priority.
- void receiver() {
- static unsigned int width;
-
- static unsigned long previous_temp0 = 0; // Get the current time
- static unsigned long previous_temp1 = 0; // Get the current time
- static unsigned long previous_temp2 = 0; // Get the current time
- static unsigned long previous_temp3 = 0; // Get the current time
- static unsigned long previous_now = 0; // Get the current time
- unsigned long now = millis(); // Get the current time
-
- if( receiverEnabled == 0 ) return;
-
- // Check millis() for wrapping (after 49 days)
- if( previous_now > now ) {
- previous_temp3 = 0;
- }
-
- while( rcvDeQueue(&width) ) {
-
- // ***************** NEXA *********************
- /* if( nextPulseNexa(width) ) {
- if( now > (previous_temp0+1000) ) {
- wifi_rcvEnQueue( 0, (unsigned int)(x_data & 0xFFFFFFFF)); // Send to queue to be sent to WiFi (in WiFi.c via main-loop in app.c)
- previous_temp0 = now;
- }
- resetDecoder();
- blinkTheLED();
- }
- */
- /*
- // TEMP 1
- if( nextPulseTemp1(width) ) {
- if( now > (previous_temp1+1000) ) {
- wifi_rcvEnQueue( 1, (unsigned int)(temp1_x_data & 0xFFFFFFFF)); // Send to queue to be sent to WiFi (in WiFi.c via main-loop in app.c)
- previous_temp1 = now;
- }
- temp1ResetDecoder();
- blinkTheLED();
- }
- */
- /*
- // TEMP 2
- if( nextPulseTemp2(width) ) {
- if( now > (previous_temp2+1000) ) {
- wifi_rcvEnQueue( 2, temp2_x_data ); // Send to queue to be sent to WiFi (in WiFi.c via main-loop in app.c)
- previous_temp2 = now;
- }
- temp2ResetDecoder();
- blinkTheLED();
- } */
- // TEMP 3
- if( nextPulseTemp3(width) ) {
-
- if( ((temp3_x_data & 0xFC000000) >> 26) == 4 ) {
- startLogging = millis()+59500; // Reset the timer for the next sample-event
- startLoggingState = 1;
- }
-
- if( now > (previous_temp3+1000) ) {
- wifi_rcvEnQueue( 3, (unsigned int)(temp3_x_data & 0xFFFFFFFF)); // Send to queue to be sent to WiFi (in WiFi.c via main-loop in app.c)
- previous_temp3 = now;
- }
- temp3ResetDecoder();
- blinkTheLED();
- }
-
- // Handle logging
- if( startLoggingState == 1 ) {
- if( now >= startLogging ) {
- // Start sampling
- startLoggingPos = logCounter; // Save start-log-position
- startLogging = now + 1000; // Set timer for next event
- startLoggingState = 2;
- }
- }
- if( startLoggingState == 2 ) {
- // Logging is occuring....
- if( now >= startLogging ) {
- // Stop sampling
- stopLoggingPos = logCounter; // Save end-log-position
- startLogging = now + 59500; // Set timer for next event
- startLoggingState = 1;
- loggingReady = 1;
- noLogsSent++;
- if( noLogsSent == 3 ) {
- startLoggingState=0; // Turn off log-send after 3 missed messages
- }
- }
- }
- }
-
- previous_now = now;
- }
|