24 #include <QDomElement>
26 #include <QXmlStreamWriter>
46 , qsHost(
"127.0.0.1" )
49 , pqSocketNotifier( 0 )
66 switch( _eOperatingMode )
85 qCritical(
"ERROR[%s]: Failed to switch operating mode; host=%s, port=%d", Q_FUNC_INFO, qPrintable(
qsHost ),
iPort );
101 if( __poDeviceGpsdAisEditView->exec() == QDialog::Accepted )
showDetail();
102 delete __poDeviceGpsdAisEditView;
107 QDomElement __qDomElement = _rqDomElement.firstChildElement(
"Configuration" );
108 if( __qDomElement.isNull() )
return;
109 qsHost = __qDomElement.attribute(
"host",
"127.0.0.1" );
110 iPort = __qDomElement.attribute(
"port",
"2947" ).toInt();
116 _rqXmlStreamWriter.writeStartElement(
"Device" );
118 _rqXmlStreamWriter.writeAttribute(
"name",
qsName );
119 _rqXmlStreamWriter.writeAttribute(
"driver",
"gpsd_ais" );
121 _rqXmlStreamWriter.writeStartElement(
"Configuration" );
122 _rqXmlStreamWriter.writeAttribute(
"host",
qsHost );
123 _rqXmlStreamWriter.writeAttribute(
"port", QString::number(
iPort ) );
124 _rqXmlStreamWriter.writeEndElement();
126 _rqXmlStreamWriter.writeEndElement();
141 __pqMutexDataChange->lock();
150 #if GPSD_API_MAJOR_VERSION >= 7
151 __iStatus = gps_read(
psGpsData, NULL, 0 );
152 #elif GPSD_API_MAJOR_VERSION >= 5
157 if( __iStatus == 0 )
break;
160 qCritical(
"ERROR[%s]: Failed to read data from device; status=%d", Q_FUNC_INFO, __iStatus );
161 emit
signalError( QString( tr(
"Failed to read data from device")+
"; status=%1" ).arg( __iStatus ) );
172 if( !(
psGpsData->set & PACKET_SET ) )
continue;
176 if( !(
psGpsData->set & AIS_SET ) )
continue;
178 QString __qsSource = QString::number(
psGpsData->ais.mmsi );
186 bool __bDataAvailable =
false;
187 int __iSecond = AIS_SEC_NOT_AVAILABLE, __iLongitude = AIS_LON_NOT_AVAILABLE, __iLatitude = AIS_LAT_NOT_AVAILABLE;
188 int __iCourse = AIS_COURSE_NOT_AVAILABLE, __iSpeed = AIS_SPEED_NOT_AVAILABLE;
189 QString __qsShipname;
190 QString __qsCallsign;
197 if(
psGpsData->ais.type1.lon != AIS_LON_NOT_AVAILABLE ) __iLongitude =
psGpsData->ais.type1.lon;
198 if(
psGpsData->ais.type1.lat != AIS_LAT_NOT_AVAILABLE ) __iLatitude =
psGpsData->ais.type1.lat;
204 __qsShipname =
psGpsData->ais.type5.shipname;
205 __qsCallsign =
psGpsData->ais.type5.callsign;
210 if(
psGpsData->ais.type18.lon != AIS_LON_NOT_AVAILABLE ) __iLongitude =
psGpsData->ais.type18.lon;
211 if(
psGpsData->ais.type18.lat != AIS_LAT_NOT_AVAILABLE ) __iLatitude =
psGpsData->ais.type18.lat;
218 if(
psGpsData->ais.type19.lon != AIS_LON_NOT_AVAILABLE ) __iLongitude =
psGpsData->ais.type19.lon;
219 if(
psGpsData->ais.type19.lat != AIS_LAT_NOT_AVAILABLE ) __iLatitude =
psGpsData->ais.type19.lat;
225 __qsShipname =
psGpsData->ais.type24.shipname;
226 __qsCallsign =
psGpsData->ais.type24.callsign;
235 if( __iSecond != AIS_SEC_NOT_AVAILABLE )
237 uint __iCurrentTime = QDateTime::currentDateTime().toTime_t();
238 int __iCurrentSecond = __iCurrentTime % 60;
239 __iCurrentTime -= __iCurrentSecond;
240 __iCurrentTime += __iSecond;
241 if( __iSecond > 45 && __iCurrentSecond < 15 ) __iCurrentTime -= 60;
242 __oDeviceDataFix.
setTime( (
double)__iCurrentTime );
243 __bDataAvailable =
true;
247 if( __iLongitude != AIS_LON_NOT_AVAILABLE && __iLatitude != AIS_LAT_NOT_AVAILABLE )
249 __oDeviceDataFix.
setPosition( (
double)__iLongitude / 600000.0, (
double)__iLatitude / 600000.0 );
251 __bDataAvailable =
true;
255 if( __iCourse != AIS_COURSE_NOT_AVAILABLE )
257 __oDeviceDataFix.
setBearing( (
double)__iCourse / 10.0 );
258 __bDataAvailable =
true;
262 if( __iSpeed != AIS_SPEED_NOT_AVAILABLE && __iSpeed > 0 )
264 __oDeviceDataFix.
setSpeed( __iSpeed / 19.4384449244 );
265 __bDataAvailable =
true;
269 if( !__qsShipname.isEmpty() || !__qsCallsign.isEmpty() )
271 QString __qsName = __qsShipname;
272 if( !__qsCallsign.isEmpty() ) __qsName += __qsName.isEmpty() ? __qsCallsign :
" ("+__qsCallsign+
")";
273 __oDeviceDataFix.
setText( __qsName );
274 __bDataAvailable =
true;
278 if( __bDataAvailable )
287 __pqMutexDataChange->unlock();
307 gps_stream(
psGpsData, WATCH_DISABLE, NULL );
311 qDebug(
"DEBUG[%s]: Device successfully stopped", Q_FUNC_INFO );
322 qDebug(
"DEBUG[%s]: Device successfully paused", Q_FUNC_INFO );
336 #if GPSD_API_MAJOR_VERSION >= 5
337 __iStatus = gps_open(
qsHost.toLocal8Bit().constData(), QString::number(
iPort ).toLocal8Bit().constData(), &
sGpsData );
340 psGpsData = gps_open(
qsHost.toLocal8Bit().constData(), QString::number(
iPort ).toLocal8Bit().constData() );
346 qCritical(
"ERROR[%s]: Failed to open device; status=%d", Q_FUNC_INFO, __iStatus );
347 emit
signalError( QString( tr(
"Failed to open device")+
"; status=%1" ).arg( __iStatus ) );
352 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
361 __iStatus = gps_stream(
psGpsData, WATCH_ENABLE|WATCH_NEWSTYLE, NULL );
364 qCritical(
"ERROR[%s]: Failed to stream data from device; status=%d", Q_FUNC_INFO, __iStatus );
365 emit
signalError( QString( tr(
"Failed to stream data from device")+
"; status=%1" ).arg( __iStatus ) );
377 qDebug(
"DEBUG[%s]: Device successfully started; socket=%d", Q_FUNC_INFO,
psGpsData->gps_fd );
379 qDebug(
"DEBUG[%s]: Device successfully started; socket=%p", Q_FUNC_INFO,
psGpsData->gps_fd );
void setBearing(double _fdBearing)
Sets this course's bearing, in degrees.
void setSpeed(double _fdSpeed, double _fdSpeedVertical=UNDEFINED_SPEED)
Sets this course's horizontal speed, in meters per second.
void setPosition(double _fdLongitude, double _fdLatitude, double _fdElevation=UNDEFINED_ELEVATION)
Sets new coordinates.
void setTime(double _fdTime)
Sets the time, in seconds from Unix epoch.
Fix data [source,time,position,course,DOPs,...].
void setText(const QString &_rqsText)
Sets the additional textual data string.
void setType(int _eType)
Sets the fix type.
void setCourseFromPosition(bool _bCourseFromPosition)
Sets whether to use position to compute course.
void setSourceType(EType _eType)
Sets the source type.
virtual void refreshContent()
Refreshes the content of the underlying widget.
[UI] Route container's edit view
void dumpQVCT(QXmlStreamWriter &_rqXmlStreamWriter) const
Stores the device's configuration to the given QVCT destination (file)
QVCT::EStatus setOperatingMode(CDevice::EOperatingMode _eOperatingMode)
Sets the device's operating mode.
void parseQVCT(const QDomElement &_rqDomElement)
Retrieves the device's configuration from the given QVCT source (file)
QVCT::EStatus stop()
Start the device.
QString qsHost
Network host.
virtual void showDetail()
Displays the device's details (in the appropriate widget/view)
QVCT::EStatus start()
Stop the device.
void slotProcessData(int)
Slots to process device data.
CDeviceGpsdAis(const QString &_rqsName)
CDevice::EOperatingMode status()
Returns the device's status (operating mode)
bool bPaused
Pause status.
QVCT::EStatus pause()
Pause the device.
virtual ~CDeviceGpsdAis()
struct gps_data_t sGpsData
GPSD data.
struct gps_data_t * psGpsData
GPSD data pointer.
virtual void showEdit()
Displays the device's edit (configuration) widget/view.
QSocketNotifier * pqSocketNotifier
Socket notifier.
Generic navigation device (GPS, speedometer, compass, etc.)
void signalDataFix(const CDeviceDataFix &_roDeviceDataFix)
Signal emitted by the device when an updated fix is available.
void signalActivity()
Signal emitted by the device when activity occures.
EOperatingMode
Device operating mode (stop, start, pause)
void signalError(const QString &_rqsErrorMessage)
Signal emitted by the device when an error occured.
void signalOperatingMode(CDevice::EOperatingMode _eOperatingMode)
Signal emitted by the device when its operating mode changed.
void switchView(EView eView)
Displays the requested container/item details (switching to the appropriate widget)
void switchView(EView eView)
Displays the requested overlay (switching to the appropriate tab)
void setOverlayObject(COverlayObject *_poOverlayObject)
Sets the overlay object to be displayed (and refreshes the underlying widget)
QString qsName
Object name.
static COverlayDetailView * useOverlayDetailView()
static CDeviceDetailView * useDeviceDetailView()
static QMutex * useMutexDataChange()
static COverlayListView * useOverlayListView()