]> git.zerfleddert.de Git - fhem-stuff/commitdiff
better fix for receiving multiple packets, read them all from the fifo!
authorMichael Gernoth <michael@gernoth.net>
Thu, 20 Jun 2013 19:06:23 +0000 (21:06 +0200)
committerMichael Gernoth <michael@gernoth.net>
Thu, 20 Jun 2013 19:06:23 +0000 (21:06 +0200)
culfw/culfw-asksin-fix.diff

index b17fd05a3c6f7af7c486277d95f894535d01a8c4..5c8db334e05ae4c2c040584baacd09bdb67baa55 100644 (file)
@@ -16,7 +16,7 @@ Index: clib/rf_asksin.c
       0x12, 0x03,
       0x15, 0x34,
 -     0x17, 0x30, // always go into IDLE
       0x12, 0x03,
       0x15, 0x34,
 -     0x17, 0x30, // always go into IDLE
-+     0x17, 0x33, // always go into RX after TX, CCA, ELV uses 0x03
++     0x17, 0x3F, // always go into RX after TX, CCA, ELV uses 0x03
       0x18, 0x18,
       0x19, 0x16,
       0x1B, 0x43,
       0x18, 0x18,
       0x19, 0x16,
       0x1B, 0x43,
@@ -55,37 +55,109 @@ Index: clib/rf_asksin.c
  }
  
  void
  }
  
  void
-@@ -97,13 +96,13 @@
-     }
-     
-     rssi = cc1100_sendbyte( 0 );
+@@ -77,80 +76,74 @@
+   uint8_t dec[MAX_ASKSIN_MSG];
+   uint8_t rssi;
+   uint8_t l;
++  uint8_t rxfifo_cnt;
+   if(!asksin_on)
+     return;
+   // see if a CRC OK pkt has been arrived
+   if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
++    while((rxfifo_cnt = cc1100_readReg(CC1100_RXBYTES)) != 0x00) {
++      if (rxfifo_cnt & 0x80) // Overflow
++        break;
+-    enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
++      enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
+-    if (enc[0]>=MAX_ASKSIN_MSG)
+-         enc[0] = MAX_ASKSIN_MSG-1;
 -    
 -    
-+
-     CC1100_DEASSERT;
+-    CC1100_ASSERT;
+-    cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
+-    
+-    for (uint8_t i=0; i<enc[0]; i++) {
+-         enc[i+1] = cc1100_sendbyte( 0 );
+-    }
+-    
+-    rssi = cc1100_sendbyte( 0 );
+-    
+-    CC1100_DEASSERT;
++      if (enc[0]>=MAX_ASKSIN_MSG)
++           enc[0] = MAX_ASKSIN_MSG-1;
++      
++      CC1100_ASSERT;
++      cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
++      
++      for (uint8_t i=0; i<enc[0]; i++) {
++           enc[i+1] = cc1100_sendbyte( 0 );
++      }
++      
++      rssi = cc1100_sendbyte( 0 );
++      /* LQI = */ cc1100_sendbyte( 0 );
  
 -    ccStrobe( CC1100_SFRX  );
 -    ccStrobe( CC1100_SIDLE );
 -    ccStrobe( CC1100_SNOP  );
 -    ccStrobe( CC1100_SRX   );
  
 -    ccStrobe( CC1100_SFRX  );
 -    ccStrobe( CC1100_SIDLE );
 -    ccStrobe( CC1100_SNOP  );
 -    ccStrobe( CC1100_SRX   );
-+    while(cc1100_readReg(CC1100_RXBYTES) & 0x7f)
-+          cc1100_readReg( CC1100_RXFIFO );
-+ 
-+    ccRX();
-     dec[0] = enc[0];
-     dec[1] = (~enc[1]) ^ 0x89;
-@@ -113,7 +112,6 @@
-     
-     dec[l] = enc[l] ^ dec[2];
-     
++      CC1100_DEASSERT;
+-    dec[0] = enc[0];
+-    dec[1] = (~enc[1]) ^ 0x89;
+-    
+-    for (l = 2; l < dec[0]; l++)
+-         dec[l] = (enc[l-1] + 0xdc) ^ enc[l];
+-    
+-    dec[l] = enc[l] ^ dec[2];
 -    
 -    
-     if (tx_report & REP_BINTIME) {
+-    
+-    if (tx_report & REP_BINTIME) {
++      while(cc1100_readReg(CC1100_RXBYTES) & 0x7f)
++              cc1100_readReg( CC1100_RXFIFO );
++ 
++      dec[0] = enc[0];
++      dec[1] = (~enc[1]) ^ 0x89;
        
        
-       DC('a');
-@@ -133,24 +131,17 @@
+-      DC('a');
+-      for (uint8_t i=0; i<=dec[0]; i++)
+-      DC( dec[i] );
+-         
+-    } else {
+-      DC('A');
++      for (l = 2; l < dec[0]; l++)
++           dec[l] = (enc[l-1] + 0xdc) ^ enc[l];
+       
+-      for (uint8_t i=0; i<=dec[0]; i++)
+-        DH2( dec[i] );
++      dec[l] = enc[l] ^ dec[2];
+       
+-      if (tx_report & REP_RSSI)
+-        DH2(rssi);
+-      
+-      DNL();
++      if (tx_report & REP_BINTIME) {
++        
++        DC('a');
++        for (uint8_t i=0; i<=dec[0]; i++)
++        DC( dec[i] );
++           
++      } else {
++        DC('A');
++        
++        for (uint8_t i=0; i<=dec[0]; i++)
++          DH2( dec[i] );
++        
++        if (tx_report & REP_RSSI)
++          DH2(rssi);
++        
++        DNL();
++      }
      }
      }
-     return;
+-
+-    return;
 -       
    }
 -       
 -       
    }
 -       
@@ -116,7 +188,7 @@ Index: clib/rf_asksin.c
  }
  
  void
  }
  
  void
-@@ -173,20 +164,7 @@
+@@ -173,20 +166,7 @@
      my_delay_ms(3);             // 3ms: Found by trial and error
    }
  
      my_delay_ms(3);             // 3ms: Found by trial and error
    }
  
@@ -137,7 +209,7 @@ Index: clib/rf_asksin.c
    enc[0] = dec[0];
    enc[1] = (~dec[1]) ^ 0x89;
  
    enc[0] = dec[0];
    enc[1] = (~dec[1]) ^ 0x89;
  
-@@ -195,6 +173,15 @@
+@@ -195,6 +175,15 @@
    
    enc[l] = dec[l] ^ dec[2];
  
    
    enc[l] = dec[l] ^ dec[2];
  
@@ -153,7 +225,7 @@ Index: clib/rf_asksin.c
    // send
    CC1100_ASSERT;
    cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
    // send
    CC1100_ASSERT;
    cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
-@@ -205,12 +192,17 @@
+@@ -205,12 +194,17 @@
  
    CC1100_DEASSERT;
  
  
    CC1100_DEASSERT;
  
Impressum, Datenschutz