-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrtty.ino
171 lines (145 loc) · 3.82 KB
/
rtty.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
/* ========================================================================== */
/* rtty.ino */
/* */
/* Interrupt-driven RTTY transmission for MTX2 or HX1 */
/* */
/* ========================================================================== */
bool SendingNow = false;
unsigned long last_rtty = 0;
#ifdef RTTY_BAUD
#ifdef RTTY_DATA
// Our variables
char TxLine[SENTENCE_LENGTH];
volatile int SendBit = 0;
int StopBits, DataBits;
int Timer2Count;
int RTTY_Counter;
int SettingFrequency;
unsigned long nextRTTY = 0;
// Code
void SetupRTTY(void){
pinMode(RTTY_DATA, OUTPUT);
#ifdef RTTY_ENABLE
pinMode(RTTY_ENABLE, OUTPUT);
digitalWrite(RTTY_ENABLE, LOW);
#endif
DataBits = 7;
StopBits = 2;
#ifdef RTTY_PWM
TCCR3B = TCCR3B & 0b11111000 | 0x01; //pin 5 only
#endif
}
void CheckRTTY(void){
if(((GPS.Satellites>=4 && GPS.Lock==1) || getLogStarted()) && (GPS.AltitudeF >= 5000 || GPS.AltitudeF < 2000) && !isTX()){
if ((millis() - last_rtty) >= (getRTTYInterval() * 1000L)){
SendingNow = true;
BuildSentence(TxLine, RTTY_PAYLOAD_ID);
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(TxLine);
DEBUG_SERIAL.print('\r');
#endif
for(uint8_t i=0;i<RTTY_ATTEMPTS;i++){
rtty_txstring(TxLine);
}
if((millis() >= NextAPRS)){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("Delaying NextAPRS by 5 seconds"));
#endif
NextAPRS = millis() + 5000L;
}
SendingNow = false;
last_rtty = millis();
}
}
}
void rtty_txbit (int bit) {
int upper = 114;
if (bit) {
analogWrite(RTTY_DATA,upper);
}else {
analogWrite(RTTY_DATA,100);
}
if(RTTY_BAUD==600){
delayMicroseconds(1667); //600 baud
}else if(RTTY_BAUD==300){
delayMicroseconds(3370); // 300 baud
}else if(RTTY_BAUD==100){
delayMicroseconds(10000);
}else if(RTTY_BAUD==75){
delayMicroseconds(13333);
}else{
delayMicroseconds(10000);
delayMicroseconds(10150); // You can't do 20150
}
}
void rtty_txstring (char * string) {
char c;
#ifdef RTTY_ENABLE
digitalWrite(RTTY_ENABLE,HIGH);
#endif
#ifdef LED_TX
allLEDoff();
if (GPS.AltitudeF < 2000){
digitalWrite(LED_TX,HIGH);
}
#endif
c = *string++;
while ( c != '\0') {
rtty_txbyte (c);
c = *string++;
}
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("Done RTTY"));
#endif
#ifdef RTTY_ENABLE
digitalWrite(RTTY_ENABLE,LOW);
#endif
#ifdef LED_TX
digitalWrite(LED_TX,LOW);
#endif
}
void rtty_txbyte (char c) {
int i;
rtty_txbit (0); // Start bit
//if(debug) DEBUG_SERIAL.print(c);
for (i=0;i<DataBits;i++) {
if (c & 1) rtty_txbit(1);
else rtty_txbit(0);
c = c >> 1;
}
for(i=0;i<StopBits;i++){
rtty_txbit (1); // Stop bits
}
}
#endif
#endif
bool isSendingRTTY(){
return SendingNow;
}
void setLastRTTY(unsigned long v){
last_rtty = v;
}
unsigned long getLastRTTY(){
return last_rtty;
}
int getRTTYInterval(){
if(GPS.AltitudeF>40000){
return 600;
}else if(GPS.AltitudeF>20000){
return 300;
}else if(GPS.AltitudeF>10000){
return 120;
}else if(GPS.AltitudeF>1000){
return 60;
}else{
#ifdef RTTY_INTERVAL
return RTTY_INTERVAL;
#else
return 45;
#endif
}
}
int getRTTYAttempts(){
//TODO: perform more broadcast sentence repeats when landed and more when long gaps between transmissions?
//TODO: move this to a dedicated transmitter on a different frequency from APRS
}