]> git.zerfleddert.de Git - fhem-stuff/blame - culfw/culfw-asksin-fix.diff
don't get confused when more than one packet is received
[fhem-stuff] / culfw / culfw-asksin-fix.diff
CommitLineData
b2720844
MG
1Index: clib/rf_asksin.c
2===================================================================
3--- clib/rf_asksin.c (revision 373)
4+++ clib/rf_asksin.c (working copy)
5@@ -11,7 +11,7 @@
6
7 uint8_t asksin_on = 0;
8
9-const uint8_t PROGMEM ASKSIN_CFG[50] = {
10+const uint8_t PROGMEM ASKSIN_CFG[] = {
11 0x00, 0x07,
12 0x02, 0x2e,
13 0x03, 0x0d,
777ef621 14@@ -26,16 +26,17 @@
b2720844
MG
15 0x11, 0x93,
16 0x12, 0x03,
17 0x15, 0x34,
18- 0x17, 0x30, // always go into IDLE
65862dac 19+ 0x17, 0x33, // always go into RX after TX, CCA, ELV uses 0x03
b2720844
MG
20 0x18, 0x18,
21 0x19, 0x16,
22 0x1B, 0x43,
23 0x21, 0x56,
24 0x25, 0x00,
25 0x26, 0x11,
26+ 0x29, 0x59,
27+ 0x2c, 0x81,
28 0x2D, 0x35,
777ef621 29- 0x3e, 0xc3,
b2720844 30- 0xff
777ef621 31+ 0x3e, 0xc3
b2720844
MG
32 };
33
34 void
777ef621 35@@ -56,18 +57,16 @@
b2720844
MG
36 my_delay_us(100);
37
38 // load configuration
39- for (uint8_t i = 0; i<50; i += 2) {
777ef621
MG
40-
41- if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
42- break;
43-
b2720844 44+ for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) {
777ef621
MG
45 cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]),
46 pgm_read_byte(&ASKSIN_CFG[i+1]) );
47 }
b2720844
MG
48
49 ccStrobe( CC1100_SCAL );
50
51- my_delay_ms(1);
52+ my_delay_ms(4);
53+
54+ ccRX();
55 }
56
57 void
65862dac 58@@ -97,13 +96,13 @@
b2720844
MG
59 }
60
61 rssi = cc1100_sendbyte( 0 );
65862dac
MG
62-
63+
b2720844
MG
64 CC1100_DEASSERT;
65
66- ccStrobe( CC1100_SFRX );
67- ccStrobe( CC1100_SIDLE );
68- ccStrobe( CC1100_SNOP );
69- ccStrobe( CC1100_SRX );
65862dac
MG
70+ while(cc1100_readReg(CC1100_RXBYTES) & 0x7f)
71+ cc1100_readReg( CC1100_RXFIFO );
72+
73+ ccRX();
74
b2720844
MG
75 dec[0] = enc[0];
76 dec[1] = (~enc[1]) ^ 0x89;
65862dac 77@@ -113,7 +112,6 @@
b2720844
MG
78
79 dec[l] = enc[l] ^ dec[2];
80
81-
82 if (tx_report & REP_BINTIME) {
83
84 DC('a');
65862dac 85@@ -133,24 +131,17 @@
b2720844
MG
86 }
87
88 return;
89-
90 }
91-
92-
93- switch (cc1100_readReg( CC1100_MARCSTATE )) {
94-
95- // RX_OVERFLOW
96- case 17:
97- // IDLE
98- case 1:
99- ccStrobe( CC1100_SFRX );
100- ccStrobe( CC1100_SIDLE );
101- ccStrobe( CC1100_SNOP );
102- ccStrobe( CC1100_SRX );
103- break;
104-
105- }
106
65862dac
MG
107+ switch(cc1100_readReg( CC1100_MARCSTATE )) {
108+ case MARCSTATE_RXFIFO_OVERFLOW:
b2720844 109+ ccStrobe( CC1100_SFRX );
65862dac 110+ case MARCSTATE_IDLE:
b2720844
MG
111+ ccStrobe( CC1100_SIDLE );
112+ ccStrobe( CC1100_SNOP );
113+ ccStrobe( CC1100_SRX );
65862dac 114+ break;
b2720844
MG
115+ }
116 }
117
118 void
65862dac 119@@ -173,20 +164,7 @@
b2720844
MG
120 my_delay_ms(3); // 3ms: Found by trial and error
121 }
122
123- ccStrobe(CC1100_SIDLE);
124- ccStrobe(CC1100_SFRX );
125- ccStrobe(CC1100_SFTX );
126-
127- if (dec[2] & (1 << 4)) { //BURST-bit set?
128- ccStrobe(CC1100_STX ); //We need to send a burst
129-
130- //According to ELV, devices get activated every 300ms, so send burst for 360ms
131- for(l = 0; l < 3; l++)
132- my_delay_ms(120); //arg is uint_8, so loop
133- }
134-
135 // "crypt"
136-
137 enc[0] = dec[0];
138 enc[1] = (~dec[1]) ^ 0x89;
139
65862dac 140@@ -195,6 +173,15 @@
b2720844
MG
141
142 enc[l] = dec[l] ^ dec[2];
143
144+ ccTX();
145+ if (dec[2] & (1 << 4)) { // BURST-bit set?
146+ // According to ELV, devices get activated every 300ms, so send burst for 360ms
147+ for(l = 0; l < 3; l++)
148+ my_delay_ms(120); // arg is uint_8, so loop
5f2228fc
MG
149+ } else {
150+ my_delay_ms(10);
b2720844
MG
151+ }
152+
153 // send
154 CC1100_ASSERT;
155 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
65862dac 156@@ -205,12 +192,17 @@
b2720844
MG
157
158 CC1100_DEASSERT;
159
160- ccStrobe( CC1100_SFRX );
161- ccStrobe( CC1100_STX );
162+ // wait for TX to finish
163+ while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX)
164+ ;
777ef621
MG
165+
166+ if (cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TXFIFO_UNDERFLOW) {
167+ ccStrobe( CC1100_SFTX );
168+ ccStrobe( CC1100_SIDLE );
169+ ccStrobe( CC1100_SNOP );
170+ ccStrobe( CC1100_SRX );
171+ }
b2720844
MG
172
173- while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )
174- my_delay_ms(5);
175-
176 if(asksin_on) {
177 ccRX();
178 } else {
Impressum, Datenschutz