forked from Openvario/sensord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nmea.c
executable file
·208 lines (180 loc) · 5.2 KB
/
nmea.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
/*
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 <string.h>
#include "nmea.h"
#include "def.h"
extern int g_debug;
extern FILE *fp_console;
/**
* @brief Implements the $POV NMEA Sentence for pressure data
* @param sentence char pointer for created string
* @param static_pressure
* @param dynamic_pressure
* @param tek_pressure // not implemented yet !!
* @return result
*
* Implementation of the properitary NMEA sentence for AKF Glidecomputer
* \n
*
* $POV,P,static_pressure,Q,dynamic_pressure*CRC
* | | | | |
* 1 2 3 4 5
*
* 1: $P Properitary NMEA Sentence
* OV Manufacturer Code: OpenVario
*
* 2: P Code for static pressure in hPa
*
* 3: static_pressure Format: 1013.34
* Range: 0..1500
*
* 4: Q Code for dynamic pressure in Pa
*
* 5: dynamic_pressure Format: 12.34
* Range: -999 .. 999
*
*
* @date 23.02.2014 born
*
*/
int Compose_Pressure_POV_slow(char *sentence, float static_pressure, float dynamic_pressure)
{
int length;
int success = 1;
// check static_pressure input value for validity
if ((static_pressure < 0) || (static_pressure > 2000))
{
static_pressure = 9999;
success = 10;
}
// check dynamic_pressure input value for validity
/// @todo add useful range for dynamic_pressure vales !!
if ((dynamic_pressure < -999.0) || (dynamic_pressure > 9998.0))
{
dynamic_pressure = 9999;
success = 20;
}
// compose NMEA String
length = sprintf(sentence, "$POV,P,%+07.2f,Q,%+05.2f", static_pressure, (dynamic_pressure));
// Calculate NMEA checksum and add to string
sprintf(sentence + length, "*%02X\n", NMEA_checksum(sentence));
//print sentence for debug
debug_print("POV slow NMEA sentence: %s\n", sentence);
return (success);
}
/**
* @brief Implements the $POV NMEA Sentence for fast data
* @param sentence char pointer for created string
* @param TE vario
* @return result
*
* Implementation of the properitary NMEA sentence for AKF Glidecomputer
* \n
*
* $POV,E,TE_vario*CRC
* | | | |
* 1 2 3 4
*
* 1: $P Properitary NMEA Sentence
* OV Manufacturer Code: OpenVario
*
* 2: E Code for TE vario in m/s
*
* 3: TE vario Format: 3.4
*
* @date 09.03.2014 born
*
*/
int Compose_Pressure_POV_fast(char *sentence, float te_vario)
{
int length;
int success = 1;
// check te_vario input value for validity
if ((te_vario < -50) || (te_vario > 50))
{
te_vario = 99;
success = 10;
}
// compose NMEA String
length = sprintf(sentence, "$POV,E,%+05.2f", te_vario);
// Calculate NMEA checksum and add to string
sprintf(sentence + length, "*%02X\n", NMEA_checksum(sentence));
//print sentence for debug
debug_print("NMEA sentence: %s\n", sentence);
return (success);
}
/**
* @brief Implements the $POV NMEA Sentence for voltage data
* @param sentence char pointer for created string
* @param Battery Voltage
* @return result
*
* Implementation of the properitary NMEA sentence for AKF Glidecomputer
* \n
*
* $POV,V,Bat_voltage*CRC
* | | | |
* 1 2 3 4
*
* 1: $P Properitary NMEA Sentence
* OV Manufacturer Code: OpenVario
*
* 2: V Code for Battery Voltage in V
*
* 3: Battery Voltage Format: 12.02
*
* @date 13.03.2016 born
*
*/
int Compose_Voltage_POV(char *sentence, float voltage)
{
int length;
int success = 1;
// check voltage input value for validity
if ((voltage < 2.) || (voltage > 20.))
{
voltage = 0.;
success = 10;
}
// compose NMEA String
length = sprintf(sentence, "$POV,V,%+05.2f", voltage);
// Calculate NMEA checksum and add to string
sprintf(sentence + length, "*%02X\n", NMEA_checksum(sentence));
//print sentence for debug
debug_print("NMEA sentence: %s\n", sentence);
return (success);
}
/**
* @brief Implements the NMEA Checksum
* @param char* NMEA string
* @return int Calculated Checksum for string
*
* The NMEA Checksum is calulated over the NMEA string between $ and *\n
* The checksum is a hexadecimal number representing the XOR of all bytes
*/
unsigned char NMEA_checksum(char *string)
{
unsigned char value=0;
int i=1;
int l;
l = strlen(string);
for (; i < l; i++)
{
value ^= string[i];
}
return value;
}