Skip to content

Commit f8c221e

Browse files
Thomas HabetsThomasHabets
Thomas Habets
authored andcommitted
Add option -m to decode to metric
This enables the natural unit for 96% of the world's population.
1 parent 8ac14f8 commit f8c221e

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

Diff for: src/atest.c

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

881881
decode_aprs_t A;
882882

883-
decode_aprs (&A, pp, 0);
883+
decode_aprs (&A, pp, 0, 0);
884884

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

Diff for: src/decode_aprs.c

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

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

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

167167
A->g_quiet = quiet;
168+
A->g_metric = metric;
168169

169170
if (isprint(*pinfo)) {
170171
snprintf (A->g_msg_type, sizeof(A->g_msg_type), "Unknown APRS Data Type Indicator \"%c\"", *pinfo);
@@ -542,7 +543,11 @@ void decode_aprs_print (decode_aprs_t *A) {
542543
char spd[20];
543544

544545
if (strlen(stemp) > 0) strlcat (stemp, ", ", sizeof(stemp));
545-
snprintf (spd, sizeof(spd), "%.0f MPH", A->g_speed_mph);
546+
if (A->g_metric) {
547+
snprintf (spd, sizeof(spd), "%.0f km/h", DW_MILES_TO_KM(A->g_speed_mph));
548+
} else {
549+
snprintf (spd, sizeof(spd), "%.0f MPH", A->g_speed_mph);
550+
}
546551
strlcat (stemp, spd, sizeof(stemp));
547552
};
548553

@@ -558,7 +563,11 @@ void decode_aprs_print (decode_aprs_t *A) {
558563
char alt[20];
559564

560565
if (strlen(stemp) > 0) strlcat (stemp, ", ", sizeof(stemp));
561-
snprintf (alt, sizeof(alt), "alt %.0f ft", A->g_altitude_ft);
566+
if (A->g_metric) {
567+
snprintf (alt, sizeof(alt), "alt %.0f m", DW_FEET_TO_METERS(A->g_altitude_ft));
568+
} else {
569+
snprintf (alt, sizeof(alt), "alt %.0f ft", A->g_altitude_ft);
570+
}
562571
strlcat (stemp, alt, sizeof(stemp));
563572
};
564573

@@ -4780,6 +4789,7 @@ int main (int argc, char *argv[])
47804789
int num_bytes;
47814790
char *p;
47824791
packet_t pp;
4792+
int metric = 0;
47834793

47844794
#if __WIN32__
47854795

@@ -4941,7 +4951,7 @@ int main (int argc, char *argv[])
49414951
ax25_safe_print ((char *)pinfo, info_len, 1); // Display non-ASCII to hexadecimal.
49424952
dw_printf ("\n");
49434953

4944-
decode_aprs (&A, pp, 0); // Extract information into structure.
4954+
decode_aprs (&A, pp, 0, metric); // Extract information into structure.
49454955

49464956
decode_aprs_print (&A); // Now print it in human readable format.
49474957

@@ -4962,9 +4972,9 @@ int main (int argc, char *argv[])
49624972
if (pp != NULL) {
49634973
decode_aprs_t A;
49644974

4965-
decode_aprs (&A, pp, 0); // Extract information into structure.
4975+
decode_aprs (&A, pp, 0, metric); // Extract information into structure.
49664976

4967-
decode_aprs_print (&A); // Now print it in human readable format.
4977+
decode_aprs_print (&A); // Now print it in human readable format.
49684978

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

Diff for: 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

Diff for: 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

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

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

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

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

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

1250-
decode_aprs (&A, pp, q_d_opt);
1255+
decode_aprs (&A, pp, q_d_opt, m_opt);
12511256

12521257
if ( ! q_d_opt ) {
12531258

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

Diff for: 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)

Diff for: 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)