1 /*
2  * This file is part of nmealib.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __NMEALIB_VALIDATE_H__
19 #define __NMEALIB_VALIDATE_H__
20 
21 #include <nmealib/info.h>
22 #include <stdbool.h>
23 #include <stddef.h>
24 
25 #ifdef  __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
29 /**
30  * The type definition for an invalid NMEA character/description pair
31  */
32 typedef struct _NmeaInvalidCharacter {
33   const char  character;
34   const char *description;
35 } NmeaInvalidCharacter;
36 
37 /**
38  * Determine whether the given character is not allowed in an NMEA string
39  *
40  * @param c The character to check
41  *
42  * @return The invalid character character/description pair when the string
43  * has invalid characters, NULL otherwise
44  */
45 const NmeaInvalidCharacter *nmeaValidateIsInvalidCharacter(const char c);
46 
47 /**
48  * Determine whether the specified string contains characters that are not
49  * allowed in an NMEA string
50  *
51  * @param s The string to check
52  * @param sz The length of the string to check
53  *
54  * @return The invalid character character/description pair when the string
55  * has invalid characters, NULL otherwise
56  */
57 const NmeaInvalidCharacter *nmeaValidateSentenceHasInvalidCharacters(const char *s, const size_t sz);
58 
59 /**
60  * Validate the time fields in an NmeaTime structure.
61  *
62  * Expects:
63  * <pre>
64  *   hour [0, 23]
65  *   min  [0, 59]
66  *   sec  [0, 60] (1 leap second)
67  *   hsec [0, 99]
68  * </pre>
69  *
70  * @param t The structure
71  * @param prefix The NMEA prefix
72  * @param s The NMEA sentence
73  * @return True when valid, false otherwise
74  */
75 bool nmeaValidateTime(const NmeaTime *t, const char *prefix, const char *s);
76 
77 /**
78  * Validate the date fields in an NmeaTime structure.
79  *
80  * Expects:
81  * <pre>
82  *   year  [90, 189]
83  *   month [ 0,  11]
84  *   day   [ 1,  31]
85  * </pre>
86  *
87  * @param t a pointer to the structure
88  * @param prefix The NMEA prefix
89  * @param s The NMEA sentence
90  * @return true when valid, false otherwise
91  */
92 bool nmeaValidateDate(const NmeaTime *t, const char *prefix, const char *s);
93 
94 /**
95  * Validate north/south or east/west and upper-case it.
96  *
97  * Expects:
98  * <pre>
99  *   c in { N, S } (for north/south)
100  *   c in { E, W } (for east/west)
101  * </pre>
102  *
103  * @param c The character
104  * @param ns Evaluate north/south when true, evaluate east/west otherwise
105  * @param prefix The NMEA prefix
106  * @param s The NMEA sentence
107  * @return True when valid, false otherwise
108  */
109 bool nmeaValidateNSEW(char c, const bool ns, const char *prefix, const char *s);
110 
111 /**
112  * Validate a fix.
113  *
114  * Expects:
115  * <pre>
116  *   fix in [NMEALIB_FIX_FIRST, NMEALIB_FIX_LAST]
117  * </pre>
118  *
119  * @param fix The fix
120  * @param prefix The NMEA prefix
121  * @param s The NMEA sentence
122  * @return True when valid, false otherwise
123  */
124 bool nmeaValidateFix(NmeaFix fix, const char *prefix, const char *s);
125 
126 /**
127  * Validate a signal.
128  *
129  * Expects:
130  * <pre>
131  *   sig in [NMEALIB_SIG_FIRST, NMEALIB_SIG_LAST]
132  * </pre>
133  *
134  * @param sig The signal
135  * @param prefix The NMEA prefix
136  * @param s The NMEA sentence
137  * @return True when valid, false otherwise
138  */
139 bool nmeaValidateSignal(NmeaSignal sig, const char *prefix, const char *s);
140 
141 /**
142  * Validate and upper-case the mode.
143  *
144  * Expects:
145  * <pre>
146  *   c in { A, D, E, F, M, N, P, R, S }
147  *
148  *   A = Autonomous
149  *   D = Differential
150  *   E = Estimated (dead reckoning)
151  *   F = Float RTK (using floating integers)
152  *   M = Manual input
153  *   N = No fix
154  *   P = Precise
155  *   R = Real Time Kinematic (using fixed integers)
156  *   S = Simulation mode
157  * </pre>
158  *
159  * @param c The character, will also be converted to upper-case.
160  * @param prefix The NMEA prefix
161  * @param s The NMEA sentence
162  * @return True when valid, false otherwise
163  */
164 bool nmeaValidateMode(char c, const char *prefix, const char *s);
165 
166 /**
167  * Validate a satellite
168  *
169  * Expects:
170  * <pre>
171  *   elevation: in the range [-180, 180]
172  *   azimuth  : in the range [   0, 359]
173  *   signal   : in the range [   0,  99]
174  * </pre>
175  */
176 bool nmeaValidateSatellite(NmeaSatellite *sat, const char *prefix, const char *s);
177 
178 #ifdef  __cplusplus
179 }
180 #endif /* __cplusplus */
181 
182 #endif /* __NMEALIB_VALIDATE_H__ */
183