forked from wb2osz/direwolf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.c
4359 lines (3656 loc) · 129 KB
/
config.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, 2016 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/>.
//
#define CONFIG_C 1
// #define DEBUG 1
/*------------------------------------------------------------------
*
* Module: config.c
*
* Purpose: Read configuration information from a file.
*
* Description: This started out as a simple little application with a few
* command line options. Due to creeping featurism, it's now
* time to add a configuration file to specify options.
*
*---------------------------------------------------------------*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#if ENABLE_GPSD
#include <gps.h> /* for DEFAULT_GPSD_PORT (2947) */
#endif
#include "ax25_pad.h"
#include "textcolor.h"
#include "audio.h"
#include "digipeater.h"
#include "config.h"
#include "aprs_tt.h"
#include "igate.h"
#include "latlong.h"
#include "symbols.h"
#include "xmit.h"
#include "tt_text.h"
// geotranz
#include "utm.h"
#include "mgrs.h"
#include "usng.h"
#include "error_string.h"
#define D2R(d) ((d) * M_PI / 180.)
#define R2D(r) ((r) * 180. / M_PI)
//#include "tq.h"
/*
* Conversions from various units to meters.
* There is some disagreement about the exact values for some of these.
* Close enough for our purposes.
* Parsec, light year, and angstrom are probably not useful.
*/
static const struct units_s {
char *name;
float meters;
} units[] = {
{ "barleycorn", 0.008466667 },
{ "inch", 0.0254 },
{ "in", 0.0254 },
{ "hand", 0.1016 },
{ "shaku", 0.3030 },
{ "foot", 0.304801 },
{ "ft", 0.304801 },
{ "cubit", 0.4572 },
{ "megalithicyard", 0.8296 },
{ "my", 0.8296 },
{ "yard", 0.914402 },
{ "yd", 0.914402 },
{ "m", 1. },
{ "meter", 1. },
{ "metre", 1. },
{ "ell", 1.143 },
{ "ken", 1.818 },
{ "hiro", 1.818 },
{ "fathom", 1.8288 },
{ "fath", 1.8288 },
{ "toise", 1.949 },
{ "jo", 3.030 },
{ "twain", 3.6576074 },
{ "rod", 5.0292 },
{ "rd", 5.0292 },
{ "perch", 5.0292 },
{ "pole", 5.0292 },
{ "rope", 6.096 },
{ "dekameter", 10. },
{ "dekametre", 10. },
{ "dam", 10. },
{ "chain", 20.1168 },
{ "ch", 20.1168 },
{ "actus", 35.47872 },
{ "arpent", 58.471 },
{ "hectometer", 100. },
{ "hectometre", 100. },
{ "hm", 100. },
{ "cho", 109.1 },
{ "furlong", 201.168 },
{ "fur", 201.168 },
{ "kilometer", 1000. },
{ "kilometre", 1000. },
{ "km", 1000. },
{ "mile", 1609.344 },
{ "mi", 1609.344 },
{ "ri", 3927. },
{ "league", 4828.032 },
{ "lea", 4828.032 } };
#define NUM_UNITS (sizeof(units) / sizeof(struct units_s))
static int beacon_options(char *cmd, struct beacon_s *b, int line, struct audio_s *p_audio_config);
/* Do we have a string of all digits? */
static int alldigits(char *p)
{
if (p == NULL) return (0);
if (strlen(p) == 0) return (0);
while (*p != '\0') {
if ( ! isdigit(*p)) return (0);
p++;
}
return (1);
}
/* Do we have a string of all letters or + or - ? */
static int alllettersorpm(char *p)
{
if (p == NULL) return (0);
if (strlen(p) == 0) return (0);
while (*p != '\0') {
if ( ! isalpha(*p) && *p != '+' && *p != '-') return (0);
p++;
}
return (1);
}
/*------------------------------------------------------------------
*
* Name: parse_ll
*
* Purpose: Parse latitude or longitude from configuration file.
*
* Inputs: str - String like [-]deg[^min][hemisphere]
*
* which - LAT or LON for error checking and message.
*
* line - Line number for use in error message.
*
* Returns: Coordinate in signed degrees.
*
*----------------------------------------------------------------*/
/* Acceptable symbols to separate degrees & minutes. */
/* Degree symbol is not in ASCII so documentation says to use "^" instead. */
/* Some wise guy will try to use degree symbol. */
/* UTF-8 is more difficult because it is a two byte sequence, c2 b0. */
#define DEG1 '^'
#define DEG2 0xb0 /* ISO Latin1 */
#define DEG3 0xf8 /* Microsoft code page 437 */
enum parse_ll_which_e { LAT, LON };
static double parse_ll (char *str, enum parse_ll_which_e which, int line)
{
char stemp[40];
int sign;
double degrees, minutes;
char *endptr;
char hemi;
int limit;
unsigned char sep;
/*
* Remove any negative sign.
*/
strlcpy (stemp, str, sizeof(stemp));
sign = +1;
if (stemp[0] == '-') {
sign = -1;
stemp[0] = ' ';
}
/*
* Process any hemisphere on the end.
*/
if (strlen(stemp) >= 2) {
endptr = stemp + strlen(stemp) - 1;
if (isalpha(*endptr)) {
hemi = *endptr;
*endptr = '\0';
if (islower(hemi)) {
hemi = toupper(hemi);
}
if (hemi == 'W' || hemi == 'S') {
sign = -sign;
}
if (which == LAT) {
if (hemi != 'N' && hemi != 'S') {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Latitude hemisphere in \"%s\" is not N or S.\n", line, str);
}
}
else {
if (hemi != 'E' && hemi != 'W') {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Longitude hemisphere in \"%s\" is not E or W.\n", line, str);
}
}
}
}
/*
* Parse the degrees part.
*/
degrees = strtod (stemp, &endptr);
/*
* Is there a minutes part?
*/
sep = *endptr;
if (sep != '\0') {
if (sep == DEG1 || sep == DEG2 || sep == DEG3) {
minutes = strtod (endptr+1, &endptr);
if (*endptr != '\0') {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Unexpected character '%c' in location \"%s\"\n", line, sep, str);
}
if (minutes >= 60.0) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Number of minutes in \"%s\" is >= 60.\n", line, str);
}
degrees += minutes / 60.0;
}
else {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Unexpected character '%c' in location \"%s\"\n", line, sep, str);
}
}
degrees = degrees * sign;
limit = which == LAT ? 90 : 180;
if (degrees < -limit || degrees > limit) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Number of degrees in \"%s\" is out of range for %s\n", line, str,
which == LAT ? "latitude" : "longitude");
}
//dw_printf ("%s = %f\n", str, degrees);
return (degrees);
}
/*------------------------------------------------------------------
*
* Name: parse_utm_zone
*
* Purpose: Parse UTM zone from configuration file.
*
* Inputs: szone - String like [-]number[letter]
*
* Outputs: latband - Latitude band if specified, otherwise space or -.
*
* hemi - Hemisphere, always one of 'N' or 'S'.
*
* Returns: Zone as number.
* Type is long because Convert_UTM_To_Geodetic expects that.
*
* Errors: Prints message and return 0.
*
* Description:
* It seems there are multiple conventions for specifying the UTM hemisphere.
*
* - MGRS latitude band. North if missing or >= 'N'.
* - Negative zone for south.
* - Separate North or South.
*
* I'm using the first alternatve.
* GEOTRANS uses the third.
* We will also recognize the second one but I'm not sure if I want to document it.
*
*----------------------------------------------------------------*/
long parse_utm_zone (char *szone, char *latband, char *hemi)
{
long lzone;
char *zlet;
*latband = ' ';
*hemi = 'N'; /* default */
lzone = strtol(szone, &zlet, 10);
if (*zlet == '\0') {
/* Number is not followed by letter something else. */
/* Allow negative number to mean south. */
if (lzone < 0) {
*latband = '-';
*hemi = 'S';
lzone = (- lzone);
}
}
else {
if (islower (*zlet)) {
*zlet = toupper(*zlet);
}
*latband = *zlet;
if (strchr ("CDEFGHJKLMNPQRSTUVWX", *zlet) != NULL) {
if (*zlet < 'N') {
*hemi = 'S';
}
}
else {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Latitudinal band in \"%s\" must be one of CDEFGHJKLMNPQRSTUVWX.\n", szone);
*hemi = '?';
}
}
if (lzone < 1 || lzone > 60) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("UTM Zone number %ld must be in range of 1 to 60.\n", lzone);
}
return (lzone);
} /* end parse_utm_zone */
#if 0
main ()
{
parse_ll ("12.5", LAT);
parse_ll ("12.5N", LAT);
parse_ll ("12.5E", LAT); // error
parse_ll ("-12.5", LAT);
parse_ll ("12.5S", LAT);
parse_ll ("12.5W", LAT); // error
parse_ll ("12.5", LON);
parse_ll ("12.5E", LON);
parse_ll ("12.5N", LON); // error
parse_ll ("-12.5", LON);
parse_ll ("12.5W", LON);
parse_ll ("12.5S", LON); // error
parse_ll ("12^30", LAT);
parse_ll ("12\xb030", LAT); // ISO Latin-1 degree symbol
parse_ll ("91", LAT); // out of range
parse_ll ("91", LON);
parse_ll ("181", LON); // out of range
parse_ll ("12&5", LAT); // bad character
}
#endif
/*------------------------------------------------------------------
*
* Name: parse_interval
*
* Purpose: Parse time interval from configuration file.
*
* Inputs: str - String like 10 or 9:30
*
* line - Line number for use in error message.
*
* Returns: Number of seconds.
*
* Description: This is used by the BEACON configuration items
* for initial delay or time between beacons.
*
* The format is either minutes or minutes:seconds.
*
*----------------------------------------------------------------*/
static int parse_interval (char *str, int line)
{
char *p;
int sec;
int nc = 0;
int bad = 0;
for (p = str; *p != '\0'; p++) {
if (*p == ':') nc++;
else if ( ! isdigit(*p)) bad++;
}
if (bad > 0 || nc > 1) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file, line %d: Time interval must be of the form minutes or minutes:seconds.\n", line);
}
p = strchr (str, ':');
if (p != NULL) {
sec = atoi(str) * 60 + atoi(p+1);
}
else {
sec = atoi(str) * 60;
}
return (sec);
} /* end parse_interval */
/*-------------------------------------------------------------------
*
* Name: split
*
* Purpose: Separate a line into command and parameters.
*
* Inputs: string - Complete command line to start process.
* NULL for subsequent calls.
*
* rest_of_line - Caller wants remainder of line, not just
* the next parameter.
*
* Returns: Pointer to next part with any quoting removed.
*
* Description: the configuration file started out very simple and strtok
* was used to split up the lines. As more complicated options
* were added, there were several different situations where
* parameter values might contain spaces. These were handled
* inconsistently in different places. In version 1.3, we now
* treat them consistently in one place.
*
*
*--------------------------------------------------------------------*/
#define MAXCMDLEN 256
static char *split (char *string, int rest_of_line)
{
static char cmd[MAXCMDLEN];
static char token[MAXCMDLEN];
static char *c; // current position in cmd.
char *s, *t;
int in_quotes;
/*
* If string is provided, make a copy.
* Drop any CRLF at the end.
* Change any tabs to spaces so we don't have to check for it later.
*/
if (string != NULL) {
// dw_printf("split in: '%s'\n", string);
c = cmd;
for (s = string; *s != '\0'; s++) {
if (*s == '\t') {
*c++ = ' ';
}
else if (*s == '\r' || *s == '\n') {
;
}
else {
*c++ = *s;
}
}
*c = '\0';
c = cmd;
}
/*
* Get next part, separated by whitespace, keeping spaces within quotes.
* Quotation marks inside need to be doubled.
*/
while (*c == ' ') {
c++;
};
t = token;
in_quotes = 0;
for ( ; *c != '\0'; c++) {
if (*c == '"') {
if (in_quotes) {
if (c[1] == '"') {
*t++ = *c++;
}
else {
in_quotes = 0;
}
}
else {
in_quotes = 1;
}
}
else if (*c == ' ') {
if (in_quotes || rest_of_line) {
*t++ = *c;
}
else {
break;
}
}
else {
*t++ = *c;
}
}
*t = '\0';
// dw_printf("split out: '%s'\n", token);
t = token;
if (*t == '\0') {
return (NULL);
}
return (t);
} /* end split */
/*-------------------------------------------------------------------
*
* Name: config_init
*
* Purpose: Read configuration file when application starts up.
*
* Inputs: fname - Name of configuration file.
*
* Outputs: p_audio_config - Radio channel parameters stored here.
*
* p_digi_config - Digipeater configuration stored here.
*
* p_tt_config - APRStt stuff.
*
* p_igate_config - Internet Gateway.
*
* p_misc_config - Everything else. This wasn't thought out well.
*
* Description: Apply default values for various parameters then read the
* the configuration file which can override those values.
*
* Errors: For invalid input, display line number and message on stdout (not stderr).
* In many cases this will result in keeping the default rather than aborting.
*
* Bugs: Very simple-minded parsing.
* Not much error checking. (e.g. atoi() will return 0 for invalid string.)
* Not very forgiving about sloppy input.
*
*--------------------------------------------------------------------*/
void config_init (char *fname, struct audio_s *p_audio_config,
struct digi_config_s *p_digi_config,
struct tt_config_s *p_tt_config,
struct igate_config_s *p_igate_config,
struct misc_config_s *p_misc_config)
{
FILE *fp;
char filepath[128];
char stuff[MAXCMDLEN];
int line;
int channel;
int adevice;
int m;
#if DEBUG
text_color_set(DW_COLOR_DEBUG);
dw_printf ("config_init ( %s )\n", fname);
#endif
/*
* First apply defaults.
*/
memset (p_audio_config, 0, sizeof(struct audio_s));
/* First audio device is always available with defaults. */
/* Others must be explicitly defined before use. */
for (adevice=0; adevice<MAX_ADEVS; adevice++) {
strlcpy (p_audio_config->adev[adevice].adevice_in, DEFAULT_ADEVICE, sizeof(p_audio_config->adev[adevice].adevice_in));
strlcpy (p_audio_config->adev[adevice].adevice_out, DEFAULT_ADEVICE, sizeof(p_audio_config->adev[adevice].adevice_out));
p_audio_config->adev[adevice].defined = 0;
p_audio_config->adev[adevice].num_channels = DEFAULT_NUM_CHANNELS; /* -2 stereo */
p_audio_config->adev[adevice].samples_per_sec = DEFAULT_SAMPLES_PER_SEC; /* -r option */
p_audio_config->adev[adevice].bits_per_sample = DEFAULT_BITS_PER_SAMPLE; /* -8 option for 8 instead of 16 bits */
}
p_audio_config->adev[0].defined = 1;
for (channel=0; channel<MAX_CHANS; channel++) {
int ot;
p_audio_config->achan[channel].valid = 0; /* One or both channels will be */
/* set to valid when corresponding */
/* audio device is defined. */
p_audio_config->achan[channel].modem_type = MODEM_AFSK;
p_audio_config->achan[channel].mark_freq = DEFAULT_MARK_FREQ; /* -m option */
p_audio_config->achan[channel].space_freq = DEFAULT_SPACE_FREQ; /* -s option */
p_audio_config->achan[channel].baud = DEFAULT_BAUD; /* -b option */
/* None. Will set default later based on other factors. */
strlcpy (p_audio_config->achan[channel].profiles, "", sizeof(p_audio_config->achan[channel].profiles));
p_audio_config->achan[channel].num_freq = 1;
p_audio_config->achan[channel].offset = 0;
p_audio_config->achan[channel].fix_bits = DEFAULT_FIX_BITS;
p_audio_config->achan[channel].sanity_test = SANITY_APRS;
p_audio_config->achan[channel].passall = 0;
for (ot = 0; ot < NUM_OCTYPES; ot++) {
p_audio_config->achan[channel].octrl[ot].ptt_method = PTT_METHOD_NONE;
strlcpy (p_audio_config->achan[channel].octrl[ot].ptt_device, "", sizeof(p_audio_config->achan[channel].octrl[ot].ptt_device));
p_audio_config->achan[channel].octrl[ot].ptt_line = PTT_LINE_NONE;
p_audio_config->achan[channel].octrl[ot].ptt_line2 = PTT_LINE_NONE;
p_audio_config->achan[channel].octrl[ot].ptt_gpio = 0;
p_audio_config->achan[channel].octrl[ot].ptt_lpt_bit = 0;
p_audio_config->achan[channel].octrl[ot].ptt_invert = 0;
p_audio_config->achan[channel].octrl[ot].ptt_invert2 = 0;
}
p_audio_config->achan[channel].dwait = DEFAULT_DWAIT;
p_audio_config->achan[channel].slottime = DEFAULT_SLOTTIME;
p_audio_config->achan[channel].persist = DEFAULT_PERSIST;
p_audio_config->achan[channel].txdelay = DEFAULT_TXDELAY;
p_audio_config->achan[channel].txtail = DEFAULT_TXTAIL;
}
/* First channel should always be valid. */
/* If there is no ADEVICE, it uses default device in mono. */
p_audio_config->achan[0].valid = 1;
memset (p_digi_config, 0, sizeof(struct digi_config_s));
p_digi_config->dedupe_time = DEFAULT_DEDUPE;
memset (p_tt_config, 0, sizeof(struct tt_config_s));
p_tt_config->gateway_enabled = 0;
p_tt_config->ttloc_size = 2; /* Start with at least 2. */
/* When full, it will be increased by 50 %. */
p_tt_config->ttloc_ptr = malloc (sizeof(struct ttloc_s) * p_tt_config->ttloc_size);
p_tt_config->ttloc_len = 0;
/* Retention time and decay algorithm from 13 Feb 13 version of */
/* http://www.aprs.org/aprstt/aprstt-coding24.txt */
/* Reduced by transmit count by one. An 8 minute delay in between transmissions seems awful long. */
p_tt_config->retain_time = 80 * 60;
p_tt_config->num_xmits = 6;
assert (p_tt_config->num_xmits <= TT_MAX_XMITS);
p_tt_config->xmit_delay[0] = 3; /* Before initial transmission. */
p_tt_config->xmit_delay[1] = 16;
p_tt_config->xmit_delay[2] = 32;
p_tt_config->xmit_delay[3] = 64;
p_tt_config->xmit_delay[4] = 2 * 60;
p_tt_config->xmit_delay[5] = 4 * 60;
p_tt_config->xmit_delay[6] = 8 * 60; // not currently used.
strlcpy (p_tt_config->status[0], "", sizeof(p_tt_config->status[0]));
strlcpy (p_tt_config->status[1], "/off duty", sizeof(p_tt_config->status[1]));
strlcpy (p_tt_config->status[2], "/enroute", sizeof(p_tt_config->status[2]));
strlcpy (p_tt_config->status[3], "/in service", sizeof(p_tt_config->status[3]));
strlcpy (p_tt_config->status[4], "/returning", sizeof(p_tt_config->status[4]));
strlcpy (p_tt_config->status[5], "/committed", sizeof(p_tt_config->status[5]));
strlcpy (p_tt_config->status[6], "/special", sizeof(p_tt_config->status[6]));
strlcpy (p_tt_config->status[7], "/priority", sizeof(p_tt_config->status[7]));
strlcpy (p_tt_config->status[8], "/emergency", sizeof(p_tt_config->status[8]));
strlcpy (p_tt_config->status[9], "/custom 1", sizeof(p_tt_config->status[9]));
for (m = 0; m < TT_ERROR_MAXP1; m++) {
strlcpy (p_tt_config->response[m].method, "MORSE", sizeof(p_tt_config->response[m].method));
strlcpy (p_tt_config->response[m].mtext, "?", sizeof(p_tt_config->response[m].mtext));
}
strlcpy (p_tt_config->response[TT_ERROR_OK].mtext, "R", sizeof(p_tt_config->response[TT_ERROR_OK].mtext));
memset (p_misc_config, 0, sizeof(struct misc_config_s));
p_misc_config->agwpe_port = DEFAULT_AGWPE_PORT;
p_misc_config->kiss_port = DEFAULT_KISS_PORT;
p_misc_config->enable_kiss_pt = 0; /* -p option */
/* Defaults from http://info.aprs.net/index.php?title=SmartBeaconing */
p_misc_config->sb_configured = 0; /* TRUE if SmartBeaconing is configured. */
p_misc_config->sb_fast_speed = 60; /* MPH */
p_misc_config->sb_fast_rate = 180; /* seconds */
p_misc_config->sb_slow_speed = 5; /* MPH */
p_misc_config->sb_slow_rate = 1800; /* seconds */
p_misc_config->sb_turn_time = 15; /* seconds */
p_misc_config->sb_turn_angle = 30; /* degrees */
p_misc_config->sb_turn_slope = 255; /* degrees * MPH */
memset (p_igate_config, 0, sizeof(struct igate_config_s));
p_igate_config->t2_server_port = DEFAULT_IGATE_PORT;
p_igate_config->tx_chan = -1; /* IS->RF not enabled */
p_igate_config->tx_limit_1 = IGATE_TX_LIMIT_1_DEFAULT;
p_igate_config->tx_limit_5 = IGATE_TX_LIMIT_5_DEFAULT;
/* People find this confusing. */
/* Ideally we'd like to figure out if com0com is installed */
/* and automatically enable this. */
//strlcpy (p_misc_config->nullmodem, DEFAULT_NULLMODEM, sizeof(p_misc_config->nullmodem));
strlcpy (p_misc_config->nullmodem, "", sizeof(p_misc_config->nullmodem));
strlcpy (p_misc_config->gpsnmea_port, "", sizeof(p_misc_config->gpsnmea_port));
strlcpy (p_misc_config->nmea_port, "", sizeof(p_misc_config->nmea_port));
strlcpy (p_misc_config->logdir, "", sizeof(p_misc_config->logdir));
/*
* Try to extract options from a file.
*
* Windows: File must be in current working directory.
*
* Linux: Search current directory then home directory.
*
* Future possibility - Could also search home directory
* for Windows by combinting two variables:
* HOMEDRIVE=C:
* HOMEPATH=\Users\John
*
* It's not clear if this always points to same location:
* USERPROFILE=C:\Users\John
*/
channel = 0;
adevice = 0;
// TODO: Would be better to have a search list and loop thru it.
strlcpy(filepath, fname, sizeof(filepath));
fp = fopen (filepath, "r");
#ifndef __WIN32__
if (fp == NULL && strcmp(fname, "direwolf.conf") == 0) {
/* Failed to open the default location. Try home dir. */
char *p;
strlcpy (filepath, "", sizeof(filepath));
p = getenv("HOME");
if (p != NULL) {
strlcpy (filepath, p, sizeof(filepath));
strlcat (filepath, "/direwolf.conf", sizeof(filepath));
fp = fopen (filepath, "r");
}
}
#endif
if (fp == NULL) {
// TODO: not exactly right for all situations.
text_color_set(DW_COLOR_ERROR);
dw_printf ("ERROR - Could not open config file %s\n", filepath);
dw_printf ("Try using -c command line option for alternate location.\n");
return;
}
dw_printf ("\nReading config file %s\n", filepath);
line = 0;
while (fgets(stuff, sizeof(stuff), fp) != NULL) {
char *t;
line++;
t = split(stuff,0);
if (t == NULL) {
continue;
}
if (*t == '#' || *t == '*') {
continue;
}
/*
* ==================== Audio device parameters ====================
*/
/*
* ADEVICE[n] - Name of input sound device, and optionally output, if different.
*
* ADEVICE plughw:1,0 -- same for in and out.
* ADEVICE plughw:2,0 plughw:3,0 -- different in/out for a channel or channel pair.
*
*/
/* Note that ALSA name can contain comma such as hw:1,0 */
if (strncasecmp(t, "ADEVICE", 7) == 0) {
adevice = 0;
if (isdigit(t[7])) {
adevice = t[7] - '0';
}
if (adevice < 0 || adevice >= MAX_ADEVS) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: Device number %d out of range for ADEVICE command on line %d.\n", adevice, line);
adevice = 0;
continue;
}
t = split(NULL,0);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: Missing name of audio device for ADEVICE command on line %d.\n", line);
continue;
}
p_audio_config->adev[adevice].defined = 1;
/* First channel of device is valid. */
p_audio_config->achan[ADEVFIRSTCHAN(adevice)].valid = 1;
strlcpy (p_audio_config->adev[adevice].adevice_in, t, sizeof(p_audio_config->adev[adevice].adevice_in));
strlcpy (p_audio_config->adev[adevice].adevice_out, t, sizeof(p_audio_config->adev[adevice].adevice_out));
t = split(NULL,0);
if (t != NULL) {
strlcpy (p_audio_config->adev[adevice].adevice_out, t, sizeof(p_audio_config->adev[adevice].adevice_out));
}
}
/*
* PAIDEVICE[n] input-device
* PAODEVICE[n] output-device
*
* This was submitted by KK5VD for the Mac OS X version. (__APPLE__)
*
* It looks like device names can contain spaces making it a little
* more difficult to put two names on the same line unless we come up with
* some other delimiter between them or a quoting scheme to handle
* embedded spaces in a name.
*
* It concerns me that we could have one defined without the other
* if we don't put in more error checking later.
*
* version 1.3 dev snapshot C:
*
* We now have a general quoting scheme so the original ADEVICE can handle this.
* These options will probably be removed before general 1.3 release.
*/
else if (strcasecmp(t, "PAIDEVICE") == 0) {
adevice = 0;
if (isdigit(t[9])) {
adevice = t[9] - '0';
}
if (adevice < 0 || adevice >= MAX_ADEVS) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: Device number %d out of range for PADEVICE command on line %d.\n", adevice, line);
adevice = 0;
continue;
}
t = split(NULL,1);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: Missing name of audio device for PADEVICE command on line %d.\n", line);
continue;
}
p_audio_config->adev[adevice].defined = 1;
/* First channel of device is valid. */
p_audio_config->achan[ADEVFIRSTCHAN(adevice)].valid = 1;
strlcpy (p_audio_config->adev[adevice].adevice_in, t, sizeof(p_audio_config->adev[adevice].adevice_in));
}
else if (strcasecmp(t, "PAODEVICE") == 0) {
adevice = 0;
if (isdigit(t[9])) {
adevice = t[9] - '0';
}
if (adevice < 0 || adevice >= MAX_ADEVS) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: Device number %d out of range for PADEVICE command on line %d.\n", adevice, line);
adevice = 0;
continue;
}
t = split(NULL,1);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Config file: Missing name of audio device for PADEVICE command on line %d.\n", line);
continue;
}
p_audio_config->adev[adevice].defined = 1;
/* First channel of device is valid. */
p_audio_config->achan[ADEVFIRSTCHAN(adevice)].valid = 1;
strlcpy (p_audio_config->adev[adevice].adevice_out, t, sizeof(p_audio_config->adev[adevice].adevice_out));
}
/*
* ARATE - Audio samples per second, 11025, 22050, 44100, etc.
*/
else if (strcasecmp(t, "ARATE") == 0) {
int n;
t = split(NULL,0);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Missing audio sample rate for ARATE command.\n", line);
continue;
}
n = atoi(t);
if (n >= MIN_SAMPLES_PER_SEC && n <= MAX_SAMPLES_PER_SEC) {
p_audio_config->adev[adevice].samples_per_sec = n;
}
else {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Use a more reasonable audio sample rate in range of %d - %d.\n",
line, MIN_SAMPLES_PER_SEC, MAX_SAMPLES_PER_SEC);
}
}
/*
* ACHANNELS - Number of audio channels for current device: 1 or 2
*/
else if (strcasecmp(t, "ACHANNELS") == 0) {
int n;
t = split(NULL,0);
if (t == NULL) {
text_color_set(DW_COLOR_ERROR);
dw_printf ("Line %d: Missing number of audio channels for ACHANNELS command.\n", line);
continue;
}
n = atoi(t);
if (n ==1 || n == 2) {
p_audio_config->adev[adevice].num_channels = n;
/* Set valid channels depending on mono or stereo. */
p_audio_config->achan[ADEVFIRSTCHAN(adevice)].valid = 1;
if (n == 2) {
p_audio_config->achan[ADEVFIRSTCHAN(adevice) + 1].valid = 1;
}