Skip to content

Commit 43fb18d

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 a1e2d1c commit 43fb18d

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

Diff for: atest.c

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

759759
decode_aprs_t A;
760760

761-
decode_aprs (&A, pp, 0);
761+
decode_aprs (&A, pp, 0, 0);
762762

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

Diff for: decode_aprs.c

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

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

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

165165
A->g_quiet = quiet;
166+
A->g_metric = metric;
166167

167168
snprintf (A->g_msg_type, sizeof(A->g_msg_type), "Unknown APRS Data Type Indicator \"%c\"", *pinfo);
168169

@@ -543,7 +544,11 @@ void decode_aprs_print (decode_aprs_t *A) {
543544
char spd[20];
544545

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

@@ -559,7 +564,11 @@ void decode_aprs_print (decode_aprs_t *A) {
559564
char alt[20];
560565

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

@@ -4719,6 +4728,7 @@ int main (int argc, char *argv[])
47194728
int num_bytes;
47204729
char *p;
47214730
packet_t pp;
4731+
int metric = 0;
47224732

47234733
#if __WIN32__
47244734

@@ -4879,7 +4889,7 @@ int main (int argc, char *argv[])
48794889
ax25_safe_print ((char *)pinfo, info_len, 1); // Display non-ASCII to hexadecimal.
48804890
dw_printf ("\n");
48814891

4882-
decode_aprs (&A, pp, 0); // Extract information into structure.
4892+
decode_aprs (&A, pp, 0, metric); // Extract information into structure.
48834893

48844894
decode_aprs_print (&A); // Now print it in human readable format.
48854895

@@ -4900,9 +4910,9 @@ int main (int argc, char *argv[])
49004910
if (pp != NULL) {
49014911
decode_aprs_t A;
49024912

4903-
decode_aprs (&A, pp, 0); // Extract information into structure.
4913+
decode_aprs (&A, pp, 0, metric); // Extract information into structure.
49044914

4905-
decode_aprs_print (&A); // Now print it in human readable format.
4915+
decode_aprs_print (&A); // Now print it in human readable format.
49064916

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

Diff for: 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: direwolf.c

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

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

180181

181182

@@ -352,7 +353,7 @@ int main (int argc, char *argv[])
352353

353354
/* ':' following option character means arg is required. */
354355

355-
c = getopt_long(argc, argv, "P:B:D:c:pxr:b:n:d:q:t:Ul:L:Sa:E:T:",
356+
c = getopt_long(argc, argv, "P:B:D:c:pxr:b:mn:d:q:t:Ul:L:Sa:E:T:",
356357
long_options, &option_index);
357358
if (c == -1)
358359
break;
@@ -436,6 +437,10 @@ int main (int argc, char *argv[])
436437
}
437438
break;
438439

440+
case 'm': /* -m set metric */
441+
m_opt = 1;
442+
break;
443+
439444
case 'n': /* -n number of audio channels for first audio device. 1 or 2. */
440445

441446
n_opt = atoi(optarg);
@@ -1089,7 +1094,7 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
10891094
// we still want to decode it for logging and other processing.
10901095
// Just be quiet about errors if "-qd" is set.
10911096

1092-
decode_aprs (&A, pp, q_d_opt);
1097+
decode_aprs (&A, pp, q_d_opt, m_opt);
10931098

10941099
if ( ! q_d_opt ) {
10951100

@@ -1246,6 +1251,7 @@ static void usage (char **argv)
12461251
dw_printf (" -c fname Configuration file name.\n");
12471252
dw_printf (" -l logdir Directory name for log files. Use . for current.\n");
12481253
dw_printf (" -r n Audio sample rate, per sec.\n");
1254+
dw_printf (" -m Use metric instead of US customary units.\n");
12491255
dw_printf (" -n n Number of audio channels, 1 or 2.\n");
12501256
dw_printf (" -b n Bits per audio sample, 8 or 16.\n");
12511257
dw_printf (" -B n Data rate in bits/sec for channel 0. Standard values are 300, 1200, 2400, 4800, 9600.\n");

Diff for: direwolf.h

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
#define DW_METERS_TO_FEET(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 3.2808399)
169169
#define DW_FEET_TO_METERS(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 0.3048)
170170
#define DW_KM_TO_MILES(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 0.621371192)
171+
#define DW_MILES_TO_KM(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 1.609344)
171172

172173
#define DW_KNOTS_TO_MPH(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 1.15077945)
173174
#define DW_KNOTS_TO_METERS_PER_SEC(x) ((x) == G_UNKNOWN ? G_UNKNOWN : (x) * 0.51444444444)

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