forked from mlaurijsse/linux-mpu9150
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfigfile_parser.c
More file actions
executable file
·154 lines (126 loc) · 4.02 KB
/
configfile_parser.c
File metadata and controls
executable file
·154 lines (126 loc) · 4.02 KB
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
/*
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 "mpu9150.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_mpu9150 *mpu_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);
}
// check for mpu orientation config
if (strcmp(tmp,"mpu_rotation") == 0)
{
// get config data for mpu orientation
sscanf(line, "%s %d", tmp, &mpu_sensor->rotation);
}
// check for mpu roll adjustment
if (strcmp(tmp,"roll_adjust") == 0)
{
// get config data for mpu roll adjustment
sscanf(line, "%s %f", tmp, &mpu_sensor->roll_adjust);
}
// check for mpu pitch adjustment
if (strcmp(tmp,"pitch_adjust") == 0)
{
// get config data for mpu pitch adjustment
sscanf(line, "%s %f", tmp, &mpu_sensor->pitch_adjust);
}
// check for mpu yaw adjustment
if (strcmp(tmp,"yaw_adjust") == 0)
{
// get config data for mpu yaw adjustment
sscanf(line, "%s %f", tmp, &mpu_sensor->yaw_adjust);
}
}
}
return(1);
}
else
{
// no config file used
return (0);
}
}