forked from wb2osz/direwolf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decode_aprs.c
4927 lines (4037 loc) · 142 KB
/
decode_aprs.c
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2017 John Langner, WB2OSZ
//
// 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, see <http://www.gnu.org/licenses/>.
//
/*------------------------------------------------------------------
*
* File: decode_aprs.c
*
* Purpose: Decode the information part of APRS frame.
*
* Description: Present the packet contents in human readable format.
* This is a fairly complete implementation with error messages
* pointing out various specication violations.
*
* Assumptions: ax25_from_frame() has been called to
* separate the header and information.
*
*------------------------------------------------------------------*/
#include "direwolf.h"
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include <stdlib.h> /* for atof */
#include <string.h> /* for strtok */
#include <math.h> /* for pow */
#include <ctype.h> /* for isdigit */
#include <fcntl.h>
#include "regex.h"
#include "ax25_pad.h"
#include "textcolor.h"
#include "symbols.h"
#include "latlong.h"
#include "dwgpsnmea.h"
#include "decode_aprs.h"
#include "telemetry.h"
#define TRUE 1
#define FALSE 0
/* Position & symbol fields common to several message formats. */
typedef struct {
char lat[8];
char sym_table_id; /* / \ 0-9 A-Z */
char lon[9];
char symbol_code;
} position_t;
typedef struct {
char sym_table_id; /* / \ a-j A-Z */
/* "The presence of the leading Symbol Table Identifier */
/* instead of a digit indicates that this is a compressed */
/* Position Report and not a normal lat/long report." */
/* "a-j" is not a typographical error. */
/* The first 10 lower case letters represent the overlay */
/* characters of 0-9 in the compressed format. */
char y[4]; /* Compressed Latitude. */
char x[4]; /* Compressed Longitude. */
char symbol_code;
char c; /* Course/speed or altitude. */
char s;
char t ; /* Compression type. */
} compressed_position_t;
/* Range of digits for Base 91 representation. */
#define B91_MIN '!'
#define B91_MAX '{'
#define isdigit91(c) ((c) >= B91_MIN && (c) <= B91_MAX)
//static void print_decoded (decode_aprs_t *A);
static void aprs_ll_pos (decode_aprs_t *A, unsigned char *, int);
static void aprs_ll_pos_time (decode_aprs_t *A, unsigned char *, int);
static void aprs_raw_nmea (decode_aprs_t *A, unsigned char *, int);
static void aprs_mic_e (decode_aprs_t *A, packet_t, unsigned char *, int);
//static void aprs_compressed_pos (decode_aprs_t *A, unsigned char *, int);
static void aprs_message (decode_aprs_t *A, unsigned char *, int, int quiet);
static void aprs_object (decode_aprs_t *A, unsigned char *, int);
static void aprs_item (decode_aprs_t *A, unsigned char *, int);
static void aprs_station_capabilities (decode_aprs_t *A, char *, int);
static void aprs_status_report (decode_aprs_t *A, char *, int);
static void aprs_general_query (decode_aprs_t *A, char *, int, int quiet);
static void aprs_directed_station_query (decode_aprs_t *A, char *addressee, char *query, int quiet);
static void aprs_telemetry (decode_aprs_t *A, char *info, int info_len, int quiet);
static void aprs_raw_touch_tone (decode_aprs_t *A, char *, int);
static void aprs_morse_code (decode_aprs_t *A, char *, int);
static void aprs_positionless_weather_report (decode_aprs_t *A, unsigned char *, int);
static void weather_data (decode_aprs_t *A, char *wdata, int wind_prefix);
static void aprs_ultimeter (decode_aprs_t *A, char *, int);
static void third_party_header (decode_aprs_t *A, char *, int);
static void decode_position (decode_aprs_t *A, position_t *ppos);
static void decode_compressed_position (decode_aprs_t *A, compressed_position_t *ppos);
static double get_latitude_8 (char *p, int quiet);
static double get_longitude_9 (char *p, int quiet);
static time_t get_timestamp (decode_aprs_t *A, char *p);
static int get_maidenhead (decode_aprs_t *A, char *p);
static int data_extension_comment (decode_aprs_t *A, char *pdext);
static void decode_tocall (decode_aprs_t *A, char *dest);
//static void get_symbol (decode_aprs_t *A, char dti, char *src, char *dest);
static void process_comment (decode_aprs_t *A, char *pstart, int clen);
/*------------------------------------------------------------------
*
* Function: decode_aprs
*
* Purpose: Split APRS packet into separate properties that it contains.
*
* Inputs: pp - APRS packet object.
*
* quiet - Suppress error messages.
*
* Outputs: A-> g_symbol_table, g_symbol_code,
* g_lat, g_lon,
* g_speed_mph, g_course, g_altitude_ft,
* g_comment
* ... and many others...
*
* Major Revisions: 1.1 Reorganized so parts are returned in a structure.
* Print function is now called separately.
*
*------------------------------------------------------------------*/
void decode_aprs (decode_aprs_t *A, packet_t pp, int quiet)
{
char dest[AX25_MAX_ADDR_LEN];
unsigned char *pinfo;
int info_len;
info_len = ax25_get_info (pp, &pinfo);
memset (A, 0, sizeof (*A));
A->g_quiet = quiet;
snprintf (A->g_msg_type, sizeof(A->g_msg_type), "Unknown APRS Data Type Indicator \"%c\"", *pinfo);
A->g_symbol_table = '/'; /* Default to primary table. */
A->g_symbol_code = ' '; /* What should we have for default symbol? */
A->g_lat = G_UNKNOWN;
A->g_lon = G_UNKNOWN;
A->g_speed_mph = G_UNKNOWN;
A->g_course = G_UNKNOWN;
A->g_power = G_UNKNOWN;
A->g_height = G_UNKNOWN;
A->g_gain = G_UNKNOWN;
A->g_range = G_UNKNOWN;
A->g_altitude_ft = G_UNKNOWN;
A->g_freq = G_UNKNOWN;
A->g_tone = G_UNKNOWN;
A->g_dcs = G_UNKNOWN;
A->g_offset = G_UNKNOWN;
A->g_footprint_lat = G_UNKNOWN;
A->g_footprint_lon = G_UNKNOWN;
A->g_footprint_radius = G_UNKNOWN;
/*
* Extract source and destination including the SSID.
*/
ax25_get_addr_with_ssid (pp, AX25_SOURCE, A->g_src);
ax25_get_addr_with_ssid (pp, AX25_DESTINATION, dest);
/*
* Report error if the information part contains a nul character.
* There are two known cases where this can happen.
*
* - The Kenwood TM-D710A sometimes sends packets like this:
*
* VA3AJ-9>T2QU6X,VE3WRC,WIDE1,K8UNS,WIDE2*:4P<0x00><0x0f>4T<0x00><0x0f>4X<0x00><0x0f>4\<0x00>`nW<0x1f>oS8>/]"6M}driving fast=
* K4JH-9>S5UQ6X,WR4AGC-3*,WIDE1*:4P<0x00><0x0f>4T<0x00><0x0f>4X<0x00><0x0f>4\<0x00>`jP}l"&>/]"47}QRV from the EV =
*
* Notice that the data type indicator of "4" is not valid. If we remove
* 4P<0x00><0x0f>4T<0x00><0x0f>4X<0x00><0x0f>4\<0x00> we are left with a good MIC-E format.
* This same thing has been observed from others and is intermittent.
*
* - AGW Tracker can send UTF-16 if an option is selected. This can introduce nul bytes.
* This is wrong, it should be using UTF-8.
*/
if ( ( ! A->g_quiet ) && ( (int)strlen((char*)pinfo) != info_len) ) {
text_color_set(DW_COLOR_ERROR);
dw_printf("'nul' character found in Information part. This should never happen.\n");
dw_printf("It seems that %s is transmitting with defective software.\n", A->g_src);
if (strcmp((char*)pinfo, "4P") == 0) {
dw_printf("The TM-D710 will do this intermittently. A firmware upgrade is needed to fix it.\n");
}
}
switch (*pinfo) { /* "DTI" data type identifier. */
case '!': /* Position without timestamp (no APRS messaging). */
/* or Ultimeter 2000 WX Station */
case '=': /* Position without timestamp (with APRS messaging). */
if (strncmp((char*)pinfo, "!!", 2) == 0)
{
aprs_ultimeter (A, (char*)pinfo, info_len);
}
else
{
aprs_ll_pos (A, pinfo, info_len);
}
break;
//case '#': /* Peet Bros U-II Weather station */
//case '*': /* Peet Bros U-II Weather station */
//break;
case '$': /* Raw GPS data or Ultimeter 2000 */
if (strncmp((char*)pinfo, "$ULTW", 5) == 0)
{
aprs_ultimeter (A, (char*)pinfo, info_len);
}
else
{
aprs_raw_nmea (A, pinfo, info_len);
}
break;
case '\'': /* Old Mic-E Data (but Current data for TM-D700) */
case '`': /* Current Mic-E Data (not used in TM-D700) */
aprs_mic_e (A, pp, pinfo, info_len);
break;
case ')': /* Item. */
aprs_item (A, pinfo, info_len);
break;
case '/': /* Position with timestamp (no APRS messaging) */
case '@': /* Position with timestamp (with APRS messaging) */
aprs_ll_pos_time (A, pinfo, info_len);
break;
case ':': /* Message: for one person, a group, or a bulletin. */
/* Directed Station Query */
/* Telemetry metadata. */
aprs_message (A, pinfo, info_len, quiet);
break;
case ';': /* Object */
aprs_object (A, pinfo, info_len);
break;
case '<': /* Station Capabilities */
aprs_station_capabilities (A, (char*)pinfo, info_len);
break;
case '>': /* Status Report */
aprs_status_report (A, (char*)pinfo, info_len);
break;
case '?': /* General Query */
aprs_general_query (A, (char*)pinfo, info_len, quiet);
break;
case 'T': /* Telemetry */
aprs_telemetry (A, (char*)pinfo, info_len, quiet);
break;
case '_': /* Positionless Weather Report */
aprs_positionless_weather_report (A, pinfo, info_len);
break;
case '{': /* user defined data */
/* http://www.aprs.org/aprs11/expfmts.txt */
if (strncmp((char*)pinfo, "{tt", 3) == 0) {
aprs_raw_touch_tone (A, (char*)pinfo, info_len);
}
else if (strncmp((char*)pinfo, "{mc", 3) == 0) {
aprs_morse_code (A, (char*)pinfo, info_len);
}
else {
//aprs_user_defined (A, pinfo, info_len);
}
break;
case 't': /* Raw touch tone data - NOT PART OF STANDARD */
/* Used to convey raw touch tone sequences to */
/* to an application that might want to interpret them. */
/* Might move into user defined data, above. */
aprs_raw_touch_tone (A, (char*)pinfo, info_len);
break;
case 'm': /* Morse Code data - NOT PART OF STANDARD */
/* Used by APRStt gateway to put audible responses */
/* into the transmit queue. Could potentially find */
/* other uses such as CW ID for station. */
/* Might move into user defined data, above. */
aprs_morse_code (A, (char*)pinfo, info_len);
break;
case '}': /* third party header */
third_party_header (A, (char*)pinfo, info_len);
break;
//case '\r': /* CR or LF? */
//case '\n':
//break;
default:
break;
}
/*
* Look in other locations if not found in information field.
*/
if (A->g_symbol_table == ' ' || A->g_symbol_code == ' ') {
symbols_from_dest_or_src (*pinfo, A->g_src, dest, &A->g_symbol_table, &A->g_symbol_code);
}
/*
* Application might be in the destination field for most message types.
* MIC-E format has part of location in the destination field.
*/
switch (*pinfo) { /* "DTI" data type identifier. */
case '\'': /* Old Mic-E Data */
case '`': /* Current Mic-E Data */
break;
default:
decode_tocall (A, dest);
break;
}
} /* end decode_aprs */
void decode_aprs_print (decode_aprs_t *A) {
char stemp[200];
//char tmp2[2];
double absll;
char news;
int deg;
double min;
char s_lat[30];
char s_lon[30];
int n;
char symbol_description[100];
/*
* First line has:
* - message type
* - object name
* - symbol
* - manufacturer/application
* - mic-e status
* - power/height/gain, range
*/
strlcpy (stemp, A->g_msg_type, sizeof(stemp));
if (strlen(A->g_name) > 0) {
strlcat (stemp, ", \"", sizeof(stemp));
strlcat (stemp, A->g_name, sizeof(stemp));
strlcat (stemp, "\"", sizeof(stemp));
}
if (A->g_symbol_code != ' ') {
symbols_get_description (A->g_symbol_table, A->g_symbol_code, symbol_description, sizeof(symbol_description));
strlcat (stemp, ", ", sizeof(stemp));
strlcat (stemp, symbol_description, sizeof(stemp));
}
if (strlen(A->g_mfr) > 0) {
strlcat (stemp, ", ", sizeof(stemp));
strlcat (stemp, A->g_mfr, sizeof(stemp));
}
if (strlen(A->g_mic_e_status) > 0) {
strlcat (stemp, ", ", sizeof(stemp));
strlcat (stemp, A->g_mic_e_status, sizeof(stemp));
}
if (A->g_power > 0) {
char phg[100];
/* Protcol spec doesn't mention whether this is dBd or dBi. */
/* Clarified later. */
/* http://eng.usna.navy.mil/~bruninga/aprs/aprs11.html */
/* "The Antenna Gain in the PHG format on page 28 is in dBi." */
snprintf (phg, sizeof(phg), ", %d W height=%d %ddBi %s", A->g_power, A->g_height, A->g_gain, A->g_directivity);
strlcat (stemp, phg, sizeof(stemp));
}
if (A->g_range > 0) {
char rng[100];
snprintf (rng, sizeof(rng), ", range=%.1f", A->g_range);
strlcat (stemp, rng, sizeof(stemp));
}
text_color_set(DW_COLOR_DECODED);
dw_printf("%s\n", stemp);
/*
* Second line has:
* - Latitude
* - Longitude
* - speed
* - direction
* - altitude
* - frequency
*/
/*
* Convert Maidenhead locator to latitude and longitude.
*
* Any example was checked for each hemihemisphere using
* http://www.amsat.org/cgi-bin/gridconv
*/
if (strlen(A->g_maidenhead) > 0) {
if (A->g_lat == G_UNKNOWN && A->g_lon == G_UNKNOWN) {
ll_from_grid_square (A->g_maidenhead, &(A->g_lat), &(A->g_lon));
}
dw_printf("Grid square = %s, ", A->g_maidenhead);
}
strlcpy (stemp, "", sizeof(stemp));
if (A->g_lat != G_UNKNOWN || A->g_lon != G_UNKNOWN) {
// Have location but it is posible one part is invalid.
if (A->g_lat != G_UNKNOWN) {
if (A->g_lat >= 0) {
absll = A->g_lat;
news = 'N';
}
else {
absll = - A->g_lat;
news = 'S';
}
deg = (int) absll;
min = (absll - deg) * 60.0;
snprintf (s_lat, sizeof(s_lat), "%c %02d%s%07.4f", news, deg, CH_DEGREE, min);
}
else {
strlcpy (s_lat, "Invalid Latitude", sizeof(s_lat));
}
if (A->g_lon != G_UNKNOWN) {
if (A->g_lon >= 0) {
absll = A->g_lon;
news = 'E';
}
else {
absll = - A->g_lon;
news = 'W';
}
deg = (int) absll;
min = (absll - deg) * 60.0;
snprintf (s_lon, sizeof(s_lon), "%c %03d%s%07.4f", news, deg, CH_DEGREE, min);
}
else {
strlcpy (s_lon, "Invalid Longitude", sizeof(s_lon));
}
snprintf (stemp, sizeof(stemp), "%s, %s", s_lat, s_lon);
}
if (strlen(A->g_aprstt_loc) > 0) {
if (strlen(stemp) > 0) strlcat (stemp, ", ", sizeof(stemp));
strlcat (stemp, A->g_aprstt_loc, sizeof(stemp));
};
if (A->g_speed_mph != G_UNKNOWN) {
char spd[20];
if (strlen(stemp) > 0) strlcat (stemp, ", ", sizeof(stemp));
snprintf (spd, sizeof(spd), "%.0f MPH", A->g_speed_mph);
strlcat (stemp, spd, sizeof(stemp));
};
if (A->g_course != G_UNKNOWN) {
char cse[20];
if (strlen(stemp) > 0) strlcat (stemp, ", ", sizeof(stemp));
snprintf (cse, sizeof(cse), "course %.0f", A->g_course);
strlcat (stemp, cse, sizeof(stemp));
};
if (A->g_altitude_ft != G_UNKNOWN) {
char alt[20];
if (strlen(stemp) > 0) strlcat (stemp, ", ", sizeof(stemp));
snprintf (alt, sizeof(alt), "alt %.0f ft", A->g_altitude_ft);
strlcat (stemp, alt, sizeof(stemp));
};
if (A->g_freq != G_UNKNOWN) {
char ftemp[30];
snprintf (ftemp, sizeof(ftemp), ", %.3f MHz", A->g_freq);
strlcat (stemp, ftemp, sizeof(stemp));
}
if (A->g_offset != G_UNKNOWN) {
char ftemp[30];
if (A->g_offset % 1000 == 0) {
snprintf (ftemp, sizeof(ftemp), ", %+dM", A->g_offset/1000);
}
else {
snprintf (ftemp, sizeof(ftemp), ", %+dk", A->g_offset);
}
strlcat (stemp, ftemp, sizeof(stemp));
}
if (A->g_tone != G_UNKNOWN) {
if (A->g_tone == 0) {
strlcat (stemp, ", no PL", sizeof(stemp));
}
else {
char ftemp[30];
snprintf (ftemp, sizeof(ftemp), ", PL %.1f", A->g_tone);
strlcat (stemp, ftemp, sizeof(stemp));
}
}
if (A->g_dcs != G_UNKNOWN) {
char ftemp[30];
snprintf (ftemp, sizeof(ftemp), ", DCS %03o", A->g_dcs);
strlcat (stemp, ftemp, sizeof(stemp));
}
if (strlen (stemp) > 0) {
text_color_set(DW_COLOR_DECODED);
dw_printf("%s\n", stemp);
}
/*
* Finally, any weather and/or comment.
*
* Non-printable characters are changed to safe hexadecimal representations.
* For example, carriage return is displayed as <0x0d>.
*
* Drop annoying trailing CR LF. Anyone who cares can see it in the raw datA->
*/
n = strlen(A->g_weather);
if (n >= 1 && A->g_weather[n-1] == '\n') {
A->g_weather[n-1] = '\0';
n--;
}
if (n >= 1 && A->g_weather[n-1] == '\r') {
A->g_weather[n-1] = '\0';
n--;
}
if (n > 0) {
ax25_safe_print (A->g_weather, -1, 0);
dw_printf("\n");
}
if (strlen(A->g_telemetry) > 0) {
ax25_safe_print (A->g_telemetry, -1, 0);
dw_printf("\n");
}
n = strlen(A->g_comment);
if (n >= 1 && A->g_comment[n-1] == '\n') {
A->g_comment[n-1] = '\0';
n--;
}
if (n >= 1 && A->g_comment[n-1] == '\r') {
A->g_comment[n-1] = '\0';
n--;
}
if (n > 0) {
int j;
ax25_safe_print (A->g_comment, -1, 0);
dw_printf("\n");
/*
* Point out incorrect attempts a degree symbol.
* 0xb0 is degree in ISO Latin1.
* To be part of a valid UTF-8 sequence, it would need to be preceded by 11xxxxxx or 10xxxxxx.
* 0xf8 is degree in Microsoft code page 437.
* To be part of a valid UTF-8 sequence, it would need to be followed by 10xxxxxx.
*/
if ( ! A->g_quiet) {
for (j=0; j<n; j++) {
if ((unsigned char)(A->g_comment[j]) == 0xb0 && (j == 0 || ! (A->g_comment[j-1] & 0x80))) {
text_color_set(DW_COLOR_ERROR);
dw_printf("Character code 0xb0 is probably an attempt at a degree symbol.\n");
dw_printf("The correct encoding is 0xc2 0xb0 in UTF-8.\n");
}
}
for (j=0; j<n; j++) {
if ((unsigned char)(A->g_comment[j]) == 0xf8 && (j == n-1 || (A->g_comment[j+1] & 0xc0) != 0xc0)) {
text_color_set(DW_COLOR_ERROR);
dw_printf("Character code 0xf8 is probably an attempt at a degree symbol.\n");
dw_printf("The correct encoding is 0xc2 0xb0 in UTF-8.\n");
}
}
}
}
}
/*------------------------------------------------------------------
*
* Function: aprs_ll_pos
*
* Purpose: Decode "Lat/Long Position Report - without Timestamp"
*
* Reports without a timestamp can be regarded as real-time.
*
* Inputs: info - Pointer to Information field.
* ilen - Information field length.
*
* Outputs: A->g_lat, A->g_lon, A->g_symbol_table, A->g_symbol_code, A->g_speed_mph, A->g_course, A->g_altitude_ft.
*
* Description: Type identifier '=' has APRS messaging.
* Type identifier '!' does not have APRS messaging.
*
* The location can be in either compressed or human-readable form.
*
* When the symbol code is '_' this is a weather report.
*
* Examples: !4309.95NS07307.13W#PHG3320 W2,NY2 Mt Equinox VT k2lm@arrl.net
* !4237.14NS07120.83W#
* =4246.40N/07115.15W# {UIV32}
*
* TODO: (?) Special case, DF report when sym table id = '/' and symbol code = '\'.
*
* =4903.50N/07201.75W\088/036/270/729
*
*------------------------------------------------------------------*/
static void aprs_ll_pos (decode_aprs_t *A, unsigned char *info, int ilen)
{
struct aprs_ll_pos_s {
char dti; /* ! or = */
position_t pos;
char comment[43]; /* Start of comment could be data extension(s). */
} *p;
struct aprs_compressed_pos_s {
char dti; /* ! or = */
compressed_position_t cpos;
char comment[40]; /* No data extension allowed for compressed location. */
} *q;
strlcpy (A->g_msg_type, "Position", sizeof(A->g_msg_type));
p = (struct aprs_ll_pos_s *)info;
q = (struct aprs_compressed_pos_s *)info;
if (isdigit((unsigned char)(p->pos.lat[0]))) /* Human-readable location. */
{
decode_position (A, &(p->pos));
if (A->g_symbol_code == '_') {
/* Symbol code indidates it is a weather report. */
/* In this case, we expect 7 byte "data extension" */
/* for the wind direction and speed. */
strlcpy (A->g_msg_type, "Weather Report", sizeof(A->g_msg_type));
weather_data (A, p->comment, TRUE);
}
else {
/* Regular position report. */
data_extension_comment (A, p->comment);
}
}
else /* Compressed location. */
{
decode_compressed_position (A, &(q->cpos));
if (A->g_symbol_code == '_') {
/* Symbol code indidates it is a weather report. */
/* In this case, the wind direction and speed are in the */
/* compressed data so we don't expect a 7 byte "data */
/* extension" for them. */
strlcpy (A->g_msg_type, "Weather Report", sizeof(A->g_msg_type));
weather_data (A, q->comment, FALSE);
}
else {
/* Regular position report. */
process_comment (A, q->comment, -1);
}
}
}
/*------------------------------------------------------------------
*
* Function: aprs_ll_pos_time
*
* Purpose: Decode "Lat/Long Position Report - with Timestamp"
*
* Reports sent with a timestamp might contain very old information.
*
* Otherwise, same as above.
*
* Inputs: info - Pointer to Information field.
* ilen - Information field length.
*
* Outputs: A->g_lat, A->g_lon, A->g_symbol_table, A->g_symbol_code, A->g_speed_mph, A->g_course, A->g_altitude_ft.
*
* Description: Type identifier '@' has APRS messaging.
* Type identifier '/' does not have APRS messaging.
*
* The location can be in either compressed or human-readable form.
*
* When the symbol code is '_' this is a weather report.
*
* Examples: @041025z4232.32N/07058.81W_124/000g000t036r000p000P000b10229h65/wx rpt
* @281621z4237.55N/07120.20W_017/002g006t022r000p000P000h85b10195.Dvs
* /092345z4903.50N/07201.75W>Test1234
*
* I think the symbol code of "_" indicates weather report.
*
* (?) Special case, DF report when sym table id = '/' and symbol code = '\'.
*
* @092345z4903.50N/07201.75W\088/036/270/729
* /092345z4903.50N/07201.75W\000/000/270/729
*
*------------------------------------------------------------------*/
static void aprs_ll_pos_time (decode_aprs_t *A, unsigned char *info, int ilen)
{
struct aprs_ll_pos_time_s {
char dti; /* / or @ */
char time_stamp[7];
position_t pos;
char comment[43]; /* First 7 bytes could be data extension. */
} *p;
struct aprs_compressed_pos_time_s {
char dti; /* / or @ */
char time_stamp[7];
compressed_position_t cpos;
char comment[40]; /* No data extension in this case. */
} *q;
strlcpy (A->g_msg_type, "Position with time", sizeof(A->g_msg_type));
time_t ts = 0;
p = (struct aprs_ll_pos_time_s *)info;
q = (struct aprs_compressed_pos_time_s *)info;
if (isdigit((unsigned char)(p->pos.lat[0]))) /* Human-readable location. */
{
ts = get_timestamp (A, p->time_stamp);
decode_position (A, &(p->pos));
if (A->g_symbol_code == '_') {
/* Symbol code indidates it is a weather report. */
/* In this case, we expect 7 byte "data extension" */
/* for the wind direction and speed. */
strlcpy (A->g_msg_type, "Weather Report", sizeof(A->g_msg_type));
weather_data (A, p->comment, TRUE);
}
else {
/* Regular position report. */
data_extension_comment (A, p->comment);
}
}
else /* Compressed location. */
{
ts = get_timestamp (A, p->time_stamp);
decode_compressed_position (A, &(q->cpos));
if (A->g_symbol_code == '_') {
/* Symbol code indidates it is a weather report. */
/* In this case, the wind direction and speed are in the */
/* compressed data so we don't expect a 7 byte "data */
/* extension" for them. */
strlcpy (A->g_msg_type, "Weather Report", sizeof(A->g_msg_type));
weather_data (A, q->comment, FALSE);
}
else {
/* Regular position report. */
process_comment (A, q->comment, -1);
}
}
(void)(ts); // suppress 'set but not used' warning.
}
/*------------------------------------------------------------------
*
* Function: aprs_raw_nmea
*
* Purpose: Decode "Raw NMEA Position Report"
*
* Inputs: info - Pointer to Information field.
* ilen - Information field length.
*
* Outputs: A-> ...
*
* Description: APRS recognizes raw ASCII data strings conforming to the NMEA 0183
* Version 2.0 specification, originating from navigation equipment such
* as GPS and LORAN receivers. It is recommended that APRS stations
* interpret at least the following NMEA Received Sentence types:
*
* GGA Global Positioning System Fix Data
* GLL Geographic Position, Latitude/Longitude Data
* RMC Recommended Minimum Specific GPS/Transit Data
* VTG Velocity and Track Data
* WPL Way Point Location
*
* We presently recognize only RMC and GGA.
*
* Examples: $GPGGA,102705,5157.9762,N,00029.3256,W,1,04,2.0,75.7,M,47.6,M,,*62
* $GPGLL,2554.459,N,08020.187,W,154027.281,A
* $GPRMC,063909,A,3349.4302,N,11700.3721,W,43.022,89.3,291099,13.6,E*52
* $GPVTG,318.7,T,,M,35.1,N,65.0,K*69
*
*------------------------------------------------------------------*/
static void aprs_raw_nmea (decode_aprs_t *A, unsigned char *info, int ilen)
{
if (strncmp((char*)info, "$GPRMC,", 7) == 0)
{
float speed_knots = G_UNKNOWN;
(void) dwgpsnmea_gprmc ((char*)info, A->g_quiet, &(A->g_lat), &(A->g_lon), &speed_knots, &(A->g_course));
A->g_speed_mph = DW_KNOTS_TO_MPH(speed_knots);
}
else if (strncmp((char*)info, "$GPGGA,", 7) == 0)
{
float alt_meters = G_UNKNOWN;
int num_sat = 0;
(void) dwgpsnmea_gpgga ((char*)info, A->g_quiet, &(A->g_lat), &(A->g_lon), &alt_meters, &num_sat);
A->g_altitude_ft = DW_METERS_TO_FEET(alt_meters);
}
// TODO (low): add a few other sentence types.
} /* end aprs_raw_nmea */
/*------------------------------------------------------------------
*
* Function: aprs_mic_e
*
* Purpose: Decode MIC-E (also Kenwood D7 & D700) packet.
*
* Inputs: info - Pointer to Information field.
* ilen - Information field length.
*
* Outputs:
*
* Description:
*
* Destination Address Field -
*
* The 7-byte Destination Address field contains
* the following encoded information:
*
* * The 6 latitude digits.
* * A 3-bit Mic-E message identifier, specifying one of 7 Standard Mic-E
* Message Codes or one of 7 Custom Message Codes or an Emergency
* Message Code.
* * The North/South and West/East Indicators.
* * The Longitude Offset Indicator.
* * The generic APRS digipeater path code.
*
* "Although the destination address appears to be quite unconventional, it is
* still a valid AX.25 address, consisting only of printable 7-bit ASCII values."
*
* References: Mic-E TYPE CODES -- http://www.aprs.org/aprs12/mic-e-types.txt
*
* This is up to date with the 24 Aug 16 version mentioning the TH-D74.
*
* Mic-E TEST EXAMPLES -- http://www.aprs.org/aprs12/mic-e-examples.txt
*
* Examples: `b9Z!4y>/>"4N}Paul's_TH-D7
*
* TODO: Destination SSID can contain generic digipeater path.
*
* Bugs: Doesn't handle ambiguous position. "space" treated as zero.
* Invalid data results in a message but latitude is not set to unknown.
*
*------------------------------------------------------------------*/
/* a few test cases
# example from http://www.aprs.org/aprs12/mic-e-examples.txt produces 4 errors.
# TODO: Analyze all the bits someday and possibly report problem with document.
N0CALL>ABCDEF:'abc123R/text
# Let's use an actual valid location and concentrate on the manufacturers
# as listed in http://www.aprs.org/aprs12/mic-e-types.txt
N1ZZN-9>T2SP0W:`c_Vm6hk/`"49}Jeff Mobile_%