summaryrefslogtreecommitdiffhomepage
path: root/FaceTrackNoIR/FGServer.cpp
diff options
context:
space:
mode:
authorWim Vriend <facetracknoir@gmail.com>2010-12-30 18:13:00 +0000
committerWim Vriend <facetracknoir@gmail.com>2010-12-30 18:13:00 +0000
commit26a42de2b739b8bf2cf9f1e1c849a681c1fcdc89 (patch)
treea44dfec3a52af472c14fe9009dfe9cbff507a097 /FaceTrackNoIR/FGServer.cpp
parent016d79347d429c291ea65eb95663e200e1e601f2 (diff)
Spent the day removing some bad-bugs in the fake TrackIR protocol and the SCServer protocol. Seems to work now?!
git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@34 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
Diffstat (limited to 'FaceTrackNoIR/FGServer.cpp')
-rw-r--r--FaceTrackNoIR/FGServer.cpp50
1 files changed, 24 insertions, 26 deletions
diff --git a/FaceTrackNoIR/FGServer.cpp b/FaceTrackNoIR/FGServer.cpp
index 9f362e52..dfcb3d21 100644
--- a/FaceTrackNoIR/FGServer.cpp
+++ b/FaceTrackNoIR/FGServer.cpp
@@ -60,6 +60,24 @@ FGServer::~FGServer() {
//
void FGServer::sendHeadposeToGame() {
int no_bytes;
+QHostAddress sender;
+quint16 senderPort;
+
+ //
+ // Create UDP-sockets if they don't exist already.
+ // They must be created here, because they must be in the Tracker thread (Tracker::run())
+ //
+ if (inSocket == 0) {
+ qDebug() << "FGServer::sendHeadposeToGame creating sockets";
+ inSocket = new QUdpSocket();
+ // Connect the inSocket to the port, to receive messages
+// inSocket->bind(QHostAddress::LocalHost, 5551);
+ inSocket->bind(QHostAddress::Any, destPort+1);
+ }
+
+ if (outSocket == 0) {
+ outSocket = new QUdpSocket();
+ }
//
// Copy the Raw measurements directly to the client.
@@ -86,31 +104,19 @@ int no_bytes;
qDebug() << "FGServer::writePendingDatagrams says: nothing send!";
}
-}
-
-//
-// Callback function registered in the run() method.
-// Retrieve all pending Datagrams (typically 1) and send a reply, containing the headpose-data.
-//
-void FGServer::readPendingDatagrams()
-{
-QHostAddress sender;
-quint16 senderPort;
-
//
- // Read data from FlightGear
+ // FlightGear keeps sending data, so we must read that here.
//
while (inSocket->hasPendingDatagrams()) {
+
QByteArray datagram;
datagram.resize(inSocket->pendingDatagramSize());
-// qDebug() << "FGServer::readPendingDatagrams says: size =" << inSocket->pendingDatagramSize();
-
inSocket->readDatagram( (char * ) &cmd, sizeof(cmd), &sender, &senderPort);
-// qDebug() << "FGServer::readPendingDatagrams says: data =" << cmd;
fg_cmd = cmd; // Let's just accept that command for now...
if ( cmd > 0 ) {
+ qDebug() << "FGServer::sendHeadposeToGame hasPendingDatagrams, cmd = " << cmd;
headTracker->handleGameCommand ( cmd ); // Send it upstream, for the Tracker to handle
}
}
@@ -130,18 +136,10 @@ bool FGServer::checkServerInstallationOK( HANDLE handle )
TestData.p = 0.0f;
TestData.r = 0.0f;
TestData.status = 0;
- fg_cmd = 0;
-
- // Create UDP-sockets
- inSocket = new QUdpSocket();
- outSocket = new QUdpSocket();
-
- // Connect the inSocket to the port, to receive readyRead messages
-// inSocket->bind(QHostAddress::LocalHost, 5551);
- inSocket->bind(QHostAddress::Any, destPort+1);
+ fg_cmd = 1;
- // Connect the inSocket to the member-function, to read FlightGear commands
- connect(inSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()), Qt::DirectConnection);
+ inSocket = 0;
+ outSocket = 0;
return true;
}