diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-12-31 13:06:30 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-12-31 13:06:30 +0100 |
commit | 4411f8aa4508f2759c29181b668ebf949dc3bc8c (patch) | |
tree | 408e24fd5b30fcaf856f30dd74fd804c345bedf8 /ftnoir_tracker_udp/ftnoir_tracker_udp.cpp | |
parent | edcdcaadb5920cebc9aaa34572cba74de5637241 (diff) |
udp: use settings framework
Diffstat (limited to 'ftnoir_tracker_udp/ftnoir_tracker_udp.cpp')
-rw-r--r-- | ftnoir_tracker_udp/ftnoir_tracker_udp.cpp | 119 |
1 files changed, 14 insertions, 105 deletions
diff --git a/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp b/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp index e70bfdc7..02ae21f0 100644 --- a/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp +++ b/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp @@ -25,18 +25,8 @@ #include "ftnoir_tracker_udp.h" #include "facetracknoir/global-settings.h" -FTNoIR_Tracker::FTNoIR_Tracker() +FTNoIR_Tracker::FTNoIR_Tracker() : should_quit(false) { - inSocket = 0; - outSocket = 0; - - bEnableRoll = true; - bEnablePitch = true; - bEnableYaw = true; - bEnableX = true; - bEnableY = true; - bEnableZ = true; - portAddress = 5551; should_quit = false; for (int i = 0; i < 6; i++) @@ -47,127 +37,46 @@ FTNoIR_Tracker::~FTNoIR_Tracker() { should_quit = true; wait(); - if (inSocket) { - inSocket->close(); - delete inSocket; - } - - if (outSocket) { - outSocket->close(); - delete outSocket; - } } /** QThread run @override **/ void FTNoIR_Tracker::run() { - -QHostAddress sender; -quint16 senderPort; - - // - // Read the data that was received. - // forever { if (should_quit) break; - if (inSocket != 0) { - while (inSocket->hasPendingDatagrams()) { - + while (inSocket.hasPendingDatagrams()) { + QMutexLocker foo(&mutex); QByteArray datagram; - datagram.resize(inSocket->pendingDatagramSize()); - mutex.lock(); - inSocket->readDatagram( (char * ) &newHeadPose, sizeof(newHeadPose), &sender, &senderPort); - mutex.unlock(); - } - } - else { - break; - } - + datagram.resize(sizeof(newHeadPose)); + inSocket.readDatagram((char * ) newHeadPose, sizeof(double[6])); + } usleep(10000); } } void FTNoIR_Tracker::StartTracker(QFrame*) { - loadSettings(); - // - // Create UDP-sockets if they don't exist already. - // They must be created here, because they must be in the new thread (FTNoIR_Tracker::run()) - // - if (inSocket == 0) { - qDebug() << "FTNoIR_Tracker::Initialize() creating insocket"; - inSocket = new QUdpSocket(); - // Connect the inSocket to the port, to receive messages - - if (!inSocket->bind(QHostAddress::Any, (int) portAddress, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) { - QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to bind UDP-port",QMessageBox::Ok,QMessageBox::NoButton); - delete inSocket; - inSocket = 0; - } - } + (void) inSocket.bind(QHostAddress::Any, (int) s.port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); start(); - return; } void FTNoIR_Tracker::GetHeadPoseData(double *data) { - mutex.lock(); - if (bEnableX) { + QMutexLocker foo(&mutex); + if (s.enable_x) data[TX] = newHeadPose[TX]; - } - if (bEnableX) { + if (s.enable_y) data[TY] = newHeadPose[TY]; - } - if (bEnableX) { + if (s.enable_z) data[TZ] = newHeadPose[TZ]; - } - if (bEnableYaw) { + if (s.enable_yaw) data[Yaw] = newHeadPose[Yaw]; - } - if (bEnablePitch) { + if (s.enable_pitch) data[Pitch] = newHeadPose[Pitch]; - } - if (bEnableRoll) { + if (s.enable_roll) data[Roll] = newHeadPose[Roll]; - } - mutex.unlock(); } -// -// Load the current Settings from the currently 'active' INI-file. -// -void FTNoIR_Tracker::loadSettings() { - - qDebug() << "FTNoIR_Tracker::loadSettings says: Starting "; - QSettings settings("opentrack"); // Registry settings (in HK_USER) - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - qDebug() << "FTNoIR_Tracker::loadSettings says: iniFile = " << currentFile; - - iniFile.beginGroup ( "FTNClient" ); - bEnableRoll = iniFile.value ( "EnableRoll", 1 ).toBool(); - bEnablePitch = iniFile.value ( "EnablePitch", 1 ).toBool(); - bEnableYaw = iniFile.value ( "EnableYaw", 1 ).toBool(); - bEnableX = iniFile.value ( "EnableX", 1 ).toBool(); - bEnableY = iniFile.value ( "EnableY", 1 ).toBool(); - bEnableZ = iniFile.value ( "EnableZ", 1 ).toBool(); - portAddress = (float) iniFile.value ( "PortNumber", 5550 ).toInt(); - iniFile.endGroup (); -} - - -//////////////////////////////////////////////////////////////////////////////// -// Factory function that creates instances if the Tracker object. - -// Export both decorated and undecorated names. -// GetTracker - Undecorated name, which can be easily used with GetProcAddress -// Win32 API function. -// _GetTracker@0 - Common name decoration for __stdcall functions in C language. -//#pragma comment(linker, "/export:GetTracker=_GetTracker@0") - extern "C" FTNOIR_TRACKER_BASE_EXPORT ITracker* CALLING_CONVENTION GetConstructor() { return new FTNoIR_Tracker; |