-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapleSduino_SER2WLAN.ino
2995 lines (2733 loc) · 74.4 KB
/
MapleSduino_SER2WLAN.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* RF_RECEIVER v4.xx for Arduino
* Sketch to use an arduino as a receiver/sending device for digital signals
*
* The Sketch can also encode and send data via a transmitter,
* while only PT2262 type-signals for Intertechno devices are implemented in the sketch,
* there is an option to send almost any data over a send raw interface
* 2014-2015 N.Butzek, S.Butzek
* 2016 S.Butzek
* This software focuses on remote sensors like weather sensors (temperature,
* humidity Logilink, TCM, Oregon Scientific, ...), remote controlled power switches
* (Intertechno, TCM, ARCtech, ...) which use encoder chips like PT2262 and
* EV1527-type and manchester encoder to send information in the 433MHz Band.
* But the sketch will also work for infrared or other medias. Even other frequencys
* can be used
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
Version from: https://github.com/Ralf9/SIGNALDuino/blob/dev-r41x_cc110
Diese Version kompiliert mit *Arduino* und muss auf Adresse: 0x08002000 gelegt werden.
PINS:
======
MOSI = 28 (SPI,gemeinsam RADIO_1(A) + 2(B))
SCLK = 30 (SPI, gemeinsam RADIO_1(A) + 2(B))
MISO = 29 (SPI, gemeinsam RADIO_1(A) + 2(B))
Radio_1.GD02 = 11
Radio_1.GD00 = 12
Radio_1.CSN = 31
Radio_2.GD02 = 18
Radio_2.GD00 = 17
Radio_2.CSN = 12
20200606_juergs: initiale Version vom 6.6.2020 für Ranseyer's "MapleSDuino V0.2"
*-------------------------------------------------------------------------------------------------------------------
*/
// Config flags for compiling correct options / boards Define only one
#define MAPLE_SDUINO 1
//#define MAPLE_CUL 1
//#define LAN_WIZ 1
//#define ARDUINO_ATMEGA328P_MINICUL 1
//#define OTHER_BOARD_WITH_CC1101 1
//#define CMP_MEMDBG 1
// bitte auch das "#define LAN_WIZ 1" in der SignalDecoder.h beachten
// bitte auch das "#define CMP_CC1101" in der SignalDecoder.h beachten
#define PROGNAME "RF_RECEIVER"
#define PROGVERS "4.2.0-dev20050z6_juergs"
#define VERSION_1 0x41
#define VERSION_2 0x0d
#ifdef OTHER_BOARD_WITH_CC1101
#define CMP_CC1101
#endif
#ifdef ARDUINO_ATMEGA328P_MINICUL
#define CMP_CC1101
#endif
#ifdef ARDUINO_AVR_ICT_BOARDS_ICT_BOARDS_AVR_RADINOCC1101
#define CMP_CC1101
#endif
#ifdef MAPLE_SDUINO
#define MAPLE_Mini
#define CMP_CC1101
#endif
#ifdef MAPLE_CUL
#define MAPLE_Mini
#define CMP_CC1101
#endif
#ifdef CMP_CC1101
#ifdef MAPLE_SDUINO
#define PIN_LED 33 // PB1 for Maple
#define PIN_SEND 17 // gdo0 out
#define PIN_RECEIVE 18 // gdo2
#define PIN_WIZ_RST 27
#elif MAPLE_CUL
#define PIN_LED 33
#define PIN_SEND 17 // gdo0 Pin TX out
#define PIN_RECEIVE 18
#define PIN_WIZ_RST 27
#else
#define PIN_LED 9
#define PIN_SEND 3 // gdo0Pin TX out
#define PIN_RECEIVE 2
#endif
#else
#define PIN_RECEIVE 2
#define PIN_LED 13 // Message-LED
#define PIN_SEND 11
#endif
#ifdef MAPLE_Mini
#define BAUDRATE 115200
#define FIFO_LENGTH 170
const uint8_t pinReceive[] = {11, 18, 16, 14};
#else
#define BAUDRATE 57600
#define FIFO_LENGTH 140 // 50
#endif
//#define WATCHDOG 1 // Der Watchdog ist in der Entwicklungs und Testphase deaktiviert. Es muss auch ohne Watchdog stabil funktionieren.
//#define DEBUGSENDCMD 1
//(#define SENDTODECODER 1) ist neu ccmode=15 -> damit wird in der send_raw Routine anstatt zu senden, die Pulse direkt dem Decoder uebergeben
#define DEBUG 1
#ifdef WATCHDOG
#include <avr/wdt.h>
#endif
//----Includes-----------------------------------------------------------------------------------------
#include "cc1101.h"
#include "FastDelegate.h"
#include "output.h"
#include "bitstore.h"
#include "signalDecoder4.h"
#include "SimpleFIFO.h"
#include <HardwareSerial.h>
//---------------------------------------------------------------------------------------------
SimpleFIFO<int16_t,FIFO_LENGTH> FiFo; //store FIFO_LENGTH # ints
SignalDetectorClass musterDec;
#ifdef MAPLE_Mini
#include <malloc.h>
extern char _estack;
extern char _Min_Stack_Size;
static char *ramend = &_estack;
static char *minSP = (char*)(ramend - &_Min_Stack_Size);
extern "C" char *sbrk(int i);
#else
#include <TimerOne.h> // Timer for LED Blinking
#endif
#ifdef LAN_WIZ
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAE, 0xBE, 0xEF, 0xF9, 0xE9 };
byte ip[] = { 192, 168, 0, 85 };
byte gateway[] = { 192, 168, 0, 191 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server = EthernetServer(23);
EthernetClient client;
#endif
#define pulseMin 90
#ifdef MAPLE_Mini
#define maxCmdString 600
#else
#define maxCmdString 350
#endif
#define maxSendPattern 10
#define mcMinBitLenDef 17
#define ccMaxBuf 64
#define defMaxMsgSize 1500 // selber Wert wie in signalDecoder4.h
#define maxSendEcho 100
#define radioOokAsk 1
#define defSelRadio 1 // B
#define defStatRadio 0xFF
//--- EEProm Address
#define EE_MAGIC_OFFSET 0
#define addr_togglesec 0x3C
#define addr_ccN 0x3D
#define addr_ccmode 0x3E
#define addr_statRadio 0xEB // A=EB B=EC C=ED D=EE Bit 0-3 Bank, 1F-Init, Bit 6 = 1 - Fehler bei Erkennung, Bit 6&7 = 1 - Miso Timeout, FF-deaktiviert
#define addr_selRadio 0xEF
#define addr_features 0xFF
//#define addr_featuresB 0x3F
//#define addr_bank 0xFD
volatile bool blinkLED = false;
String cmdstring = "";
char msg_cmd0 = ' ';
char msg_cmd1 = ' ';
volatile unsigned long lastTime = micros();
bool hasCC1101 = false;
bool LEDenabled = true;
bool toggleBankEnabled = false;
bool RXenabled[] = {false, false, false, false}; // true - enable receive, Zwischenspeicher zum enablereceive merken
bool unsuppCmd = false;
uint8_t MdebFifoLimit = 120;
uint8_t bank = 0;
uint16_t bankOffset = 0;
uint8_t ccN = 0;
uint8_t ccmode = 0; // cc1101 Mode: 0 - normal, 1 - FIFO, 2 - FIFO ohne dup, 3 - FIFO LaCrosse, 9 - FIFO mit Debug Ausgaben
uint8_t radionr = defSelRadio;
uint8_t radio_bank[4];
uint8_t ccBuf[4][ccMaxBuf];
bool _command_available = false;
//----Prototypes--------------------------------------------------------------------------
void cmd_help_S();
void cmd_help();
void cmd_bank();
void configCMD();
void configRadio();
void getConfig();
void configSET();
void ccRegWrite();
void cmd_config();
void cmd_configFactoryReset();
void cmd_ccFactoryReset();
void getPing();
void cmd_readEEPROM();
void cmd_freeRam();
void cmd_send();
void cmd_uptime();
void cmd_toggleBank();
void cmd_Version();
void cmd_writeEEPROM();
void cmd_writePatable();
void changeReceiver();
void handleInterrupt();
void enableReceive();
void disableReceive();
void serialEvent();
void cronjob();
void HandleCommand();
void printHex2(const byte hex);
void storeFunctions(const int8_t ms=1, int8_t mu=1, int8_t mc=1, int8_t red=1, int8_t deb=0, int8_t led=1, int8_t overfl=0);
void getFunctions(bool *ms,bool *mu,bool *mc, bool *red, bool *deb, bool *led, bool *overfl);
void initEEPROM(void);
void setCCmode();
void print_Bank();
void print_radio_sum();
void serial2Event();
void serial3Event();
int freeRam();
unsigned long getUptime();
uint16_t getBankOffset(uint8_t tmpBank);
uint8_t radioDetekt(bool confmode, uint8_t Dstat);
uint8_t rssiCallback() { return 0; }; // Dummy return if no rssi value can be retrieved from receiver
//----END-Prototypes--------------------------------------------------------------------------
//typedef void (* GenericFP)(int); //function pointer prototype to a function which takes an 'int' an returns 'void'
#define cmdAnz 23
const char cmd0[] = {'?', '?', 'b', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'e', 'e', 'P', 'r', 'R', 'S', 't', 'T', 'V', 'W', 'x', 'X', 'X'};
const char cmd1[] = {'S', ' ', ' ', 'E', 'D', 'G', 'R', 'S', 'W', ' ', 'C', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'E', 'Q'};
const bool cmdCC[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 };
void (*cmdFP[])(void) =
{
cmd_help_S, // ?S
cmd_help, // ?
cmd_bank, // b
configCMD, // CE
configCMD, // CD
getConfig, // CG
configRadio,// CR
configSET, // CS
ccRegWrite, // CW
cmd_config, // C
cmd_configFactoryReset, // eC
cmd_ccFactoryReset, // e
getPing, // P
cmd_readEEPROM, // r
cmd_freeRam, // R
cmd_send, // S
cmd_uptime, // t
cmd_toggleBank, // T
cmd_Version, // V
cmd_writeEEPROM,// W
cmd_writePatable,// x
changeReceiver, // XE
changeReceiver // XQ
};
#define CSetAnz 10
#define CSetAnzEE 12
#define CSet16 8
#define CSccN 6
#define CSccmode 7
//const char *CSetCmd[] = {"fifolimit", "mcmbl", "mscnt", "maxMuPrintx256", "maxMsgSizex256", "maxnumpat", "ccN", "ccmode", "muthresh", "L", "maxpulse", "L" };
const uint8_t CSetAddr[] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, addr_ccN, addr_ccmode, 0xf8, 0xf9, 0xfa, 0xfb };
const uint8_t CSetDef[] = { 120, 0, 4, 3, 4, 8, 0, 0, 0, 0, 0, 0 };
const char string_0[] PROGMEM = "fifolimit";
const char string_1[] PROGMEM = "mcmbl";
const char string_2[] PROGMEM = "mscnt";
const char string_3[] PROGMEM = "maxMuPrintx256";
const char string_4[] PROGMEM = "maxMsgSizex256";
const char string_5[] PROGMEM = "maxnumpat";
const char string_6[] PROGMEM = "ccN";
const char string_7[] PROGMEM = "ccmode";
const char string_8[] PROGMEM = "muthresh";
const char string_9[] PROGMEM = "maxpulse";
const char * const CSetCmd[] PROGMEM = { string_0, string_1, string_2, string_3, string_4, string_5, string_6, string_7, string_8, string_9};
#ifdef CMP_MEMDBG
extern unsigned int __data_start;
extern unsigned int __data_end;
extern unsigned int __bss_start;
extern unsigned int __bss_end;
extern unsigned int __heap_start;
extern void *__brkval;
uint8_t *heapptr, *stackptr;
uint16_t diff=0;
void check_mem() {
stackptr = (uint8_t *)malloc(4); // use stackptr temporarily
heapptr = stackptr; // save value of heap pointer
free(stackptr); // free up the memory again (sets stackptr to 0)
stackptr = (uint8_t *)(SP); // save value of stack pointer
}
//extern int __bss_end;
//extern void *__brkval;
int get_free_memory()
{
int free_memory;
if((int)__brkval == 0)
free_memory = ((int)&free_memory) - ((int)&__bss_end);
else
free_memory = ((int)&free_memory) - ((int)__brkval);
return free_memory;
}
int16_t ramSize=0; // total amount of ram available for partitioning
int16_t dataSize=0; // partition size for .data section
int16_t bssSize=0; // partition size for .bss section
int16_t heapSize=0; // partition size for current snapshot of the heap section
int16_t stackSize=0; // partition size for current snapshot of the stack section
int16_t freeMem1=0; // available ram calculation #1
int16_t freeMem2=0; // available ram calculation #2
#endif // CMP_MEMDBG
//HardwareSerial Serial2(PA3, PA2);
//HardwareSerial Serial3(PB11, PB10);
HardwareSerial Serial2(USART2, SERIAL_8N1);
HardwareSerial Serial3(USART3, SERIAL_8N1);
//---------------------------------------------------------------------------------------------------
void setup()
{
#ifdef MAPLE_Mini
pinAsOutput(PIN_WIZ_RST);
#ifndef LAN_WIZ
digitalWrite(PIN_WIZ_RST, HIGH);
#endif
#endif
#ifdef LAN_WIZ
digitalWrite(PIN_WIZ_RST, LOW); // RESET should be heldlowat least 500 us for W5500
delayMicroseconds(500);
digitalWrite(PIN_WIZ_RST, HIGH);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin(); // start listening for clients
#else
//Serial1.setTx(PA9);
//Serial1.setRx(PA10);
Serial2.setTx(PA2);
Serial2.setRx(PA3);
Serial3.setTx(PB10);
Serial3.setRx(PB11);
Serial.begin(BAUDRATE);
Serial2.begin(BAUDRATE);
Serial3.begin(BAUDRATE);
//while (!Serial) {
// ; // wait for serial port to connect. Needed for native USB
//}
for (uint8_t sw=0;sw<255;sw++ )
{
delay(10);
if (Serial)
{
break;
}
}
//--- first Test
Serial1.println("* - Hello UART 1!");
Serial2.println("* - Hello UART 2!");
Serial3.println("* - Hello UART 3!");
#endif
if (musterDec.MdebEnabled)
{
DBG_PRINTLN(F("Using sFIFO"));
}
#ifdef WATCHDOG
if (MCUSR & (1 << WDRF)) {
MSG_PRINTLN(F("Watchdog caused a reset"));
}
/*
if (MCUSR & (1 << BORF)) {
DBG_PRINTLN("brownout caused a reset");
}
if (MCUSR & (1 << EXTRF)) {
DBG_PRINTLN("external reset occured");
}
if (MCUSR & (1 << PORF)) {
DBG_PRINTLN("power on reset occured");
}
*/
wdt_reset();
wdt_enable(WDTO_2S); // Enable Watchdog
#endif
//delay(2000);
pinAsInput(PIN_RECEIVE);
pinAsOutput(PIN_LED);
// CC1101
#ifdef WATCHDOG
wdt_reset();
#endif
#ifdef CMP_CC1101
cc1101::setup();
#endif
initEEPROM();
#ifdef CMP_CC1101
MSG_PRINTLN(F("CCInit "));
uint8_t remRadionr = radionr;
uint8_t remBankOffset = bankOffset;
uint8_t statRadio;
for (radionr = 0; radionr < 4; radionr++)
{
// init radio
statRadio = tools::EEread(addr_statRadio + radionr);
if (statRadio == 0xFF) {
radio_bank[radionr] = 0xFF;
continue;
}
statRadio = radioDetekt(false, statRadio);
if (statRadio < 10) {
bankOffset = getBankOffset(statRadio);
cc1101::CCinit_reg();
}
radio_bank[radionr] = statRadio;
if (statRadio != tools::EEread(addr_statRadio + radionr)) {
tools::EEwrite(addr_statRadio+radionr,statRadio);
tools::EEstore();
}
}
if (radio_bank[remRadionr] < 10)
{
musterDec.setRSSICallback(&cc1101::getRSSI); // Provide the RSSI Callback
}
else
musterDec.setRSSICallback(&rssiCallback); // Provide the RSSI Callback
#endif
if (ccmode == 0)
{
pinAsOutput(PIN_SEND);
}
if (musterDec.MdebEnabled)
{
MSG_PRINTLN(F("Starting timerjob"));
}
delay(50);
#ifdef MAPLE_Mini
TIM_TypeDef *Instance = TIM1;
HardwareTimer *MyTim = new HardwareTimer(Instance);
MyTim->setMode(2, TIMER_OUTPUT_COMPARE);
MyTim->setOverflow(31*1000, MICROSEC_FORMAT);
MyTim->attachInterrupt(cronjob);
MyTim->resume();
#else
Timer1.initialize(31*1000); //Interrupt wird jede 31 Millisekunden ausgeloest
Timer1.attachInterrupt(cronjob);
#endif
cmdstring.reserve(maxCmdString);
hasCC1101 = true;
uint8_t remccmode = ccmode;
for (radionr = 0; radionr < 4; radionr++)
{
//--- enableReceive bei allen korrekt erkannten radios denen eine Bank zugeordnet ist
if (radio_bank[radionr] < 10) {
bankOffset = getBankOffset(radio_bank[radionr]);
ccmode = tools::EEbankRead(addr_ccmode);
if (radionr != 1 || ccmode > 0 || cc1101::regCheck()) {
en_dis_receiver(true);
}
else {
MSG_PRINT(F("cc1101 "));
MSG_WRITE('A' + radionr);
MSG_PRINT(F(" is for OOK not correctly set. "));
}
}
}
MSG_PRINTLN("");
ccmode = remccmode;
bankOffset = remBankOffset;
radionr = remRadionr;
}
//---------------------------------------------------------------------------------------------
void loop()
{
static int16_t aktVal=0;
bool state;
uint8_t fifoCount;
serialEvent();
if (!_command_available)
{
serial2Event();
}
if (!_command_available)
{
serial3Event();
}
#ifdef LAN_WIZ
ethernetLoop();
#endif
if (_command_available)
{
_command_available = false;
HandleCommand();
if (!_command_available) { cmdstring = ""; }
if (LEDenabled)
{
blinkLED=true;
}
}
#ifdef WATCHDOG
wdt_reset();
#endif
uint8_t remRadionr = radionr;
uint8_t remccmode = ccmode;
uint8_t tmpBank;
uint16_t bankoff;
for (radionr = 0; radionr < 4; radionr++)
{
if (radio_bank[radionr] > 9)
{
continue;
}
tmpBank = radio_bank[radionr];
bankoff = getBankOffset(tmpBank);
ccmode = tools::EEread(bankoff + addr_ccmode);
if (ccmode == 0)
{
musterDec.printMsgSuccess = false;
while (FiFo.count()>0 )
{
//--- Puffer auslesen und an Dekoder uebergeben
aktVal=FiFo.dequeue();
state = musterDec.decode(&aktVal);
if (musterDec.MdebEnabled && musterDec.printMsgSuccess)
{
fifoCount = FiFo.count();
if (fifoCount > MdebFifoLimit)
{
MSG_PRINT(F("MF="));
MSG_PRINTLN(fifoCount, DEC);
//MSG_PRINTLN("");
}
}
if (musterDec.printMsgSuccess && LEDenabled)
{
//--- blinken, wenn Meldung dekodiert
blinkLED = true;
}
musterDec.printMsgSuccess = false;
}
}
else if (ccmode < 15)
{
getRxFifo(bankoff);
}
}
radionr = remRadionr;
ccmode = remccmode;
}
//---------------------------------------------------------------------------------------------
#ifdef MAPLE_Mini
void cronjob(HardwareTimer*)
{
noInterrupts();
static uint16_t cnt0 = 0;
static uint8_t cnt1 = 0;
const unsigned long duration = micros() - lastTime;
if (duration > maxPulse && RXenabled[radioOokAsk])
{
//--- auf Maximalwert pruefen.
int16_t sDuration = maxPulse;
if (isLow(PIN_RECEIVE))
{
//--- wenn jetzt low ist, ist auch weiterhin low
sDuration = -sDuration;
}
FiFo.enqueue(sDuration);
lastTime = micros();
}
digitalWrite(PIN_LED, blinkLED);
blinkLED = false;
interrupts();
if (cnt0++ == 0)
{
if (cnt1++ == 0)
{
getUptime();
}
}
}
#elif
void cronjob()
{
cli();
static uint16_t cnt0 = 0;
static uint8_t cnt1 = 0;
const unsigned long duration = micros() - lastTime;
if (duration > maxPulse && RXenabled[radioOokAsk])
{
//--- auf Maximalwert pruefen.
int16_t sDuration = maxPulse;
if (isLow(PIN_RECEIVE))
{
//--- wenn jetzt low ist, ist auch weiterhin low
sDuration = -sDuration;
}
FiFo.enqueue(sDuration);
lastTime = micros();
}
digitalWrite(PIN_LED, blinkLED);
blinkLED = false;
sei();
if (cnt0++ == 0)
{
if (cnt1++ == 0)
{
getUptime();
}
}
}
#endif
//---------------------------------------------------------------------------------------------
void getRxFifo(uint16_t Boffs)
{
uint8_t fifoBytes;
bool dup; // true bei identischen Wiederholungen bei readRXFIFO
if (isHigh(pinReceive[radionr])) { // wait for CC1100_FIFOTHR given bytes to arrive in FIFO
if (LEDenabled) {
blinkLED=true;
}
fifoBytes = cc1101::getRXBYTES(); // & 0x7f; // read len, transfer RX fifo
if (fifoBytes > 0) {
uint8_t marcstate;
uint8_t RSSI = cc1101::getRSSI();
if (ccmode == 9) {
MSG_PRINT(F("RX("));
MSG_PRINT(fifoBytes);
MSG_PRINT(F(") "));
}
if (fifoBytes < 0x80) { // RXoverflow?
if (fifoBytes > ccMaxBuf) {
fifoBytes = ccMaxBuf;
}
dup = cc1101::readRXFIFO(fifoBytes);
if (ccmode != 2 || dup == false) {
if (ccmode != 9) {
MSG_PRINT(MSG_START);
MSG_PRINT(F("MN;D="));
}
for (uint8_t i = 0; i < fifoBytes; i++) {
printHex2(ccBuf[radionr][i]);
//MSG_PRINT(" ");
}
if (ccmode == 9) {
MSG_PRINT(F(" ("));
MSG_PRINT(cc1101::getRXBYTES());
MSG_PRINT(F(")"));
}
else {
uint8_t n = tools::EEread(Boffs + addr_ccN);
if (n > 0) {
MSG_PRINT(F(";N="));
MSG_PRINT(n);
}
MSG_PRINT(F(";R="));
MSG_PRINT(RSSI);
MSG_PRINT(F(";"));
MSG_PRINT(MSG_END);
MSG_PRINT("\n");
}
}
}
marcstate = cc1101::getMARCSTATE();
if (ccmode == 9) {
MSG_PRINT(F(" M"));
MSG_PRINTLN(marcstate);
}
if (marcstate == 17 || ccmode == 3) { // RXoverflow oder LaCrosse?
if (cc1101::flushrx()) { // Flush the RX FIFO buffer
cc1101::setReceiveMode();
}
}
}
}
}
//---------------------------------------------------------------------------------------------
// Pulseauswertung
void handleInterrupt()
{
//--- keine Interrupts jetzt
noInterrupts();
const unsigned long Time=micros();
const unsigned long duration = Time - lastTime;
lastTime = Time;
if (duration >= pulseMin)
{//kleinste zulaessige Pulslaenge
int16_t sDuration;
if (duration < maxPulse)
{//groesste zulaessige Pulslaenge, max = 32000
sDuration = int16_t(duration); //das wirft bereits hier unnoetige Nullen raus und vergroessert den Wertebereich
}else
{
// Maximalwert set to maxPulse defined in lib.
sDuration = maxPulse;
}
if (isHigh(PIN_RECEIVE))
{
//--- wenn jetzt high ist, dann muss vorher low gewesen sein, und dafuer gilt die gemessene Dauer.
sDuration=-sDuration;
}
//MSG_PRINTLN(sDuration);
FiFo.enqueue(sDuration);
//++fifocnt;
} // else => trash
//--- wieder zulassen
interrupts();
}
//---------------------------------------------------------------------------------------------
void enableReceive()
{
if (RXenabled[radionr] == true)
{
if (ccmode == 0 && radionr == 1)
{
attachInterrupt(digitalPinToInterrupt(PIN_RECEIVE), handleInterrupt, CHANGE);
}
#ifdef CMP_CC1101
if (hasCC1101 && ccmode < 15)
{
cc1101::setIdleMode();
cc1101::setReceiveMode();
}
#endif
}
}
//---------------------------------------------------------------------------------------------
void disableReceive()
{
if (ccmode == 0 && radionr == 1)
{
detachInterrupt(digitalPinToInterrupt(PIN_RECEIVE));
}
#ifdef CMP_CC1101
if (hasCC1101) cc1101::setIdleMode();
#endif
FiFo.flush();
}
//---------------------------------------------------------------------------------------------
/*void send_rawx(const uint8_t startpos,const uint16_t endpos,const int16_t *buckets, String *source=&cmdstring)
{
// int16_t sendarr[] ={200,-200,300,-300,500,-400,600,-600,800,-800,500,-500,200,-200,300,-300,500,-400,600,-600,800,-800,500,-500,200,-200,500,-300,400,-400,500,-600,800,-800,500,-500,200,-200,300,-300,400,-400,600,-600,1100,-1100,800,-800,500,-500};
int16_t sendarr[] = {-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-154,260,-1400,1724,-154,260,-367,260,-154,940,-572,260,-154,260,-154,1312,-154,940,-367,468,-1200,940,-1200,260,-784,260,-154,260};
int16_t p;
for (uint8_t i=0;i<62;i++ ) {
p = sendarr[i];
//MSG_PRINTLN(p);
musterDec.decode(&p);
}
}*/
//---------------------------------------------------------------------------------------------
// *RAW Send*
void send_raw(const uint8_t startpos,const uint16_t endpos,const int16_t *buckets, String *source=&cmdstring)
{
uint8_t index=0;
unsigned long stoptime=micros();
bool isLow;
int16_t dur;
if (ccmode == 0)
{
for (uint16_t i=startpos;i<=endpos;i++ )
{
//MSG_PRINT(cmdstring.substring(i,i+1));
index = source->charAt(i) - '0';
//MSG_PRINT(index);
isLow=buckets[index] >> 15;
dur = abs(buckets[index]); //isLow ? dur = abs(buckets[index]) : dur = abs(buckets[index]);
while (stoptime > micros())
{
;
}
isLow ? digitalLow(PIN_SEND): digitalHigh(PIN_SEND);
stoptime+=dur;
}
while (stoptime > micros()){
;
}
}
else
{
//--- send to decoder
for (uint16_t i=startpos;i<=endpos;i++ )
{
//MSG_PRINT(cmdstring.substring(i,i+1));
index = source->charAt(i) - '0';
//MSG_PRINT(index);
isLow=buckets[index] >> 15;
dur = abs(buckets[index]);
if (isLow) dur = -dur;
musterDec.decode(&dur);
}
}
//MSG_PRINTLN("");
}
//SM;R=2;C=400;D=AFAFAF;
//---------------------------------------------------------------------------------------------
void send_mc(const uint8_t startpos,const uint8_t endpos, const int16_t clock)
{
int8_t b;
char c;
//digitalHigh(PIN_SEND);
//delay(1);
uint8_t bit;
unsigned long stoptime =micros();
for (uint8_t i = startpos; i <= endpos; i++)
{
c = cmdstring.charAt(i);
b = ((byte)c) - (c <= '9' ? 0x30 : 0x37);
for (bit = 0x8; bit>0; bit >>= 1)
{
for (byte i = 0; i <= 1; i++)
{
if ((i == 0 ? (b & bit) : !(b & bit)))
digitalLow(PIN_SEND);
else
digitalHigh(PIN_SEND);
stoptime += clock;
while (stoptime > micros())
;
}
}
}
// MSG_PRINTLN("");
}
//---------------------------------------------------------------------------------------------
bool split_cmdpart(int16_t *startpos, int16_t *startdata)
{
int16_t endpos=0;
*startdata = -1;
endpos=cmdstring.indexOf(";",*startpos); // search next ";"
if (endpos ==-1 || *startpos== -1)
{
*startdata = 0;
return false;
}
msg_cmd0 = cmdstring.charAt(*startpos);
msg_cmd1 = cmdstring.charAt(*startpos+1);
/*MSG_PRINT("split_spos=");
MSG_PRINT(*startpos);
MSG_PRINT(" cmd=");
MSG_PRINT(msg_cmd0);
MSG_PRINTLN(msg_cmd1);*/
if (msg_cmd0 == 'S')
{
*startdata = 0;
}
else if (msg_cmd0 == 'P')
{
if (cmdstring.charAt(*startpos+2) != '=')
return false;
*startdata = *startpos+3;
}
else
{
if (msg_cmd1 != '=')
return false;
*startdata = *startpos+2;
}
*startpos = endpos + 1; // Set startpos to endpos to extract next part
return true;
}
// SC;R=4;SM;C=400;D=AFFFFFFFFE;SR;P0=-2500;P1=400;D=010;SM;D=AB6180;SR;D=101;
// SC;R=4;SM;C=400;D=FFFFFFFF;SR;P0=-400;P1=400;D=101;SM;D=AB6180;SR;D=101;
// SR;R=3;P0=1230;P1=-3120;P2=-400;P3=-900;D=030301010101010202020202020101010102020202010101010202010120202;
// SM;C=400;D=AAAAFFFF;F=123456;
// SR;R=10;P0=-2000;P1=-1000;P2=500;P3=-6000;D=2020202021212020202121212021202021202121212023;
//---------------------------------------------------------------------------------------------
struct s_sendcmd
{
int16_t sendclock;
uint8_t datastart;
uint16_t dataend;
int16_t buckets[maxSendPattern];
uint8_t repeats;
} ;
//---------------------------------------------------------------------------------------------
void send_cmd()
{
#define combined 0
#define manchester 1
#define raw 2
#define maxSendCmd 5
uint16_t tmpBankoff;
uint8_t remccmode = ccmode;
uint8_t tmpBank;
tmpBank = radio_bank[1]; // Modul B
if (tmpBank > 9)
{
MSG_PRINTLN(F("Radio B is not active!"));
return;
}
tmpBankoff = getBankOffset(tmpBank);
ccmode = tools::EEread(tmpBankoff + addr_ccmode);
if ( ccmode != 0
&& ccmode != 15 )
{
MSG_PRINTLN(F("ASK/OOK send is only with ccmode 0 or 15 possible!"));
ccmode = remccmode;
return;