Simple Geolocalization and Course Transmission Protocol (SGCTP)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
data.hpp
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 #ifndef SGCTP_CDATA_HPP
21 #define SGCTP_CDATA_HPP
22 
23 // C
24 #include <math.h>
25 #include <stdint.h>
26 #include <string.h>
27 
28 // C++
29 #include <string>
30 using namespace std;
31 
32 // SGCTP namespace
33 namespace SGCTP
34 {
35 
37 
44  class CData
45  {
46  friend class CPayload;
47 
48  //----------------------------------------------------------------------
49  // CONSTANTS / STATIC
50  //----------------------------------------------------------------------
51 
52  public:
54  enum ESourceType {
55  SOURCE_UNDEFINED = 0,
56  SOURCE_GPS = 1,
57  SOURCE_AIS = 2,
58  SOURCE_ADSB = 3,
59  SOURCE_FLARM = 4
60  };
61 
62  private:
64  static const uint32_t UNDEFINED_UINT32 = 0x80000000;
66  static const uint32_t OVERFLOW_UINT32 = 0x7FFFFFFF;
67 
68  public:
70  static const double UNDEFINED_VALUE;
72  static const double OVERFLOW_VALUE;
74  static const uint8_t MAX_ID_LENGTH = 127;
76  static const uint8_t MAX_ID_SIZE = 128;
78  static const uint16_t MAX_DATA_SIZE = 32767;
80  inline static bool isDefined( double _fdValue )
81  {
82  return !__isnanl( _fdValue );
83  };
85  inline static bool isValid( double _fdValue ) {
86  return !__isinfl( _fdValue );
87  };
89 
93  static string stringSourceType( int _iSourceType );
95  static double epoch();
97 
102  static double toEpoch( double _fdTime,
103  double _fdEpochReference = 0 );
105 
109  static void toIso8601( char *_pcIso8601,
110  double _fdEpoch );
112 
116  static double fromIso8601( const char *_pcIso8601 );
117 
118 
119  //----------------------------------------------------------------------
120  // FIELDS
121  //----------------------------------------------------------------------
122 
123  private:
125  char pcID[MAX_ID_SIZE];
127  unsigned char *pucData;
129  uint16_t ui16tDataSize;
131  uint32_t ui32tTime;
133  uint32_t ui32tLatitude;
135  uint32_t ui32tLongitude;
137  uint32_t ui32tElevation;
139  uint32_t ui32tBearing;
141  uint32_t ui32tGndSpeed;
143  uint32_t ui32tVrtSpeed;
145  uint32_t ui32tBearingDt;
147  uint32_t ui32tGndSpeedDt;
149  uint32_t ui32tVrtSpeedDt;
151  uint32_t ui32tHeading;
153  uint32_t ui32tAppSpeed;
155  uint32_t ui32tSourceType;
178 
179 
180  //----------------------------------------------------------------------
181  // CONSTRUCTORS / DESTRUCTOR
182  //----------------------------------------------------------------------
183 
184  public:
186  : pucData( NULL )
187  {
188  reset();
189  }
190  ~CData();
191 
192 
193  //----------------------------------------------------------------------
194  // METHODS
195  //----------------------------------------------------------------------
196 
197  //
198  // SETTERS
199  //
200 
201  public:
203 
206  void reset( bool _bDataFree = true );
208  void setID( const char *_pcID );
210  uint16_t setData( const unsigned char *_pucData,
211  uint16_t _ui16tDataSize );
213 
216  void setTime( double _fdEpoch );
218  void setLatitude( double _fdLatitude );
220  void setLongitude( double _fdLongitude );
222  void setElevation( double _fdElevation );
224  void setBearing( double _fdBearing );
226  void setGndSpeed( double _fdGndSpeed );
228  void setVrtSpeed( double _fdVrtSpeed );
230  void setBearingDt( double _fdBearingDt );
232  void setGndSpeedDt( double _fdGndSpeedDt );
234  void setVrtSpeedDt( double _fdVrtSpeedDt );
236  void setHeading( double _fdHeading );
238  void setAppSpeed( double _fdApparentSpeed );
240  void setSourceType( ESourceType _eSourceType )
241  { ui32tSourceType =
242  ( _eSourceType != SOURCE_UNDEFINED )
243  ? _eSourceType
244  : UNDEFINED_UINT32;
245  };
247  void setLatitudeError( double _fdLatitudeError );
249  void setLongitudeError( double _fdLongitudeError );
251  void setElevationError( double _fdElevationError );
253  void setBearingError( double _fdBearingError );
255  void setGndSpeedError( double _fdGndSpeedError );
257  void setVrtSpeedError( double _fdVrtSpeedError );
259  void setBearingDtError( double _fdBearingDtError );
261  void setGndSpeedDtError( double _fdGndSpeedDtError );
263  void setVrtSpeedDtError( double _fdVrtSpeedDtError );
265  void setHeadingError( double _fdHeadingError );
267  void setAppSpeedError( double _fdApparentSpeedError );
268 
269 
270  //
271  // GETTERS
272  //
273 
274  public:
276  const char* getID() const
277  {
278  return pcID;
279  };
281  void getData( unsigned char *_pucData,
282  uint16_t *_pui16tDataSize ) const;
284  const unsigned char* getData() const
285  {
286  return pucData;
287  };
289  const uint16_t getDataSize() const
290  {
291  return ui16tDataSize;
292  };
294  double getTime() const;
296  double getLatitude() const;
298  double getLongitude() const;
300  double getElevation() const;
302  double getBearing() const;
304  double getGndSpeed() const;
306  double getVrtSpeed() const;
308  double getBearingDt() const;
310  double getGndSpeedDt() const;
312  double getVrtSpeedDt() const;
314  double getHeading() const;
316  double getAppSpeed() const;
319  {
320  return (ESourceType)(ui32tSourceType & 0xFF);
321  };
323  double getLatitudeError() const;
325  double getLongitudeError() const;
327  double getElevationError() const;
329  double getBearingError() const;
331  double getGndSpeedError() const;
333  double getVrtSpeedError() const;
335  double getBearingDtError() const;
337  double getGndSpeedDtError() const;
339  double getVrtSpeedDtError() const;
341  double getHeadingError() const;
343  double getAppSpeedError() const;
344 
345 
346  //
347  // OTHERS
348  //
349 
350  private:
352  uint16_t allocData( uint16_t _ui16tDataSize );
353 
354  public:
356  void freeData();
358  void copy( const CData &_roData );
360 
363  bool sync( const CData &_roData );
364 
365  };
366 
367 }
368 
369 #endif // SGCTP_CDATA_HPP
static const double OVERFLOW_VALUE
Overflow value.
Definition: data.hpp:72
uint32_t ui32tHeadingError
Heading error.
Definition: data.hpp:175
const uint16_t getDataSize() const
Return the data size.
Definition: data.hpp:289
uint32_t ui32tElevationError
Elevation error.
Definition: data.hpp:161
static bool isDefined(double _fdValue)
Return whether the given value is defined.
Definition: data.hpp:80
uint32_t ui32tSourceType
Source type.
Definition: data.hpp:155
ESourceType getSourceType() const
Return the source type.
Definition: data.hpp:318
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
ESourceType
Data source types.
Definition: data.hpp:54
uint32_t ui32tElevation
Elevation.
Definition: data.hpp:137
uint32_t ui32tLatitudeError
Latitude error.
Definition: data.hpp:157
SGCTP data container.
Definition: data.hpp:44
void setSourceType(ESourceType _eSourceType)
Set the source type.
Definition: data.hpp:240
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
(Raw) SGCTP payload
Definition: payload.hpp:41
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
const char * getID() const
Return the ID string.
Definition: data.hpp:276
static const double UNDEFINED_VALUE
Undefined value.
Definition: data.hpp:70
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
static bool isValid(double _fdValue)
Return whether the given value is valid (does not overflow)
Definition: data.hpp:85
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
const unsigned char * getData() const
Return the data.
Definition: data.hpp:284
uint32_t ui32tVrtSpeedDtError
Vertical speed variation over time (acceleration) error.
Definition: data.hpp:173
uint32_t ui32tAppSpeed
Apparent speed.
Definition: data.hpp:153