ccNOos  v0.0.0
Build Portable Microcontroller Applications!
Functions
NEO_LEA_M8T.c File Reference

IMS: ccNOos, Implementation for straight C More...

#include "NEO_LEA_M8T.h"
Include dependency graph for NEO_LEA_M8T.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct gpsData createGPSDataStruct ()
 
UI_8 tryParseZDAString (char *gpsStringin, struct gpsData *gpsDataPtr, int iZDA, int commaCount)
 
UI_8 tryParseGGAString (char *gpsStringin, struct gpsData *gpsDataPtr, int iGGA, int commaCount)
 
UI_8 tryParseGPSData (char *gpsStringin, struct gpsData *gpsDataPtr)
 

Detailed Description

IMS: ccNOos, Implementation for straight C

Copyright 2021 InMechaSol, Inc

Licensed under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Notes: (.c includes .h) - for straight C or (.cpp includes .c which includes .h) - for C++ wrapped straight C Always compiled to a single compilation unit, either C or CPP, not both

Definition in file NEO_LEA_M8T.c.

Function Documentation

◆ createGPSDataStruct()

struct gpsData createGPSDataStruct ( )

Definition at line 1 of file NEO_LEA_M8T.c.

30 {
31  struct gpsData outStruct;
32  outStruct.altitude = 0;
33  outStruct.day = 0;
34  outStruct.lattitude = 0;
35  outStruct.longitude = 0;
36  outStruct.month = 0;
37  outStruct.utctime = 0;
38  outStruct.year = 0;
39  return outStruct;
40 }

◆ tryParseGGAString()

UI_8 tryParseGGAString ( char *  gpsStringin,
struct gpsData gpsDataPtr,
int  iGGA,
int  commaCount 
)

Definition at line 95 of file NEO_LEA_M8T.c.

96 {
97  if (commaCount > 9)
98  {
99  commaCount = 0;
100  int lastCommaIndex = 0;
101  int I_dot = 0;
102  float minutes = 0;
103  char tempChar = 0x00;
104 
105 
106  for (int i = iGGA; i < charBuffMax; i++)
107  {
108  if (gpsStringin[i] == ',')
109  {
110  commaCount++;
111  if (i > lastCommaIndex + 1)
112  {
113  // temporarily null terminate token sub string
114  gpsStringin[i] = '\0';
115 
116  switch (commaCount)
117  {
118  case 2: // utc time
119  if (!ATO_F(&gpsStringin[lastCommaIndex + 1], &gpsDataPtr->utctime))
120  {
121  gpsStringin[i] = ',';
122  return ui8FALSE;
123  }
124  break;
125  case 3: // latitude
126  I_dot = lastCommaIndex;
127  while (gpsStringin[++I_dot] != '.') { if (I_dot > charBuffMax - 2) break; }
128 
129  if (I_dot < i)
130  {
131  tempChar = gpsStringin[I_dot-2];
132  gpsStringin[I_dot-2] = '\0';
133 
134  if (ATO_F(&gpsStringin[lastCommaIndex + 1], &gpsDataPtr->lattitude))
135  {
136  gpsStringin[I_dot-2] = tempChar;
137  if (ATO_F(&gpsStringin[I_dot-2], &minutes))
138  {
139  gpsDataPtr->lattitude += minutes / 60.0f;
140  }
141  else
142  {
143  gpsStringin[I_dot] = '.';
144  gpsStringin[i] = ',';
145  return ui8FALSE;
146  }
147  }
148  else
149  {
150  gpsStringin[I_dot] = '.';
151  gpsStringin[i] = ',';
152  return ui8FALSE;
153  }
154  }
155  else
156  {
157  gpsStringin[i] = ',';
158  return ui8FALSE;
159  }
160  break;
161  case 4: // latitude direction
162  if (gpsStringin[lastCommaIndex + 1] == 'S')
163  gpsDataPtr->lattitude = -gpsDataPtr->lattitude;
164  break;
165  case 5: // longitude
166  I_dot = lastCommaIndex;
167  while (gpsStringin[++I_dot] != '.') { if (I_dot > charBuffMax - 2) break; }
168 
169 
170 
171  if (I_dot < i)
172  {
173  tempChar = gpsStringin[I_dot-2];
174  gpsStringin[I_dot-2] = '\0';
175 
176  if (ATO_F(&gpsStringin[lastCommaIndex + 1], &gpsDataPtr->longitude))
177  {
178  gpsStringin[I_dot-2] = tempChar;
179 
180  if (ATO_F(&gpsStringin[I_dot-2], &minutes))
181  {
182  gpsDataPtr->longitude += minutes / 60.0f;
183  }
184  else
185  {
186  gpsStringin[I_dot] = '.';
187  gpsStringin[i] = ',';
188  return ui8FALSE;
189  }
190  }
191  else
192  {
193  gpsStringin[I_dot] = '.';
194  gpsStringin[i] = ',';
195  return ui8FALSE;
196  }
197  gpsStringin[I_dot] = '.';
198  }
199  else
200  {
201  gpsStringin[i] = ',';
202  return ui8FALSE;
203  }
204  break;
205  case 6: // longitude direction
206  if (gpsStringin[lastCommaIndex + 1] == 'W')
207  gpsDataPtr->longitude = -gpsDataPtr->longitude;
208  break;
209  case 10: // altitude
210  if (!ATO_F(&gpsStringin[lastCommaIndex + 1], &gpsDataPtr->altitude))
211  {
212  gpsStringin[i] = ',';
213  return ui8FALSE;
214  }
215  break;
216  }
217  // reset to comma
218  gpsStringin[i] = ',';
219  }
220  lastCommaIndex = i;
221  }
222  }
223  }
224  return ui8TRUE;
225 }

