Skip to content

Commit 6f0c151

Browse files
committed
More error checking.
1 parent 12abb8d commit 6f0c151

File tree

1 file changed

+72
-14
lines changed

1 file changed

+72
-14
lines changed

src/config.c

+72-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// This file is part of Dire Wolf, an amateur radio packet TNC.
33
//
4-
// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2021 John Langner, WB2OSZ
4+
// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2021, 2023 John Langner, WB2OSZ
55
//
66
// This program is free software: you can redistribute it and/or modify
77
// it under the terms of the GNU General Public License as published by
@@ -755,12 +755,13 @@ void config_init (char *fname, struct audio_s *p_audio_config,
755755
strlcpy (p_audio_config->adev[adevice].adevice_out, DEFAULT_ADEVICE, sizeof(p_audio_config->adev[adevice].adevice_out));
756756

757757
p_audio_config->adev[adevice].defined = 0;
758+
p_audio_config->adev[adevice].copy_from = -1;
758759
p_audio_config->adev[adevice].num_channels = DEFAULT_NUM_CHANNELS; /* -2 stereo */
759760
p_audio_config->adev[adevice].samples_per_sec = DEFAULT_SAMPLES_PER_SEC; /* -r option */
760761
p_audio_config->adev[adevice].bits_per_sample = DEFAULT_BITS_PER_SAMPLE; /* -8 option for 8 instead of 16 bits */
761762
}
762763

763-
p_audio_config->adev[0].defined = 1;
764+
p_audio_config->adev[0].defined = 2; // 2 means it was done by default and not the user's config file.
764765

