-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRadio.ino
More file actions
725 lines (651 loc) · 23.6 KB
/
Copy pathRadio.ino
File metadata and controls
725 lines (651 loc) · 23.6 KB
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
//============================================================================
// Radio related functions
//============================================================================
// include the library
#include <RadioLib.h>
// max packet length
#define PACKETLEN 255
// Create radio modules depending on what RF chip you use
#if defined(USE_SX127X)
SX1278 radio = new Module(PIN_NSS, PIN_DIO0, PIN_RESET, PIN_DIO1);
#else
#if defined(USE_LLCC68)
LLCC68 radio = new Module(PIN_NSS, PIN_DIO1, PIN_RESET, PIN_BUSY);
#else
#if defined(USE_SX1268)
SX1268 radio = new Module(PIN_NSS, PIN_DIO1, PIN_RESET, PIN_BUSY);
#else
#if defined(USE_SX1262)
SX1262 radio = new Module(PIN_NSS, PIN_DIO1, PIN_RESET, PIN_BUSY);
#else
#if defined(USE_RF69)
RF69 radio = new Module(PIN_NSS, PIN_DIO0, PIN_RESET);
#endif
#endif
#endif
#endif
#endif
// create RTTY client instance using the radio module
RTTYClient rtty(&radio);
//============================================================================
// this function is called when a complete packet is received by the radio module
// in receiving mode.
// IMPORTANT: this function MUST be 'void' type and MUST NOT have any arguments!
//============================================================================
void setFlag(void) {
// we got a packet, set the flag
receivedFlag = true;
}
//============================================================================
// Clear the interupt flag when in receiving mode
//============================================================================
void unsetFlag(void) {
#if defined(USE_SX127X)
radio.clearDio0Action();
#else
radio.clearDio1Action();
#endif
}
//============================================================================
// Do the setup for RTTY
//============================================================================
void SetupRTTY() {
// First setup FSK
SetupFSK();
// RTTY
toSerialConsole("RTTY init..");
// Setup for RTTY
Radiolib_assert(
rtty.begin(RTTYSettings.Frequency,
RTTYSettings.Shift,
RTTYSettings.Baud,
RTTYSettings.Encoding,
RTTYSettings.StopBits));
}
//============================================================================
// Setup the radio for APRS and send an APRS packet
//============================================================================
void SendAPRS() {
// PIN_DIO2 needs to be connected
AFSKClient audio(&radio, PIN_DIO2);
// create AX.25 client instance using the FSK module
AX25Client ax25(&audio);
// create APRS client instance using the AX.25 client
APRSClient aprs(&ax25);
toSerialConsole("\nSetting up radio for APRS...");
#if defined(USE_RF69)
Radiolib_assert(radio.begin(APRS_AFSK_FREQUENCY + APRS_AFSK_FREQ_OFFSET));
#else
Radiolib_assert(radio.beginFSK(APRS_AFSK_FREQUENCY + APRS_AFSK_FREQ_OFFSET));
#endif
Radiolib_assert(radio.setOutputPower(APRS_AFSK_POWER));
// If we get this far, the radio is initialized
// initialize AX.25 client
toSerialConsole("[AX.25] Initializing ... ");
// Source call, ssid, preamble length
Radiolib_assert(ax25.begin(APRS_AFSK_CALLSIGN, APRS_AFSK_SSID, APRS_AFSK_PREAMBLE));
// Correct tone if necessary
// Radiolib_assert(ax25.setCorrection(1, 2));
// initialize APRS client
toSerialConsole("[APRS] Initializing ... ");
// symbol:'O' (Balloon)
Radiolib_assert(aprs.begin('O'));
// If we get here we are ready send an APRS packet using AFSK/AX.25
String lStr;
toSerialConsole("[APRS] Sending location report\n");
// The DESTID that TBTracker was assigned. Do not change.
char destination[] = "APETBT";
// Get the current latitude
char latitude[10];
lStr = getAPRSlat(UGPS.Latitude);
lStr.toCharArray(latitude, lStr.length() + 1);
// Get thre current longitude
char longitude[10];
lStr = getAPRSlon(UGPS.Longitude);
lStr.toCharArray(longitude, lStr.length() + 1);
// Get the current altitude
char altitude[10];
lStr = getAPRSAlt(UGPS.Altitude);
lStr.toCharArray(altitude, lStr.length() + 1);
// Get the current time
char timestamp[10];
lStr = getAPRStimestamp();
lStr.toCharArray(timestamp, lStr.length() + 1);
// Send the actual APRS packet
Radiolib_assert(aprs.sendPosition(destination, 0, latitude, longitude, altitude, timestamp));
}
//============================================================================
// Set the radio for Horus 4FSK
//============================================================================
void SetupHorus(float lFreq) {
toSerialConsole("\nSetting up radio for Horus...\n");
// Initialize the radio in FSK mode
#if defined(USE_SX1262)
Radiolib_assert(radio.beginFSK(FSK_FREQUENCY, FSK_BITRATE, FSK_FREQDEV, FSK_RXBANDWIDTH_sx126, FSK_POWER, FSK_PREAMBLELENGTH, USE_TCXO, FSK_USERREGULATORLDO));
#else
#if defined(USE_SX1268)
Radiolib_assert(radio.beginFSK(FSK_FREQUENCY, FSK_BITRATE, FSK_FREQDEV, FSK_RXBANDWIDTH_sx126, FSK_POWER, FSK_PREAMBLELENGTH, USE_TCXO, FSK_USERREGULATORLDO));
#else
#if defined(USE_SX127X)
Radiolib_assert(radio.beginFSK(FSK_FREQUENCY, FSK_BITRATE, FSK_FREQDEV, FSK_RXBANDWIDTH_sx127, FSK_POWER, FSK_PREAMBLELENGTH, FSK_ENABLEOOK));
#else
#if defined (USE_LLCC68)
Radiolib_assert(radio.beginFSK(FSK_FREQUENCY, FSK_BITRATE, FSK_FREQDEV, FSK_RXBANDWIDTH_sx126, FSK_POWER, FSK_PREAMBLELENGTH, USE_TCXO, FSK_USERREGULATORLDO));
#else
#if defined (USE_RF69)
Radiolib_assert(radio.begin(FSK_FREQUENCY, FSK_BITRATE, FSK_FREQDEV, FSK_RXBANDWIDTH_sx127, FSK_POWER, FSK_PREAMBLELENGTH));
#endif
#endif
#endif
#endif
#endif
toSerialConsole("[FSK4] Initializing ... ");
// initialize FSK4 transmitter
// NOTE: FSK4 frequency shift will be rounded
// to the nearest multiple of frequency step size.
// The exact value depends on the module:
// SX127x/RFM9x - 61 Hz
// RF69 - 61 Hz
// CC1101 - 397 Hz
// SX126x - 1 Hz
// nRF24 - 1000000 Hz
// Si443x/RFM2x - 156 Hz
// SX128x - 198 Hz
// Set the outputpower for Horus
Radiolib_assert(radio.setOutputPower(HORUS_POWER));
// Setup everything for Horus
Radiolib_assert(fsk4_setup(&radio, lFreq + HORUS_FREQ_OFFSET, HORUS_SPACING, HORUS_BAUD));
}
//============================================================================
// Set the radio for FSK modulation
//============================================================================
void SetupFSK() {
toSerialConsole("\nSetting up radio for RTTY...");
// Initialize the radio in FSK mode
#if defined(USE_SX1262)
Radiolib_assert(radio.beginFSK(FSK_FREQUENCY, FSK_BITRATE, FSK_FREQDEV, FSK_RXBANDWIDTH_sx126, FSK_POWER, FSK_PREAMBLELENGTH, USE_TCXO, FSK_USERREGULATORLDO));
#else
#if defined(USE_SX1268)
Radiolib_assert(radio.beginFSK(FSK_FREQUENCY, FSK_BITRATE, FSK_FREQDEV, FSK_RXBANDWIDTH_sx126, FSK_POWER, FSK_PREAMBLELENGTH, USE_TCXO, FSK_USERREGULATORLDO));
#else
#if defined(USE_SX127X)
Radiolib_assert(radio.beginFSK(FSK_FREQUENCY, FSK_BITRATE, FSK_FREQDEV, FSK_RXBANDWIDTH_sx127, FSK_POWER, FSK_PREAMBLELENGTH, FSK_ENABLEOOK));
#else
#if defined (USE_LLCC68)
Radiolib_assert(radio.beginFSK(FSK_FREQUENCY, FSK_BITRATE, FSK_FREQDEV, FSK_RXBANDWIDTH_sx126, FSK_POWER, FSK_PREAMBLELENGTH, USE_TCXO, FSK_USERREGULATORLDO));
#else
#if defined (USE_RF69)
Radiolib_assert(radio.begin(FSK_FREQUENCY, FSK_BITRATE, FSK_FREQDEV, FSK_RXBANDWIDTH_sx127, FSK_POWER, FSK_PREAMBLELENGTH));
#endif
#endif
#endif
#endif
#endif
}
//============================================================================
// Set the radio for LoRa modulation
//============================================================================
void SetupLoRa(int aMode) {
#if !defined(USE_RF69)
// Initialize the SX1278
toSerialConsole("[LoRA] Initializing ... ");
ResetRadio();
switch (aMode) {
case 0:
LoRaSettings.CodeRate = 8;
LoRaSettings.Bandwidth = 20.8;
LoRaSettings.SpreadFactor = 11;
LoRaSettings.Frequency = LORA_FREQUENCY;
break;
case 1:
LoRaSettings.CodeRate = 5;
LoRaSettings.Bandwidth = 20.8;
LoRaSettings.SpreadFactor = 6;
LoRaSettings.implicitHeader = 255;
LoRaSettings.Frequency = LORA_FREQUENCY;
break;
case 2:
LoRaSettings.CodeRate = 8;
LoRaSettings.Bandwidth = 62.5;
LoRaSettings.SpreadFactor = 8;
LoRaSettings.Frequency = LORA_FREQUENCY;
break;
case 3:
LoRaSettings.CodeRate = 6;
LoRaSettings.Bandwidth = 250;
LoRaSettings.SpreadFactor = 7;
LoRaSettings.Frequency = LORA_FREQUENCY;
break;
case 4:
LoRaSettings.CodeRate = 5;
LoRaSettings.Bandwidth = 250;
LoRaSettings.SpreadFactor = 6;
LoRaSettings.Frequency = LORA_FREQUENCY;
break;
case 5:
LoRaSettings.CodeRate = 8;
LoRaSettings.Bandwidth = 41.7;
LoRaSettings.SpreadFactor = 11;
LoRaSettings.Frequency = LORA_FREQUENCY;
break;
case 6:
LoRaSettings.CodeRate = 5;
LoRaSettings.Bandwidth = 41.7;
LoRaSettings.SpreadFactor = 6;
LoRaSettings.Frequency = LORA_FREQUENCY;
break;
case 7:
LoRaSettings.CodeRate = 5;
LoRaSettings.Bandwidth = 20.8;
LoRaSettings.SpreadFactor = 7;
LoRaSettings.Frequency = LORA_FREQUENCY;
break;
case 8:
LoRaSettings.CodeRate = 5;
LoRaSettings.Bandwidth = 62.5;
LoRaSettings.SpreadFactor = 6;
LoRaSettings.Frequency = LORA_FREQUENCY;
break;
case 97: // LORA-APRS UK Frequency
LoRaSettings.CodeRate = 5;
LoRaSettings.Bandwidth = 125;
LoRaSettings.SpreadFactor = 12;
LoRaSettings.Frequency = LORA_APRS_FREQUENCY_UK;
break;
case 98: // LORA-APRS Poland frequency
LoRaSettings.CodeRate = 7;
LoRaSettings.Bandwidth = 125;
LoRaSettings.SpreadFactor = 9;
LoRaSettings.Frequency = LORA_APRS_FREQUENCY_PL;
break;
case 99: // LORA-APRS world frequency
LoRaSettings.CodeRate = 5;
LoRaSettings.Bandwidth = 125;
LoRaSettings.SpreadFactor = 12;
LoRaSettings.Frequency = LORA_APRS_FREQUENCY;
break;
}
//Add the frequency error from settings.h to the LoRa frequency
if (aMode < 90) {
LoRaSettings.Frequency += LORA_FREQ_OFFSET;
} else {
LoRaSettings.Frequency += LORA_APRS_FREQ_OFFSET;
}
#if defined(USE_SX1262)
Radiolib_assert(
radio.begin(
LoRaSettings.Frequency,
LoRaSettings.Bandwidth,
LoRaSettings.SpreadFactor,
LoRaSettings.CodeRate,
LoRaSettings.SyncWord,
LoRaSettings.Power,
LoRaSettings.PreambleLength,
USE_TCXO));
#else
#if defined(USE_SX1268)
Radiolib_assert(
radio.begin(
LoRaSettings.Frequency,
LoRaSettings.Bandwidth,
LoRaSettings.SpreadFactor,
LoRaSettings.CodeRate,
LoRaSettings.SyncWord,
LoRaSettings.Power,
LoRaSettings.PreambleLength,
USE_TCXO));
#else
#if defined(USE_LLCC68)
Radiolib_assert(
radio.begin(
LoRaSettings.Frequency,
LoRaSettings.Bandwidth,
LoRaSettings.SpreadFactor,
LoRaSettings.CodeRate,
LoRaSettings.SyncWord,
LoRaSettings.Power,
LoRaSettings.PreambleLength,
USE_TCXO));
#else
Radiolib_assert(
radio.begin(
LoRaSettings.Frequency,
LoRaSettings.Bandwidth,
LoRaSettings.SpreadFactor,
LoRaSettings.CodeRate,
LoRaSettings.SyncWord,
LoRaSettings.Power,
LoRaSettings.PreambleLength,
LoRaSettings.Gain));
#endif
#endif
#endif
switch (LORA_MODE) {
case 0:
Radiolib_assert(radio.explicitHeader());
Radiolib_assert(radio.forceLDRO(true));
Radiolib_assert(radio.setCRC(true));
break;
case 1:
Radiolib_assert(radio.implicitHeader(PACKETLEN));
Radiolib_assert(radio.autoLDRO());
Radiolib_assert(radio.setCRC(true));
break;
default:
Radiolib_assert(radio.explicitHeader());
Radiolib_assert(radio.autoLDRO());
Radiolib_assert(radio.setCRC(true));
break;
}
#endif
}
//============================================================================
// Send RTTY over the radio
//============================================================================
void sendRTTY(String TxLine) {
SetupRTTY();
// Send only idle carrier to let people get their tuning right
rtty.idle();
delay(RTTY_IDLE_TIME);
// Send the string
toSerialConsole("Send RTTY: ");
toSerialConsole(TxLine);toSerialConsole("\n");
Radiolib_assert(rtty.println(TxLine));
Radiolib_assert(rtty.standby());
}
//============================================================================
// Hardware reset of the radio
//============================================================================
void ResetRadio() {
// Use for ESP based boards
pinMode(PIN_RESET, OUTPUT);
digitalWrite(PIN_RESET, LOW);
delay(100);
digitalWrite(PIN_RESET, HIGH);
delay(100);
}
//============================================================================
// Send a LoRa packet over the radio
//============================================================================
void sendLoRa(String TxLine, int aMode) {
#if !defined(USE_RF69)
SetupLoRa(aMode);
toSerialConsole(TxLine);toSerialConsole("\n");
switch (LORA_MODE) {
case 1:
int i;
int j;
// Send the string
char buf[PACKETLEN];
for (j = 0; j < PACKETLEN; j++) { buf[j] = '\0'; }
for (i = 0; i < TxLine.length(); i++) { buf[i] = TxLine[i]; }
Radiolib_assert(radio.transmit((uint8_t*)buf, PACKETLEN));
break;
default:
// Send the string
toSerialConsole("Transmitting LoRa ");
Radiolib_assert(radio.transmit(TxLine));
break;
}
#endif
}
//============================================================================
// Send a Horus V1 packet over the radio
//============================================================================
void sendHorusV1() {
int pkt_len;
int coded_len;
// Start Horus Binary V1
toSerialConsole("Generating Horus Binary v1 Packet");
// Generate packet for V1
pkt_len = build_horus_binary_packet_v1(rawbuffer);
PrintHex(rawbuffer, pkt_len, debugbuffer);
toSerialConsole("Uncoded Length (bytes): ");
toSerialConsole(pkt_len);toSerialConsole("\n");
toSerialConsole("Uncoded: ");
toSerialConsole(debugbuffer);toSerialConsole("\n");
// Apply Encoding
coded_len = horus_l2_encode_tx_packet((unsigned char*)codedbuffer, (unsigned char*)rawbuffer, pkt_len);
PrintHex(codedbuffer, coded_len, debugbuffer);
toSerialConsole("Encoded Length (bytes): ");
toSerialConsole(coded_len); toSerialConsole("\n");
toSerialConsole("Coded: ");
toSerialConsole(debugbuffer);toSerialConsole("\n");
// Setup the radio for Horus communication of frequency 1
if (HORUS_FREQUENCY_1 != 0.0) {
SetupHorus(HORUS_FREQUENCY_1);
// Transmit!
toSerialConsole("Transmitting Horus Binary v1 Packet on: ");
toSerialConsole(HORUS_FREQUENCY_1);
toSerialConsole("MHz\n");
fsk4_idle(&radio);
delay(100);
fsk4_preamble(&radio, 8);
fsk4_write(&radio, codedbuffer, coded_len);
toSerialConsole("\n");
}
// Setup the radio for Horus communication of frequency 2
if (HORUS_FREQUENCY_2 != 0.0) {
SetupHorus(HORUS_FREQUENCY_2);
// Transmit!
toSerialConsole(F("Transmitting Horus Binary v1 Packet on: "));
toSerialConsole(HORUS_FREQUENCY_2);
toSerialConsole("MHz\n");
fsk4_idle(&radio);
delay(100);
fsk4_preamble(&radio, 8);
fsk4_write(&radio, codedbuffer, coded_len);
toSerialConsole("\n");
}
}
//============================================================================
// Send a Horus V2 packet over the radio
//============================================================================
void sendHorusV2() {
int pkt_len;
int coded_len;
// Start Horus Binary V2
toSerialConsole("Generating Horus Binary v2 Packet");
// Generate packet for V2
pkt_len = build_horus_binary_packet_v2(rawbuffer);
PrintHex(rawbuffer, pkt_len, debugbuffer);
toSerialConsole("Uncoded Length (bytes): ");
toSerialConsole(pkt_len);toSerialConsole("\n");
toSerialConsole("Uncoded: ");
toSerialConsole(debugbuffer);toSerialConsole("\n");
// Apply Encoding
coded_len = horus_l2_encode_tx_packet((unsigned char*)codedbuffer, (unsigned char*)rawbuffer, pkt_len);
PrintHex(codedbuffer, coded_len, debugbuffer);
toSerialConsole("Encoded Length (bytes): ");
toSerialConsole(coded_len); toSerialConsole("\n");
toSerialConsole("Coded: ");
toSerialConsole(debugbuffer); toSerialConsole("\n");
// Setup the radio for Horus communication of frequency 1
if (HORUS_FREQUENCY_1 != 0.0) {
SetupHorus(HORUS_FREQUENCY_1);
// Transmit!
toSerialConsole("Transmitting Horus Binary v2 Packet on: ");
toSerialConsole(HORUS_FREQUENCY_1);
toSerialConsole("MHz\n");
fsk4_idle(&radio);
delay(100);
fsk4_preamble(&radio, 8);
fsk4_write(&radio, codedbuffer, coded_len);
toSerialConsole("\n");
}
// Setup the radio for Horus communication of frequency 2
if (HORUS_FREQUENCY_2 != 0.0) {
SetupHorus(HORUS_FREQUENCY_2);
// Transmit!
toSerialConsole("Transmitting Horus Binary v2 Packet on: ");
toSerialConsole(HORUS_FREQUENCY_2);
toSerialConsole("MHz\n");
fsk4_idle(&radio);
delay(100);
fsk4_preamble(&radio, 8);
fsk4_write(&radio, codedbuffer, coded_len);
toSerialConsole("\n");
}
}
//============================================================================
// Send a Horus V3 packet over the radio
//============================================================================
void sendHorusV3() {
int pkt_len;
int coded_len;
// Start Horus Binary V2
toSerialConsole("Generating Horus Binary v3 Packet");
// Generate packet for V3
pkt_len = build_horus_binary_packet_v3(rawbuffer);
PrintHex(rawbuffer, pkt_len, debugbuffer);
toSerialConsole("Uncoded Length (bytes): ");
toSerialConsole(pkt_len);toSerialConsole("\n");
toSerialConsole("Uncoded: ");
toSerialConsole(debugbuffer);toSerialConsole("\n");
// Apply Encoding
coded_len = horus_l2_encode_tx_packet((unsigned char*)codedbuffer, (unsigned char*)rawbuffer, pkt_len);
PrintHex(codedbuffer, coded_len, debugbuffer);
toSerialConsole("Encoded Length (bytes): ");
toSerialConsole(coded_len); toSerialConsole("\n");
toSerialConsole("Coded: ");
toSerialConsole(debugbuffer);toSerialConsole("\n");
// Setup the radio for Horus communication of frequency 1
if (HORUS_FREQUENCY_1 != 0.0) {
SetupHorus(HORUS_FREQUENCY_1);
// Transmit!
toSerialConsole("Transmitting Horus Binary v3 Packet on: ");
toSerialConsole(HORUS_FREQUENCY_1);
toSerialConsole("MHz\n");
fsk4_idle(&radio);
delay(100);
fsk4_preamble(&radio, 8);
fsk4_write(&radio, codedbuffer, coded_len);
toSerialConsole("\n");
}
// Setup the radio for Horus communication of frequency 2
if (HORUS_FREQUENCY_2 != 0.0) {
SetupHorus(HORUS_FREQUENCY_2);
// Transmit!
toSerialConsole("Transmitting Horus Binary v3 Packet on: ");
toSerialConsole(HORUS_FREQUENCY_2);
toSerialConsole("MHz\n");
fsk4_idle(&radio);
delay(100);
fsk4_preamble(&radio, 8);
fsk4_write(&radio, codedbuffer, coded_len);
toSerialConsole("\n");
}
}
//============================================================================
// Send a LoRa APRS packet over the radio
//============================================================================
void sendLoRaAprs() {
String aprs_packet;
String lat = "";
String lon = "";
int deg;
int min;
float minute_remainder;
float second_remainder;
aprs_packet = "";
aprs_packet += "<\xff\x01";
// Add Source
aprs_packet += LORA_APRS_PAYLOAD_ID;
// Add SSID
aprs_packet += LORA_APRS_SSID;
//Add Destination (do not use digipeating)
aprs_packet += ">";
aprs_packet += "APETBT"; // destination callsign_APRS_DEST;
// start of "real" data (Coordinates with timestamp)
aprs_packet += ":@";
// get the APRS timestamp
aprs_packet += getAPRStimestamp();
// get the APRS latitude
aprs_packet += getAPRSlat(UGPS.Latitude);
// Add the symbol for the primary symbol table
aprs_packet += "/";
// Add the longitude
aprs_packet += getAPRSlon(UGPS.Longitude);
// Add the symbol for balloon
aprs_packet += "O";
// Add the altitude
aprs_packet += getAPRSAlt(UGPS.Altitude);
// Add the voltage only if it was defined in the settings file
#if defined(USE_VOLTAGE_IN_APRS)
aprs_packet += " " + String(ReadVCC(),2) + "V";
#endif
#if defined(USE_BME280_TEMP_IN_APRS)
aprs_packet += " " + String(bme280_temperature(),0) + "C";
#endif
#if defined(USE_BME280_PRESSURE_IN_APRS)
aprs_packet += " " + String(bme280_pressure(),0) + "hPa";
#endif
#if defined(USE_BME280_HUMIDITY_IN_APRS)
aprs_packet += " " + String(bme280_humidity(),0) + "%";
#endif
aprs_packet += " " ;
aprs_packet += LORA_APRS_CUSTOM_MESSAGE;
if (LORA_APRS_WORLD_ENABLED) {
toSerialConsole("Sending LoRa APRS packet on the world frequency\n");
sendLoRa(aprs_packet, LORA_APRS_MODE);
}
if (LORA_APRS_PL_ENABLED && inPoland()) {
toSerialConsole("Sending LoRa APRS packet on the Poland frequency\n");
sendLoRa(aprs_packet, LORA_APRS_MODE_PL);
}
if (LORA_APRS_UK_ENABLED && inUK()) {
toSerialConsole("Sending LoRa APRS packet on the UK frequency\n");
sendLoRa(aprs_packet, LORA_APRS_MODE_UK);
}
}
//============================================================================
// Send a tone on a specific frequency for calibration purposes
// You can enable this in the settings.h file
//============================================================================
void FreqCalibration(float Frequency) {
toSerialConsole("Starting calibration...");
// create FSK4 client instance using the FSK module
FSK4Client fsk4(&radio);
#if defined(USE_RF69)
Radiolib_assert(radio.begin());
#else
Radiolib_assert(radio.beginFSK());
#endif
// Starting fsk4
toSerialConsole("Starting Radio...");
Radiolib_assert(fsk4.begin(Frequency, 270, 100));
// Send a carrier for 10 seconds, wait 5 seconds, loop.
while (true) {
fsk4.idle();
delay(10000);
fsk4.standby();
delay(5000);
} // go on forever
}
//============================================================================
// Put the radio in RX mode. enable this in settings.
// LoRa should be enabled
//============================================================================
void StartReceiveLoRaPacket()
{
#if !defined(USE_RF69)
SetupLoRa(LORA_MODE);
#if defined(USE_SX127X)
radio.setDio0Action(setFlag, RISING); // As of RadioLib 6.0.0 all methods to attach interrupts no longer have a default level change direction
#else
radio.setDio1Action(setFlag);
#endif
if (LORA_MODE == 1) {
Radiolib_assert(radio.startReceive(LoRaSettings.implicitHeader));
} else {
Radiolib_assert(radio.startReceive());
}
// If we get here, we are listening on the frequency
toSerialConsole("[LoRa] Waiting for packets on: ");
toSerialConsole(LoRaSettings.Frequency, 3);
toSerialConsole(" MHz\n");
toSerialConsole("----------------------------\n");
#else
toSerialConsole("Receiving LoRa packets not supported for RF69 modules.\n");
#endif
}