From: Michael Gernoth Date: Fri, 21 Jun 2013 11:16:08 +0000 (+0200) Subject: fix logic error in comparison and handle rx overflow X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/fhem-stuff/commitdiff_plain/1bfa61a8221f20d0454347161dbc69a27e1d4cb0 fix logic error in comparison and handle rx overflow --- diff --git a/culfw/culfw-asksin-fix.diff b/culfw/culfw-asksin-fix.diff index bbe630f..2a84f89 100644 --- a/culfw/culfw-asksin-fix.diff +++ b/culfw/culfw-asksin-fix.diff @@ -2,8 +2,13 @@ Index: clib/rf_asksin.c =================================================================== --- clib/rf_asksin.c (revision 373) +++ clib/rf_asksin.c (working copy) -@@ -11,13 +11,13 @@ +@@ -9,15 +9,18 @@ + #include "rf_asksin.h" + ++//we receive a new byte approximately every 7 ms... ++#define RX_TIMEOUT_MS 10 ++ uint8_t asksin_on = 0; -const uint8_t PROGMEM ASKSIN_CFG[50] = { @@ -19,7 +24,7 @@ Index: clib/rf_asksin.c 0x0B, 0x06, 0x0D, 0x21, 0x0E, 0x65, -@@ -26,18 +26,22 @@ +@@ -26,18 +29,22 @@ 0x11, 0x93, 0x12, 0x03, 0x15, 0x34, @@ -45,7 +50,7 @@ Index: clib/rf_asksin.c void rf_asksin_init(void) { -@@ -56,20 +60,44 @@ +@@ -56,20 +63,44 @@ my_delay_us(100); // load configuration @@ -96,11 +101,12 @@ Index: clib/rf_asksin.c void rf_asksin_task(void) { -@@ -77,18 +105,41 @@ +@@ -77,18 +108,51 @@ uint8_t dec[MAX_ASKSIN_MSG]; uint8_t rssi; uint8_t l; + uint8_t rxfifo_cnt; ++ uint16_t timeout; if(!asksin_on) return; @@ -128,22 +134,31 @@ Index: clib/rf_asksin.c + return; + } + -+ l = 50; -+ while (l-- && ((enc[0] + 2) < rxfifo_cnt)) { // Wait for more data -+ my_delay_ms(1); -+ rxfifo_cnt = (read_cc1100_rxbytes() & 0x7f); -+ } ++ if ((enc[0] + 2) > rxfifo_cnt) { ++ timeout = RX_TIMEOUT_MS * ((enc[0] + 2) - rxfifo_cnt); ++ while (timeout-- && ((enc[0] + 2) > rxfifo_cnt)) { // Wait for more data ++ my_delay_ms(1); ++ rxfifo_cnt = read_cc1100_rxbytes(); + -+ if (!l) { -+ // Not enough data received, out of sync? -+ rf_asksin_reset_rx(); -+ return; ++ if (rxfifo_cnt & 0x80) { // Overflow ++ rf_asksin_reset_rx(); ++ return; ++ } ++ ++ rxfifo_cnt &= 0x7f; ++ } ++ ++ if (!timeout) { ++ // Not enough data received, out of sync? ++ rf_asksin_reset_rx(); ++ return; ++ } + } + CC1100_ASSERT; cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO ); -@@ -97,14 +148,19 @@ +@@ -97,14 +161,19 @@ } rssi = cc1100_sendbyte( 0 ); @@ -168,7 +183,7 @@ Index: clib/rf_asksin.c dec[0] = enc[0]; dec[1] = (~enc[1]) ^ 0x89; -@@ -113,7 +169,6 @@ +@@ -113,7 +182,6 @@ dec[l] = enc[l] ^ dec[2]; @@ -176,7 +191,7 @@ Index: clib/rf_asksin.c if (tx_report & REP_BINTIME) { DC('a'); -@@ -131,26 +186,17 @@ +@@ -131,26 +199,17 @@ DNL(); } @@ -212,7 +227,7 @@ Index: clib/rf_asksin.c } void -@@ -173,20 +219,7 @@ +@@ -173,20 +232,7 @@ my_delay_ms(3); // 3ms: Found by trial and error } @@ -233,7 +248,7 @@ Index: clib/rf_asksin.c enc[0] = dec[0]; enc[1] = (~dec[1]) ^ 0x89; -@@ -195,6 +228,15 @@ +@@ -195,6 +241,15 @@ enc[l] = dec[l] ^ dec[2]; @@ -249,7 +264,7 @@ Index: clib/rf_asksin.c // send CC1100_ASSERT; cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO); -@@ -205,12 +247,17 @@ +@@ -205,12 +260,17 @@ CC1100_DEASSERT;