-
Notifications
You must be signed in to change notification settings - Fork 1
/
Repeater.ino
174 lines (135 loc) · 3.68 KB
/
Repeater.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
#include "DRA818.h"
HardwareSerial Serial1(1);
HardwareSerial Serial2(2);
#define TX1_pin 27
#define RX1_pin 14
#define TX2_pin 4
#define RX2_pin 13
#define RxPTT 2
#define RxPD 5
#define RxAudioOn 39
#define RxAudioOut 26
#define RxAudioIn 33
#define TxPTT 15
#define TxPD 23
#define TxAudioOn 34
#define TxAudioOut 25
#define TxAudioIn 32
#define GPIO3 21
#define GPIO4 19
#define GPIO5 18
#define GPIO6 22
#define GPIO7 36
#define GPIO8 35
#define GPIO9 0
#define RXFreq 446.5000
#define TXFreq 441.5000
const String morseArray[63] = {"-.-.--", "", "", "...-..-", "", ".-...", ".----.", "-.--.", "-.--.-", "", ".-.-.", "--..--", "-....-", ".-.-.-", "-..-.", "-----", ".----", "..---", "...--",
"....-", ".....", "-....", "--...", "---..", "----.", "---...", "-.-.-.", "", "-...-", "", "..--..", ".--.-.", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---",
"-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "", "", "", "", "..--.-"}; // letters, numbers, symbols
const String Ident = "KD9KCK REPEATER";
const int MorseCodeDelay = 80;
DRA818 *SA818In;
DRA818 *SA818Out;
unsigned long TxStart = 0;
bool TXOn = false;
unsigned long LastIdent = 0;
void initPins(){
pinMode(RxPTT,OUTPUT);
digitalWrite(RxPTT,HIGH);
pinMode(RxPD,OUTPUT);
digitalWrite(RxPD,LOW);
pinMode(RxAudioOn,INPUT);
pinMode(RxAudioOut,INPUT);
pinMode(RxAudioIn,INPUT);
pinMode(TxPTT,OUTPUT);
digitalWrite(TxPTT,HIGH);
pinMode(TxPD,OUTPUT);
digitalWrite(TxPD,LOW);
pinMode(TxAudioOn,INPUT);
pinMode(TxAudioOut,INPUT);
pinMode(TxAudioIn,INPUT);
}
void initModules(){
digitalWrite(RxPD,HIGH);
digitalWrite(TxPD,HIGH);
SA818In = DRA818::configure(Serial1, DRA818_VHF, RXFreq, RXFreq, 1, 8, 12, 12, DRA818_12K5, false, false, false, &Serial);
SA818Out = DRA818::configure(Serial2, DRA818_VHF,TXFreq, TXFreq, 1, 8, 12, 12, DRA818_12K5, false, false, false, &Serial);
}
void registerISR(){
attachInterrupt(RxAudioOn, RxAudioOnFALLING, FALLING);
attachInterrupt(RxAudioOn, RxAudioOnRISING, RISING);
}
void playIdent(){
for(int i = 0; i <= Ident.length(); i++)
{
if(Ident[i]>=33 && Ident[i]<=95) // check for targeted ASCII range
{
String morseToSend = morseArray[Ident[i]-33]; // use morse array to covert
for(int x = 0; x <= morseToSend.length(); x++)
{
if(TXOn):
return
sendDashOrDot(morseToSend[x]);
}
delay(MorseCodeDelay*3); //between letters delay.
}
if (Ident[i]==32) // if space
{
delay(MorseCodeDelay*4); // delay for space (adding oneUnitDelay*4 delay to get oneUnitDelay*7 in total)
}
}
}
void sendDashOrDot(byte sendChar){
if (sendChar==0x2E) // if dot
{
ledcWriteTone(1,800);
delay(MorseCodeDelay);
ledcWrite(1,0);
delay(MorseCodeDelay);
}
if (sendChar==0x2D) // if dash
{
ledcWriteTone(1,550);
delay(MorseCodeDelay);
ledcWrite(1,0);
delay(MorseCodeDelay);
}
}
void setup() {
initPins();
initModules();
LastIdent = millis();
ledcSetup(1,800,1);
ledcAttachPin(TxAudioOut,1);
digitalWrite(TxPTT,LOW);
playIdent();
delay(10);
digitalWrite(TxPTT,HIGH);
}
void loop() {
noInterrupts();
if(TxStart - millis() > 180000){
TxOn = false;
digitalWrite(TxPTT,HIGH);
}
interrupts();
if(LastIdent-millis() > 1800000){
digitalWrite(TxPTT,LOW);
playIdent();
delay(10);
if(!TxOn){
digitalWrite(TxPTT,HIGH);
}
LastIdent = millis();
}
}
void IRAM_ATTR RxAudioOnRISING() {
TXOn = false;
digitalWrite(TxPTT,HIGH);
}
void IRAM_ATTR RxAudioOnFALLING() {
TXOn = true;;
TxStart = millis();
digitalWrite(TxPTT,LOW);
}