-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigfile_parser.c
executable file
·122 lines (101 loc) · 3.2 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
/*
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 "def.h"
#include "ms5611.h"
#include "ams5915.h"
#include "ads1110.h"
#include "configfile_parser.h"
extern int g_debug;
extern FILE *fp_console;
int cfgfile_parser(FILE *fp, t_ms5611 *static_sensor, t_ms5611 *tek_sensor, t_ams5915 *dynamic_sensor, t_ads1110 *voltage_sensor, t_config *config)
{
char line[70];
char tmp[20];
// 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 output of POV_E sentence
if (strcmp(tmp,"output_POV_E") == 0)
{
config->output_POV_E = 1;
//printf("OUTput POV_E enabled !! \n");
}
// check for output of POV_P_Q sentence
if (strcmp(tmp,"output_POV_P_Q") == 0)
{
config->output_POV_P_Q = 1;
//printf("OUTput POV_P_Q enabled !! \n");
}
// check for output of POV_V sentence
if (strcmp(tmp,"output_POV_V") == 0)
{
config->output_POV_V= 1;
//printf("OUTput POV_P_Q enabled !! \n");
}
// check for static_sensor
if (strcmp(tmp,"static_sensor") == 0)
{
// get config data for static sensor
sscanf(line, "%s %f %f", tmp, &static_sensor->offset, &static_sensor->linearity);
}
// check for tek_sensor
if (strcmp(tmp,"tek_sensor") == 0)
{
// get config data for tek sensor
sscanf(line, "%s %f %f", tmp, &tek_sensor->offset, &tek_sensor->linearity);
}
// check for dynamic_sensor
if (strcmp(tmp,"dynamic_sensor") == 0)
{
// get config data for dynamic sensor
sscanf(line, "%s %f %f", tmp, &dynamic_sensor->offset, &dynamic_sensor->linearity);
}
// check for vario config
if (strcmp(tmp,"vario_config") == 0)
{
// get config data for dynamic sensor
sscanf(line, "%s %f", tmp, &config->vario_x_accel);
}
// check for voltage sensor config
if (strcmp(tmp,"voltage_config") == 0)
{
// get config data for dynamic sensor
sscanf(line, "%s %f", tmp, &voltage_sensor->voltage_factor);
}
}
}
return(1);
}
else
{
// no config file used
return (0);
}
}