ITS
GPSProvider.cpp
Go to the documentation of this file.
1 #include "GPSProvider.h"
2 
3 #include <QDebug>
4 
5 #include <math.h>
6 
7 #include <apiCDD.h>
8 
10 {
11 }
12 
14 {
15 }
16 
18 {
19  int rc; /* Return code. */
20 
21  struct gps_data_t gps_data; /* Data from GPS signal. */
22  memset(&gps_data, 0, sizeof gps_data);
23  if ((rc = gps_open(m_data.m_address.toStdString().c_str(), m_data.m_port.toStdString().c_str(), &gps_data)) == -1)
24  {
25  qDebug() << "code: " << rc << ", reason: ", gps_errstr(rc);
29  getTimestamp();
30  return;
31  }
32  gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL);
33 
34  while(true)
35  {
36  /* Wait for 100 milliseconds to receive data/ */
37  if (gps_waiting (&gps_data, 1000000))
38  {
39  printf("Read GPS data\n");
40  /* Read data. */
41  if ((rc = gps_read(&gps_data)) == -1)
42  {
43  qDebug() << "error occured reading gps data. code: " << rc << ", reason: " << gps_errstr(rc);
47  getTimestamp();
48  } else
49  {
50  /* Feed data from the GPS receiver. */
51  if ((gps_data.status == STATUS_FIX) &&
52  (gps_data.fix.mode == MODE_2D || gps_data.fix.mode == MODE_3D) &&
53  !isnan(gps_data.fix.latitude) &&
54  !isnan(gps_data.fix.longitude))
55  {
56  m_data.m_referencePosition.altitude.altitudeValue = gps_data.fix.altitude * 100;
58  m_data.m_referencePosition.latitude = gps_data.fix.latitude * 10000000;
59  m_data.m_referencePosition.longitude = gps_data.fix.longitude * 10000000;
60  m_data.m_speed.speedValue = gps_data.fix.speed * 100;
61  if(isnan(gps_data.fix.eps))
63  else
64  {
65  if((gps_data.fix.eps * 100) > SpeedConfidence_outOfRange)
67  else
68  m_data.m_speed.speedConfidence = gps_data.fix.eps;
69  }
70  m_data.m_heading.headingValue = gps_data.fix.track * 10;
71  if(isnan(gps_data.fix.epd))
73  else
74  {
75  if((gps_data.fix.epd * 10) > HeadingConfidence_outOfRange)
77  else
78  m_data.m_heading.headingConfidence = gps_data.fix.epd * 10;
79  }
80  getTimestamp();
82  emit positionChanged();
83  } else
84  {
85  qDebug() << "no GPS data available";
89  getTimestamp();
90  }
91  }
92  }
93  else
94  {
98  getTimestamp();
99  }
100  }
101  printf("Leaving GPS\n");
102 
103  /* When you are done... */
104  gps_stream(&gps_data, WATCH_DISABLE, NULL);
105  gps_close (&gps_data);
106 }
107 
109 {
110  if(!epv || isnan(epv))
112  if(epv < 10)
114  if(epv < 20)
116  if(epv < 50)
118  if(epv < 100)
120  if(epv < 200)
122  if(epv < 500)
124  if(epv < 1000)
126  if(epv < 2000)
128  if(epv < 5000)
130  if(epv < 10000)
132  if(epv < 20000)
134  if(epv < 50000)
136  if(epv < 100000)
138  if(epv < 200000)
141 }
142 
144 {
145  getPosition();
146 }
147 
149 {
150  constr_ReferencePosition(&(data().m_referencePosition));
151  constr_Speed(&(data().m_speed));
152  constr_Heading(&(data().m_heading));
153  /*constr_TimestampIts(&(data().m_timestamp));*/
154 }
Heading_t m_heading
Definition: ParameterGPS.h:25
ReferencePosition_t make_ReferencePosition()
make_ReferencePosition Make a default ReferencePosition_t.
Definition: apiCDD.cpp:2836
SpeedValue_t speedValue
Definition: Speed.h:24
void constr_Speed(Speed_t *s)
constr_Speed Check Speed_t constraints.
Definition: apiCDD.cpp:385
HeadingConfidence_t headingConfidence
Definition: Heading.h:25
QString m_address
Definition: ParameterGPS.h:24
Speed_t m_speed
Definition: ParameterGPS.h:28
void constr_ReferencePosition(ReferencePosition_t *r)
constr_ReferencePosition Check ReferencePosition_t constraints.
Definition: apiCDD.cpp:365
void getPosition()
getPosition Get the position from GPSProvider signal. (c.f. execute()).
Definition: GPSProvider.cpp:17
Heading_t make_Heading()
make_Heading Make a default Heading_t.
Definition: apiCDD.cpp:2685
AltitudeConfidence_t getAltitudeConfidence(int epv)
getAltitudeConfidence Translate altitude uncertainty from GPS signal to ETSI&#39;s altitude confidence...
quint64 getTimestamp()
getTimestamp Get ITS timestamp from system timestamp.
HeadingValue_t headingValue
Definition: Heading.h:24
void execute()
execute Execute the GPS client. I.e. wait for GPS signal and feed GPS attributes. If no GPS signal or...
ParameterGPS m_data
ParameterGPS & data()
data GPS data getter.
AltitudeConfidence_t altitudeConfidence
Definition: Altitude.h:25
long AltitudeConfidence_t
void checkConstraints()
checkConstraints Check the constraints and change to correct values.
Real GPS sensor.
void positionChanged()
positionChanged Signal used when GPS position change.
AltitudeValue_t altitudeValue
Definition: Altitude.h:24
Speed_t make_Speed()
make_Speed Make a default Speed_t.
Definition: apiCDD.cpp:2864
QString m_port
Definition: ParameterGPS.h:26
GPSProvider()
GPSProvider GPSProvider constructor.
Definition: GPSProvider.cpp:9
void constr_Heading(Heading_t *h)
constr_Heading Make a check of an Heading_t constraints.
Definition: apiCDD.cpp:259
ReferencePosition_t m_referencePosition
Definition: ParameterGPS.h:27
SpeedConfidence_t speedConfidence
Definition: Speed.h:25