Qt Virtual Chart Table (QVCT)
CDeviceTcpSbs1.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  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is 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 Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 #ifndef QVCT_CDEVICETCPSBS1_HPP
20 #define QVCT_CDEVICETCPSBS1_HPP
21 
22 // QT
23 #include <QAbstractSocket> // QtNetwork module
24 #include <QDomElement> // QtXml module
25 #include <QHash>
26 #include <QString>
27 #include <QTcpSocket> // QtNetwork module
28 #include <QXmlStreamWriter>
29 
30 // QVCT
31 #include "devices/CDevice.hpp"
33 #include "units/CUnitTimeZone.hpp"
34 
35 
37 
42 class CDeviceTcpSbs1: public CDevice
43 {
44  Q_OBJECT
45 
46  //------------------------------------------------------------------------------
47  // FIELDS
48  //------------------------------------------------------------------------------
49 
50 private:
52 
53  QString qsHost;
55 
56  int iPort;
58 
61 
64 
67  QTcpSocket* pqTcpSocket;
69  bool bStarted;
71  bool bPaused;
72 
74  class CCallsign
75  {
76  public:
78  QString qsCallsign;
80  double fdTimestamp;
81  public:
83  CCallsign( const QString& _rqsCallsign, double _fdTimestamp ) : qsCallsign( _rqsCallsign ), fdTimestamp( _fdTimestamp ) {};
84  void update( const QString& _rqsCallsign, double _fdTimestamp ) { qsCallsign = _rqsCallsign; fdTimestamp = _fdTimestamp; };
85  QString& get( double _fdTimestamp ) { fdTimestamp = _fdTimestamp; return qsCallsign; };
86  };
88  QHash<QString,CCallsign> qHashCallsign;
91 
92  //------------------------------------------------------------------------------
93  // CONSTRUCTORS / DESTRUCTOR
94  //------------------------------------------------------------------------------
95 
96 public:
97  CDeviceTcpSbs1( const QString& _rqsName );
98  virtual ~CDeviceTcpSbs1();
99 
100 
101  //------------------------------------------------------------------------------
102  // METHODS: CDevice (implement/override)
103  //------------------------------------------------------------------------------
104 
105 public:
107 
108 public:
110  virtual int getCapabilities() const { return CDevice::FIX; };
111 
112 public:
113  virtual void showDetail();
114  virtual void showEdit();
115 
116 public:
117  void parseQVCT( const QDomElement& _rqDomElement );
118  void dumpQVCT( QXmlStreamWriter & _rqXmlStreamWriter ) const;
119 
120 
121  //------------------------------------------------------------------------------
122  // METHODS
123  //------------------------------------------------------------------------------
124 
125  // SLOTS
126 private slots:
128  void slotTcpConnected();
130  void slotTcpError( QAbstractSocket::SocketError _qSocketError );
132  void slotProcessData();
133 
134  // SETTERS
135 public:
136  // Sets the SBS-1 device's network host
137  void setHost( const QString& _rqsHost ) { qsHost = _rqsHost; };
138  // Sets the SBS-1 device's network port
139  void setPort( int _iPort ) { iPort = _iPort; };
140  // Sets the SBS-1 device's time zone
141  void setTimeZone( CUnitTimeZone::EUnit _eTimeZone ) { eTimeZone = _eTimeZone; };
142  // Sets callsign lookup state
143  void setCallsignLookup( bool _bCallsignLookup ) { bCallsignLookup = _bCallsignLookup; };
144  // Sets ground traffic (inclusion/track) state
145  void setGroundTraffic( bool _bGroundTraffic ) { bGroundTraffic = _bGroundTraffic; };
146 
147  // GETTERS
148 public:
149  // Returns the SBS-1 device's network host
150  QString getHost() { return qsHost; };
151  // Returns the SBS-1 device's network port
152  int getPort() { return iPort; };
153  // Returns the SBS-1 device's time zone
155  // Returns callsign lookup state
156  bool isCallsignLookup() { return bCallsignLookup; };
157  // Returns ground traffic (inclusion/track) state
158  bool isGroundTraffic() { return bGroundTraffic; };
159 
160  // OTHER
161 private:
170 
171 };
172 
173 #endif // QVCT_CDEVICETCPSBS1_HPP
EDriver
Driver ID.
@ TCP_SBS1
TCP socket, SBS-1 protocol.
Callsign dictionary entry.
double fdTimestamp
Insert/update timestamp.
QString qsCallsign
Callsign.
void update(const QString &_rqsCallsign, double _fdTimestamp)
QString & get(double _fdTimestamp)
CCallsign(const QString &_rqsCallsign, double _fdTimestamp)
SBS-1 protocol (TCP socket) navigation device.
virtual CDeviceDriver::EDriver getDriver() const
Returns the device's driver ID.
QTcpSocket * pqTcpSocket
TCP socket.
void setPort(int _iPort)
virtual void showDetail()
Displays the device's details (in the appropriate widget/view)
void parseQVCT(const QDomElement &_rqDomElement)
Retrieves the device's configuration from the given QVCT source (file)
double fdCallsignCleanupTimestamp
Callsign dictionary cleanup timestamp.
virtual int getCapabilities() const
Returns the device's capabilities.
CUnitTimeZone::EUnit eTimeZone
Time zone.
bool bPaused
Pause status.
bool bStarted
Start status.
virtual void showEdit()
Displays the device's edit (configuration) widget/view.
void setGroundTraffic(bool _bGroundTraffic)
void setHost(const QString &_rqsHost)
QString qsHost
Network host.
QVCT::EStatus pause()
Pause the device.
void slotProcessData()
Slots to process device data.
CUnitTimeZone::EUnit getTimeZone()
void setTimeZone(CUnitTimeZone::EUnit _eTimeZone)
virtual ~CDeviceTcpSbs1()
CDeviceTcpSbs1(const QString &_rqsName)
void slotTcpConnected()
Slots to report TCP connection.
void slotTcpError(QAbstractSocket::SocketError _qSocketError)
Slots to report TCP error.
QHash< QString, CCallsign > qHashCallsign
Callsign dictionary.
bool bGroundTraffic
Ground traffic (inclusion/track)
int iPort
Network port.
QVCT::EStatus start()
Stop the device.
bool bCallsignLookup
Callsign lookup.
QVCT::EStatus setOperatingMode(CDevice::EOperatingMode _eOperatingMode)
Sets the device's operating mode.
QVCT::EStatus stop()
Start the device.
void dumpQVCT(QXmlStreamWriter &_rqXmlStreamWriter) const
Stores the device's configuration to the given QVCT destination (file)
CDevice::EOperatingMode status()
Returns the device's status (operating mode)
void setCallsignLookup(bool _bCallsignLookup)
Generic navigation device (GPS, speedometer, compass, etc.)
Definition: CDevice.hpp:43
@ FIX
Device emits 'newDataFix' signal.
Definition: CDevice.hpp:54
EOperatingMode
Device operating mode (stop, start, pause)
Definition: CDevice.hpp:58
EUnit
Format/unit ID.
EStatus
Definition: QVCT.hpp:41