Browse Source

Improved reception and log output.

Thomas Chef 5 years ago
parent
commit
836fbfc3fd
5 changed files with 64 additions and 35 deletions
  1. 20 18
      main/Sensors/ClasOSensor.c
  2. 4 0
      main/Sensors/oregon.c
  3. 37 14
      main/Sensors/proovesmartSensor.c
  4. 1 1
      main/main.c
  5. 2 2
      main/receiver.c

+ 20 - 18
main/Sensors/ClasOSensor.c

@@ -21,14 +21,12 @@ static uint8_t rx_state = UNKNOWN;
 static uint64_t sensor_data;
 static uint32_t rx_numBits;
 
-static uint32_t debug_width;
 
 void ClasO_ResetDecoder()
 {
     sensor_data = 0;
     rx_numBits = 0;
     rx_state = UNKNOWN;
-    debug_width = 0;
 }
 
 static void addBit(uint8_t value)
@@ -40,14 +38,26 @@ static void addBit(uint8_t value)
     rx_state = TEMP1_OK;
 }
 
+#define START_PULSE_MIN (3880-200)
+#define START_PULSE_MAX (4010+200)
+
+#define T0_PULSE_MIN (380-100)
+#define T0_PULSE_MAX (520+100)
+
+#define SHORT_PULSE_MIN (890-100)
+#define SHORT_PULSE_MAX (990+100)
+
+#define LONG_PULSE_MIN (1880-150)
+#define LONG_PULSE_MAX (1980+150)
+
+
 static int32_t rx_decode(uint32_t width)
 {
     switch (rx_state) {
         case UNKNOWN: // Start of frame
-            if (3700 <= width && width <= 4150)
+            if ( START_PULSE_MIN <= width && width <= START_PULSE_MAX )
             {
                 rx_state = T0;
-                debug_width = width;
             }
             else
             {
@@ -60,17 +70,16 @@ static int32_t rx_decode(uint32_t width)
             if (rx_numBits == 32)
             { // end of frame
                 rx_state = DONE;
-                //printf("c");
                 sensor_data = (sensor_data >> 8); // Mask away some bits at the end
                 return 1;
             }
-            else if (420 <= width && width <= 560)
+            else if( T0_PULSE_MIN <= width && width <= T0_PULSE_MAX )
             {
                 rx_state = T1;
             }
             else
             {
-                if (rx_numBits == 0 && 3700 <= width && width <= 4150 )
+                if (rx_numBits == 0 && START_PULSE_MIN <= width && width <= START_PULSE_MAX )
                 {
                     rx_state = T0;
                 }
@@ -82,13 +91,12 @@ static int32_t rx_decode(uint32_t width)
             break;
 
         case T1:
-            if (880 <= width && width <= 1080)
+            if( SHORT_PULSE_MIN <= width && width <= SHORT_PULSE_MAX )
             {
                 addBit(0);
             }
-            else if (1800 <= width && width <= 2100)
+            else if( LONG_PULSE_MIN <= width && width <= LONG_PULSE_MAX )
             {
-                //debug_width = width;
                 addBit(1);
             }
             else
@@ -119,7 +127,6 @@ int64_t nextPulseClasOSensor(uint32_t width)
                 break;
             case 1:
                 rx_state = DONE;
-                //printf("%d\n",debug_width);
                 break;
             }
         }
@@ -127,17 +134,12 @@ int64_t nextPulseClasOSensor(uint32_t width)
     if (rx_state == DONE) {
         now = millis();
 
-        // For debug only
-        if( ((sensor_data>>12) & 0x007) == 1 ) {
-            ESP_LOGE("CLAS","Width:%u",debug_width);
-        }
-
-
-
         if( sensor_data != previous_data || (now > (old_time+1000)) ) {
             previous_data = sensor_data;
             retVal = sensor_data;
             blinkTheLED();
+
+            
         }
         old_time = now;
         ClasO_ResetDecoder();

+ 4 - 0
main/Sensors/oregon.c

@@ -6,6 +6,8 @@
 #include <string.h>
 #include "esp_log.h"
 
+
+
 static void done ();
 
 static unsigned char total_bits, bits, flip, state, pos, data[25];
@@ -62,6 +64,7 @@ static int rx_decode( int width ) {
                     state = T0;
                 else 
                     manchester(1);  // Width 980
+
                 break;
             case T0:
                 if (w == 0)
@@ -95,6 +98,7 @@ char * nextPulseOregonSensor(uint32_t width) {
             for( int i=0; i<pos; i++ ) {
                 sprintf(result_str+(i*2),"%02X",data[i] );
             }
+
             return result_str;
         }
         else {

+ 37 - 14
main/Sensors/proovesmartSensor.c

@@ -6,6 +6,24 @@
 #include <string.h>
 #include "esp_log.h"
 
+typedef struct {
+    uint32_t max;
+    uint32_t min;
+    uint32_t cnt;
+    uint32_t total;
+} debug_data_t;
+
+debug_data_t debug_data = { 0,99999,0,0 };
+debug_data_t debug_data_tot = { 0,99999,0,0 };
+
+#define DEBUG_WIDTH_FUNC() { \
+                    if( width > debug_data.max ) debug_data.max = width; \
+                    if( width < debug_data.min ) debug_data.min = width; \
+                    debug_data.total += width; \
+                    debug_data.cnt++; \
+                }
+
+
 enum { UNKNOWN, T0, T1, T2, T3, OK_Sensor, DONE };
 
 static unsigned char rx_state = T0;
@@ -32,8 +50,6 @@ static void addBit (uint8_t value) {
 	rx_state = OK_Sensor;
 }
 
-#define MARG 55
-
 static int rx_decode (uint32_t width) {
         
 	switch (rx_state) {
@@ -42,26 +58,27 @@ static int rx_decode (uint32_t width) {
 
         case T0: // First ON-half of pulse : HIGH around 910
 
-            if ( (1010-MARG) <= width && width <= (1080) ) {
+            if ( (960-100) <= width && width <= (1080+100) ) {
                 rx_state = T1;
             }
             else {
-                if( isTrigged ) {
-                    //ESP_LOGE("PROOVE", "T0 Un-Trig B:%u W:%u",rx_numBits,width);
-                }
                 return -1;	// error, reset
             }
             break;
 
         case T1:
-            if ( (445-MARG) <= width && width <= (445+MARG)) {
-                bitData = 1;
-            } else if ( (1420-MARG) <= width && width <= (1420+MARG) ) {
-                bitData = 0;
-            } else  {
-                if( isTrigged ) {
-                    //ESP_LOGE("PROOVE", "T1 Un-Trig B:%u W:%u",rx_numBits,width);
+            
+            if ( 200 <= width && width <= 2000 ) {
+                
+                if( width > 1000 ) {
+                    bitData = 0;
                 }
+                else {
+                    //DEBUG_WIDTH_FUNC();
+                    bitData = 1;
+                }
+
+            } else  {
                 return -1;	// error, reset
             }
 
@@ -123,11 +140,17 @@ int64_t nextPulseProovesmartSensor(uint32_t width)
     if (rx_state == DONE) {
         now = millis();
         sensor_data <<= 8;
+
+        /*
+        if( debug_data.max > debug_data_tot.max ) debug_data_tot.max = debug_data.max;
+        if( debug_data.min < debug_data_tot.min ) debug_data_tot.min = debug_data.min;
+        printf("OREGON DEbug min,max:%u %u\n",debug_data_tot.min,debug_data_tot.max);
+        */
+
         if( sensor_data != previous_data || (now > (old_time+1000)) ) {
             previous_data = sensor_data;
             retVal = sensor_data;
             blinkTheLED();
-            //printf("%d\n",debug_width);
         }
         old_time = now;
         ProovesmartSensor_ResetDecoder();

+ 1 - 1
main/main.c

@@ -61,7 +61,7 @@ void app_main(void)
             int idx=dataArrIdx;
             for(int i=0;i<500;i++) {
                 
-                if( dataArr[idx] > 200 && dataArr[idx] < 5000 ) 
+                if( dataArr[idx] > 40 && dataArr[idx] < 25000 ) 
                     printf("%u\n",dataArr[idx]);
                 else
                     printf("-\n");

+ 2 - 2
main/receiver.c

@@ -58,7 +58,7 @@ void receiverTask(void *pvParameter)
                 int value      = convertToSignedTemp( data & 0xFFF );
                 unsigned char id         = (data>>12) & 0x007;
 
-                ESP_LOGI("RX", "ClasO:  <TR%08llX> %u %d",data,id, value);
+                ESP_LOGI("RX", "ClasO:  <TR%08llX> %u               %4.1f",data,id, (float)value/10);
 
                 sprintf(dataStr,"<TR%08llX>\n",data);
 #ifdef WIFI_ENABLED
@@ -73,7 +73,7 @@ void receiverTask(void *pvParameter)
                 const int value = (data & 0x00FFF0000) >> 16;
                 const int id = (data & 0xFF0000000) >> 28;
 
-                ESP_LOGI("RX", "Proove: <Tr%016llX> ID:%d  %d",data,id,value);
+                ESP_LOGI("RX", "Proove: <Tr%016llX> ID:%d  %4.1f",data,id,(float)value/10);
 
                 sprintf(dataStr,"<Tr%016llX>\n",data);
 #ifdef WIFI_ENABLED