Browse Source

Added the oregon PCR800 Rain-sensor. Sending the raw 10 bytes to the Pi.
Oregon V3-protocol added.

TC 7 years ago
parent
commit
fe033872e9
5 changed files with 568 additions and 368 deletions
  1. 58 0
      PCR800 Anteckningar.txt
  2. 426 291
      Projects/EWARM/Test1.dep
  3. 19 1
      Src/app.c
  4. 63 68
      Src/oregon.c
  5. 2 8
      Src/oregon.h

+ 58 - 0
PCR800 Anteckningar.txt

@@ -0,0 +1,58 @@
+Cnt: 10
+
+------------------------ Data received (OV3):
+Data: 2A 19 04 97   00 00 10 68    00 F0 
+Data: 2A 19 04 97   90 83 73 80    00 60
+
+---------------------------------------------
+
+Sensor ID: (16 bits):       2A19
+Channel: ( 4 bits ):           0
+Rolling code:                 49
+Flags:                         7
+
+Data 1:
+Data 2: 
+
+Checksum:                     00
+Post-amble:                   60
+
+------------------------- Nedan från: https://www.disk91.com/2013/technology/hardware/oregon-scientific-sensors-with-raspberry-pi/
+Example:
+OSV2 1A2D1002 502060552A4C
+OSV2 A 1D20 1 20 0 502 0 655 2A 4
+
+My case 1:
+2A 19 04 97   00 00 10 68    00 F0
+A291497900000186 00F0 
+A 2914 9 79 0 0000 18600F 0   (681)               = 17.3mm ????
+
+My case 2:
+2A 19 04 97   90 83 73 80    00 60
+A 2914 9 79 0 9383 708000 6    (807) ??? * 0.001" = 20.5mm ????
+
+------------------------- Nedan från källkod för Windows program: https://sourceforge.net/projects/wmrx00/?source=typ_redirect
+Varje nibble kommer som en egen data, dvs 20 data nibblar i detta paket (med 10 bytes)
+
+Data: 2A 19 04 97   00 00 10 68    00 F0
+
+bool rainGageBatteryOk = (Message[7] & 0x4) == 0;
+I fallet ovan blir det då 0x7 & 0x4 = 1 = Dåligt batteri ?
+Eller om man vänder på kvartarna:
+A29149790000 018600 F0
+0x9 & 0x4 = 0 = Bra batteri
+
+double total = 100 * Message[17] + 10 * Message[16] + Message[15] + 0.1 * Message[14] + 0.01 * Message[13] + 0.001 * Message[12];
+Vända nibblar:   100*0          +  10*0             +  6          + 0.1*8             + 0.01*1             + 0.001 * 0 = 006.810 
+
+A29149790938 370800 06 = 008.073  
+
+2A190497000020020150
+A29140790000 022010 50 = 010.220
+
+2A190497000010060180
+A29140790000 016010 80 = 010.610  <-- En flip mer än exemplet ovan ~ 1mm mera. Värdet kanske är i 0.001" ??  
+
+
+
+

File diff suppressed because it is too large
+ 426 - 291
Projects/EWARM/Test1.dep


+ 19 - 1
Src/app.c

@@ -71,6 +71,8 @@ void setup() {
   
   rcvInitQueue();
   
+  resetOV3Decoder();
+  
   disableRx = false;
 }
 
