-
Notifications
You must be signed in to change notification settings - Fork 1
/
APRS_Tracker.ino
196 lines (170 loc) · 4.84 KB
/
APRS_Tracker.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
#include <LibAPRS.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
// gps serial TX to pin 12
SoftwareSerial gpsSerial(12, 11);
Adafruit_GPS GPS(&gpsSerial);
#define OPEN_SQUELCH false
#define ADC_REFERENCE REF_3V3
randomSeed(analogRead(A0)); //init random numbers
int sendsecond = random(1, 59);
void cw_led_blink(int i, int j)
{ // cw_led_blink((short or long = 0 or 1) , (how often blink))
if (i == 0) { // short
for (int k = 0; k < 1; k++) {
digitalWrite(15, HIGH);
delay(200);
digitalWrite(15, LOW);
}
}
else {
for (int k = 0; k < 1; k++) {
digitalWrite(15, HIGH);
delay(350);
digitalWrite(15, LOW);
}
}
}
void error()
{
for (int i = 0; i < 2; i++) {
cw_led_blink(0, 3);
cw_led_blink(1, 3);
cw_led_blink(0, 3);
}
}
char lastsec = 0;
void setup()
{
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(13, OUTPUT);
APRS_init(ADC_REFERENCE, OPEN_SQUELCH);
// define callsign
char Callsign[] = "DK5RA";
APRS_setPreamble(550);
// "intelligent" mode selector use only 3 bit and pins(2,3,4)
int aprsmode = 0;
if (digitalRead(2) == LOW && digitalRead(3) == LOW && digitalRead(4) == LOW && digitalRead(5) == LOW) {
aprsmode = 0;
}
else if (digitalRead(2) == HIGH && digitalRead(3) == LOW && digitalRead(4) == LOW && digitalRead(5) == LOW) {
aprsmode = 1;
}
else if (digitalRead(2) == LOW && digitalRead(3) == HIGH && digitalRead(4) == LOW && digitalRead(5) == LOW) {
aprsmode = 2;
}
else if (digitalRead(2) == LOW && digitalRead(3) == LOW && digitalRead(4) == HIGH && digitalRead(5) == LOW) {
aprsmode = 3;
}
else if (digitalRead(2) == HIGH && digitalRead(3) == HIGH && digitalRead(4) == LOW && digitalRead(5) == LOW) {
aprsmode = 4;
}
else if (digitalRead(2) == LOW && digitalRead(3) == HIGH && digitalRead(4) == HIGH && digitalRead(5) == LOW) {
aprsmode = 5;
}
else if (digitalRead(2) == HIGH && digitalRead(3) == HIGH && digitalRead(4) == HIGH && digitalRead(5) == LOW) {
aprsmode = 6;
}
switch (aprsmode) {
case 0:
APRS_setCallsign(Callsign, 9);
APRS_setSymbol('>');
break; // car portable
case 1:
APRS_setCallsign(Callsign, 7);
APRS_setSymbol('[');
break; // walk
case 2:
APRS_setCallsign(Callsign, 8);
APRS_setSymbol('b');
break; // bycicle portable
case 3:
APRS_setCallsign(Callsign, 6);
APRS_setSymbol(';');
break; // fieldday cmaping
case 4:
APRS_setCallsign(Callsign, 8);
APRS_setSymbol('=');
break; // train
case 5:
APRS_setCallsign(Callsign, 9);
APRS_setSymbol('>');
error();
break; // not defined
case 6:
APRS_setCallsign(Callsign, 5);
APRS_setSymbol('O');
break; // balloon
default:
APRS_setCallsign("ERROR", 0);
APRS_setSymbol(' ');
error();
break;
}
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPS.sendCommand(PGCMD_ANTENNA);
// enable tim0 interrupt at value 0x7F
OCR0A = 0x7F;
TIMSK0 |= _BV(OCIE0A);
delay(1000);
gpsSerial.println(PMTK_Q_RELEASE);
}
// tim0 ISR for gps parser
SIGNAL(TIMER0_COMPA_vect)
{
char c = GPS.read();
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA()))
return;
}
}
void locationUpdate()
{
char lats[10], latvs[10];
char lons[10], lonvs[10];
// the only way i found to set the variables the correct way for libAPRS
// since sprintf doesn't like float on AVRs
dtostrf(GPS.latitude, 6, 2, latvs);
dtostrf(GPS.longitude, 6, 2, lonvs);
sprintf(lats, "%s%c", latvs, GPS.lat);
if (GPS.longitude >= 10000) {
sprintf(lons, "%s%c", lonvs, GPS.lon);
}
else {
sprintf(lons, "0%s%c", lonvs, GPS.lon);
}
APRS_setLat(lats);
APRS_setLon(lons);
char* comment = "AVR APRS Tracker";
// turn off soft serial to stop interrupting tx
gpsSerial.end();
//set random value for sending period
// TX
APRS_sendLoc(comment, strlen(comment));
// read blue TX LED pin and wait till TX has finished (PB1, Pin 1)
while (bitRead(PORTB, 1))
;
//start soft serial again
GPS.begin(9600);
}
void loop()
{
if (GPS.fix) {
if (((GPS.seconds == sendsecond && (lastsec != GPS.seconds)))) {
locationUpdate();
}
}
else {
delay(350);
}
lastsec = GPS.seconds;
}
// need to keep that unless i edit libAPRS (fucnt. only needed for rx, but compiler wants it)
void aprs_msg_callback(struct AX25Msg* msg)
{
}