Skip to content

Commit 76dfec2

Browse files
Thomas HabetsThomasHabets
Thomas Habets
authored andcommittedDec 27, 2020
Add option -m to decode to metric
This enables the natural unit for 96% of the world's population.
1 parent 07fdc75 commit 76dfec2

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed
 

‎src/atest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ void dlq_rec_frame (int chan, int subchan, int slice, packet_t pp, alevel_t alev
882882

883883
decode_aprs_t A;
884884

885-
decode_aprs (&A, pp, 0);
885+
decode_aprs (&A, pp, 0, 0);
886886

887887
// Temp experiment to see how different systems set the RR bits in the source and destination.
888888
// log_rr_bits (&A, pp);

‎src/decode_aprs.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static void process_comment (decode_aprs_t *A, char *pstart, int clen);
151151
*
152152
*------------------------------------------------------------------*/
153153

154-
void decode_aprs (decode_aprs_t *A, packet_t pp, int quiet)
154+
void decode_aprs (decode_aprs_t *A, packet_t pp, int quiet, int metric)
155155
{
156156

157157
char dest[AX25_MAX_ADDR_LEN];
@@ -164,6 +164,7 @@ void decode_aprs (decode_aprs_t *A, packet_t pp, int quiet)
164164
memset (A, 0, sizeof (*A));
165165

166166
A->g_quiet = quiet;
167+
A->g_metric = metric;
167168

168169
if (isprint(*pinfo)) {
169170
snprintf (A->g_msg_type, sizeof(A->g_msg_type), "Unknown APRS Data Type Indicator \"%c\"", *pinfo);
@@ -559,7 +560,11 @@ void decode_aprs_print (decode_aprs_t *A) {
559560
char spd[20];
560561

561562
if (strlen(stemp) > 0) strlcat (stemp, ", ", sizeof(stemp));
562-
snprintf (spd, sizeof(spd), "%.0f MPH", A->g_speed_mph);
563+
if (A->g_metric) {
564+
snprintf (spd, sizeof(spd), "%.0f km/h", DW_MILES_TO_KM(A->g_speed_mph));
565+
} else {
566+
snprintf (spd, sizeof(spd), "%.0f MPH", A->g_speed_mph);
567+
}
563568
strlcat (stemp, spd, sizeof(stemp));
564569
};
565570

@@ -575,7 +580,11 @@ void decode_aprs_print (decode_aprs_t *A) {
575580
char alt[20];
576581

577582
if (strlen(stemp) > 0) strlcat (stemp, ", ", sizeof(stemp));
578-
snprintf (alt, sizeof(alt), "alt %.0f ft", A->g_altitude_ft);
583+
if (A->g_metric) {
584+
snprintf (alt, sizeof(alt), "alt %.0f m", DW_FEET_TO_METERS(A->g_altitude_ft));
585+
} else {
586+
snprintf (alt, sizeof(alt), "alt %.0f ft", A->g_altitude_ft);
587+
}
579588
strlcat (stemp, alt, sizeof(stemp));
580589
};
581590

@@ -4772,6 +4781,7 @@ int main (int argc, char *argv[])
47724781
int num_bytes;
47734782
char *p;
47744783
packet_t pp;
4784+
int metric = 0;
47754785

47764786
#if __WIN32__
47774787

@@ -4933,7 +4943,7 @@ int main (int argc, char *argv[])
49334943
ax25_safe_print ((char *)pinfo, info_len, 1); // Display non-ASCII to hexadecimal.
49344944
dw_printf ("\n");
49354945

4936-
decode_aprs (&A, pp, 0); // Extract information into structure.
4946+
decode_aprs (&A, pp, 0, metric); // Extract information into structure.
49374947

49384948
decode_aprs_print (&A); // Now print it in human readable format.
49394949

@@ -4954,9 +4964,9 @@ int main (int argc, char *argv[])
49544964
if (pp != NULL) {
49554965
decode_aprs_t A;
49564966

4957-
decode_aprs (&A, pp, 0); // Extract information into structure.
4967+
decode_aprs (&A, pp, 0, metric); // Extract information into structure.
49584968

4959-
decode_aprs_print (&A); // Now print it in human readable format.
4969+
decode_aprs_print (&A); // Now print it in human readable format.
49604970

49614971
// This seems to be redundant because we used strict option
49624972
// when parsing the monitoring format text.

‎src/decode_aprs.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ typedef struct decode_aprs_s {
2424

2525
int g_quiet; /* Suppress error messages when decoding. */
2626

27+
int g_metric; /* Print metric instead of US customary units */
28+
2729
char g_src[AX25_MAX_ADDR_LEN];
2830

2931
char g_msg_type[60]; /* APRS data type. Telemetry descriptions get pretty long. */
@@ -135,7 +137,7 @@ typedef struct decode_aprs_s {
135137

136138

137139

138-
extern void decode_aprs (decode_aprs_t *A, packet_t pp, int quiet);
140+
extern void decode_aprs (decode_aprs_t *A, packet_t pp, int quiet, int metric);
139141

140142
extern void decode_aprs_print (decode_aprs_t *A);
141143

‎src/direwolf.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ static int d_p_opt = 0; /* "-d p" option for dumping packets over radio. */
183183

184184
static int q_h_opt = 0; /* "-q h" Quiet, suppress the "heard" line with audio level. */
185185
static int q_d_opt = 0; /* "-q d" Quiet, suppress the printing of decoded of APRS packets. */
186+
static int m_opt = 0; /* "-m" for metric output. */
186187

187188
static int A_opt_ais_to_obj = 0; /* "-A" Convert received AIS to APRS "Object Report." */
188189

@@ -388,7 +389,7 @@ int main (int argc, char *argv[])
388389

389390
/* ':' following option character means arg is required. */
390391

391-
c = getopt_long(argc, argv, "hP:B:gjJD:U:c:pxr:b:n:d:q:t:ul:L:Sa:E:T:e:X:A",
392+
c = getopt_long(argc, argv, "hP:B:gjJD:U:c:pxr:b:mn:d:q:t:ul:L:Sa:E:T:e:X:A",
392393
long_options, &option_index);
393394
if (c == -1)
394395
break;
@@ -506,6 +507,10 @@ int main (int argc, char *argv[])
506507
}
507508
break;
508509

510+
case 'm': /* -m set metric */
511+
m_opt = 1;
512+
break;
513+
509514
case 'n': /* -n number of audio channels for first audio device. 1 or 2. */
510515

511516
n_opt = atoi(optarg);
@@ -1249,7 +1254,7 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
12491254
// we still want to decode it for logging and other processing.
12501255
// Just be quiet about errors if "-qd" is set.
12511256

1252-
decode_aprs (&A, pp, q_d_opt);
1257+
decode_aprs (&A, pp, q_d_opt, m_opt);
12531258

12541259
if ( ! q_d_opt ) {
12551260

@@ -1461,6 +1466,7 @@ static void usage (char **argv)
14611466
dw_printf (" -c fname Configuration file name.\n");
14621467
dw_printf (" -l logdir Directory name for log files. Use . for current.\n");
14631468
dw_printf (" -r n Audio sample rate, per sec.\n");
1469+
dw_printf (" -m Use metric instead of US customary units.\n");
14641470
dw_printf (" -n n Number of audio channels, 1 or 2.\n");
14651471
dw_printf (" -b n Bits per audio sample, 8 or 16.\n");
14661472
dw_printf (" -B n Data rate in bits/sec for channel 0. Standard values are 300, 1200, 2400, 4800, 9600.\n");

‎src/direwolf.h

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
#define DW_METERS_TO_FEET(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 3.2808399)
177177
#define DW_FEET_TO_METERS(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 0.3048)
178178
#define DW_KM_TO_MILES(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 0.621371192)
179+
#define DW_MILES_TO_KM(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 1.609344)
179180

180181
#define DW_KNOTS_TO_MPH(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 1.15077945)
181182
#define DW_KNOTS_TO_METERS_PER_SEC(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 0.51444444444)

‎src/pfilter.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ int pfilter (int from_chan, int to_chan, char *filter, packet_t pp, int is_aprs)
200200
pfstate_t pfstate;
201201
char *p;
202202
int result;
203+
int metric = 0;
203204

204205
assert (from_chan >= 0 && from_chan <= MAX_CHANS);
205206
assert (to_chan >= 0 && to_chan <= MAX_CHANS);
@@ -235,7 +236,7 @@ int pfilter (int from_chan, int to_chan, char *filter, packet_t pp, int is_aprs)
235236
pfstate.is_aprs = is_aprs;
236237

237238
if (is_aprs) {
238-
decode_aprs (&pfstate.decoded, pp, 1);
239+
decode_aprs (&pfstate.decoded, pp, 1, metric);
239240
}
240241

241242
next_token(&pfstate);

0 commit comments

Comments
 (0)