-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTTY.cpp
More file actions
144 lines (112 loc) · 3.38 KB
/
RTTY.cpp
File metadata and controls
144 lines (112 loc) · 3.38 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
#include "RTTY.h"
#include "GPS.h"
static unsigned long rtty_timer = 0;
RTTY::RTTY() : NTX2EN(13, RADIOEN){
SoftwareSerial NTX2EN(13, RADIOEN);
//delay(10);
//this->RTTY_SetChannel();
}
void RTTY::check_RTTY() {
static unsigned long MessageDelay = 0; //takes account of delayed APRS messages due to GPS signal loss
// Time for another APRS frame
if ((int32_t) (millis() - rtty_timer) >= 0) {
if (gps.ValidLocation() && (gps.AgeLocation() < (5 * GPS_VALID_POS_TIMEOUT) ) ) {
RTTY::Transmit_RTTY_GPS();
rtty_timer += ( (RTTY_PERIOD * 1000L) + MessageDelay);
MessageDelay = 0;
DEBUG_PRINT("\nRTTY with GPS sent.\n");
} /*else {
RTTY::Transmit_RTTY_NO_GPS();
rtty_timer += ( (RTTY_PERIOD * 1000L) + MessageDelay);
MessageDelay = 0;
RTTY_DEBUG(F("\nRTTY without GPS sent.\n"));
}*/
} else {
MessageDelay = millis();
DEBUG_PRINT("\nrtty notsend\n");
}
}
void RTTY::RTTY_Setup() {
pinMode(RTTY_DATA_PIN, OUTPUT);
}
void RTTY::RTTY_SetChannel() {
// RX, TX
int i=0;
for (i = 1; i <= 2; i++)
{
SoftwareSerial NTX2EN(13, RADIOEN);
NTX2EN.begin(RTTY_BAUDRATE);
delay(100);
NTX2EN.write(0x80);
NTX2EN.print("wr");
NTX2EN.print(RTTY_Channel);
NTX2EN.print("\r");
delay(100);
NTX2EN.end();
}
}
void RTTY::rtty_txbit (int bit) {
/* NOTE: This new analog write values are for 12 bit analogwriteresolution.
** See afsk setup for details. Values for 8 bit default resolution are
** 110 high and 100 low
*/
if (bit) {
// high
analogWrite(RTTY_DATA_PIN, 1766);
}
else {
// low
analogWrite(RTTY_DATA_PIN, 1606);
}
delayMicroseconds(3370); // 300 baud
//delayMicroseconds(10000); // For 50 Baud uncomment this and the line below.
//delayMicroseconds(10150);
}
void RTTY::rtty_txbyte (char c) {
/* Simple function to sent each bit of a char to
** rtty_txbit function.
** NB The bits are sent Least Significant Bit first
**
** All chars should be preceded with a 0 and
** proceded with a 1. 0 = Start bit; 1 = Stop bit
**
*/
int i;
rtty_txbit (0); // Start bit
// Send bits for for char LSB first
for (i = 0; i < 7; i++) { // Change this here 7 or 8 for ASCII-7 / ASCII-8
if (c & 1) {
rtty_txbit(1);
}
else {
rtty_txbit(0);
}
c = c >> 1;
}
rtty_txbit (1); // Stop bit
rtty_txbit (1); // Stop bit
}
void RTTY::rtty_txstring (char *string) {
/* Simple function to sent a char at a time to
** rtty_txbyte function.
** NB Each char is one byte (8 Bits)
*/
char c;
c = *string++;
while ( c != '\0') {
rtty_txbyte (c);
c = *string++;
}
}
void RTTY::Transmit_RTTY_GPS() {
digitalWrite(RADIOEN, HIGH);
snprintf(datastring, 22, "%f %f",gps.GetLatitude(),gps.GetLongitude()); // Puts the text in the datastring
strcat(datastring, "\n");
rtty_txstring (datastring);
}
void RTTY::Transmit_RTTY_NO_GPS() {
digitalWrite(RADIOEN, HIGH);
snprintf(datastring, 22, "KN4JLK RTTY NO GPS"); // Puts the text in the datastring
strcat(datastring, "\n");
rtty_txstring (datastring);
}