-
Notifications
You must be signed in to change notification settings - Fork 7
/
aprs.cpp
389 lines (295 loc) · 11.8 KB
/
aprs.cpp
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
/* trackuino copyright (C) 2010 EA5HAV Javi
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "ax25.h"
#include "gps.h"
#include "aprs.h"
#include "sensors.h"
#include "modem.h"
#include <stdio.h>
#include <stdlib.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
//extern void *__bss_end;
//extern void *__brkval;
// Module globals
static unsigned int telemetry_counter = 0;
static unsigned int loss_of_gps_counter = 0;
static unsigned int ariss_counter = 0;
char gps_aprs_lat_old[10] = "2943.5387";
char gps_aprs_lon_old[11]= "09530.4670";
char gps_time_old[7] = "000000";
/*
struct s_address {
{const char[7] *d_call, const int *d_id},
{const char[7] *s_call, const int *s_id},
#ifdef DIGI_PATH1
{const char[7] *d1_call, const int *d1_id},
#endif
#ifdef DIGI_PATH2
{const char[7] *d2_call, const int *d2_id}
#endif
} ;
//s_address *addresses;
*/
// changed from const
struct s_address addresses[] =
{
{D_CALLSIGN, D_CALLSIGN_ID}, // Destination callsign
{S_CALLSIGN, S_CALLSIGN_ID}, // Source callsign (-11 = balloon, -9 = car)
#ifdef DIGI_PATH1
{DIGI_PATH1, DIGI_PATH1_TTL}, // Digi1 (first digi in the chain)
#endif
#ifdef DIGI_PATH2
{DIGI_PATH2, DIGI_PATH2_TTL}, // Digi2 (second digi in the chain)
#endif
};
// Module functions
float meters_to_feet(float m)
{
// 10000 ft = 3048 m
return m / 0.3048;
}
long addtime( unsigned long original, unsigned long seconds2add)
{
unsigned int hours = original / 10000UL;
unsigned int minutes = (original % 10000UL) / 100UL;
unsigned int seconds = (original % 10000UL) % 100UL;
seconds += seconds2add;
minutes += seconds / 60UL;
seconds = seconds % 60UL;
hours += minutes / 60UL;
minutes = minutes % 60UL;
hours = hours % 24UL;
return 10000UL * (unsigned long)hours + 100UL * (unsigned long)minutes + (unsigned long)seconds;
}
// Exported functions
void aprs_send()
{
char temp[12]; // Temperature (int/ext)
unsigned long frequency;
float altitude = 0;
int value;
short bmp085temp;
long bmp085pressure;
bmp085temp = bmp085GetTemperature(bmp085ReadUT()) / 10; // Must read temperature from BMP085 before you can read pressure!
bmp085pressure = bmp085GetPressure(bmp085ReadUP()) ;
// Send a telemetry package
ax25_send_header(addresses, sizeof(addresses)/sizeof(s_address));
ax25_send_string("T#"); // Telemetry Report
telemetry_counter++;
if (telemetry_counter > 999) {
telemetry_counter = 0;
}
snprintf(temp, 4, "%03d", telemetry_counter);
ax25_send_string(temp); // sequential id
ax25_send_byte(',');
analogReference(DEFAULT);
// adc0 = Battery Voltage ; Write to T# pos 1
analogRead(A1); // Disregard the 1st conversion after changing ref
value = analogRead(A1); // read ADC
snprintf(temp, 4, "%03d", value/4L); // Arduino has 1023 max.; APRS has 255 max.; So divide by 4
ax25_send_string(temp); // write 8 bit ADC value
ax25_send_byte(',');
// adc7 = uBlox Voltage ; Write to T# pos 2
analogRead(A7); // Disregard the 1st conversion after changing ref
value = analogRead(A7); // read ADC
snprintf(temp, 4, "%03d", value/4L); // Arduino has 1023 max.; APRS has 255 max.; So divide by 4
ax25_send_string(temp); // write 8 bit ADC value
ax25_send_byte(',');
// fill the 3rd telemetry value with a number that's proportional to the altitude:
snprintf(temp, 4, "%03d", (long)abs((meters_to_feet(gps_altitude) + 0.5)/1000L)); // Altitude in kfeet; Must be > 0, therefore abs()
ax25_send_string(temp); // write 8 bit value
ax25_send_byte(',');
// adc3 = PLL MUX, (skip)
// adc6 = ADF7012 MUXOUT; Write to T# pos 4
snprintf(temp, 4, "%03d", modem_get_powerlevel());
ax25_send_string(temp); // write power level from last tx cycle
ax25_send_byte(',');
// adc3 = Attach a LM50 temp sensor here ; Write to T# pos 5
analogRead(A3); // Disregard the 1st conversion after changing ref
value = analogRead(A3); // read ADC
snprintf(temp, 4, "%03d", value/4L); // Arduino has 1023 max.; APRS has 255 max.; So divide by 4
ax25_send_string(temp); // write 8 bit ADC value
ax25_send_byte(',');
/*
// fill the fourth telemetry value with the loss_of_gps_counter
snprintf(temp, 4, "%03d", loss_of_gps_counter);
ax25_send_string(temp); // write 8 bit value
ax25_send_byte(',');
// fill the fifth telemetry value with the number of ARISS packets transmitted
snprintf(temp, 4, "%03d", ariss_counter);
ax25_send_string(temp); // write 8 bit value
ax25_send_byte(',');
*/
ax25_send_string("0000000"); // More room to send binary info. Still unused bits...
//Todo: PLL MUX info
if(satInView)
{
ax25_send_byte('1');
frequency = RADIO_FREQUENCY_ARISS;
ariss_counter++;
if(ariss_counter > 199) // prevent overflow but still produce interpretable graphs
{
ariss_counter = 100; // this will likely never happen :) However just in case...
}
s_address addresses[] = {
{D_CALLSIGN, D_CALLSIGN_ID}, // Destination callsign still APRS
{S_CALLSIGN, S_CALLSIGN_ID}, // Source callsign (-11 = balloon, -9 = car)
#ifdef DIGI_PATH1
{DIGI_PATH1_SAT, DIGI_PATH1_TTL_SAT}, // Digi1 = ARISS
#endif
#ifdef DIGI_PATH2
{DIGI_PATH2_SAT, DIGI_PATH2_TTL_SAT}, // Digi2 = SGATE
#endif
};
}
else
{
ax25_send_byte('0');
frequency = gps_get_region_frequency();
s_address addresses[] = {
{D_CALLSIGN, D_CALLSIGN_ID}, // Destination callsign changed back to normal
{S_CALLSIGN, S_CALLSIGN_ID}, // Source callsign (-11 = balloon, -9 = car)
#ifdef DIGI_PATH1
{DIGI_PATH1, DIGI_PATH1_TTL}, // Digi1 (first digi in the chain)
#endif
#ifdef DIGI_PATH2
{DIGI_PATH2, DIGI_PATH2_TTL}, // Digi2 (second digi in the chain)
#endif
};
}
// Announce the next transmission
// ax25_send_byte(' ');
// snprintf(temp, 4, "%lu", frequency/1000000UL);
// ax25_send_string(temp);
// ax25_send_byte('.');
// snprintf(temp, 7, "%03lu", (frequency%1000000UL)/1000UL);
// ax25_send_string(temp);
// ax25_send_string("MHz"); // Comment
// ax25_send_string(" next ISS:");
// snprintf(temp, 7, "%d", iss_lat);
// ax25_send_string(temp); // ISS lat
// ax25_send_byte('/');
// snprintf(temp, 7, "%d", iss_lon);
// ax25_send_string(temp); // ISS lon
// ax25_send_byte('/');
// snprintf(temp, 7, "%u", iss_datapoint);
// ax25_send_string(temp);
// if(newPositionStillUnknown) // append the last known position in case we lost GPS
// {
// ax25_send_string(" old:");
// ax25_send_string(old_lease);
// }
// some output for debugging via packet:
// ax25_send_string(gps_date); // 241211 = Christmas 2011
// ax25_send_string(dtostrf(gps_get_variable(),7,4,temp));
// ax25_send_byte('/');
// ax25_send_string(dtostrf(gps_get_lat(),7,4,temp));
// ax25_send_byte('/');
// ax25_send_string(dtostrf(gps_get_lon(),7,4,temp));
// ax25_send_byte('/');
// snprintf(temp, 7, "%lu", gps_get_time());
// ax25_send_string(temp);
// ax25_send_byte('/');
// snprintf(temp, 7, "%lu", gps_get_date());
// ax25_send_string(temp);
// snprintf(temp, 7, "%du", p13.Sx);
// ax25_send_string(temp);
ax25_send_footer();
ax25_flush_frame(); // Tell the modem to go
// Wait a few seconds (Else aprs.fi reports "[Rate limited (< 5 sec)]")
delay(6000);
ax25_send_header(addresses, sizeof(addresses)/sizeof(s_address));
ax25_send_byte('/'); // Report w/ timestamp, no APRS messaging. $ = NMEA raw data
altitude = gps_get_altitude();
if(newPositionStillUnknown)
{
//use the old position
strcpy(gps_aprs_lat, gps_aprs_lat_old);
strcpy(gps_aprs_lon, gps_aprs_lon_old);
snprintf(gps_time, 7, "%06ld", addtime( atol(gps_time_old), APRS_PERIOD_SECONDS ) );
//calculate altitude from pressure
//This is the original formula. Not accurate for high altitudes!
//altitude = (float)44330 * (1 - pow((float)bmp085pressure / P0, 0.190295));
//This is the empirical altitude formula determined by a PecanPico1 flight (N0D-11) using BMP085 and GPS altitude data
if (bmp085pressure < 1) { bmp085pressure = 1; } //make sure we can calculate the logaritm without errors
altitude = ((float)-22069 * log( (double)bmp085pressure ) + (float)255946) * 0.3048 ;
}
// else
// {
// altitude = gps_get_altitude();
// }
// if (altitude < 1000.0) // At low altitudes pressure altitude is more precise than GPS
// {
// altitude = (float)44330 * (1 - pow((float)bmp085pressure / P0, 0.190295));
// }
// ax25_send_string("021709z"); // 021709z = 2nd day of the month, 17:09 zulu (UTC/GMT)
ax25_send_string(gps_time); // 170915 = 17h:09m:15s zulu (not allowed in Status Reports)
ax25_send_byte('h');
ax25_send_string(gps_aprs_lat); // Lat: 38deg and 22.20 min (.20 are NOT seconds, but 1/100th of minutes)
ax25_send_byte(APRS_SYMBOL_TABLE); // Symbol table
ax25_send_string(gps_aprs_lon); // Lon: 000deg and 25.80 min
ax25_send_byte(APRS_SYMBOL_ID); // Symbol: /O=balloon, /-=QTH, \N=buoy
snprintf(temp, 4, "%03d", (int)(gps_course + 0.5));
ax25_send_string(temp); // Course (degrees)
ax25_send_byte('/'); // and
snprintf(temp, 4, "%03d", (int)(gps_speed + 0.5));
ax25_send_string(temp); // speed (knots)
ax25_send_string("/A="); // Altitude (feet). Goes anywhere in the comment area
if (altitude < 0) { altitude = 0.0; }; // Negative altitudes are not displayed correctly at aprs.fi :(
snprintf(temp, 7, "%06ld", (long)abs((meters_to_feet(altitude) + 0.5)));
ax25_send_string(temp);
ax25_send_string(" ");
ax25_send_string(dtostrf((getUBatt()/1000.0),4,1,temp));
ax25_send_string("V ");
// ax25_send_string(itoa(sensors_lm335(), temp, 10));
// ax25_send_string(itoa(sensors_lm50(), temp, 10));
ax25_send_string(itoa(bmp085temp, temp, 10));
ax25_send_string("C ");
ax25_send_string(ltoa(bmp085pressure, temp, 10));
ax25_send_string("Pa ");
ax25_send_string("SATS");
snprintf(temp, 3, "%02d", gps_sats);
ax25_send_string(temp);
ax25_send_string(" ");
ax25_send_string(APRS_COMMENT); // Comment
if(newPositionStillUnknown)
{
loss_of_gps_counter++;
if(loss_of_gps_counter >= 1000) // make sure we don't get above 1000
{
loss_of_gps_counter = 100; // will show a sawtooth pattern 100 -> 1000 at permanent gps loss.
}
ax25_send_string(" GPS loss ");
snprintf(temp, 4, "%3d", loss_of_gps_counter);
ax25_send_string(temp); // write 8 bit value
}
else
{
loss_of_gps_counter = 0;
}
ax25_send_footer();
ax25_flush_frame(); // Tell the modem to go
strcpy(gps_aprs_lat_old, gps_aprs_lat);
strcpy(gps_aprs_lon_old, gps_aprs_lon);
strcpy(gps_time_old, gps_time);
modem_set_tx_freq(frequency); // actually do the QSY
}