◆ tryParseGPSData()

UI_8 tryParseGPSData ( char *  gpsStringin,
struct gpsData gpsDataPtr 
)

Definition at line 227 of file NEO_LEA_M8T.c.

228 {
229  // check string begins with $
230 // if (gpsStringin[0] == '$')
231 // {
232  int CommaCount = 0;
233  int I_GGA = 0;
234  int I_ZDA = 0;
235  int I_GNS = 0;
236  UI_8 retVal = ui8FALSE;
237 
238  // scan message for valid tokens
239  for (int i = 5; i < charBuffMax; i++)
240  {
241  // find ZDA or GGA token
242  if(gpsStringin[i]=='A')
243  {
244  // ZDA
245  if (gpsStringin[i - 1] == 'D')
246  {
247  if (gpsStringin[i - 2] == 'Z' && gpsStringin[i - 5] == '$')
248  {
249  I_ZDA = i - 2;
250  }
251  }
252  // GGA
253  else if (gpsStringin[i - 1] == 'G')
254  {
255  if (gpsStringin[i - 2] == 'G' && gpsStringin[i - 5] == '$')
256  {
257  I_GGA = i - 2;
258  }
259  }
260  }
261  else if(gpsStringin[i]=='S')
262  {
263  // GNS
264  if (gpsStringin[i - 1] == 'N')
265  {
266  if (gpsStringin[i - 2] == 'G' && gpsStringin[i - 5] == '$')
267  {
268  I_GNS = i - 2;
269  }
270  }
271  }
272 
273  // count all commas
274  if (gpsStringin[i] == ',')
275  CommaCount++;
276 
277  // find star
278  if (gpsStringin[i] == '*')
279  {
280  // try parse GGA string
281  if (I_GGA > 0)
282  {
283  if(tryParseGGAString(gpsStringin, gpsDataPtr, I_GGA, CommaCount)==ui8TRUE)
284  retVal |= ui8TRUE ;
285  I_GGA = 0;
286  }
287  // try parse ZDA string
288  else if (I_ZDA > 0)
289  {
290  if(tryParseZDAString(gpsStringin, gpsDataPtr, I_ZDA, CommaCount)==ui8TRUE)
291  retVal |= ui8TRUE;
292  I_ZDA = 0;
293 
294  }
295  // try parse GNS
296  else if (I_GNS > 0)
297  {
298  if(tryParseGGAString(gpsStringin, gpsDataPtr, I_GNS, CommaCount)==ui8TRUE)
299  retVal |= ui8TRUE;
300  I_GNS = 0;
301  }
302  CommaCount = 0;
303 
304  }
305  }
306 
307 
308 // }
309  return retVal;
310 }

◆ tryParseZDAString()

UI_8 tryParseZDAString ( char *  gpsStringin,
struct gpsData gpsDataPtr,
int  iZDA,
int  commaCount 
)

Definition at line 43 of file NEO_LEA_M8T.c.

44 {
45  if (commaCount > 4)
46  {
47  commaCount = 0;
48  int lastCommaIndex = 0;
49 
50  for (int i = iZDA; i < charBuffMax; i++)
51  {
52  if (gpsStringin[i] == ',')
53  {
54  commaCount++;
55  if (i > lastCommaIndex + 1)
56  {
57  // temporarily null terminate token sub string
58  gpsStringin[i] = '\0';
59 
60  switch (commaCount)
61  {
62  case 3: // day
63  if (!ATO_I16(&gpsStringin[lastCommaIndex + 1], &gpsDataPtr->day))
64  {
65  gpsStringin[i] = ',';
66  return ui8FALSE;
67  }
68  break;
69  case 4: // month
70  if (!ATO_I16(&gpsStringin[lastCommaIndex + 1], &gpsDataPtr->month))
71  {
72  gpsStringin[i] = ',';
73  return ui8FALSE;
74  }
75  break;
76  case 5: // year
77  if (!ATO_I16(&gpsStringin[lastCommaIndex + 1], &gpsDataPtr->year))
78  {
79  gpsStringin[i] = ',';
80  return ui8FALSE;
81  }
82  break;
83  }
84  // reset to comma
85  gpsStringin[i] = ',';
86  }
87  lastCommaIndex = i;
88  }
89  }
90 
91  }
92  return ui8TRUE;
93 }
gpsData::day
I_16 day
Definition: NEO_LEA_M8T.h:36
tryParseGGAString
UI_8 tryParseGGAString(char *gpsStringin, struct gpsData *gpsDataPtr, int iGGA, int commaCount)
Definition: NEO_LEA_M8T.c:95
tryParseZDAString
UI_8 tryParseZDAString(char *gpsStringin, struct gpsData *gpsDataPtr, int iZDA, int commaCount)
Definition: NEO_LEA_M8T.c:43
gpsData::year
I_16 year
Definition: NEO_LEA_M8T.h:36
gpsData::utctime
float utctime
Definition: NEO_LEA_M8T.h:35
ui8FALSE
#define ui8FALSE
Definition: version_config.h:190
gpsData::altitude
float altitude
Definition: NEO_LEA_M8T.h:35
ATO_F
UI_8 ATO_F(const char *str, float *val)
ui8TRUE
#define ui8TRUE
Definition: version_config.h:191
charBuffMax
#define charBuffMax
Definition: version_config.h:78
gpsData::longitude
float longitude
Definition: NEO_LEA_M8T.h:35
gpsData::month
I_16 month
Definition: NEO_LEA_M8T.h:36
gpsData::lattitude
float lattitude
Definition: NEO_LEA_M8T.h:35
gpsData
Definition: NEO_LEA_M8T.h:34