765766
for (channel=0; channel<MAX_CHANS; channel++) {
766767
int ot, it;
@@ -925,10 +926,13 @@ void config_init (char *fname, struct audio_s *p_audio_config,
925926

926927
p_misc_config->maxframe_extended = AX25_K_MAXFRAME_EXTENDED_DEFAULT; /* Max frames to send before ACK. mod 128 "Window" size. */
927928

928-
p_misc_config->maxv22 = AX25_N2_RETRY_DEFAULT / 3; /* Max SABME before falling back to SABM. */
929-
p_misc_config->v20_addrs = NULL; /* Go directly to v2.0 for stations listed. */
929+
p_misc_config->maxv22 = AX25_N2_RETRY_DEFAULT / 3; /* Send SABME this many times before falling back to SABM. */
930+
p_misc_config->v20_addrs = NULL; /* Go directly to v2.0 for stations listed */
931+
/* without trying v2.2 first. */
930932
p_misc_config->v20_count = 0;
931933
p_misc_config->noxid_addrs = NULL; /* Don't send XID to these stations. */
934+
/* Might work with a partial v2.2 implementation */
935+
/* on the other end. */
932936
p_misc_config->noxid_count = 0;
933937

934938
/*
@@ -1012,7 +1016,11 @@ void config_init (char *fname, struct audio_s *p_audio_config,
10121016
* ADEVICE plughw:1,0 -- same for in and out.
10131017
* ADEVICE plughw:2,0 plughw:3,0 -- different in/out for a channel or channel pair.
10141018
* ADEVICE1 udp:7355 default -- from Software defined radio (SDR) via UDP.
1015-
*
1019+
*
1020+
* New in 1.8: Ability to map to another audio device.
1021+
* This allows multiple modems (i.e. data speeds) on the same audio interface.
1022+
*
1023+
* ADEVICEn = n -- Copy from different already defined channel.
10161024
*/
10171025

10181026
/* Note that ALSA name can contain comma such as hw:1,0 */
@@ -1040,17 +1048,42 @@ void config_init (char *fname, struct audio_s *p_audio_config,
10401048
exit(EXIT_FAILURE);
10411049
}
10421050

1051+
// Do not allow same adevice to be defined more than once.
1052+
// Overriding the default for adevice 0 is ok.
1053+
// In that case definded was 2. That's why we check for 1, not just non-zero.
1054+
1055+
if (p_audio_config->adev[adevice].defined == 1) { // 1 means defined by user.
1056+
text_color_set(DW_COLOR_ERROR);
1057+
dw_printf ("Config file: ADEVICE%d can't be defined more than once. Line %d.\n", adevice, line);
1058+
continue;
1059+
}
1060+
10431061
p_audio_config->adev[adevice].defined = 1;
1044-
1045-
/* First channel of device is valid. */
1046-
p_audio_config->chan_medium[ADEVFIRSTCHAN(adevice)] = MEDIUM_RADIO;
10471062

1048-
strlcpy (p_audio_config->adev[adevice].adevice_in, t, sizeof(p_audio_config->adev[adevice].adevice_in));
1049-
strlcpy (p_audio_config->adev[adevice].adevice_out, t, sizeof(p_audio_config->adev[adevice].adevice_out));
1063+
// New case for release 1.8.
10501064

1051-
t = split(NULL,0);
1052-
if (t != NULL) {
1065+
if (strcmp(t, "=") == 0) {
1066+
t = split(NULL,0);
1067+
if (t != NULL) {
1068+
1069+
}
1070+
1071+
///////// to be continued.... FIXME
1072+
1073+
}
1074+
else {
1075+
/* First channel of device is valid. */
1076+
// This might be changed to UDP or STDIN when the device name is examined.
1077+
p_audio_config->chan_medium[ADEVFIRSTCHAN(adevice)] = MEDIUM_RADIO;
1078+
1079+
strlcpy (p_audio_config->adev[adevice].adevice_in, t, sizeof(p_audio_config->adev[adevice].adevice_in));
10531080
strlcpy (p_audio_config->adev[adevice].adevice_out, t, sizeof(p_audio_config->adev[adevice].adevice_out));
1081+
1082+
t = split(NULL,0);
1083+
if (t != NULL) {
1084+
// Different audio devices for receive and transmit.
1085+
strlcpy (p_audio_config->adev[adevice].adevice_out, t, sizeof(p_audio_config->adev[adevice].adevice_out));
1086+
}
10541087
}
10551088
}
10561089

@@ -2173,7 +2206,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
21732206
else {
21742207
p_audio_config->achan[channel].slottime = DEFAULT_SLOTTIME;
21752208
text_color_set(DW_COLOR_ERROR);
2176-
dw_printf ("Line %d: Invalid delay time for persist algorithm. Using %d.\n",
2209+
dw_printf ("Line %d: Invalid delay time for persist algorithm. Using default %d.\n",
21772210
line, p_audio_config->achan[channel].slottime);
21782211
}
21792212
}
@@ -2197,7 +2230,7 @@ void config_init (char *fname, struct audio_s *p_audio_config,
21972230
else {
21982231
p_audio_config->achan[channel].persist = DEFAULT_PERSIST;
21992232
text_color_set(DW_COLOR_ERROR);
2200-
dw_printf ("Line %d: Invalid probability for persist algorithm. Using %d.\n",
2233+
dw_printf ("Line %d: Invalid probability for persist algorithm. Using default %d.\n",
22012234
line, p_audio_config->achan[channel].persist);
22022235
}
22032236
}
@@ -2216,6 +2249,19 @@ void config_init (char *fname, struct audio_s *p_audio_config,
22162249
}
22172250
n = atoi(t);
22182251
if (n >= 0 && n <= 255) {
2252+
text_color_set(DW_COLOR_ERROR);
2253+
if (n == 0) {
2254+
dw_printf ("Line %d: Setting TXDELAY to 0 is a REALLY BAD idea if you want other stations to hear you.\n",
2255+
line);
2256+
dw_printf ("Line %d: See User Guide, \"Radio Channel - Transmit Timing\" for an explanation.\n",
2257+
line);
2258+
}
2259+
if (n >= 100) {
2260+
dw_printf ("Line %d: Keeping with tradition, going back to the 1980s, TXDELAY is in 10 millisecond units.\n",
2261+
line);
2262+
dw_printf ("Line %d: The value %d would be %.3f seconds which seems rather excessive. Are you sure you want that?\n",
2263+
line, n, (double)n * 10. / 1000.);
2264+
}
22192265
p_audio_config->achan[channel].txdelay = n;
22202266
}
22212267
else {
@@ -2240,6 +2286,18 @@ void config_init (char *fname, struct audio_s *p_audio_config,
22402286
}
22412287
n = atoi(t);
22422288
if (n >= 0 && n <= 255) {
2289+
if (n == 0) {
2290+
dw_printf ("Line %d: Setting TXTAIL to 0 is a REALLY BAD idea if you want other stations to hear you.\n",
2291+
line);
2292+
dw_printf ("Line %d: See User Guide, \"Radio Channel - Transmit Timing\" for an explanation.\n",
2293+
line);
2294+
}
2295+
if (n >= 50) {
2296+
dw_printf ("Line %d: Keeping with tradition, going back to the 1980s, TXTAIL is in 10 millisecond units.\n",
2297+
line);
2298+
dw_printf ("Line %d: The value %d would be %.3f seconds which seems rather excessive. Are you sure you want that?\n",
2299+
line, n, (double)n * 10. / 1000.);
2300+
}
22432301
p_audio_config->achan[channel].txtail = n;
22442302
}
22452303
else {

0 commit comments

Comments
 (0)