@@ -136,7 +138,23 @@ void loop() {
   
   if( rcvDeQueue(&width) ) {
     
-    // Oregon V3
+    // ---------- Oregon V3 --------------
+    if( nextPulseoregonV3(width) ) {
+      
+      unsigned char count;
+      const unsigned char* data = getOV3Data(&count);
+
+      sprintf(hex,"<RR");
+      
+      if( count == 10 ) {
+        for( int i=0; i<count; i++ ) {
+          sprintf(hex+3+(i*2),"%02X",data[i] );
+        }
+        sprintf(hex+3+(10*2),">" );
+        printf(hex);
+      }
+      resetOV3Decoder();
+    }
     
     
     // ********** TEMP1 ***********

+ 63 - 68
Src/oregon.c

@@ -2,50 +2,51 @@
 #include "nexa.h"
 #include "oregon.h"
 
-// Constructor must run resetDecoder()
+// Constructor must run resetOV3Decoder()
 
-unsigned char total_bits, bits, flip, state, pos, data[25];
+static int decode(int width);
+static void done ();
+static boolean isDone();
+
+
+static unsigned char total_bits, bits, flip, state, pos, data[25];
 
 enum { UNKNOWN, T0, T1, T2, T3, OK, DONE };
 
 
-    boolean nextPulse (unsigned short width) {
+    boolean nextPulseoregonV3(unsigned int width) {
         if (state != DONE)
         
             switch (decode(width)) {
-                case -1: resetDecoder(); break;
+                case -1: resetOV3Decoder(); break;
                 case 1:  done(); break;
             }
         return isDone();
     }
     
-    boolean isDone() {
+    static boolean isDone() {
       return state == DONE;
     }
 
-    const unsigned char* getData (unsigned char& count) {
-        count = pos;
+    const unsigned char* getOV3Data (unsigned char *count) {
+        *count = pos;
         return data; 
     }
     
-    void resetDecoder () {
+    void resetOV3Decoder () {
         total_bits = bits = pos = flip = 0;
         state = UNKNOWN;
     }
     
-    // add one bit to the packet data buffer
-    
-    virtual void gotBit (unsigned char value) {
+   
+    // V3-Version of the gitBit-function
+    void gotBit (char value) {
+        data[pos] = (data[pos] >> 1) | (value ? 0x80 : 00);
         total_bits++;
-        byte *ptr = data + pos;
-        *ptr = (*ptr >> 1) | (value << 7);
-
-        if (++bits >= 8) {
-            bits = 0;
-            if (++pos >= sizeof data) {
-                resetDecoder();
-                return;
-            }
+        pos = total_bits >> 3;
+        if (pos >= sizeof data) {
+            resetOV3Decoder();
+            return;
         }
         state = OK;
     }
@@ -55,41 +56,8 @@ enum { UNKNOWN, T0, T1, T2, T3, OK, DONE };
         flip ^= value; // manchester code, long pulse flips the bit
         gotBit(flip);
     }
-    
-    // move bits to the front so that all the bits are aligned to the end
-    void alignTail (byte max =0) {
-        // align bits
-        if (bits != 0) {
-            data[pos] >>= 8 - bits;
-            for (byte i = 0; i < pos; ++i)
-                data[i] = (data[i] >> bits) | (data[i+1] << (8 - bits));
-            bits = 0;
-        }
-        // optionally shift bytes down if there are too many of 'em
-        if (max > 0 && pos > max) {
-            byte n = pos - max;
-            pos = max;
-            for (byte i = 0; i < pos; ++i)
-                data[i] = data[i+n];
-        }
-    }
-    
-    void reverseBits () {
-        for (byte i = 0; i < pos; ++i) {
-            byte b = data[i];
-            for (byte j = 0; j < 8; ++j) {
-                data[i] = (data[i] << 1) | (b & 1);
-                b >>= 1;
-            }
-        }
-    }
-    
-    void reverseNibbles () {
-        for (byte i = 0; i < pos; ++i)
-            data[i] = (data[i] << 4) | (data[i] >> 4);
-    }
-    
-    void done () {
+   
+    static void done () {
         while (bits)
             gotBit(0); // padding
         state = DONE;
@@ -97,21 +65,11 @@ enum { UNKNOWN, T0, T1, T2, T3, OK, DONE };
 
 
     
-    // add one bit to the packet data buffer
-    void gotBit (char value) {
-        data[pos] = (data[pos] >> 1) | (value ? 0x80 : 00);
-        total_bits++;
-        pos = total_bits >> 3;
-        if (pos >= sizeof data) {
-            resetDecoder();
-            return;
-        }
-        state = OK;
-    }
+
     
-    virtual char decode (word width) {
+    static int decode (int width) {
         if (200 <= width && width < 1200) {
-            byte w = width >= 700;
+            char w = width >= 700;
             switch (state) {
                 case UNKNOWN:
                     if (w == 0)
@@ -141,4 +99,41 @@ enum { UNKNOWN, T0, T1, T2, T3, OK, DONE };
         return  total_bits == 80 ? 1: 0;
     }
 
+/*    
+    // move bits to the front so that all the bits are aligned to the end
+    static void alignTail(char max) {
+        // align bits
+        if (bits != 0) {
+            data[pos] >>= 8 - bits;
+            for (char i = 0; i < pos; ++i)
+                data[i] = (data[i] >> bits) | (data[i+1] << (8 - bits));
+            bits = 0;
+        }
+        // optionally shift bytes down if there are too many of 'em
+        if (max > 0 && pos > max) {
+            char n = pos - max;
+            pos = max;
+            for (char i = 0; i < pos; ++i)
+                data[i] = data[i+n];
+        }
+    }
+*/
 
+/*    
+    static void reverseBits () {
+        for (char i = 0; i < pos; ++i) {
+            char b = data[i];
+            for (char j = 0; j < 8; ++j) {
+                data[i] = (data[i] << 1) | (b & 1);
+                b >>= 1;
+            }
+        }
+    }
+*/
+
+/*    
+    static void reverseNibbles () {
+        for (char i = 0; i < pos; ++i)
+            data[i] = (data[i] << 4) | (data[i] >> 4);
+    }
+*/ 

+ 2 - 8
Src/oregon.h

@@ -3,19 +3,13 @@
 
 #include "app.h"
 
-void oregonV3ResetDecoder ();
+void resetOV3Decoder();
 
 extern unsigned long long oregonV3_x_data;
 
 boolean nextPulseoregonV3(unsigned int width);
 
-typedef struct {
-unsigned int remote_id;
-unsigned char group;
-unsigned char onOff;
-unsigned char channel;
-unsigned char button;
-} OREGONV3_QUEUE_DATA;
+const unsigned char* getOV3Data (unsigned char *count);