source: pacpussensors/trunk/Gps/gpsComponent.cpp@ 77

Last change on this file since 77 was 77, checked in by DHERBOMEZ Gérald, 10 years ago

Deletion of useless code

File size: 24.5 KB
RevLine 
[59]1/// Purpose: Implementation of the GpsComponent class
2///
3/// @date created 2005/09/02 - 14:16
4/// @author Gerald Dherbomez
5/// @copyright Heudiasyc UMR UTC/CNRS 6599
6/// @version $Id: gpsComponent.cpp 1278 2013-01-16 16:40:11Z bonnetst $
7
8#include "gpsComponent.h"
9
10#include <qfile.h>
11#include <qapplication.h>
12
13#include "Pacpus/kernel/ComponentFactory.h"
14#include "Pacpus/kernel/Log.h"
15#include "Pacpus/kernel/DbiteFileTypes.h"
16
17#include <qdebug.h>
18#include <iostream>
19
20namespace pacpus {
21
22/// Construct the factory
23ComponentFactory<GpsComponent> sFactory("GpsComponent");
24
25DECLARE_STATIC_LOGGER("pacpus.base.GpsComponent");
26
27#define UNKNOWN_NMEA_FRAME -1
28
29//////////////////////////////////////////////////////////////////////////
30/*!
31* Constructor of GpsComponent class
32*/
33//////////////////////////////////////////////////////////////////////////
34GpsComponent::GpsComponent(QString name)
35 : semaphore_(0)
36 , ComponentBase(name)
37
38{
39
40 ppsRecording = TRUE;
41 ggaRecording = TRUE;
42 gsaRecording = TRUE;
43 gstRecording = TRUE;
44 gsvRecording = TRUE;
45 hdtRecording = TRUE;
46 rmcRecording = TRUE;
47 rotRecording = TRUE;
48 vtgRecording = TRUE;
49 zdaRecording = TRUE;
50
51/* ppshdFile = NULL;
52 ggahdFile = NULL;
53 gsahdFile = NULL;
54 gsthdFile = NULL;
55 gsvhdFile = NULL;
56 hdthdFile = NULL;
57 rmchdFile = NULL;
58 rothdFile = NULL;
59 vtghdFile = NULL;
60 zdahdFile = NULL;
61*/
62
63
64 nextByteToProcess_ = 0;
65 currentFrame_ = NULL;
66 newFrameToDecode_ = false;
67 startOfFrame_ = false;
68 endOfFrame_ = false;
69}
70
71
72/*!
73* Destructor of the GpsComponent class
74*/
75GpsComponent::~GpsComponent()
76{
77
78}
79
80
81ComponentBase::COMPONENT_CONFIGURATION GpsComponent::configureComponent(XmlComponentConfig config)
82{
83 setPortCOM( config.getProperty("port").toLatin1() );
[72]84 setRecording ((config.getProperty("recording") == "true" ? true : false));
[59]85
86 return ComponentBase::CONFIGURED_OK;
87}
88
89
90void GpsComponent::setPortCOM(const char * port)
91{
92 portName_ = port;
93}
94
95
96void GpsComponent::enableSocketServer(int /*portNumber*/)
97{
[77]98
[59]99}
100
101
102void GpsComponent::disableSocketServer()
103{
[77]104
[59]105}
106
107
108/************************************************************************/
109/* Main loop of the thread */
110/************************************************************************/
111void GpsComponent::run()
112{
113 int type = -1;
114
115 // parity:0-4=no,odd,even,mark,space
116 // byteSize:number of bits/byte, 4-8
117 // baudRate:port speed (ex:38400)
118 // stopBits:0,1,2 = 1, 1.5, 2
119
120 serialPort->configurePort(xmlParameters().getProperty("baudrate").toLong(),
121 xmlParameters().getProperty("bytesize").toUInt(),
122 // config.getProperty("parity").at(0).toLatin1(),
123 xmlParameters().getProperty("parity").toShort(),
124 xmlParameters().getProperty("stopbits").toUInt() - 1);
125
126
127 serialPort->start();
128
129 while (isActive())
130 {
131 // If there are no bytes remaining in the current frame, delete it
132 if ((currentFrame_ != NULL) && (nextByteToProcess_ >= currentFrame_->data.length())) {
133 delete currentFrame_;
134 currentFrame_ = NULL;
135 }
136
137 // If there is no current frame, get one. Wait for one if none is available.
138 if (currentFrame_ == NULL) {
139 semaphore_.acquire();
140 if ((currentFrame_ = serialPort->getNextFrame()) == NULL) {
141 // Should never get to this point as the semaphore counts the frames, unless
142 // the thread is being stopped.
143 continue;
144 } else {
145 nextByteToProcess_ = 0;
146 }
147 }
148
149 // Check if we got a PPS frame
150 if (currentFrameIsPps()) {
151 lastPpsTime_ = currentFrame_->t;
152 decodeFrame(SIGNAL_PPS);
153 } else if (analyzeFrame()) {
154 // a new complete NMEA frame has arrived, decode it.
155 type = frameType(frameToDecode_.data);
156 if (type != -1) {
157 if (decodeFrame(type) == -1) {
158 qWarning("Failed to decode the dataframe\n");
159 }
160 }
161
162 setState(ComponentBase::MONITOR_OK);
163 }
164 }
165
166 qDebug() << "The thread of " << name() << " GPS component is stopped";
167}
168
169
170
171/************************************************************************/
172/* Method to stop the thread */
173/************************************************************************/
174void GpsComponent::stopActivity()
175{
176 setActive( FALSE );
177 unlockProcessing(1); // to unblock the thread that is waiting new data
178
179 serialPort->THREAD_ALIVE = FALSE;
180
181 if (!serialPort->wait(2000))
182 {
183 serialPort->terminate();
184 qDebug("The Win32SerialPort thread blocks anormally, it has been killed !!");
185 }
186 if ( !serialPort->closePort() )
187 qDebug("Failed to close the port");
188 else
189 qDebug("The port is closed");
190 delete serialPort;
191
192 if (ppshdFile.isOpen())
193 ppshdFile.close();
194 if (ggahdFile.isOpen())
195 ggahdFile.close();
196 if (gsahdFile.isOpen())
197 gsahdFile.close();
198 if (gsthdFile.isOpen())
199 gsthdFile.close();
200 if (gsvhdFile.isOpen())
201 gsvhdFile.close();
202 if (hdthdFile.isOpen())
203 hdthdFile.close();
204 if (rmchdFile.isOpen())
205 rmchdFile.close();
206 if (rothdFile.isOpen())
207 rothdFile.close();
208 if (vtghdFile.isOpen())
209 vtghdFile.close();
210 if (zdahdFile.isOpen())
211 zdahdFile.close();
212}
213
214
215/************************************************************************/
216/* Method to start the thread */
217/************************************************************************/
218void GpsComponent::startActivity()
219{
220 ppsIndex_ = 0;
221
222 setActive( TRUE );
223
224#if WIN32
225 serialPort = new Win32SerialPort(portName_.toLatin1());
226 // Asynchrone
227 serialPort->setMode(FILE_FLAG_OVERLAPPED);
228 // Synchrone
229 //serialPort->setMode(0);
230#else
231 serialPort = new PosixSerialPort(portName.toLatin1());
232#endif
233
234 if (!serialPort->openPort(portName_.toLatin1()))
235 {
236 qDebug() << "Failed to open the port " << portName_;
237 qDebug() << "The GPS Component " << name() << " didn't start";
238 return;
239 }
240
241 serialPort->THREAD_ALIVE = TRUE;
242 if (!QApplication::connect(serialPort,SIGNAL(newDataAvailable(int)),this, SLOT(unlockProcessing(int))))
243 qWarning("Failed to connect SIGNAL(newDataAvailable(int)) with SLOT(unlockProcessing(int)\n" );
244 start();
245 qDebug() << "The Component " << name() << " is started";
246}
247
248
249/************************************************************************/
250/* To get the type of the received frame */
251/************************************************************************/
252
253// The NMEA frame code <-> pacpus type map
254GpsComponent::FrameTypeMap GpsComponent::frameTypes[GpsComponent::MAX_FRAMES] = {
255 { "PPS", SIGNAL_PPS },
256 { "$GPGGA", TRAME_GGA_DBL},
257 { "$GPGSA", TRAME_GSA },
258 { "$GPHDT", TRAME_HDT },
259 { "$GPGST", TRAME_GST },
260 { "$GPGSV", TRAME_GSV },
261 { "$GPRMC", TRAME_RMC },
262 { "$GPVTG", TRAME_VTG },
263 { "$GPZDA", TRAME_ZDA },
264};
265
266int GpsComponent::frameType(const QByteArray& frame)
267{
268 for (int i = 0; i < MAX_FRAMES; i++) {
269 if (frame.startsWith(frameTypes[i].code)) {
270 return frameTypes[i].type;
271 }
272 }
273
274 return UNKNOWN_NMEA_FRAME;
275}
276
277/************************************************************************/
278/* Returns true is the frame is a pps, without updating frameToDecode_ */
279/* which may already contain an in-band NMEA partial frame */
280/************************************************************************/
281bool GpsComponent::currentFrameIsPps() {
282 if (currentFrame_->data == "PPS") {
283 nextByteToProcess_ = 3;
284 return true;
285 } else {
286 return false;
287 }
288}
289
290/************************************************************************/
291/* Reconstruct the frame starting from the received fragments */
292/************************************************************************/
293bool GpsComponent::analyzeFrame()
294{
295 // Process the remaining bytes in the current frame
296 while(nextByteToProcess_ < currentFrame_->data.length()) {
297
298 char currentChar = currentFrame_->data[nextByteToProcess_++];
299
300 // first looking for start-of-frame
301 if (!startOfFrame_ && (currentChar == '$')) {
302 startOfFrame_ = true;
303 endOfFrame_ = false;
304
305 frameToDecode_.t = currentFrame_->t;
306 frameToDecode_.data.clear();
307 } else if (startOfFrame_ && !endOfFrame_ && (currentChar == '\n')) {
308 // Looking for end-of-frame
309 startOfFrame_ = false;
310 endOfFrame_ = true;
311 frameToDecode_.t = road_time();
312 //frameToDecode_.tr = static_cast<road_timerange_t>(currentFrame_->t - frameToDecode_.t);
313 return true; // There is a new frame to decode
314 }
315
316 if ((startOfFrame_) && (!endOfFrame_)) {
317 frameToDecode_.data.append(currentChar);
318 }
319 }
320 return false; // No new frame to decode, wait for more data
321}
322
323
324void GpsComponent::unlockProcessing(int v)
325{
326 // new frame available
327 semaphore_.release( v );
328}
329
330
331int GpsComponent::decodeFrame(int type)
332{
333 double lat_rad = 0, lon_rad = 0;
334 int indexGSV = 0;
335 int indexGSA = 0;
336
337
338 SENTENCE sentence;
339 sentence.Sentence = frameToDecode_.data;
340
341 switch(type)
342 {
343 case UNKNOWN_NMEA_FRAME:
344 qDebug("Unknown frame received !");
345 break;
346 case SIGNAL_PPS:
347 ppsFrame.setRoadTime(lastPpsTime_);
348 *ppsFrame.getFrameData() = ppsIndex_++;
349
350 if ( (isRecording()) && (ppsRecording) )
351 {
352 if (!(ppshdFile.isOpen()))
353 ppshdFile.open((char *)(name() + "_pps.dbt").toLatin1().data(),WriteMode,TYPE_INT,sizeof(int));
354 if ( ppshdFile.writeRecord(frameToDecode_.t,frameToDecode_.tr,(char *) ppsFrame.getFrameData(),sizeof(int)) == 0)
355 qWarning("Failed to record PPS data ...\n");
356 }
357 ppsFrame.notifyObservers();
358
359 break;
360
361 case TRAME_GGA_DBL:
362 if (!nmea0183_.Gga.Parse(sentence)) {
363 LOG_ERROR("Failed to parse the frame " << nmea0183_.Gga.ErrorMessage.toLatin1().data());
364 } else {
365 lat_rad = nmea0183_.Gga.Position.Latitude.GetDecimalDegrees()*PACPUS_PI/180;
366 lon_rad = nmea0183_.Gga.Position.Longitude.GetDecimalDegrees()*PACPUS_PI/180;
367 ggaFrame.getFrameData()->H = nmea0183_.Gga.Time.time().hour();
368 ggaFrame.getFrameData()->Mi = nmea0183_.Gga.Time.time().minute();
369 ggaFrame.getFrameData()->S = nmea0183_.Gga.Time.time().second();
370 ggaFrame.getFrameData()->Ms = nmea0183_.Gga.Time.time().msec();
371 ggaFrame.getFrameData()->lon = lon_rad;
372 ggaFrame.getFrameData()->lat = lat_rad;
373 ggaFrame.getFrameData()->ind_qualite = nmea0183_.Gga.GPSQuality;
374 ggaFrame.getFrameData()->nb_sat = nmea0183_.Gga.NumberOfSatellitesInUse;
375 ggaFrame.getFrameData()->hdop = nmea0183_.Gga.HorizontalDilutionOfPrecision;
376 ggaFrame.getFrameData()->alt_msl = nmea0183_.Gga.AntennaAltitudeMeters;
377 ggaFrame.getFrameData()->d_geoidal = nmea0183_.Gga.GeoidalSeparationMeters;
378 ggaFrame.getFrameData()->age = nmea0183_.Gga.AgeOfDifferentialGPSDataSeconds;
379 ggaFrame.getFrameData()->dir_lat = ( (nmea0183_.Gga.Position.Latitude.Northing == North) ? 'N' : 'S' );
380 ggaFrame.getFrameData()->dir_lon = ( (nmea0183_.Gga.Position.Longitude.Easting == East) ? 'E' : 'W' );
381 ggaFrame.getFrameData()->ref_station_ID = nmea0183_.Gga.DifferentialReferenceStationID;
382 ggaFrame.setRoadTime(frameToDecode_.t);
383
384 sendDataToServerSocket(*ggaFrame.getFrameData(),type);
385 ggaFrame.notifyObservers();
386
387 if ( (isRecording()) && (ggaRecording) ) {
388 if (!(ggahdFile.isOpen()))
389 ggahdFile.open((char *)(name() + "_gga.dbt").toLatin1().data(),WriteMode,TRAME_GGA_DBL,sizeof(trame_gga_dbl));
390 if ( !ggahdFile.writeRecord(frameToDecode_.t,frameToDecode_.tr,(char *) ggaFrame.getFrameData(),sizeof(trame_gga_dbl)))
391 qWarning("Failed to record GGA data ...\n");
392 }
393 //printf("lon=%f lat=%f\n",ggaFrame.getFrameData()->lon, ggaFrame.getFrameData()->lat);
394 }
395 break;
396
397 case TRAME_GSA:
398 if (!nmea0183_.Gsa.Parse(sentence))
399 qWarning("Failed to parse the frame %s\n", nmea0183_.Gsa.ErrorMessage.toLatin1().data());
400 gsaFrame.getFrameData()->mode_select = ((nmea0183_.Gsa.OperatingMode == GSA::Manual) ? 'M' : 'A');
401 gsaFrame.getFrameData()->mode_result = 0;
402 if (nmea0183_.Gsa.FixMode == GSA::FixUnavailable)
403 gsaFrame.getFrameData()->mode_result = 1;
404 if (nmea0183_.Gsa.FixMode == GSA::TwoDimensional)
405 gsaFrame.getFrameData()->mode_result = 2;
406 if (nmea0183_.Gsa.FixMode == GSA::ThreeDimensional)
407 gsaFrame.getFrameData()->mode_result = 3;
408 for (indexGSA = 0 ; indexGSA<12 ; indexGSA++)
409 gsaFrame.getFrameData()->SV_PRN[indexGSA] = nmea0183_.Gsa.SatelliteNumber[indexGSA];
410 gsaFrame.getFrameData()->pdop = nmea0183_.Gsa.PDOP;
411 gsaFrame.getFrameData()->hdop = nmea0183_.Gsa.HDOP;
412 gsaFrame.getFrameData()->vdop = nmea0183_.Gsa.VDOP;
413 gsaFrame.setRoadTime(frameToDecode_.t);
414
415 gsaFrame.notifyObservers();
416
417 sendDataToServerSocket(*gsaFrame.getFrameData(),type);
418
419 if ( (isRecording()) && (gsaRecording) )
420 {
421 if (!(gsahdFile.isOpen()))
422 gsahdFile.open((char *)(name() + "_gsa.dbt").toLatin1().data(),WriteMode, TRAME_GSA,sizeof(trame_gsa));
423 if ( gsahdFile.writeRecord(frameToDecode_.t, frameToDecode_.tr,(char *) gsaFrame.getFrameData(),sizeof(trame_gsa)) != 1)
424 qWarning("Failed to record GSA data ...\n");
425 }
426 break;
427
428
429
430 case TRAME_GST:
431 if (!nmea0183_.Gst.Parse( sentence ))
432 qWarning("Failed to parse the frame %s\n",nmea0183_.Gst.ErrorMessage.toLatin1().data());
433 gstFrame.getFrameData()->rms = nmea0183_.Gst.RMSvalue;
434 gstFrame.getFrameData()->a = nmea0183_.Gst.ErrorEllipseMajor;
435 gstFrame.getFrameData()->b = nmea0183_.Gst.ErrorEllipseMinor;
436 gstFrame.getFrameData()->phi = nmea0183_.Gst.ErrorEllipseOrientation;
437 gstFrame.getFrameData()->sigma_lat = nmea0183_.Gst.LatitudeError;
438 gstFrame.getFrameData()->sigma_lon = nmea0183_.Gst.LongitudeError;
439 gstFrame.getFrameData()->sigma_alt = nmea0183_.Gst.HeightError;
440 gstFrame.getFrameData()->H = nmea0183_.Gst.Time.time().hour();
441 gstFrame.getFrameData()->Mi = nmea0183_.Gst.Time.time().minute();
442 gstFrame.getFrameData()->S = nmea0183_.Gst.Time.time().second();
443 gstFrame.getFrameData()->Ms = nmea0183_.Gst.Time.time().msec();
444 gstFrame.setRoadTime(frameToDecode_.t);
445
446 sendDataToServerSocket(*gstFrame.getFrameData(),type);
447 gstFrame.notifyObservers();
448
449
450 if ( (isRecording()) && (gstRecording) ) {
451 if (!gsthdFile.isOpen())
452 gsthdFile.open((char *)(name() + "_gst.dbt").toLatin1().data(),WriteMode,TRAME_GST,sizeof(trame_gst));
453 if ( !gsthdFile.writeRecord(frameToDecode_.t, frameToDecode_.tr,(char *) gstFrame.getFrameData(),sizeof(trame_gst)) )
454 qWarning("Failed to record GST data ...\n");
455 }
456 break;
457
458 case TRAME_GSV:
459 indexGSV = 0;
460 if (!nmea0183_.Gsv.Parse( sentence )) {
461 qWarning("Failed to parse the frame %s\n",nmea0183_.Gsv.ErrorMessage.toLatin1().data());
462 break;
463 }
464 // it's a new frame, reset stored value in case of the number of satellites
465 // in view has decreased
466 if (nmea0183_.Gsv.message_number == 1)
467 {
468 while (indexGSV < 36)
469 {
470 gsvFrame.getFrameData()->SatellitesInView[ indexGSV ][ 0 ] = 0;
471 gsvFrame.getFrameData()->SatellitesInView[ indexGSV ][ 1 ] = 0;
472 gsvFrame.getFrameData()->SatellitesInView[ indexGSV ][ 2 ] = 0;
473 gsvFrame.getFrameData()->SatellitesInView[ indexGSV ][ 3 ] = 0;
474 indexGSV++;
475 }
476 }
477 gsvFrame.getFrameData()->NumberOfSatellites = nmea0183_.Gsv.NumberOfSatellites;
478 gsvFrame.getFrameData()->Totalmessages = nmea0183_.Gsv.Totalmessages;
479
480 for ( indexGSV=4*(nmea0183_.Gsv.message_number-1); indexGSV<=(4*nmea0183_.Gsv.message_number)-1; indexGSV++ )
481 {
482 gsvFrame.getFrameData()->SatellitesInView[ indexGSV ][ 0 ] = nmea0183_.Gsv.SatellitesInView[ indexGSV ].SatelliteNumber;
483 gsvFrame.getFrameData()->SatellitesInView[ indexGSV ][ 1 ] = nmea0183_.Gsv.SatellitesInView[ indexGSV ].ElevationDegrees;
484 gsvFrame.getFrameData()->SatellitesInView[ indexGSV ][ 2 ] = nmea0183_.Gsv.SatellitesInView[ indexGSV ].AzimuthDegreesTrue;
485 gsvFrame.getFrameData()->SatellitesInView[ indexGSV ][ 3 ] = nmea0183_.Gsv.SatellitesInView[ indexGSV ].SignalToNoiseRatio;
486 }
487
488 if (nmea0183_.Gsv.Totalmessages == nmea0183_.Gsv.message_number) {
489 sendDataToServerSocket(*gsvFrame.getFrameData(),type);
490 gsvFrame.setRoadTime(frameToDecode_.t);
491 gsvFrame.notifyObservers();
492 }
493 if ( (isRecording()) && (gsvRecording) && (nmea0183_.Gsv.Totalmessages == nmea0183_.Gsv.message_number) )
494 {
495 if (!gsvhdFile.isOpen())
496 gsvhdFile.open((char *)(name() + "_gsv.dbt").toLatin1().data(),WriteMode,TRAME_GSV,sizeof(trame_gsv));
497 if ( gsvhdFile.writeRecord(frameToDecode_.t, frameToDecode_.tr,(char *) gsvFrame.getFrameData(),sizeof(trame_gsv)) == 0)
498 qWarning("Failed to record GSV data ...\n");
499 }
500 break;
501
502 case TRAME_HDT:
503 if (!nmea0183_.Hdt.Parse( sentence ))
504 qWarning("Failed to parse the frame %s\n",nmea0183_.Hdt.ErrorMessage.toLatin1().data());
505 hdtFrame.getFrameData()->DegreesTrue = nmea0183_.Hdt.DegreesTrue;
506 hdtFrame.setRoadTime(frameToDecode_.t);
507
508 sendDataToServerSocket(hdtFrame,type);
509 hdtFrame.notifyObservers();
510
511 if ( (isRecording()) && (hdtRecording) )
512 {
513 if (!hdthdFile.isOpen())
514 hdthdFile.open((char *)(name() + "_hdt.dbt").toLatin1().data(),WriteMode,TRAME_HDT,sizeof(trame_hdt));
515 if ( hdthdFile.writeRecord(frameToDecode_.t, frameToDecode_.tr,(char *) hdtFrame.getFrameData(),sizeof(trame_hdt)) == 0)
516 qWarning("Failed to record HDT data ...\n");
517 }
518 break;
519
520 case TRAME_RMC:
521 if (!nmea0183_.Rmc.Parse( sentence ))
522 qWarning("Failed to parse the frame %s\n",nmea0183_.Rmc.ErrorMessage.toLatin1().data());
523 rmcFrame.getFrameData()->H = nmea0183_.Rmc.Time.time().hour();
524 rmcFrame.getFrameData()->Mi = nmea0183_.Rmc.Time.time().minute();
525 rmcFrame.getFrameData()->S = nmea0183_.Rmc.Time.time().second();
526 rmcFrame.getFrameData()->Ms = nmea0183_.Rmc.Time.time().msec();
527 rmcFrame.getFrameData()->AA = nmea0183_.Rmc.Time.date().year();
528 rmcFrame.getFrameData()->MM = nmea0183_.Rmc.Time.date().month();
529 rmcFrame.getFrameData()->JJ = nmea0183_.Rmc.Time.date().day();
530 rmcFrame.getFrameData()->lat = nmea0183_.Rmc.Position.Latitude.GetDecimalDegrees()*PACPUS_PI/180;
531 rmcFrame.getFrameData()->dir_lat = ( (nmea0183_.Rmc.Position.Latitude.Northing == North) ? 'N' : 'S');
532 rmcFrame.getFrameData()->lon = nmea0183_.Rmc.Position.Longitude.GetDecimalDegrees()*PACPUS_PI/180;;
533 rmcFrame.getFrameData()->dir_lon = ( (nmea0183_.Rmc.Position.Longitude.Easting == East) ? 'E' : 'W' );
534 rmcFrame.getFrameData()->magnet_var = nmea0183_.Rmc.MagneticVariation;
535 rmcFrame.getFrameData()->dir_magnet_var = ( (nmea0183_.Rmc.MagneticVariationDirection == East) ? 'E' : 'W');
536 rmcFrame.getFrameData()->mode = -1;
537 if (nmea0183_.Rmc.ModeIndication == "A")
538 rmcFrame.getFrameData()->mode = 1;
539 if (nmea0183_.Rmc.ModeIndication == "D")
540 rmcFrame.getFrameData()->mode = 2;
541 if (nmea0183_.Rmc.ModeIndication == "N")
542 rmcFrame.getFrameData()->mode = 0;
543 rmcFrame.getFrameData()->track_true_north = nmea0183_.Rmc.TrackMadeGoodDegreesTrue;
544 rmcFrame.getFrameData()->valid_data = ( (nmea0183_.Rmc.IsDataValid == True) ? 1 : 0 );
545 rmcFrame.getFrameData()->vitesse = nmea0183_.Rmc.SpeedOverGroundKnots * 1852.0 / 3600.0; // 1 knot = 1852 m/h
546 rmcFrame.setRoadTime(frameToDecode_.t);
547
548 sendDataToServerSocket(*rmcFrame.getFrameData(),type);
549 rmcFrame.notifyObservers();
550
551 if ( (isRecording()) && (rmcRecording) )
552 {
553 if (!rmchdFile.isOpen())
554 rmchdFile.open((char *)(name() + "_rmc.dbt").toLatin1().data(),WriteMode,TRAME_RMC,sizeof(trame_rmc));
555 if (rmchdFile.writeRecord(frameToDecode_.t ,frameToDecode_.tr,(char *) rmcFrame.getFrameData(),sizeof(trame_rmc)) == 0)
556 qWarning("Failed to record RMC data ...\n");
557 }
558 break;
559
560 case TRAME_ROT:
561 if (!nmea0183_.Rot.Parse( sentence ))
562 qWarning("Failed to parse the frame %s\n",nmea0183_.Rot.ErrorMessage.toLatin1().data());
563 rotFrame.getFrameData()->RateOfTurn = nmea0183_.Rot.RateOfTurn;
564 rotFrame.getFrameData()->valid_data = ( (nmea0183_.Rot.IsDataValid == True) ? 1 : 0 );
565 rotFrame.setRoadTime(frameToDecode_.t);
566
567 sendDataToServerSocket(*rotFrame.getFrameData(),type);
568 rotFrame.notifyObservers();
569
570 if ( (isRecording()) && (rotRecording) )
571 {
572 if (!rothdFile.isOpen())
573 rothdFile.open((char *)(name() + "_rot.dbt").toLatin1().data(),WriteMode,TRAME_ROT,sizeof(trame_rot));
574 if ( rothdFile.writeRecord(frameToDecode_.t ,frameToDecode_.tr,(char *) rotFrame.getFrameData(),sizeof(trame_rot)) == 0)
575 qWarning("Failed to record ROT data ...\n");
576 }
577 break;
578
579 case TRAME_VTG:
580 if (!nmea0183_.Vtg.Parse( sentence )) {
581 LOG_WARN("Failed to parse the frame " << nmea0183_.Vtg.ErrorMessage);
582 } else {
583 vtgFrame.getFrameData()->v = nmea0183_.Vtg.SpeedKilometersPerHour;
584 vtgFrame.getFrameData()->track_true_north = nmea0183_.Vtg.TrackDegreesTrue;
585 vtgFrame.getFrameData()->track_magnet_north = nmea0183_.Vtg.TrackDegreesMagnetic;
586 vtgFrame.setRoadTime(frameToDecode_.t);
587
588 sendDataToServerSocket(vtgFrame,type);
589 vtgFrame.notifyObservers();
590
591 if (isRecording() && vtgRecording) {
592 if (!vtghdFile.isOpen())
593 vtghdFile.open((char *)(name() + "_vtg.dbt").toLatin1().data(),WriteMode,TRAME_VTG,sizeof(trame_vtg));
594 if ( vtghdFile.writeRecord(frameToDecode_.t, frameToDecode_.tr,(char *) vtgFrame.getFrameData(),sizeof(trame_vtg)) == 0)
595 qWarning("Failed to record VTG data ...\n");
596 }
597 }
598 break;
599
600 case TRAME_ZDA:
601 if (!nmea0183_.Zda.Parse( sentence )) {
602 LOG_WARN("Failed to parse the frame " << nmea0183_.Zda.ErrorMessage);
603 }
604 zdaFrame.getFrameData()->H = nmea0183_.Zda.Time.time().hour();
605 zdaFrame.getFrameData()->Mi = nmea0183_.Zda.Time.time().minute();
606 zdaFrame.getFrameData()->S = nmea0183_.Zda.Time.time().second();
607 zdaFrame.getFrameData()->Ms = nmea0183_.Zda.Time.time().msec();
608 zdaFrame.getFrameData()->AA = nmea0183_.Zda.Time.date().year();
609 zdaFrame.getFrameData()->MM = nmea0183_.Zda.Time.date().month();
610 zdaFrame.getFrameData()->JJ = nmea0183_.Zda.Time.date().day();
611 zdaFrame.getFrameData()->H_offset = nmea0183_.Zda.LocalHourDeviation;
612 zdaFrame.getFrameData()->Mi_offset = nmea0183_.Zda.LocalMinutesDeviation;
613
614 sendDataToServerSocket(*zdaFrame.getFrameData(), type);
615 zdaFrame.setRoadTime(frameToDecode_.t);
616 zdaFrame.notifyObservers();
617
618 if ( (isRecording()) && (zdaRecording) ) {
619 if (!zdahdFile.isOpen())
620 zdahdFile.open((char *)(name() + "_zda.dbt").toLatin1().data(),WriteMode,TRAME_ZDA,sizeof(trame_zda));
621 if ( zdahdFile.writeRecord(frameToDecode_.t, frameToDecode_.tr,(char *) zdaFrame.getFrameData(),sizeof(trame_zda)) == 0) {
622 LOG_WARN("Failed to record ZDA data ...");
623 }
624 }
625
626 /*
627 if (isRecording() && zdaRecording && ppsRecording) {
628 memcpy(&(synchroFrame.getFrameData()->zda), zdaFrame.getFrameData(), sizeof(zdaFrame));
629 synchroFrame.getFrameData()->timeOffset = frameToDecode_.t - lastPpsTime_;
630 synchroFrame.getFrameData()->ppsTime = lastPpsTime_;
631 synchroFrame.getFrameData()->zdaTime = frameToDecode_.t;
632 synchroFrame.setRoadTime(frameToDecode_.t);
633
634 if (!gpsSynchroFile.isOpen()) {
635 gpsSynchroFile.open((name() + "_synchro.dbt").toStdString(), WriteMode, GPS_SYNCHRO_FRAME, sizeof(GpsSynchroFrame) );
636 }
637
638 if (gpsSynchroFile.writeRecord(frameToDecode_.t, frameToDecode_.t - lastPpsTime_, reinterpret_cast<const char *>(synchroFrame.getFrameData()), sizeof(GpsSynchroFrame)) == 0) {
639 LOG_WARN("Failed to record GPS SYNCHRO data ...");
640 }
641 }
642 */
643
644 break;
645
646 default:
647 return 0;
648 }
649
650 return 1;
651}
652
653} // namespace pacpus
Note: See TracBrowser for help on using the repository browser.