-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsi5351-beacon.ino
773 lines (628 loc) · 19.8 KB
/
si5351-beacon.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
#include "src/si5351/si5351.h"
#include "src/time/time_slice_ds3231.h"
#include "src/time/time_slice_gps.h"
#include "src/time/rtc_datetime.h"
#include "src/time/ds3231.h"
#include "src/utils/symbol_rate.h"
#include "src/utils/command_buffer.h"
#include "src/jt_encoder/jt_wspr_encoder.h"
#include "src/jt_encoder/jt_mock_encoder.h"
#include "src/jt_encoder/jt_jt65_encoder.h"
#include "src/jt_encoder/jt_iscat_encoder.h"
#include "src/utils/jt_band_params.h"
#include <Wire.h>
#include <avr/pgmspace.h>
// ---------------- Global Variables -----------------
Si5351 si5351(0);
SymbolRate symbolRate;
CCommandBuffer commandBuffer;
JTEncodeBase::iterator itSymbol;
JTEncodeBase::iterator itEnd;
// To save dynamic and program space you may comment unnecessary coders and comment references to them in the code.
JTWSPREncoder wsprCoder;
JT65Encoder jt65Coder;
JTMockEncoder jt4Coder;
JTMockEncoder jt9Coder;
JTISCATEncoder jtISCATCoder;
unsigned prevSymbolIndex;
unsigned char prevSymbolValue;
JTBandParams bandParams;
enum State
{
stateIdle = 0,
stateWaitStart,
statePTTActive,
stateTransmitting
};
int currentState = stateIdle;
RtcDatetime pttStartTime;
RtcDatetime symbolsStartTime;
int prev1PPS;
int numShowTime = 0;
int prevBand;
bool timeValid = false;
enum FilterBand {
FILTER_BAND_None = 0,
FILTER_BAND_0,
FILTER_BAND_1,
FILTER_BAND_2,
FILTER_BAND_3,
FILTER_BAND_4,
FILTER_BAND_5
};
struct LPF_Band_Matching
{
unsigned char rfBand;
unsigned char filterBand;
};
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// ---- Arduino pin configuration ---
const int pinLED = LED_BUILTIN; // duplicate 1pps
const int pin1PPS = 4; // <-- 1pps signal from ds3231 (actual only if ds3131 is using)
// Active LOW relay pins as on QRP-LABS relay-switched LPF kit
const int pinBAND0 = 7;
const int pinBAND1 = A0;
const int pinBAND2 = 10;
const int pinBAND3 = 11;
const int pinBAND4 = 12;
const int pinBAND5 = A3;
// ----- Configure mapping: RF_Band -> Relay_switch_board_LPF -----
LPF_Band_Matching relaySwitchBandMatching [] = {
{RF_Band_40m, FILTER_BAND_5},
{RF_Band_30m, FILTER_BAND_3},
{RF_Band_20m, FILTER_BAND_2},
{RF_Band_15m, FILTER_BAND_1},
{RF_Band_15m, FILTER_BAND_1}
};
const FilterBand DefaultFilterBand = FILTER_BAND_0; // default band if none of relaySwitchBandMatching[] matched.
// XTAL frequency is sensitive only when LPF relay board is using.
const unsigned long xtalFrequencyInKHz = 27000;
// ----------- Startup Parameters ------------------------------
const int PTTWarmupTimeInSeconds = 2; // Number of seconds prior symbols transmission. It is for activate PTT of Power Amplifer.
const unsigned TRIntervalMultiplier = 1; // for example: value 1 means TR-TR-TR... value 3 means: TX-RX-RX-TX...
bool WorkModeActive = true; // active TX logic at power-on
bool BandHoppingEnabled = true; // band hopping state at power-on
// ------------- Predefined messages JT65,JT9,JT4
// "HELLO WORLD" encoded message. Please replace to your own.
const PROGMEM unsigned char MSG_JT65[] = {29,23,60,48,34,6,39,9,23,26,55,15,47,12,16,42,11,25,63,63,9,10,60,0,46,21,15,54,54,62,51,48,39,20,56,25,15,62,52,36,3,4,41,13,59,10,41,63,43,39,15,19,32,33,53,25,60,62,4,55,26,42,48};
const PROGMEM unsigned char MSG_JT9[] = {0,0,3,6,0,7,3,4,7,0,7,3,2,4,8,0,3,2,4,1,6,1,0,5,8,2,2,4,4,2,5,3,0,8,0,4,7,3,7,6,3,4,4,5,3,2,4,3,7,2,0,0,1,2,0,5,5,2,5,0,2,4,8,3,2,0,2,1,3,8,1,8,0,2,2,8,3,1,7,8,1,2,0,1,0};
const PROGMEM unsigned char MSG_JT4[] = {};
//---------- Begin Band Configuration ----------------------
size_t currentBandIndex = 0; // <--- Band index at power-on in the array below (zero-based)
//
// Copy vector-descriptor from web configurator and paste into bandDescrArray.
// Local configurator: ./doc/band_configurator.html
// Configurator in the Net: http://ra9yer.blogspot.com/p/si5351-configurator.html
//
JTBandDescr bandDescrArray[] = {
{Mode_JT65_B, 32, 28943, 836045, 6, 1, 441, 163840, 60} // f=144.1777 MHz; JT65B; step=5.383Hz; 2.692baud; T/R=1m
, {Mode_WSPR2, 31, 154287, 614418, 30, 1, 12, 8192, 120} // f=28.126 MHz; WSPR2; step=1.465Hz; 1.465baud; T/R=2m};
};
//---------- End Configuration ------------------------
const size_t NumBandsTotal = sizeof(bandDescrArray) / sizeof(bandDescrArray[0]); // Calc number of bands at compile time. Used for band hopping.
// ---------- Time Source Configuration. Either GPS module or DS3231.
//
// Here you need to select either DS3231 or GPS module. Please comment one and leave another one uncommented.
//
//#define TIME_SLICE_GPS
#define TIME_SLICE_DS3231
#if (!defined(TIME_SLICE_GPS) && !defined(TIME_SLICE_DS3231)) || (defined(TIME_SLICE_GPS) && defined(TIME_SLICE_DS3231))
#error "Please define either TIME_SLICE_GPS or TIME_SLICE_DS3131"
#endif
#if defined(TIME_SLICE_GPS)
HardwareSerial& gpsSerial = Serial1; // <--- Specify serial port for GPS NMEA module here
TimeSliceGPS timeSlice;
#endif
#if defined(TIME_SLICE_DS3231)
TimeSliceDS3231 timeSlice(pin1PPS);
#endif
// Enable or disable accept user's commands from terminal.
// Should be "true". However, when GPS and Terminal share the same UART port it has to be set to "false".
const bool enableReadTerminalCommands = true;
// ------ Message initialize functions -----
//--------------------------------------------------
void initializeWSPRCoder()
{
wsprCoder.encodeMessage( "AA0AAA", "NO13", 10 ); // <---- WSPR message defined here.
}
//--------------------------------------------------
void initializeISCATCoder()
{
jtISCATCoder.encodeMessage( "HELLO WORLD", 20 ); // <------ ISCAT message defined here.
}
//--------------------------------------------------
void initializeJT65Coder()
{
initCoderFromProgmemArray( jt65Coder, MSG_JT65, sizeof(MSG_JT65), 6 );
}
//--------------------------------------------------
void initializeJT9Coder()
{
initCoderFromProgmemArray( jt9Coder, MSG_JT9, sizeof(MSG_JT9), 4 );
}
//--------------------------------------------------
void initializeJT4Coder()
{
initCoderFromProgmemArray( jt4Coder, MSG_JT4, sizeof(MSG_JT4), 2 );
}
//==============================
//--------------------------------------------------
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Wire.begin();
#ifdef TIME_SLICE_GPS
gpsSerial.begin(9600);
#endif
pinMode(pinLED, OUTPUT);
switchRealyToBand(FILTER_BAND_None);
pinMode(pinBAND0, OUTPUT);
pinMode(pinBAND1, OUTPUT);
pinMode(pinBAND2, OUTPUT);
pinMode(pinBAND3, OUTPUT);
pinMode(pinBAND4, OUTPUT);
pinMode(pinBAND5, OUTPUT);
timeSlice.initialize();
si5351.initialize();
si5351.enableOutput(Si5351::OUT_0, false);
initializeWSPRCoder();
initializeISCATCoder();
initializeJT65Coder();
initializeJT9Coder();
initializeJT4Coder();
currentBandIndex = (currentBandIndex < NumBandsTotal)? currentBandIndex : 0;
bandParams.initFromJTBandDescr( bandDescrArray[currentBandIndex] );
bandParams.setXTALFrequencyInKHz( xtalFrequencyInKHz );
printBandInfo();
if( !enableReadTerminalCommands )
{
// Show notification to user.
Serial.println(F("Terminal commands disabled"));
}
}
//--------------------------------------------------
void loop() {
//
// command line interface
//
if( enableReadTerminalCommands && Serial.available() )
{
int inByte = Serial.read();
commandBuffer.handleInputChar( inByte );
if( commandBuffer.endsWith("\r") || commandBuffer.endsWith("\n") )
{
processTerminalCommands();
commandBuffer.reset();
}
}
//
// sending symbols
//
if( currentState == stateTransmitting )
{
unsigned currentSymbolIndex = symbolRate.currentSymbolIndex();
if( currentSymbolIndex != prevSymbolIndex )
{
unsigned tmpIndex = prevSymbolIndex;
// Step to next symbol.
// In some very rarely case we may skip a few symbols bacause symboldIndex is more relevant parameter.
while( tmpIndex < currentSymbolIndex )
{
if( itSymbol != itEnd )
{
++itSymbol;
}
++tmpIndex;
}
if( itSymbol != itEnd )
{
unsigned char currentSymbolValue = *itSymbol;
if( prevSymbolValue != currentSymbolValue )
{
setSymbol( currentSymbolValue );
}
prevSymbolValue = currentSymbolValue;
if( currentSymbolIndex % 5 == 0 )
{
// just to view progress
Serial.println(currentSymbolIndex);
}
}
else
{
Serial.println(F("Done"));
stop_tx();
switchToNextBandIfNeed(false);
adjustLaunchTimeIfNeed();
}
}
prevSymbolIndex = currentSymbolIndex;
}
//
// Get char from GPS UART and send it to time-slice subsystem.
//
#ifdef TIME_SLICE_GPS
while(gpsSerial.available())
{
char ch = gpsSerial.read();
timeSlice.putNMEAChar(ch);
// TODO: send 'ch' char to any other NMEA data consumers here.
}
#endif
//
// Give time to time-slice subsystem.
//
timeSlice.doWork();
//
// detect next second
//
int current1PPS = timeSlice.get1PPS();
digitalWrite(pinLED, current1PPS); // duplicate LED
bool nextSecondDetected = ( prev1PPS && !current1PPS );
prev1PPS = current1PPS;
// show time when cammand: ts N
if( nextSecondDetected && numShowTime>0 )
{
printTime(false);
--numShowTime;
}
// Actual when datitime is not valid from the beginning.
if( nextSecondDetected && !timeValid )
{
timeValid = true;
adjustLaunchTimeIfNeed();
}
//
// actions when next second event is detected
//
if( nextSecondDetected && (currentState == stateWaitStart || currentState == statePTTActive) )
{
RtcDatetime currentTime;
timeSlice.getTime(currentTime);
if( currentState == stateWaitStart && currentTime >= pttStartTime )
{
Serial.print(F("PTT active\n"));
printTime(false);
currentState = statePTTActive;
activate_ptt();
}
if( currentState == statePTTActive && currentTime >= symbolsStartTime )
{
Serial.print(F("Sending data active\n"));
printTime(false);
currentState = stateTransmitting;
start_tx();
}
}
}
//--------------------------------------------------
void initCoderFromProgmemArray(JTMockEncoder& coder, const unsigned char* srcProgMemPtr, unsigned len, unsigned pitsPerSymbol)
{
const int numberOfSymbolsLargeEnough = 206; // jt4 has 206symbols - more than others.
unsigned char buf[numberOfSymbolsLargeEnough];
memcpy_P(buf, srcProgMemPtr, len); // copy from progmem to local array
coder.initFromArray(buf, len, pitsPerSymbol);
}
//--------------------------------------------------
void processTerminalCommands()
{
if( commandBuffer.startsWith(F("setdate")) ) // update datetime in ds3231 chip
{
// process set date
unsigned params[6];
memset(params, 0, sizeof(params));
for(size_t i=0; i<6; i++ )
{
const char * ptr = commandBuffer.getNextToken(" :-");
if(ptr == NULL) {
break;
}
params[i] = atoi(ptr);
}
RtcDatetime time;
time.second = params[5];
time.minute = params[4];
time.hour = params[3];
time.day = params[2];
time.month = params[1];
time.year = params[0] % 100;
Ds3231::setTime(time);
Serial.print(F("\nDate updated\n"));
}
else if( commandBuffer.startsWith(F("ts")) ) // time show [N times]
{
// show time command
const char * ptr = commandBuffer.getNextToken(" "); // read first argument
if(ptr == NULL) {
// simple show time
printTime(false);
}
else
{
// show time N times with 1sec interval
numShowTime = atoi(ptr);
}
}
else if( commandBuffer.startsWith(F("start")) ) // manual start
{
if( currentState != stateTransmitting )
{
activate_ptt();
start_tx();
}
else
{
Serial.println(F("unable to start when tx active"));
}
}
else if( commandBuffer.startsWith(F("stop")) ) // manual stop
{
stop_tx();
if( WorkModeActive )
{
switchToNextBandIfNeed(false);
adjustLaunchTimeIfNeed();
}
else
{
currentState = stateIdle;
}
}
else if( commandBuffer.startsWith(F("activate")) ) // activate auto start mode
{
Serial.print(F("Activated"));
WorkModeActive = true;
if( currentState != stateTransmitting )
{
adjustLaunchTimeIfNeed();
}
}
else if( commandBuffer.startsWith(F("deactivate")) ) // deactivate auto start mode
{
Serial.print(F("Deactivated"));
WorkModeActive = false;
pttStartTime.reset();
symbolsStartTime.reset();
if( currentState != stateTransmitting )
{
currentState = stateIdle;
}
}
else if( commandBuffer.startsWith(F("si")) ) // system info
{
printTime(true);
printBandInfo();
}
else if( commandBuffer.startsWith(F("bhe")) ) // band hopping enable
{
Serial.print(F("Band hopping enabled"));
BandHoppingEnabled = true;
}
else if( commandBuffer.startsWith(F("bhd")) ) // band hopping disable
{
Serial.print(F("Band hopping disabled"));
BandHoppingEnabled = false;
}
else if( commandBuffer.startsWith(F("nb")) ) // next band
{
Serial.print(F("Next bend selected"));
if( currentState != stateTransmitting )
{
switchToNextBandIfNeed(true);
}
}
else if( commandBuffer.startsWith(F("temperature")) )
{
int16_t temperature = Ds3231::getTemperature();
Serial.print(F("temperature="));
Serial.print(temperature);
Serial.println();
}
}
//--------------------------------------------------
void printTime(bool includeLaunchTime)
{
char buf[20];
RtcDatetime time;
timeSlice.getTime(time);
Serial.print(F("\nClock DateTime = "));
time.formatStr(buf);
Serial.print(buf);
if( includeLaunchTime )
{
Serial.print(F("\nPTT DateTime = "));
pttStartTime.formatStr(buf);
Serial.print(buf);
Serial.print(F("\nSymbol DateTime = "));
symbolsStartTime.formatStr(buf);
Serial.print(buf);
}
Serial.print(F("\n"));
}
//--------------------------------------------------
void printBandInfo()
{
Serial.print(F("\nCurrent band: Index="));
Serial.print(currentBandIndex);
Serial.print(F("; mode="));
Serial.print((int)bandParams.getJTMode());
Serial.print(F("; F="));
Serial.print(bandParams.approxFrequencyInMHz());
Serial.print(F(" MHz"));
Serial.print(F("; RelayNumber="));
Serial.print(convertRFBandToFilterBand(bandParams.getBand())); // 0-means None (FILTER_BAND_None); 1-RL0; 2-RL1; 3-RL2; 4-RL3; 5-RL4; 6-RL5
Serial.print(F("\n"));
}
//----------------------------------------------------------
void setSymbol(unsigned symbol)
{
uint16_t a;
uint32_t b;
uint32_t c;
bandParams.getPLLParamsForSymbol(symbol, a, b, c);
si5351.setupPLLParams(Si5351::PLL_A, a, b, c);
}
//----------------------------------------------------------
void start_tx()
{
Serial.println(F("Started"));
printBandInfo();
switch( bandParams.getJTMode() )
{
case Mode_WSPR2:
case Mode_WSPR15:
// wsprCoder was already initialized at setup()
itSymbol = wsprCoder.begin();
itEnd = wsprCoder.end();
break;
case Mode_JT65_A:
case Mode_JT65_B:
case Mode_JT65_C:
case Mode_JT65_B2:
case Mode_JT65_C2:
// jt65 encoder was already initialized at setup()
itSymbol = jt65Coder.begin();
itEnd = jt65Coder.end();
break;
case Mode_JT9_1:
case Mode_JT9_2:
case Mode_JT9_5:
case Mode_JT9_10:
case Mode_JT9_30:
// jt9 encoder was already initialized at setup()
itSymbol = jt9Coder.begin();
itEnd = jt9Coder.end();
break;
case Mode_JT4_A:
case Mode_JT4_B:
case Mode_JT4_C:
case Mode_JT4_D:
case Mode_JT4_E:
case Mode_JT4_F:
case Mode_JT4_G:
// jt4 encoder was already initialized at setup()
itSymbol = jt4Coder.begin();
itEnd = jt4Coder.end();
break;
case Mode_ISCAT_A:
case Mode_ISCAT_B:
itSymbol = jtISCATCoder.begin();
itEnd = jtISCATCoder.end();
break;
default:
Serial.println(F("Unsupported encoder"));
stop_tx();
currentState = stateIdle;
return;
}
if( itSymbol == itEnd )
{
Serial.println(F("No symbols to transmit"));
stop_tx();
currentState = stateIdle;
return;
}
si5351.setupMultisyncParams(Si5351::OUT_0, bandParams.getMsyncDiv(), bandParams.getRDiv() );
unsigned char currentSymbolValue = *itSymbol;
setSymbol( currentSymbolValue );
prevSymbolValue = currentSymbolValue;
prevSymbolIndex = 0;
currentState = stateTransmitting;
symbolRate.initFromParams( bandParams.getBaudRateDividend(), bandParams.getBaudRateDivisor() );
symbolRate.resetToNow();
si5351.enableOutput(Si5351::OUT_0, true); //
}
//----------------------------------------------------------
void stop_tx()
{
Serial.println(F("Stopped"));
si5351.enableOutput(Si5351::OUT_0, false);
deactivate_ptt();
}
//----------------------------------------------------------
void switchToNextBandIfNeed( bool force )
{
if( !BandHoppingEnabled && !force )
return;
currentBandIndex++;
if( currentBandIndex >= NumBandsTotal )
{
currentBandIndex = 0;
}
bandParams.initFromJTBandDescr( bandDescrArray[currentBandIndex] );
printBandInfo();
}
//----------------------------------------------------------
void adjustLaunchTimeIfNeed()
{
if( !WorkModeActive )
{
currentState = stateIdle;
return;
}
RtcDatetime currentTime;
if( !timeSlice.getTime(currentTime) )
{
Serial.print(F("\ngetTime error"));
currentState = stateIdle;
}
unsigned trInterval = bandParams.getTRInterval();
unsigned long stamp = currentTime.stamp();
stamp += trInterval * TRIntervalMultiplier; // jump to future
stamp -= (stamp % trInterval); // round down
stamp += 1; // JT65,JT9,JT4,WSPR - all start at 01 second
symbolsStartTime.initFromStamp( stamp );
pttStartTime.initFromStamp( stamp - PTTWarmupTimeInSeconds );
printTime(true);
currentState = stateWaitStart;
}
//----------------------------------------------------------
void switchRealyToBand(FilterBand band)
{
// Activate specified relay. Debounce-free solution.
// --- Turn ALL relays off, but not specified.
if( band != FILTER_BAND_0 ) { digitalWrite(pinBAND0, HIGH); }
if( band != FILTER_BAND_1 ) { digitalWrite(pinBAND1, HIGH); }
if( band != FILTER_BAND_2 ) { digitalWrite(pinBAND2, HIGH); }
if( band != FILTER_BAND_3 ) { digitalWrite(pinBAND3, HIGH); }
if( band != FILTER_BAND_4 ) { digitalWrite(pinBAND4, HIGH); }
if( band != FILTER_BAND_5 ) { digitalWrite(pinBAND5, HIGH); }
// --- Activate specified relay.
if( band == FILTER_BAND_0 ) { digitalWrite(pinBAND0, LOW); }
if( band == FILTER_BAND_1 ) { digitalWrite(pinBAND1, LOW); }
if( band == FILTER_BAND_2 ) { digitalWrite(pinBAND2, LOW); }
if( band == FILTER_BAND_3 ) { digitalWrite(pinBAND3, LOW); }
if( band == FILTER_BAND_4 ) { digitalWrite(pinBAND4, LOW); }
if( band == FILTER_BAND_5 ) { digitalWrite(pinBAND5, LOW); }
}
//----------------------------------------------------------
FilterBand convertRFBandToFilterBand( RF_Band band )
{
unsigned len = sizeof(relaySwitchBandMatching) / sizeof(relaySwitchBandMatching[0]);
FilterBand filterBand = DefaultFilterBand;
// scan for match
for( unsigned i=0; i<len; i++ )
{
LPF_Band_Matching const& item = relaySwitchBandMatching[i];
if( item.rfBand == band )
{
filterBand = static_cast<FilterBand>(item.filterBand);
}
}
return filterBand;
}
//----------------------------------------------------------
void activate_ptt()
{
RF_Band rfBand = bandParams.getBand(); // gent band based on pll and multisync params
FilterBand filterBand = convertRFBandToFilterBand(rfBand);
switchRealyToBand( filterBand ); // on/off appropriate relay
// turn on ptt key here, if the feature present.
}
//----------------------------------------------------------
void deactivate_ptt()
{
// TODO: in some cases it is not necessary to switch relay off
switchRealyToBand( FILTER_BAND_None );
// turn off ptt key here
}