forked from Openvario/variod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigfile_parser.c
225 lines (204 loc) · 6.06 KB
/
configfile_parser.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
/*
sensord - Sensor Interface for XCSoar Glide Computer - http://www.openvario.org/
Copyright (C) 2014 The openvario project
A detailed list of copyright holders can be found in the file "AUTHORS"
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 3
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/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "configfile_parser.h"
#include "audiovario.h"
#include "stf.h"
extern int g_debug;
extern FILE *fp_console;
int cfgfile_parser(FILE *fp, t_vario_config *vario_config, t_polar *polar)
{
char line[128];
char tmp[128];
// is config file used ??
if (fp)
{
// read whole config file
while (! feof(fp))
{
// get line from config file
fgets(line, 70, fp);
//printf("getting line: '%s'\n", line);
// check if line is comment
if((!(line[0] == '#')) && (!(line[0] == '\n')))
{
// get first config tag
sscanf(line, "%s", tmp);
// check for deadband_low
if (strcmp(tmp,"deadband_low") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[vario].deadband_low));
}
// check for deadband_high
if (strcmp(tmp,"deadband_high") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[vario].deadband_high));
}
// check for pulse_length
if (strcmp(tmp,"pulse_length") == 0)
{
// get config data
sscanf(line, "%s %d", tmp, &(vario_config[vario].pulse_length));
}
// check for pulse gain
if (strcmp(tmp,"pulse_length_gain") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[vario].pulse_length_gain));
}
// check for pulse duty
if (strcmp(tmp,"pulse_duty") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[vario].pulse_duty));
}
// check for pulse rise
if (strcmp(tmp,"pulse_rise") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[vario].pulse_rise));
}
// check for pulse fall
if (strcmp(tmp,"pulse_fall") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[vario].pulse_fall));
}
// check for base frequency positive
if (strcmp(tmp,"base_freq_pos") == 0)
{
// get config data
sscanf(line, "%s %d", tmp, &(vario_config[vario].base_freq_pos));
}
// check for base frequency negative
if (strcmp(tmp,"base_freq_neg") == 0)
{
// get config data
sscanf(line, "%s %d", tmp, &(vario_config[vario].base_freq_neg));
}
// check for frequency gain positive
if (strcmp(tmp,"freq_gain_pos") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[vario].freq_gain_pos));
}
// check for frequency gain negative
if (strcmp(tmp,"freq_gain_neg") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[vario].freq_gain_neg));
}
// check for stf_deadband_low
if (strcmp(tmp,"stf_deadband_low") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[stf].deadband_low));
}
// check for stf_deadband_high
if (strcmp(tmp,"stf_deadband_high") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[stf].deadband_high));
}
// check for stf_pulse_length
if (strcmp(tmp,"stf_pulse_length") == 0)
{
// get config data
sscanf(line, "%s %d", tmp, &(vario_config[stf].pulse_length));
}
// check for stf_pulse gain
if (strcmp(tmp,"stf_pulse_length_gain") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[stf].pulse_length_gain));
}
// check for pulse duty
if (strcmp(tmp,"stf_pulse_duty") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[stf].pulse_duty));
}
// check for pulse rise
if (strcmp(tmp,"stf_pulse_rise") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[stf].pulse_rise));
}
// check for pulse fall
if (strcmp(tmp,"stf_pulse_fall") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[stf].pulse_fall));
}
// check for base frequency positive
if (strcmp(tmp,"stf_base_freq_pos") == 0)
{
// get config data
sscanf(line, "%s %d", tmp, &(vario_config[stf].base_freq_pos));
}
// check for base frequency negative
if (strcmp(tmp,"stf_base_freq_neg") == 0)
{
// get config data
sscanf(line, "%s %d", tmp, &(vario_config[stf].base_freq_neg));
}
// check for frequency gain positive
if (strcmp(tmp,"stf_freq_gain_pos") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[stf].freq_gain_pos));
}
// check for frequency gain negative
if (strcmp(tmp,"stf_freq_gain_neg") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(vario_config[stf].freq_gain_neg));
}
// check for polar values
if (strcmp(tmp,"polar_a") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(polar->a));
}
if (strcmp(tmp,"polar_b") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(polar->b));
}
if (strcmp(tmp,"polar_c") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(polar->c));
}
if (strcmp(tmp,"polar_w") == 0)
{
// get config data
sscanf(line, "%s %f", tmp, &(polar->w));
}
}
}
return(1);
}
else
{
// no config file used
return (0);
}
}