|
@@ -3,8 +3,10 @@
|
3
|
3
|
*/
|
4
|
4
|
|
5
|
5
|
#ifdef DEBUG
|
|
6
|
+
|
6
|
7
|
//#define DEBUG_TEST_PART_VERSION
|
7
|
8
|
//#define DEBUG_EEPROM_DATA_READ
|
|
9
|
+//#define DEBUG_EEPROM_DATA_WRITE
|
8
|
10
|
//#define DEBUG_MISSING_PACKETS
|
9
|
11
|
//#define DEBUG_PACKET_DUMP
|
10
|
12
|
//#define DEBUG_PACKET_DUMP_TUNE
|
|
@@ -12,7 +14,13 @@
|
12
|
14
|
//#define DEBUG_PACKET_DUMP_LIST
|
13
|
15
|
//#define DEBUG_PPM_VALUES
|
14
|
16
|
//#define DEBUG_ERROR_MESSAGES
|
15
|
|
-#define DEBUG_PACKET_DOT
|
|
17
|
+//#define DEBUG_MESSAGES
|
|
18
|
+//#define DEBUG_HOP_DATA
|
|
19
|
+
|
|
20
|
+#define DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
21
|
+
|
|
22
|
+#define ALWAYS_PERFORM_BINDING
|
|
23
|
+
|
16
|
24
|
#endif
|
17
|
25
|
|
18
|
26
|
#include <stdint.h>
|
|
@@ -29,16 +37,14 @@
|
29
|
37
|
#include "main.h"
|
30
|
38
|
|
31
|
39
|
#define CHANNELS 8
|
32
|
|
-#define PPM_MIN 1000
|
33
|
|
-#define PPM_MAX 2000
|
34
|
40
|
#define HOP_DATA_LENGTH 60
|
35
|
41
|
#define EEPROM_BASE_ADDRESS 100
|
36
|
|
-#define MISSING_PACKET_DELAY 9
|
|
42
|
+#define MISSING_PACKET_DELAY 10 // was 9 originally
|
37
|
43
|
#define SEEK_CHANNEL_SKIP 13
|
38
|
44
|
#define MAX_MISSING_PACKET 20
|
39
|
45
|
#define FAILSAFE_MISSING_PACKET 170
|
40
|
46
|
|
41
|
|
-//#define FAILSAFE_INVALID_VALUE 850
|
|
47
|
+#define FAILSAFE_INVALID_VALUE 850
|
42
|
48
|
#define FAILSAFE_INVALID_VALUE_MINIMUM 900
|
43
|
49
|
#define FAILSAFE_INVALID_VALUE_MAXIMUM 2100
|
44
|
50
|
|
|
@@ -46,6 +52,8 @@
|
46
|
52
|
#define RSSI_OFFSET 71
|
47
|
53
|
#define RSSI_MIN -103
|
48
|
54
|
#define RSSI_MAX -96
|
|
55
|
+#define PPM_MIN 1000
|
|
56
|
+#define PPM_MAX 2000
|
49
|
57
|
|
50
|
58
|
#define PPM_SCALE 2 / 3
|
51
|
59
|
|
|
@@ -59,7 +67,7 @@
|
59
|
67
|
#define FREQ_SCAN_START_1 0x76
|
60
|
68
|
#define FREQ_SCAN_START_0 0x00
|
61
|
69
|
|
62
|
|
-uint8_t ccData[27];
|
|
70
|
+uint8_t ccData[100]; // was 27, led to buffer overruns?!
|
63
|
71
|
uint8_t ccLen;
|
64
|
72
|
uint8_t packet = 0;
|
65
|
73
|
uint8_t channr = 0;
|
|
@@ -69,7 +77,7 @@ uint8_t listLength;
|
69
|
77
|
uint8_t txid[2];
|
70
|
78
|
uint8_t counter = 0;
|
71
|
79
|
uint8_t failed = 0;
|
72
|
|
-uint8_t frequencyOffsetHack = 0;
|
|
80
|
+uint16_t frequencyOffsetHack = 0;
|
73
|
81
|
uint16_t c[CHANNELS];
|
74
|
82
|
|
75
|
83
|
#ifdef FREQUENCY_SCAN
|
|
@@ -92,21 +100,30 @@ static void binding(void);
|
92
|
100
|
static void tuning(void);
|
93
|
101
|
static void performBind(void);
|
94
|
102
|
static void nextChannel(uint8_t skip);
|
95
|
|
-static void readBindingData(void);
|
96
|
103
|
static void writeBindingData(void);
|
97
|
104
|
|
|
105
|
+#ifndef ALWAYS_PERFORM_BINDING
|
|
106
|
+static void readBindingData(void);
|
|
107
|
+#endif
|
|
108
|
+
|
98
|
109
|
void rxInit(void) {
|
99
|
110
|
GDO_dir;
|
100
|
111
|
|
|
112
|
+#ifdef DEBUG_MESSAGES
|
101
|
113
|
debugWrite("RX: initializing\n");
|
|
114
|
+#endif
|
102
|
115
|
|
103
|
116
|
initialize(1); // binding
|
104
|
117
|
|
|
118
|
+#ifdef DEBUG_MESSAGES
|
105
|
119
|
debugWrite("RX: binding\n");
|
|
120
|
+#endif
|
106
|
121
|
|
107
|
122
|
binding();
|
108
|
123
|
|
|
124
|
+#ifdef DEBUG_MESSAGES
|
109
|
125
|
debugWrite("RX: receiving\n");
|
|
126
|
+#endif
|
110
|
127
|
|
111
|
128
|
initialize(0); // data
|
112
|
129
|
cc2500WriteReg(CC2500_0A_CHANNR, hopData[channr]);// 0A - hop
|
|
@@ -165,9 +182,10 @@ static void initialize(uint8_t bind) {
|
165
|
182
|
//cc2500WriteReg(CC2500_03_FIFOTHR, 0x0F); // 0x07?
|
166
|
183
|
|
167
|
184
|
cc2500WriteReg(CC2500_09_ADDR, bind ? 0x03 : txid[0]);
|
168
|
|
- //cc2500WriteReg(CC2500_09_ADDR, bind ? 0x00 : txid[0]);
|
169
|
185
|
|
|
186
|
+#ifdef DEBUG_MESSAGES
|
170
|
187
|
debugWrite("CC2500: Entering IDLE mode...\n");
|
|
188
|
+#endif
|
171
|
189
|
|
172
|
190
|
cc2500Strobe(CC2500_SIDLE); // Go to idle...
|
173
|
191
|
|
|
@@ -196,14 +214,18 @@ static void initialize(uint8_t bind) {
|
196
|
214
|
}
|
197
|
215
|
|
198
|
216
|
static void binding(void) {
|
|
217
|
+#ifndef ALWAYS_PERFORM_BINDING
|
199
|
218
|
readBindingData();
|
200
|
219
|
if ((txid[0] != 0xff) || (txid[1] != 0xff)) {
|
201
|
220
|
// valid binding data found
|
202
|
221
|
debugWrite("RX: found data in EEPROM!\n");
|
203
|
222
|
return;
|
204
|
223
|
}
|
|
224
|
+#endif
|
205
|
225
|
|
|
226
|
+#ifdef DEBUG_MESSAGES
|
206
|
227
|
debugWrite("RX: no stored data, tuning...\n");
|
|
228
|
+#endif
|
207
|
229
|
|
208
|
230
|
// No valid txid, forcing bind
|
209
|
231
|
tuning();
|
|
@@ -212,7 +234,15 @@ static void binding(void) {
|
212
|
234
|
cc2500WriteReg(CC2500_0C_FSCTRL0, frequencyOffsetHack);
|
213
|
235
|
eeprom_write_byte(EEPROM_BASE_ADDRESS + 101, frequencyOffsetHack);
|
214
|
236
|
|
|
237
|
+#ifdef DEBUG_EEPROM_DATA_WRITE
|
|
238
|
+ debugWrite("RX: Write EEPROM Frequency Offset Hack: ");
|
|
239
|
+ serialWriteUnsigned8(0, frequencyOffsetHack);
|
|
240
|
+ debugWrite("\n");
|
|
241
|
+#endif
|
|
242
|
+
|
|
243
|
+#ifdef DEBUG_MESSAGES
|
215
|
244
|
debugWrite("RX: tuned, binding...\n");
|
|
245
|
+#endif
|
216
|
246
|
|
217
|
247
|
performBind();
|
218
|
248
|
}
|
|
@@ -223,42 +253,43 @@ static void tuning() {
|
223
|
253
|
uint16_t frequencyOffsetTimer = 0;
|
224
|
254
|
while (1) {
|
225
|
255
|
frequencyOffsetTimer++;
|
226
|
|
- if (frequencyOffsetTimer > 3000) {
|
227
|
|
- frequencyOffsetTimer = 0;
|
228
|
|
- cc2500WriteReg(CC2500_0C_FSCTRL0, frequencyOffsetHack);
|
229
|
|
- if (frequencyOffsetHack <= 250) {
|
230
|
|
- frequencyOffsetHack += 5;
|
231
|
|
- } else {
|
232
|
|
- frequencyOffsetHack = 0;
|
|
256
|
+ if (frequencyOffsetHack >= 250) {
|
|
257
|
+ frequencyOffsetHack = 0;
|
233
|
258
|
|
234
|
259
|
#ifdef FREQUENCY_SCAN
|
235
|
|
- if (freq0 < 255) {
|
236
|
|
- freq0++;
|
|
260
|
+ if (freq0 < 255) {
|
|
261
|
+ freq0++;
|
|
262
|
+ } else {
|
|
263
|
+ freq0 = 0;
|
|
264
|
+ if (freq1 < 255) {
|
|
265
|
+ freq1++;
|
237
|
266
|
} else {
|
238
|
|
- freq0 = 0;
|
239
|
|
- if (freq1 < 255) {
|
240
|
|
- freq1++;
|
|
267
|
+ freq1 = 0;
|
|
268
|
+ if (freq2 < 255) {
|
|
269
|
+ freq2++;
|
241
|
270
|
} else {
|
242
|
|
- freq1 = 0;
|
243
|
|
- if (freq2 < 255) {
|
244
|
|
- freq2++;
|
245
|
|
- } else {
|
246
|
|
- freq2 = 0;
|
247
|
|
- }
|
|
271
|
+ freq2 = 0;
|
248
|
272
|
}
|
249
|
273
|
}
|
|
274
|
+ }
|
250
|
275
|
|
251
|
|
- debugWrite("0x");
|
252
|
|
- debugHex(freq2);
|
253
|
|
- debugHex(freq1);
|
254
|
|
- debugHex(freq0);
|
255
|
|
- debugWrite("\n");
|
|
276
|
+ debugWrite("0x");
|
|
277
|
+ debugHex(freq2);
|
|
278
|
+ debugHex(freq1);
|
|
279
|
+ debugHex(freq0);
|
|
280
|
+ debugWrite("\n");
|
256
|
281
|
|
257
|
|
- cc2500WriteReg(CC2500_0D_FREQ2, freq2);
|
258
|
|
- cc2500WriteReg(CC2500_0E_FREQ1, freq1);
|
259
|
|
- cc2500WriteReg(CC2500_0F_FREQ0, freq0);
|
|
282
|
+ cc2500WriteReg(CC2500_0D_FREQ2, freq2);
|
|
283
|
+ cc2500WriteReg(CC2500_0E_FREQ1, freq1);
|
|
284
|
+ cc2500WriteReg(CC2500_0F_FREQ0, freq0);
|
260
|
285
|
#endif
|
261
|
|
- }
|
|
286
|
+
|
|
287
|
+ }
|
|
288
|
+
|
|
289
|
+ if (frequencyOffsetTimer > 3000) {
|
|
290
|
+ frequencyOffsetTimer = 0;
|
|
291
|
+ cc2500WriteReg(CC2500_0C_FSCTRL0, frequencyOffsetHack);
|
|
292
|
+ frequencyOffsetHack += 10;
|
262
|
293
|
//cc2500Strobe(CC2500_SRX); // enter in rx mode
|
263
|
294
|
}
|
264
|
295
|
|
|
@@ -273,7 +304,7 @@ static void tuning() {
|
273
|
304
|
debugWrite("):\n");
|
274
|
305
|
for (uint8_t i = 0; i < ccLen; i++) {
|
275
|
306
|
debugWrite("0x")
|
276
|
|
- serialWriteHex(0, ccData[i]);
|
|
307
|
+ debugHex(ccData[i]);
|
277
|
308
|
if (i < (ccLen - 1)) {
|
278
|
309
|
debugWrite(" ");
|
279
|
310
|
} else {
|
|
@@ -282,10 +313,41 @@ static void tuning() {
|
282
|
313
|
}
|
283
|
314
|
#endif
|
284
|
315
|
|
285
|
|
- if ((ccData[ccLen - 1] & 0x80)
|
|
316
|
+ if ((ccData[ccLen - 1] & CC2500_LQI_CRC_OK_BM)
|
286
|
317
|
&& (ccData[2] == 0x01)
|
287
|
318
|
&& (ccData[5] == 0x00)) {
|
|
319
|
+#ifdef DEBUG_MESSAGES
|
|
320
|
+ debugWrite("RX: Tune: finished at: ");
|
|
321
|
+ serialWriteUnsigned8(0, frequencyOffsetHack);
|
|
322
|
+ debugWrite("!\n");
|
|
323
|
+#endif
|
|
324
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
325
|
+ serialWrite(0, 't');
|
|
326
|
+#endif
|
288
|
327
|
break;
|
|
328
|
+ } else {
|
|
329
|
+#ifdef DEBUG_ERROR_MESSAGES
|
|
330
|
+ if (!(ccData[ccLen - 1] & CC2500_LQI_CRC_OK_BM)) {
|
|
331
|
+ debugWrite("RX: Tune: invalid CRC!\n");
|
|
332
|
+ }
|
|
333
|
+ if (ccData[2] != 0x01) {
|
|
334
|
+ debugWrite("RX: Tune: invalid data[2]: ");
|
|
335
|
+ serialWriteUnsigned8(0, ccData[2]);
|
|
336
|
+ debugWrite(" != ");
|
|
337
|
+ serialWriteUnsigned8(0, 0x01);
|
|
338
|
+ debugWrite("\n");
|
|
339
|
+ }
|
|
340
|
+ if (ccData[5] != 0x00) {
|
|
341
|
+ debugWrite("RX: Tune: invalid data[5]: ");
|
|
342
|
+ serialWriteUnsigned8(0, ccData[5]);
|
|
343
|
+ debugWrite(" != ");
|
|
344
|
+ serialWriteUnsigned8(0, 0x00);
|
|
345
|
+ debugWrite("\n");
|
|
346
|
+ }
|
|
347
|
+#endif
|
|
348
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
349
|
+ serialWrite(0, 'u');
|
|
350
|
+#endif
|
289
|
351
|
}
|
290
|
352
|
}
|
291
|
353
|
}
|
|
@@ -313,7 +375,7 @@ static void performBind(void) {
|
313
|
375
|
debugWrite("):\n");
|
314
|
376
|
for (uint8_t i = 0; i < ccLen; i++) {
|
315
|
377
|
debugWrite("0x")
|
316
|
|
- serialWriteHex(0, ccData[i]);
|
|
378
|
+ debugHex(ccData[i]);
|
317
|
379
|
if (i < (ccLen - 1)) {
|
318
|
380
|
debugWrite(" ");
|
319
|
381
|
} else {
|
|
@@ -322,15 +384,57 @@ static void performBind(void) {
|
322
|
384
|
}
|
323
|
385
|
#endif
|
324
|
386
|
|
325
|
|
- if ((ccData[ccLen - 1] & 0x80)
|
|
387
|
+ if ((ccData[ccLen - 1] & CC2500_LQI_CRC_OK_BM)
|
326
|
388
|
&& (ccData[2] == 0x01)
|
327
|
389
|
&& (ccData[5] == 0x00)) {
|
328
|
390
|
txid[0] = ccData[3];
|
329
|
391
|
txid[1] = ccData[4];
|
|
392
|
+#ifdef DEBUG_MESSAGES
|
|
393
|
+ debugWrite("RX: Bind: got txid: 0x");
|
|
394
|
+ debugHex(txid[0]);
|
|
395
|
+ debugWrite(" 0x");
|
|
396
|
+ debugHex(txid[1]);
|
|
397
|
+ debugWrite("\n");
|
|
398
|
+#endif
|
|
399
|
+#ifdef DEBUG_HOP_DATA
|
|
400
|
+ debugWrite("RX: Bind: got hop list:\n");
|
|
401
|
+#endif
|
330
|
402
|
for (uint8_t n = 0; n < 5; n++) {
|
331
|
403
|
hopData[ccData[5] + n] = ccData[6 + n];
|
|
404
|
+#ifdef DEBUG_HOP_DATA
|
|
405
|
+ serialWriteUnsigned8(0, ccData[5] + n);
|
|
406
|
+ debugWrite(": ");
|
|
407
|
+ serialWriteUnsigned8(0, ccData[6 + n]);
|
|
408
|
+ debugWrite("\n");
|
|
409
|
+#endif
|
332
|
410
|
}
|
|
411
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
412
|
+ serialWrite(0, 'b');
|
|
413
|
+#endif
|
333
|
414
|
break;
|
|
415
|
+ } else {
|
|
416
|
+#ifdef DEBUG_ERROR_MESSAGES
|
|
417
|
+ if (!(ccData[ccLen - 1] & CC2500_LQI_CRC_OK_BM)) {
|
|
418
|
+ debugWrite("RX: Bind: invalid CRC!\n");
|
|
419
|
+ }
|
|
420
|
+ if (ccData[2] != 0x01) {
|
|
421
|
+ debugWrite("RX: Bind: invalid data[2]: ");
|
|
422
|
+ serialWriteUnsigned8(0, ccData[2]);
|
|
423
|
+ debugWrite(" != ");
|
|
424
|
+ serialWriteUnsigned8(0, 0x01);
|
|
425
|
+ debugWrite("\n");
|
|
426
|
+ }
|
|
427
|
+ if (ccData[5] != 0x00) {
|
|
428
|
+ debugWrite("RX: Bind: invalid data[5]: ");
|
|
429
|
+ serialWriteUnsigned8(0, ccData[5]);
|
|
430
|
+ debugWrite(" != ");
|
|
431
|
+ serialWriteUnsigned8(0, 0x00);
|
|
432
|
+ debugWrite("\n");
|
|
433
|
+ }
|
|
434
|
+#endif
|
|
435
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
436
|
+ serialWrite(0, 'c');
|
|
437
|
+#endif
|
334
|
438
|
}
|
335
|
439
|
}
|
336
|
440
|
}
|
|
@@ -342,7 +446,9 @@ static void performBind(void) {
|
342
|
446
|
#endif
|
343
|
447
|
}
|
344
|
448
|
|
|
449
|
+#ifdef DEBUG_MESSAGES
|
345
|
450
|
debugWrite("RX: got hop data, reading list...\n");
|
|
451
|
+#endif
|
346
|
452
|
|
347
|
453
|
listLength = 0;
|
348
|
454
|
uint8_t eol = 0;
|
|
@@ -359,7 +465,7 @@ static void performBind(void) {
|
359
|
465
|
debugWrite("):\n");
|
360
|
466
|
for (uint8_t i = 0; i < ccLen; i++) {
|
361
|
467
|
debugWrite("0x")
|
362
|
|
- serialWriteHex(0, ccData[i]);
|
|
468
|
+ debugHex(ccData[i]);
|
363
|
469
|
if (i < (ccLen - 1)) {
|
364
|
470
|
debugWrite(" ");
|
365
|
471
|
} else {
|
|
@@ -368,7 +474,7 @@ static void performBind(void) {
|
368
|
474
|
}
|
369
|
475
|
#endif
|
370
|
476
|
|
371
|
|
- if ((ccData[ccLen - 1] & 0x80)
|
|
477
|
+ if ((ccData[ccLen - 1] & CC2500_LQI_CRC_OK_BM)
|
372
|
478
|
&& (ccData[2] == 0x01)
|
373
|
479
|
&& (ccData[3] == txid[0])
|
374
|
480
|
&& (ccData[4] == txid[1])
|
|
@@ -382,7 +488,14 @@ static void performBind(void) {
|
382
|
488
|
}
|
383
|
489
|
hopData[ccData[5] + n] = ccData[6 + n];
|
384
|
490
|
}
|
|
491
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
492
|
+ serialWrite(0, 'l');
|
|
493
|
+#endif
|
385
|
494
|
break;
|
|
495
|
+ } else {
|
|
496
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
497
|
+ serialWrite(0, 'm');
|
|
498
|
+#endif
|
386
|
499
|
}
|
387
|
500
|
}
|
388
|
501
|
}
|
|
@@ -399,7 +512,9 @@ static void performBind(void) {
|
399
|
512
|
}
|
400
|
513
|
}
|
401
|
514
|
|
|
515
|
+#ifdef DEBUG_MESSAGES
|
402
|
516
|
debugWrite("RX: binding finished!\n");
|
|
517
|
+#endif
|
403
|
518
|
|
404
|
519
|
writeBindingData();
|
405
|
520
|
cc2500Strobe(CC2500_SIDLE); // Back to idle
|
|
@@ -415,15 +530,16 @@ static void nextChannel(uint8_t skip) {
|
415
|
530
|
cc2500WriteReg(CC2500_23_FSCAL3, 0x89);
|
416
|
531
|
}
|
417
|
532
|
|
|
533
|
+#ifndef ALWAYS_PERFORM_BINDING
|
418
|
534
|
static void readBindingData() {
|
419
|
535
|
#ifdef DEBUG_EEPROM_DATA_READ
|
420
|
|
- debugWrite("RX: EEPROM TXID: ");
|
|
536
|
+ debugWrite("RX: Read EEPROM TXID: ");
|
421
|
537
|
#endif
|
422
|
538
|
for (uint8_t i = 0; i < 2; i++) {
|
423
|
539
|
txid[i] = eeprom_read_byte(EEPROM_BASE_ADDRESS + i);
|
424
|
540
|
#ifdef DEBUG_EEPROM_DATA_READ
|
425
|
541
|
debugWrite("0x")
|
426
|
|
- serialWriteHex(0, txid[i]);
|
|
542
|
+ debugHex(txid[i]);
|
427
|
543
|
debugWrite(" ");
|
428
|
544
|
#endif
|
429
|
545
|
}
|
|
@@ -432,7 +548,7 @@ static void readBindingData() {
|
432
|
548
|
#endif
|
433
|
549
|
|
434
|
550
|
#ifdef DEBUG_EEPROM_DATA_READ
|
435
|
|
- debugWrite("RX: EEPROM Hop Data (");
|
|
551
|
+ debugWrite("RX: Read EEPROM Hop Data (");
|
436
|
552
|
serialWriteUnsigned8(0, HOP_DATA_LENGTH);
|
437
|
553
|
debugWrite(")\n");
|
438
|
554
|
#endif
|
|
@@ -440,7 +556,7 @@ static void readBindingData() {
|
440
|
556
|
hopData[i] = eeprom_read_byte(EEPROM_BASE_ADDRESS + 10 + i);
|
441
|
557
|
#ifdef DEBUG_EEPROM_DATA_READ
|
442
|
558
|
debugWrite("0x")
|
443
|
|
- serialWriteHex(0, hopData[i]);
|
|
559
|
+ debugHex(hopData[i]);
|
444
|
560
|
debugWrite(" ");
|
445
|
561
|
#endif
|
446
|
562
|
}
|
|
@@ -452,30 +568,60 @@ static void readBindingData() {
|
452
|
568
|
frequencyOffsetHack = eeprom_read_byte(EEPROM_BASE_ADDRESS + 101);
|
453
|
569
|
|
454
|
570
|
#ifdef DEBUG_EEPROM_DATA_READ
|
455
|
|
- debugWrite("RX: EEPROM List Length: ");
|
|
571
|
+ debugWrite("RX: Read EEPROM List Length: ");
|
456
|
572
|
serialWriteUnsigned8(0, listLength);
|
457
|
|
- debugWrite("\nRX: EEPROM Frequency Offset Hack: ");
|
|
573
|
+ debugWrite("\nRX: Read EEPROM Frequency Offset Hack: ");
|
458
|
574
|
serialWriteUnsigned8(0, frequencyOffsetHack);
|
459
|
575
|
debugWrite("\n");
|
460
|
576
|
#endif
|
461
|
577
|
}
|
|
578
|
+#endif
|
462
|
579
|
|
463
|
580
|
static void writeBindingData() {
|
|
581
|
+#ifdef DEBUG_EEPROM_DATA_WRITE
|
|
582
|
+ debugWrite("RX: Write EEPROM TXID: ");
|
|
583
|
+#endif
|
464
|
584
|
for (uint8_t i = 0; i < 2; i++) {
|
465
|
585
|
eeprom_write_byte(EEPROM_BASE_ADDRESS + i, txid[i]);
|
|
586
|
+#ifdef DEBUG_EEPROM_DATA_WRITE
|
|
587
|
+ debugWrite("0x")
|
|
588
|
+ debugHex(txid[i]);
|
|
589
|
+ debugWrite(" ");
|
|
590
|
+#endif
|
466
|
591
|
}
|
|
592
|
+#ifdef DEBUG_EEPROM_DATA_WRITE
|
|
593
|
+ debugWrite("\n");
|
|
594
|
+#endif
|
467
|
595
|
|
|
596
|
+#ifdef DEBUG_EEPROM_DATA_WRITE
|
|
597
|
+ debugWrite("RX: Write EEPROM Hop Data (");
|
|
598
|
+ serialWriteUnsigned8(0, HOP_DATA_LENGTH);
|
|
599
|
+ debugWrite(")\n");
|
|
600
|
+#endif
|
468
|
601
|
for (uint8_t i = 0; i < HOP_DATA_LENGTH; i++) {
|
469
|
602
|
eeprom_write_byte(EEPROM_BASE_ADDRESS + 10 + i, hopData[i]);
|
|
603
|
+#ifdef DEBUG_EEPROM_DATA_WRITE
|
|
604
|
+ debugWrite("0x")
|
|
605
|
+ debugHex(hopData[i]);
|
|
606
|
+ debugWrite(" ");
|
|
607
|
+#endif
|
470
|
608
|
}
|
|
609
|
+#ifdef DEBUG_EEPROM_DATA_WRITE
|
|
610
|
+ debugWrite("\n");
|
|
611
|
+#endif
|
471
|
612
|
|
472
|
613
|
eeprom_write_byte(EEPROM_BASE_ADDRESS + 100, listLength);
|
|
614
|
+#ifdef DEBUG_EEPROM_DATA_WRITE
|
|
615
|
+ debugWrite("RX: Write EEPROM List Length: ");
|
|
616
|
+ serialWriteUnsigned8(0, listLength);
|
|
617
|
+ debugWrite("\n");
|
|
618
|
+#endif
|
473
|
619
|
}
|
474
|
620
|
|
475
|
621
|
void rxReceivePacket() {
|
476
|
622
|
time_t time = timerGet();
|
477
|
623
|
|
478
|
|
-#ifdef DEBUG_MISSING_PACKETS
|
|
624
|
+#if defined(DEBUG_MISSING_PACKETS) || defined(DEBUG_SINGLE_CHARACTER_MESSAGES)
|
479
|
625
|
static uint8_t packetMissingNotification = 0;
|
480
|
626
|
#endif
|
481
|
627
|
|
|
@@ -485,7 +631,7 @@ void rxReceivePacket() {
|
485
|
631
|
}
|
486
|
632
|
|
487
|
633
|
while (1) {
|
488
|
|
- if ((timerGet() - time) > MISSING_PACKET_DELAY) {
|
|
634
|
+ if ((timerGet() - time) >= MISSING_PACKET_DELAY) {
|
489
|
635
|
missingPackets++;
|
490
|
636
|
cc2500Strobe(CC2500_SIDLE);
|
491
|
637
|
if (missingPackets > MAX_MISSING_PACKET) {
|
|
@@ -499,6 +645,12 @@ void rxReceivePacket() {
|
499
|
645
|
packetMissingNotification = 1;
|
500
|
646
|
}
|
501
|
647
|
#endif
|
|
648
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
649
|
+ if (packetMissingNotification < 1) {
|
|
650
|
+ serialWrite(0, '1');
|
|
651
|
+ packetMissingNotification = 1;
|
|
652
|
+ }
|
|
653
|
+#endif
|
502
|
654
|
}
|
503
|
655
|
|
504
|
656
|
if (counter == (MAX_MISSING_PACKET << 2)) {
|
|
@@ -508,6 +660,12 @@ void rxReceivePacket() {
|
508
|
660
|
packetMissingNotification = 2;
|
509
|
661
|
}
|
510
|
662
|
#endif
|
|
663
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
664
|
+ if (packetMissingNotification < 2) {
|
|
665
|
+ serialWrite(0, '2');
|
|
666
|
+ packetMissingNotification = 2;
|
|
667
|
+ }
|
|
668
|
+#endif
|
511
|
669
|
counter = 0;
|
512
|
670
|
}
|
513
|
671
|
} else {
|
|
@@ -536,7 +694,7 @@ void rxReceivePacket() {
|
536
|
694
|
debugWrite("):\n");
|
537
|
695
|
for (uint8_t i = 0; i < ccLen; i++) {
|
538
|
696
|
debugWrite("0x")
|
539
|
|
- serialWriteHex(0, ccData[i]);
|
|
697
|
+ debugHex(ccData[i]);
|
540
|
698
|
if (i < (ccLen - 1)) {
|
541
|
699
|
debugWrite(" ");
|
542
|
700
|
} else {
|
|
@@ -549,7 +707,7 @@ void rxReceivePacket() {
|
549
|
707
|
if ((ccData[0] == FRSKY_PACKET_LENGTH) // Correct length
|
550
|
708
|
&& (ccData[1] == txid[0]) // Correct txid
|
551
|
709
|
&& (ccData[2] == txid[1])) {
|
552
|
|
-#ifdef DEBUG_MISSING_PACKETS
|
|
710
|
+#if defined(DEBUG_MISSING_PACKETS) || defined(DEBUG_SINGLE_CHARACTER_MESSAGES)
|
553
|
711
|
packetMissingNotification = 0;
|
554
|
712
|
#endif
|
555
|
713
|
|
|
@@ -593,11 +751,17 @@ void rxReceivePacket() {
|
593
|
751
|
debugWrite("\n");
|
594
|
752
|
}
|
595
|
753
|
#endif
|
|
754
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
755
|
+ serialWrite(0, 'r');
|
|
756
|
+#endif
|
596
|
757
|
}
|
597
|
758
|
} else {
|
598
|
759
|
#ifdef DEBUG_ERROR_MESSAGES
|
599
|
760
|
debugWrite("RX: invalid CRC!\n");
|
600
|
761
|
#endif
|
|
762
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
763
|
+ serialWrite(0, 'q');
|
|
764
|
+#endif
|
601
|
765
|
}
|
602
|
766
|
}
|
603
|
767
|
}
|
|
@@ -657,8 +821,8 @@ void rxReceivePacket() {
|
657
|
821
|
}
|
658
|
822
|
#endif
|
659
|
823
|
|
660
|
|
-#ifdef DEBUG_PACKET_DOT
|
661
|
|
- serialWrite(0, '.');
|
|
824
|
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
|
|
825
|
+ serialWrite(0, 'p');
|
662
|
826
|
#endif
|
663
|
827
|
|
664
|
828
|
cppmCopy(ppmBuffer);
|