Simple Geolocalization and Course Transmission Protocol (SGCTP)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
data.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Simple Geolocalization and Course Transmission Protocol (SGCTP)
5  * Copyright (C) 2014 Cedric Dufour <http://cedric.dufour.name>
6  *
7  * The Simple Geolocalization and Course Transmission Protocol (SGCTP) is
8  * free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Simple Geolocalization and Course Transmission Protocol (SGCTP) is
13  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15  * PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License for more details.
18  */
19 
20 // C
21 #include <math.h>
22 #include <time.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 // C++
28 #include <string>
29 using namespace std;
30 
31 // SGCTP
32 #include "sgctp/data.hpp"
33 using namespace SGCTP;
34 
35 
36 //----------------------------------------------------------------------
37 // CONSTANTS / STATIC
38 //----------------------------------------------------------------------
39 
40 const double CData::UNDEFINED_VALUE = NAN;
41 const double CData::OVERFLOW_VALUE = INFINITY;
42 
43 string CData::stringSourceType( int _iSourceType )
44 {
45  switch( _iSourceType )
46  {
47  case SOURCE_GPS: return "GPS";
48  case SOURCE_AIS: return "AIS";
49  case SOURCE_ADSB: return "ADS-B";
50  case SOURCE_FLARM: return "FLARM";
51  }
52  return "";
53 }
54 
55 double CData::epoch()
56 {
57  timespec __tTimespec;
58  clock_gettime( CLOCK_REALTIME, &__tTimespec ) ;
59  return( (double)__tTimespec.tv_sec
60  + (double)__tTimespec.tv_nsec/1000000000.0 );
61 }
62 
63 double CData::toEpoch( double _fdTime,
64  double _fdEpochReference )
65 {
66  if( __isnanl( _fdTime ) ) return 0.0;
67 
68  // Build "fully qualified" UNIX epoch
69  double __fdEpoch;
70  tm __tTm;
71  timespec __tTimespecNow;
72  if( _fdEpochReference == 0 )
73  {
74  clock_gettime( CLOCK_REALTIME, &__tTimespecNow ) ;
75  gmtime_r( &(__tTimespecNow.tv_sec), &__tTm );
76  }
77  else
78  {
79  time_t __ttTime = (time_t)_fdEpochReference;
80  gmtime_r( &__ttTime, &__tTm );
81  }
82  __tTm.tm_hour = 0; __tTm.tm_min = 0; __tTm.tm_sec = 0;
83  __fdEpoch = timegm( &__tTm ) + _fdTime;
84 
85  // Fix midnight innacuracies
86  if( _fdEpochReference == 0
87  && _fdTime >= 43000
88  && ( __tTimespecNow.tv_sec - (time_t)__fdEpoch ) >= 43000 )
89  __fdEpoch -= 86400;
90 
91  // Done
92  return __fdEpoch;
93 }
94 
95 void CData::toIso8601( char *_pcIso8601, double _fdEpoch )
96 {
97  double __fdSeconds;
98  double __fdSubseconds = modf( _fdEpoch, &__fdSeconds );
99  time_t __tTime = (int)__fdSeconds;
100  tm __tTM;
101  gmtime_r( &__tTime, &__tTM );
102  if( _fdEpoch >= 86400 )
103  {
104  sprintf( _pcIso8601+18, "%.3fZ", __fdSubseconds );
105  strftime( _pcIso8601, 20, "%Y-%m-%dT%H:%M:%S", &__tTM );
106  _pcIso8601[19] = '.';
107  }
108  else
109  {
110  sprintf( _pcIso8601+7, "%.3fZ", __fdSubseconds );
111  strftime( _pcIso8601, 9, "%H:%M:%S", &__tTM );
112  _pcIso8601[8] = '.';
113  }
114 }
115 
116 double CData::fromIso8601( const char *_pcIso8601 )
117 {
118  double __fdEpoch = 0.0;
119 
120  // Try potential ISO-8601 formats
121  char *__pcReturn;
122  tm __tTM;
123  memset( &__tTM, 0, sizeof( struct tm ) );
124  do
125  {
126  // ... date/time (1)
127  __pcReturn = strptime( _pcIso8601, "%Y-%m-%dT%H:%M:%S", &__tTM );
128  if( __pcReturn != NULL ) break;
129  // ... date/time (2)
130  __pcReturn = strptime( _pcIso8601, "%Y-%m-%d %H:%M:%S", &__tTM );
131  if( __pcReturn != NULL ) break;
132  // ... date
133  __pcReturn = strptime( _pcIso8601, "%Y-%m-%d", &__tTM );
134  if( __pcReturn != NULL ) break;
135  // ... time
136  char __pcTimeOnly[20];
137  snprintf( __pcTimeOnly, 20, "1970-01-01T%s", _pcIso8601 );
138  __pcReturn = strptime( __pcTimeOnly, "%Y-%m-%dT%H:%M:%S", &__tTM );
139  if( __pcReturn != NULL ) break;
140  }
141  while( false );
142  if( __pcReturn != NULL )
143  {
144  __fdEpoch = timegm( &__tTM );
145  if( *__pcReturn == '.' ) __fdEpoch += strtod( __pcReturn, NULL );
146  }
147  else
148  __fdEpoch = strtod( _pcIso8601, NULL );
149 
150  // Done
151  return __fdEpoch;
152 }
153 
154 
155 
156 //----------------------------------------------------------------------
157 // CONSTRUCTORS / DESTRUCTOR
158 //----------------------------------------------------------------------
159 
160 CData::~CData()
161 {
162  if( pucData )
163  free( pucData );
164 }
165 
166 
167 //----------------------------------------------------------------------
168 // METHODS
169 //----------------------------------------------------------------------
170 
171 //
172 // SETTERS
173 //
174 
175 void CData::reset( bool _bDataFree )
176 {
177  pcID[0] = '\0';
178  if( _bDataFree )
179  freeData();
180  ui32tTime = UNDEFINED_UINT32;
181  ui32tLongitude = UNDEFINED_UINT32;
182  ui32tLatitude = UNDEFINED_UINT32;
183  ui32tElevation = UNDEFINED_UINT32;
184  ui32tBearing = UNDEFINED_UINT32;
185  ui32tGndSpeed = UNDEFINED_UINT32;
186  ui32tVrtSpeed = UNDEFINED_UINT32;
187  ui32tBearingDt = UNDEFINED_UINT32;
188  ui32tGndSpeedDt = UNDEFINED_UINT32;
189  ui32tVrtSpeedDt = UNDEFINED_UINT32;
190  ui32tHeading = UNDEFINED_UINT32;
191  ui32tAppSpeed = UNDEFINED_UINT32;
192  ui32tSourceType = UNDEFINED_UINT32;
193  ui32tLatitudeError = UNDEFINED_UINT32;
194  ui32tLongitudeError = UNDEFINED_UINT32;
195  ui32tElevationError = UNDEFINED_UINT32;
196  ui32tBearingError = UNDEFINED_UINT32;
197  ui32tGndSpeedError = UNDEFINED_UINT32;
198  ui32tVrtSpeedError = UNDEFINED_UINT32;
199  ui32tBearingDtError = UNDEFINED_UINT32;
200  ui32tGndSpeedDtError = UNDEFINED_UINT32;
201  ui32tVrtSpeedDtError = UNDEFINED_UINT32;
202  ui32tHeadingError = UNDEFINED_UINT32;
203  ui32tAppSpeedError = UNDEFINED_UINT32;
204 }
205 
206 void CData::setID( const char *_pcID )
207 {
208  uint8_t __ui8tIDLength =
209  ( strlen( _pcID ) < 127 )
210  ? strlen( _pcID )
211  : 127;
212  memcpy( pcID, _pcID, __ui8tIDLength );
213  pcID[__ui8tIDLength] = '\0';
214 }
215 
216 uint16_t CData::setData( const unsigned char *_pucData,
217  uint16_t _ui16tDataSize )
218 {
219  allocData( _ui16tDataSize );
220  if( ui16tDataSize > 0 )
221  memcpy( pucData, _pucData, ui16tDataSize );
222  return ui16tDataSize;
223 }
224 
225 void CData::setTime( double _fdEpoch )
226 {
227  tm __tTm;
228  time_t __ttTime = (time_t)_fdEpoch;
229  gmtime_r( &__ttTime, &__tTm );
230  double __fd, __fdTime =
231  (double)( 3600*__tTm.tm_hour + 60*__tTm.tm_min + __tTm.tm_sec )
232  + modf( _fdEpoch, &__fd );
233  ui32tTime = (uint32_t)( __fdTime * 10.0 + 0.5 );
234 }
235 
236 void CData::setLongitude( double _fdLongitude )
237 {
238  if( _fdLongitude < -180.0 )
239  ui32tLongitude = 0;
240  else if( _fdLongitude > 180.0 )
241  ui32tLongitude = OVERFLOW_UINT32;
242  else
243  ui32tLongitude = (uint32_t)( _fdLongitude * 3600000.0 + 1073741824.5 );
244 }
245 
246 void CData::setElevation( double _fdElevation )
247 {
248  if( _fdElevation < -13107.15 )
249  ui32tElevation = 0;
250  else if( _fdElevation > 39321.35 )
251  ui32tElevation = OVERFLOW_UINT32;
252  else
253  ui32tElevation = (uint32_t)( _fdElevation * 10.0 + 131072.5 );
254 }
255 
256 void CData::setLatitude( double _fdLatitude )
257 {
258  if( _fdLatitude < -90.0 )
259  ui32tLatitude = 0;
260  else if( _fdLatitude > 90.0 )
261  ui32tLatitude = OVERFLOW_UINT32;
262  else
263  ui32tLatitude = (uint32_t)( _fdLatitude * 3600000.0 + 536870912.5 );
264 }
265 
266 void CData::setBearing( double _fdBearing )
267 {
268  if( _fdBearing < 0.0 )
269  ui32tBearing = OVERFLOW_UINT32;
270  else if( _fdBearing >= 360.0 )
271  ui32tBearing = OVERFLOW_UINT32;
272  else
273  ui32tBearing = (uint32_t)( _fdBearing * 10.0 + 0.5 );
274 }
275 
276 void CData::setGndSpeed( double _fdGndSpeed )
277 {
278  if( _fdGndSpeed < 0.0 )
279  ui32tGndSpeed = 0;
280  else if( _fdGndSpeed > 6553.35 )
281  ui32tGndSpeed = OVERFLOW_UINT32;
282  else
283  ui32tGndSpeed = (uint32_t)( _fdGndSpeed * 10.0 + 1.5 );
284 }
285 
286 void CData::setVrtSpeed( double _fdVrtSpeed )
287 {
288  if( _fdVrtSpeed < -409.55 )
289  ui32tVrtSpeed = 0;
290  else if( _fdVrtSpeed > 409.35 )
291  ui32tVrtSpeed = OVERFLOW_UINT32;
292  else
293  ui32tVrtSpeed = (uint32_t)( _fdVrtSpeed * 10.0 + 4096.5 );
294 }
295 
296 void CData::setBearingDt( double _fdBearingDt )
297 {
298  if( _fdBearingDt < -51.15 )
299  ui32tBearingDt = 0;
300  else if( _fdBearingDt > 50.95 )
301  ui32tBearingDt = OVERFLOW_UINT32;
302  else
303  ui32tBearingDt = (uint32_t)( _fdBearingDt * 10.0 + 512.5 );
304 }
305 
306 void CData::setGndSpeedDt( double _fdGndSpeedDt )
307 {
308  if( _fdGndSpeedDt < -204.75 )
309  ui32tGndSpeedDt = 0;
310  else if( _fdGndSpeedDt > 204.55 )
311  ui32tGndSpeedDt = OVERFLOW_UINT32;
312  else
313  ui32tGndSpeedDt = (uint32_t)( _fdGndSpeedDt * 10.0 + 2048.5 );
314 }
315 
316 void CData::setVrtSpeedDt( double _fdVrtSpeedDt )
317 {
318  if( _fdVrtSpeedDt < -204.75 )
319  ui32tVrtSpeedDt = 0;
320  else if( _fdVrtSpeedDt > 204.55 )
321  ui32tVrtSpeedDt = OVERFLOW_UINT32;
322  else
323  ui32tVrtSpeedDt = (uint32_t)( _fdVrtSpeedDt * 10.0 + 2048.5 );
324 }
325 
326 void CData::setHeading( double _fdHeading )
327 {
328  if( _fdHeading < 0.0 )
329  ui32tHeading = OVERFLOW_UINT32;
330  else if( _fdHeading > 360.0 )
331  ui32tHeading = OVERFLOW_UINT32;
332  else
333  ui32tHeading = (uint32_t)( _fdHeading * 10.0 + 0.5 );
334 }
335 
336 void CData::setAppSpeed( double _fdAppSpeed )
337 {
338  if( _fdAppSpeed < 0.0 )
339  ui32tAppSpeed = 0;
340  else if( _fdAppSpeed > 6553.35 )
341  ui32tAppSpeed = OVERFLOW_UINT32;
342  else
343  ui32tAppSpeed = (uint32_t)( _fdAppSpeed * 10.0 + 1.5 );
344 }
345 
346 void CData::setLatitudeError( double _fdLatitudeError )
347 {
348  _fdLatitudeError = fabs( _fdLatitudeError );
349  if( _fdLatitudeError > 409.45 )
350  ui32tLatitudeError = OVERFLOW_UINT32;
351  else
352  ui32tLatitudeError = (uint32_t)( _fdLatitudeError * 10.0 + 0.5 );
353 }
354 
355 void CData::setLongitudeError( double _fdLongitudeError )
356 {
357  _fdLongitudeError = fabs( _fdLongitudeError );
358  if( _fdLongitudeError > 409.45 )
359  ui32tLongitudeError = OVERFLOW_UINT32;
360  else
361  ui32tLongitudeError = (uint32_t)( _fdLongitudeError * 10.0 + 0.5 );
362 }
363 
364 void CData::setElevationError( double _fdElevationError )
365 {
366  _fdElevationError = fabs( _fdElevationError );
367  if( _fdElevationError > 409.45 )
368  ui32tElevationError = OVERFLOW_UINT32;
369  else
370  ui32tElevationError = (uint32_t)( _fdElevationError * 10.0 + 0.5 );
371 }
372 
373 void CData::setBearingError( double _fdBearingError )
374 {
375  _fdBearingError = fabs( _fdBearingError );
376  if( _fdBearingError > 25.45 )
377  ui32tBearingError = OVERFLOW_UINT32;
378  else
379  ui32tBearingError = (uint32_t)( _fdBearingError * 10.0 + 0.5 );
380 }
381 
382 void CData::setGndSpeedError( double _fdGndSpeedError )
383 {
384  _fdGndSpeedError = fabs( _fdGndSpeedError );
385  if( _fdGndSpeedError > 25.45 )
386  ui32tGndSpeedError = OVERFLOW_UINT32;
387  else
388  ui32tGndSpeedError = (uint32_t)( _fdGndSpeedError * 10.0 + 0.5 );
389 }
390 
391 void CData::setVrtSpeedError( double _fdVrtSpeedError )
392 {
393  _fdVrtSpeedError = fabs( _fdVrtSpeedError );
394  if( _fdVrtSpeedError > 25.45 )
395  ui32tVrtSpeedError = OVERFLOW_UINT32;
396  else
397  ui32tVrtSpeedError = (uint32_t)( _fdVrtSpeedError * 10.0 + 0.5 );
398 }
399 
400 void CData::setBearingDtError( double _fdBearingDtError )
401 {
402  _fdBearingDtError = fabs( _fdBearingDtError );
403  if( _fdBearingDtError > 25.45 )
404  ui32tBearingDtError = OVERFLOW_UINT32;
405  else
406  ui32tBearingDtError = (uint32_t)( _fdBearingDtError * 10.0 + 0.5 );
407 }
408 
409 void CData::setGndSpeedDtError( double _fdGndSpeedDtError )
410 {
411  _fdGndSpeedDtError = fabs( _fdGndSpeedDtError );
412  if( _fdGndSpeedDtError > 25.45 )
413  ui32tGndSpeedDtError = OVERFLOW_UINT32;
414  else
415  ui32tGndSpeedDtError = (uint32_t)( _fdGndSpeedDtError * 10.0 + 0.5 );
416 }
417 
418 void CData::setVrtSpeedDtError( double _fdVrtSpeedDtError )
419 {
420  _fdVrtSpeedDtError = fabs( _fdVrtSpeedDtError );
421  if( _fdVrtSpeedDtError > 25.45 )
422  ui32tVrtSpeedDtError = OVERFLOW_UINT32;
423  else
424  ui32tVrtSpeedDtError = (uint32_t)( _fdVrtSpeedDtError * 10.0 + 0.5 );
425 }
426 
427 void CData::setHeadingError( double _fdHeadingError )
428 {
429  _fdHeadingError = fabs( _fdHeadingError );
430  if( _fdHeadingError > 25.45 )
431  ui32tHeadingError = OVERFLOW_UINT32;
432  else
433  ui32tHeadingError = (uint32_t)( _fdHeadingError * 10.0 + 0.5 );
434 }
435 
436 void CData::setAppSpeedError( double _fdAppSpeedError )
437 {
438  _fdAppSpeedError = fabs( _fdAppSpeedError );
439  if( _fdAppSpeedError > 25.45 )
440  ui32tAppSpeedError = OVERFLOW_UINT32;
441  else
442  ui32tAppSpeedError = (uint32_t)( _fdAppSpeedError * 10.0 + 0.5 );
443 }
444 
445 
446 //
447 // GETTERS
448 //
449 
450 void CData::getData( unsigned char *_pucData,
451  uint16_t *_pui16tDataSize ) const
452 {
453  if( _pucData )
454  memcpy( _pucData, pucData, ui16tDataSize );
455  if( _pui16tDataSize )
456  *_pui16tDataSize = ui16tDataSize;
457 }
458 
459 double CData::getTime() const
460 {
461  if( ui32tTime & UNDEFINED_UINT32 )
462  return UNDEFINED_VALUE;
463  return (double)ui32tTime * 0.1;
464 }
465 
466 double CData::getLatitude() const
467 {
468  if( ui32tLatitude & UNDEFINED_UINT32 )
469  return UNDEFINED_VALUE;
470  if( ui32tLatitude == 0 )
471  return -OVERFLOW_VALUE;
472  if( ui32tLatitude == OVERFLOW_UINT32 )
473  return OVERFLOW_VALUE;
474  return ( (double)ui32tLatitude - 536870912.0 ) / 36.0 * 0.00001;
475 }
476 
477 double CData::getLongitude() const
478 {
479  if( ui32tLongitude & UNDEFINED_UINT32 )
480  return UNDEFINED_VALUE;
481  if( ui32tLongitude == 0 )
482  return -OVERFLOW_VALUE;
483  if( ui32tLongitude == OVERFLOW_UINT32 )
484  return OVERFLOW_VALUE;
485  return ( (double)ui32tLongitude - 1073741824.0 ) / 36.0 * 0.00001;
486 }
487 
488 double CData::getElevation() const
489 {
490  if( ui32tElevation & UNDEFINED_UINT32 )
491  return UNDEFINED_VALUE;
492  if( ui32tElevation == 0 )
493  return -OVERFLOW_VALUE;
494  if( ui32tElevation == OVERFLOW_UINT32 )
495  return OVERFLOW_VALUE;
496  return ( (double)ui32tElevation - 131072.0 ) * 0.1;
497 }
498 
499 double CData::getBearing() const
500 {
501  if( ui32tBearing & UNDEFINED_UINT32 )
502  return UNDEFINED_VALUE;
503  if( ui32tBearing == OVERFLOW_UINT32 )
504  return OVERFLOW_VALUE;
505  return (double)ui32tBearing * 0.1;
506 }
507 
508 double CData::getGndSpeed() const
509 {
510  if( ui32tGndSpeed & UNDEFINED_UINT32 )
511  return UNDEFINED_VALUE;
512  if( ui32tGndSpeed == 0 )
513  return -OVERFLOW_VALUE;
514  if( ui32tGndSpeed == OVERFLOW_UINT32 )
515  return OVERFLOW_VALUE;
516  return ( (double)ui32tGndSpeed - 1.0 ) * 0.1;
517 }
518 
519 double CData::getVrtSpeed() const
520 {
521  if( ui32tVrtSpeed & UNDEFINED_UINT32 )
522  return UNDEFINED_VALUE;
523  if( ui32tVrtSpeed == 0 )
524  return -OVERFLOW_VALUE;
525  if( ui32tVrtSpeed == OVERFLOW_UINT32 )
526  return OVERFLOW_VALUE;
527  return ( (double)ui32tVrtSpeed - 4096.0 ) * 0.1;
528 }
529 
530 double CData::getBearingDt() const
531 {
532  if( ui32tBearingDt & UNDEFINED_UINT32 )
533  return UNDEFINED_VALUE;
534  if( ui32tBearingDt == 0 )
535  return -OVERFLOW_VALUE;
536  if( ui32tBearingDt == OVERFLOW_UINT32 )
537  return OVERFLOW_VALUE;
538  return ( (double)ui32tBearingDt - 512.0 ) * 0.1;
539 }
540 
541 double CData::getGndSpeedDt() const
542 {
543  if( ui32tGndSpeedDt & UNDEFINED_UINT32 )
544  return UNDEFINED_VALUE;
545  if( ui32tGndSpeedDt == 0 )
546  return -OVERFLOW_VALUE;
547  if( ui32tGndSpeedDt == OVERFLOW_UINT32 )
548  return OVERFLOW_VALUE;
549  return ( (double)ui32tGndSpeedDt - 2048.0 ) * 0.1;
550 }
551 
552 double CData::getVrtSpeedDt() const
553 {
554  if( ui32tVrtSpeedDt & UNDEFINED_UINT32 )
555  return UNDEFINED_VALUE;
556  if( ui32tVrtSpeedDt == 0 )
557  return -OVERFLOW_VALUE;
558  if( ui32tVrtSpeedDt == OVERFLOW_UINT32 )
559  return OVERFLOW_VALUE;
560  return ( (double)ui32tVrtSpeedDt - 2048.0 ) * 0.1;
561 }
562 
563 double CData::getHeading() const
564 {
565  if( ui32tHeading & UNDEFINED_UINT32 )
566  return UNDEFINED_VALUE;
567  if( ui32tHeading == OVERFLOW_UINT32 )
568  return OVERFLOW_VALUE;
569  return (double)ui32tHeading * 0.1;
570 }
571 
572 double CData::getAppSpeed() const
573 {
574  if( ui32tAppSpeed & UNDEFINED_UINT32 )
575  return UNDEFINED_VALUE;
576  if( ui32tAppSpeed == 0 )
577  return -OVERFLOW_VALUE;
578  if( ui32tAppSpeed == OVERFLOW_UINT32 )
579  return OVERFLOW_VALUE;
580  return ( (double)ui32tAppSpeed - 1.0 ) * 0.1;
581 }
582 
583 double CData::getLatitudeError() const
584 {
585  if( ui32tLatitudeError & UNDEFINED_UINT32 )
586  return UNDEFINED_VALUE;
587  if( ui32tLatitudeError == OVERFLOW_UINT32 )
588  return OVERFLOW_VALUE;
589  return (double)ui32tLatitudeError * 0.1;
590 }
591 
592 double CData::getLongitudeError() const
593 {
594  if( ui32tLongitudeError & UNDEFINED_UINT32 )
595  return UNDEFINED_VALUE;
596  if( ui32tLongitudeError == OVERFLOW_UINT32 )
597  return OVERFLOW_VALUE;
598  return (double)ui32tLongitudeError * 0.1;
599 }
600 
601 double CData::getElevationError() const
602 {
603  if( ui32tElevationError & UNDEFINED_UINT32 )
604  return UNDEFINED_VALUE;
605  if( ui32tElevationError == OVERFLOW_UINT32 )
606  return OVERFLOW_VALUE;
607  return (double)ui32tElevationError * 0.1;
608 }
609 
610 double CData::getBearingError() const
611 {
612  if( ui32tBearingError & UNDEFINED_UINT32 )
613  return UNDEFINED_VALUE;
614  if( ui32tBearingError == OVERFLOW_UINT32 )
615  return OVERFLOW_VALUE;
616  return (double)ui32tBearingError * 0.1;
617 }
618 
619 double CData::getGndSpeedError() const
620 {
621  if( ui32tGndSpeedError & UNDEFINED_UINT32 )
622  return UNDEFINED_VALUE;
623  if( ui32tGndSpeedError == OVERFLOW_UINT32 )
624  return OVERFLOW_VALUE;
625  return (double)ui32tGndSpeedError * 0.1;
626 }
627 
628 double CData::getVrtSpeedError() const
629 {
630  if( ui32tVrtSpeedError & UNDEFINED_UINT32 )
631  return UNDEFINED_VALUE;
632  if( ui32tVrtSpeedError == OVERFLOW_UINT32 )
633  return OVERFLOW_VALUE;
634  return (double)ui32tVrtSpeedError * 0.1;
635 }
636 
637 double CData::getBearingDtError() const
638 {
639  if( ui32tBearingDtError & UNDEFINED_UINT32 )
640  return UNDEFINED_VALUE;
641  if( ui32tBearingDtError == OVERFLOW_UINT32 )
642  return OVERFLOW_VALUE;
643  return (double)ui32tBearingDtError * 0.1;
644 }
645 
646 double CData::getGndSpeedDtError() const
647 {
648  if( ui32tGndSpeedDtError & UNDEFINED_UINT32 )
649  return UNDEFINED_VALUE;
650  if( ui32tGndSpeedDtError == OVERFLOW_UINT32 )
651  return OVERFLOW_VALUE;
652  return (double)ui32tGndSpeedDtError * 0.1;
653 }
654 
655 double CData::getVrtSpeedDtError() const
656 {
657  if( ui32tVrtSpeedDtError & UNDEFINED_UINT32 )
658  return UNDEFINED_VALUE;
659  if( ui32tVrtSpeedDtError == OVERFLOW_UINT32 )
660  return OVERFLOW_VALUE;
661  return (double)ui32tVrtSpeedDtError * 0.1;
662 }
663 
664 double CData::getHeadingError() const
665 {
666  if( ui32tHeadingError & UNDEFINED_UINT32 )
667  return UNDEFINED_VALUE;
668  if( ui32tHeadingError == OVERFLOW_UINT32 )
669  return OVERFLOW_VALUE;
670  return (double)ui32tHeadingError * 0.1;
671 }
672 
673 double CData::getAppSpeedError() const
674 {
675  if( ui32tAppSpeedError & UNDEFINED_UINT32 )
676  return UNDEFINED_VALUE;
677  if( ui32tAppSpeedError == OVERFLOW_UINT32 )
678  return OVERFLOW_VALUE;
679  return (double)ui32tAppSpeedError * 0.1;
680 }
681 
682 
683 //
684 // OTHERS
685 //
686 
687 uint16_t CData::allocData( uint16_t _ui16tDataSize )
688 {
689  int __ui16tDataSize =
690  ( _ui16tDataSize < 32767 )
691  ? _ui16tDataSize
692  : 32767;
693  if( __ui16tDataSize != ui16tDataSize )
694  {
695  pucData =
696  (unsigned char*)realloc( pucData,
697  __ui16tDataSize * sizeof( unsigned char ) );
698  ui16tDataSize =
699  pucData
700  ? __ui16tDataSize
701  : -1;
702  }
703  return ui16tDataSize;
704 }
705 
706 void CData::freeData()
707 {
708  if( pucData )
709  free( pucData );
710  pucData = NULL;
711  ui16tDataSize = 0;
712 }
713 
714 void CData::copy( const CData &_roData )
715 {
716  if( &_roData == this )
717  return;
718 
719  // Save pointers
720  unsigned char *__pucData = this->pucData;
721 
722  // Copy all
723  memcpy( this, &_roData, sizeof( CData ) );
724 
725  // Recover pointers
726  this->pucData = __pucData;
727 
728  // Copy pointers content
729  if( _roData.ui16tDataSize > 0 )
730  {
731  this->allocData( _roData.ui16tDataSize );
732  memcpy( this->pucData, _roData.pucData, _roData.ui16tDataSize );
733  }
734  else
735  this->freeData();
736 }
737 
738 bool CData::sync( const CData &_roData )
739 {
740  bool __bSynced = false;
741  if( &_roData == this )
742  return __bSynced;
743  if( _roData.ui16tDataSize > 0 )
744  {
745  this->allocData( _roData.ui16tDataSize );
746  memcpy( this->pucData, _roData.pucData, _roData.ui16tDataSize );
747  __bSynced = true;
748  }
749  else if( this->ui16tDataSize > 0 )
750  {
751  this->freeData();
752  __bSynced = true;
753  }
754  if( !( _roData.ui32tTime & UNDEFINED_UINT32 ) )
755  {
756  this->ui32tTime = _roData.ui32tTime;
757  __bSynced = true;
758  }
759  if( !( _roData.ui32tLatitude & UNDEFINED_UINT32 ) )
760  {
761  this->ui32tLatitude = _roData.ui32tLatitude;
762  __bSynced = true;
763  }
764  if( !( _roData.ui32tLongitude & UNDEFINED_UINT32 ) )
765  {
766  this->ui32tLongitude = _roData.ui32tLongitude;
767  __bSynced = true;
768  }
769  if( !( _roData.ui32tElevation & UNDEFINED_UINT32 ) )
770  {
771  this->ui32tElevation = _roData.ui32tElevation;
772  __bSynced = true;
773  }
774  if( !( _roData.ui32tBearing & UNDEFINED_UINT32 ) )
775  {
776  this->ui32tBearing = _roData.ui32tBearing;
777  __bSynced = true;
778  }
779  if( !( _roData.ui32tGndSpeed & UNDEFINED_UINT32 ) )
780  {
781  this->ui32tGndSpeed = _roData.ui32tGndSpeed;
782  __bSynced = true;
783  }
784  if( !( _roData.ui32tVrtSpeed & UNDEFINED_UINT32 ) )
785  {
786  this->ui32tVrtSpeed = _roData.ui32tVrtSpeed;
787  __bSynced = true;
788  }
789  if( !( _roData.ui32tBearingDt & UNDEFINED_UINT32 ) )
790  {
791  this->ui32tBearingDt = _roData.ui32tBearingDt;
792  __bSynced = true;
793  }
794  if( !( _roData.ui32tGndSpeedDt & UNDEFINED_UINT32 ) )
795  {
796  this->ui32tGndSpeedDt = _roData.ui32tGndSpeedDt;
797  __bSynced = true;
798  }
799  if( !( _roData.ui32tVrtSpeedDt & UNDEFINED_UINT32 ) )
800  {
801  this->ui32tVrtSpeedDt = _roData.ui32tVrtSpeedDt;
802  __bSynced = true;
803  }
804  if( !( _roData.ui32tHeading & UNDEFINED_UINT32 ) )
805  {
806  this->ui32tHeading = _roData.ui32tHeading;
807  __bSynced = true;
808  }
809  if( !( _roData.ui32tAppSpeed & UNDEFINED_UINT32 ) )
810  {
811  this->ui32tAppSpeed = _roData.ui32tAppSpeed;
812  __bSynced = true;
813  }
814  if( !( _roData.ui32tSourceType & UNDEFINED_UINT32 ) )
815  {
816  this->ui32tSourceType = _roData.ui32tSourceType;
817  __bSynced = true;
818  }
819  if( !( _roData.ui32tLatitudeError & UNDEFINED_UINT32 ) )
820  {
821  this->ui32tLatitudeError = _roData.ui32tLatitudeError;
822  __bSynced = true;
823  }
824  if( !( _roData.ui32tLongitudeError & UNDEFINED_UINT32 ) )
825  {
826  this->ui32tLongitudeError = _roData.ui32tLongitudeError;
827  __bSynced = true;
828  }
829  if( !( _roData.ui32tElevationError & UNDEFINED_UINT32 ) )
830  {
831  this->ui32tElevationError = _roData.ui32tElevationError;
832  __bSynced = true;
833  }
834  if( !( _roData.ui32tBearingError & UNDEFINED_UINT32 ) )
835  {
836  this->ui32tBearingError = _roData.ui32tBearingError;
837  __bSynced = true;
838  }
839  if( !( _roData.ui32tGndSpeedError & UNDEFINED_UINT32 ) )
840  {
841  this->ui32tGndSpeedError = _roData.ui32tGndSpeedError;
842  __bSynced = true;
843  }
844  if( !( _roData.ui32tVrtSpeedError & UNDEFINED_UINT32 ) )
845  {
846  this->ui32tVrtSpeedError = _roData.ui32tVrtSpeedError;
847  __bSynced = true;
848  }
849  if( !( _roData.ui32tBearingDtError & UNDEFINED_UINT32 ) )
850  {
851  this->ui32tBearingDtError = _roData.ui32tBearingDtError;
852  __bSynced = true;
853  }
854  if( !( _roData.ui32tGndSpeedDtError & UNDEFINED_UINT32 ) )
855  {
856  this->ui32tGndSpeedDtError = _roData.ui32tGndSpeedDtError;
857  __bSynced = true;
858  }
859  if( !( _roData.ui32tVrtSpeedDtError & UNDEFINED_UINT32 ) )
860  {
861  this->ui32tVrtSpeedDtError = _roData.ui32tVrtSpeedDtError;
862  __bSynced = true;
863  }
864  if( !( _roData.ui32tHeadingError & UNDEFINED_UINT32 ) )
865  {
866  this->ui32tHeadingError = _roData.ui32tHeadingError;
867  __bSynced = true;
868  }
869  if( !( _roData.ui32tAppSpeedError & UNDEFINED_UINT32 ) )
870  {
871  this->ui32tAppSpeedError = _roData.ui32tAppSpeedError;
872  __bSynced = true;
873  }
874  return __bSynced;
875 }
uint32_t ui32tHeadingError
Heading error.
Definition: data.hpp:175
uint32_t ui32tElevationError
Elevation error.
Definition: data.hpp:161
uint32_t ui32tSourceType
Source type.
Definition: data.hpp:155
uint32_t ui32tBearingError
Bearing error.
Definition: data.hpp:163
uint32_t ui32tVrtSpeed
Vertical speed.
Definition: data.hpp:143
uint32_t ui32tGndSpeed
Ground speed.
Definition: data.hpp:141
uint16_t ui16tDataSize
Data size.
Definition: data.hpp:129
uint32_t ui32tElevation
Elevation.
Definition: data.hpp:137
uint32_t ui32tLatitudeError
Latitude error.
Definition: data.hpp:157
SGCTP data container.
Definition: data.hpp:44
uint32_t ui32tGndSpeedError
Ground speed error.
Definition: data.hpp:165
unsigned char * pucData
Data (max. 32767 symbols)
Definition: data.hpp:127
uint32_t ui32tBearingDtError
Bearing variation over time (rate of turn) error.
Definition: data.hpp:169
uint32_t ui32tLatitude
Latitude.
Definition: data.hpp:133
uint32_t ui32tHeading
Heading.
Definition: data.hpp:151
uint32_t ui32tLongitudeError
Longitude error.
Definition: data.hpp:159
uint32_t ui32tVrtSpeedDt
Vertical speed variation over time (acceleration)
Definition: data.hpp:149
uint32_t ui32tAppSpeedError
Apparent speed error.
Definition: data.hpp:177
uint32_t ui32tTime
Time.
Definition: data.hpp:131
uint32_t ui32tLongitude
Longitude.
Definition: data.hpp:135
uint32_t ui32tBearingDt
Bearing variation over time (rate of turn)
Definition: data.hpp:145
uint32_t ui32tBearing
Bearing.
Definition: data.hpp:139
uint32_t ui32tGndSpeedDt
Ground speed variation over time (acceleration)
Definition: data.hpp:147
uint32_t ui32tVrtSpeedError
Vertical speed error.
Definition: data.hpp:167
uint32_t ui32tGndSpeedDtError
Ground speed variation over time (acceleration) error.
Definition: data.hpp:171
uint32_t ui32tVrtSpeedDtError
Vertical speed variation over time (acceleration) error.
Definition: data.hpp:173
uint32_t ui32tAppSpeed
Apparent speed.
Definition: data.hpp:153