This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added socket client to receive eye tracking data
- Loading branch information
1 parent
fa1d47b
commit 8870fd4
Showing
5 changed files
with
256 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,63 @@ | ||
#------------------------------------------------- | ||
# | ||
# Project created by QtCreator 2016-07-26T13:26:15 | ||
# | ||
#------------------------------------------------- | ||
|
||
# NOTE: COMPILES UNDER WINDOWS ONLY BECAUSE OF THE | ||
# ACTIVE-X COM OBJECT TDT REQUIRES!! :-( | ||
|
||
QT += core gui | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
CONFIG += c++11 | ||
DEFINES += APP_VERSION=\\\"0.1\\\" | ||
RESOURCES = application.qrc | ||
RC_FILE = app.rc | ||
|
||
QT += axcontainer | ||
TYPELIBS = $$system(dumpcpp -getfile {D323A622-1D13-11D4-8858-444553540000}) | ||
|
||
isEmpty(TYPELIBS) { | ||
message("TDT library not found!") | ||
} else { | ||
TYPELIBS = $$system(dumpcpp {D323A622-1D13-11D4-8858-444553540000}) | ||
HEADERS += rpcoxlib.h | ||
SOURCES += rpcoxlib.cpp | ||
} | ||
|
||
LIBS += -L"C:\\Program Files (x86)\\National Instruments\\Shared\\ExternalCompilerSupport\\C\\lib64\\msvc" \ | ||
-lNIDAQmx | ||
|
||
TARGET = AudioGameGUI | ||
TEMPLATE = app | ||
|
||
SOURCES += main.cpp\ | ||
NIDAQmxInterface.cpp \ | ||
StateMachineController.cpp \ | ||
Mainwindow.cpp \ | ||
TimerDialog.cpp \ | ||
TDTInterface.cpp \ | ||
trialseq.cpp \ | ||
LogFileWriter.cpp \ | ||
AboutDialog.cpp | ||
|
||
|
||
HEADERS += \ | ||
NIDAQmxInterface.h \ | ||
StateMachineController.h \ | ||
TimerDialog.h \ | ||
Mainwindow.h \ | ||
SettingStructures.h \ | ||
TDTInterface.h \ | ||
trialseq.h \ | ||
LogFileWriter.h \ | ||
AboutDialog.h | ||
|
||
FORMS += mainwindow.ui \ | ||
timerdialog.ui \ | ||
AboutDialog.ui | ||
|
||
DISTFILES += | ||
#------------------------------------------------- | ||
# | ||
# Project created by QtCreator 2016-07-26T13:26:15 | ||
# | ||
#------------------------------------------------- | ||
|
||
# NOTE: COMPILES UNDER WINDOWS ONLY BECAUSE OF THE | ||
# ACTIVE-X COM OBJECT TDT REQUIRES!! :-( | ||
|
||
QT += core gui network | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
CONFIG += c++11 | ||
DEFINES += APP_VERSION=\\\"0.1\\\" | ||
RESOURCES = application.qrc | ||
RC_FILE = app.rc | ||
|
||
QT += axcontainer | ||
TYPELIBS = $$system(dumpcpp -getfile {D323A622-1D13-11D4-8858-444553540000}) | ||
|
||
isEmpty(TYPELIBS) { | ||
message("TDT library not found!") | ||
} else { | ||
TYPELIBS = $$system(dumpcpp {D323A622-1D13-11D4-8858-444553540000}) | ||
HEADERS += rpcoxlib.h | ||
SOURCES += rpcoxlib.cpp | ||
} | ||
|
||
LIBS += -L"C:\\Program Files (x86)\\National Instruments\\Shared\\ExternalCompilerSupport\\C\\lib64\\msvc" \ | ||
-lNIDAQmx | ||
|
||
TARGET = AudioGameGUI | ||
TEMPLATE = app | ||
|
||
SOURCES += main.cpp\ | ||
NIDAQmxInterface.cpp \ | ||
StateMachineController.cpp \ | ||
Mainwindow.cpp \ | ||
TimerDialog.cpp \ | ||
TDTInterface.cpp \ | ||
trialseq.cpp \ | ||
LogFileWriter.cpp \ | ||
AboutDialog.cpp \ | ||
SocketClient.cpp | ||
|
||
|
||
HEADERS += \ | ||
NIDAQmxInterface.h \ | ||
StateMachineController.h \ | ||
TimerDialog.h \ | ||
Mainwindow.h \ | ||
SettingStructures.h \ | ||
TDTInterface.h \ | ||
trialseq.h \ | ||
LogFileWriter.h \ | ||
AboutDialog.h \ | ||
SocketClient.h | ||
|
||
FORMS += mainwindow.ui \ | ||
timerdialog.ui \ | ||
AboutDialog.ui | ||
|
||
DISTFILES += |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#include "SocketClient.h" | ||
|
||
SocketClient::SocketClient(QWidget *parent) | ||
{ | ||
tcpSocket = new QTcpSocket(); | ||
|
||
inBuffer.open(QIODevice::ReadWrite); | ||
inStream.setDevice(&inBuffer); | ||
inStream.setByteOrder(QDataStream::LittleEndian); | ||
inStream.setVersion(QDataStream::Qt_5_2); | ||
|
||
port = 20001; | ||
hostname = "127.0.0.1"; | ||
this->connectToHost(); | ||
} | ||
|
||
void SocketClient::onReadData() | ||
{ | ||
quint32 packetSize; | ||
quint32 packetType; | ||
|
||
inBuffer.seek(0); | ||
|
||
/*Read packet size*/ | ||
readMax(tcpSocket, sizeof(packetSize)); | ||
inBuffer.seek(0); | ||
inStream >> packetSize; | ||
|
||
/*Read packet type*/ | ||
readMax(tcpSocket, sizeof(packetSize)+sizeof(packetType)); | ||
inBuffer.seek(sizeof(packetSize)); | ||
inStream >> packetType; | ||
|
||
/*Read content*/ | ||
readMax(tcpSocket, packetSize); | ||
inBuffer.seek(sizeof(packetSize)+sizeof(packetType)); | ||
|
||
int dataSize = packetSize-(sizeof(packetSize) + sizeof(packetType)); | ||
|
||
switch(packetType){ | ||
case SOCKET_FILENAME: { | ||
char* data = new char[dataSize]; | ||
inStream >> data; | ||
QString fileName(data); | ||
emit(socketFileName(fileName)); | ||
qDebug()<<"Socket: filename" << fileName; | ||
} | ||
break; | ||
case SOCKET_START: { | ||
quint64 timeStamp; | ||
inStream >> timeStamp; | ||
emit(socketStartTimeStamp(timeStamp)); | ||
qDebug()<< "Socket: start timeStamp: " << timeStamp; | ||
} | ||
break; | ||
case SOCKET_STOP: { | ||
quint64 timeStamp; | ||
inStream >> timeStamp; | ||
emit(socketStopTimeStamp(timeStamp)); | ||
qDebug()<< "Socket: stop timeStamp: " << timeStamp; | ||
} | ||
break; | ||
case SOCKET_TIMESTAMP: { | ||
quint64 timeStamp; | ||
inStream >> timeStamp; | ||
emit(socketTimeStamp(timeStamp)); | ||
qDebug()<< "Socket: timeStamp: " << timeStamp; | ||
} | ||
break; | ||
case SOCKET_TRACKINGRESULT: { | ||
std::vector<double> data; | ||
data.resize(dataSize / sizeof(double)); | ||
for(int i = 0; i< dataSize / sizeof(double); i++){ | ||
inStream >> data[i]; | ||
} | ||
QVector<double> trackingResult = QVector<double>::fromStdVector(data); | ||
emit(socketTrackingResult(trackingResult)); | ||
} | ||
break; | ||
} | ||
inBuffer.buffer().clear(); | ||
} | ||
|
||
void SocketClient::connectToHost() | ||
{ | ||
tcpSocket->abort(); | ||
tcpSocket->connectToHost(hostname, | ||
port); | ||
if(!tcpSocket->waitForConnected(5000)){ | ||
qDebug() << "Socket: Connection error: " << tcpSocket->errorString(); | ||
}else{ | ||
connect(tcpSocket, SIGNAL(connected()), this, SLOT(onConnected())); | ||
connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(onDisconnected())); | ||
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(onReadData()), Qt::QueuedConnection); | ||
} | ||
} | ||
|
||
void SocketClient::onConnected() | ||
{ | ||
qDebug()<< "Socket: Connected"; | ||
} | ||
|
||
void SocketClient::onDisconnected() | ||
{ | ||
qDebug()<< "Socket: Disconnected"; | ||
} | ||
|
||
void SocketClient::onSocketError() | ||
{ | ||
qDebug()<< "Socket: Error"; | ||
} | ||
|
||
void SocketClient::readMax(QIODevice *io, int n) | ||
{ | ||
while(inBuffer.size() < n){ | ||
if(!io->bytesAvailable()){ | ||
io->waitForReadyRead(30000); | ||
} | ||
inBuffer.write(io->read(n - inBuffer.size())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef SOCKETCLIENT_H | ||
#define SOCKETCLIENT_H | ||
#include <QDialog> | ||
#include <QTcpSocket> | ||
#include <QDataStream> | ||
#include <QtWidgets> | ||
#include <QtNetwork> | ||
#include <QTimer> | ||
|
||
class QComboBox; | ||
class QLabel; | ||
class QLineEdit; | ||
class QPushButton; | ||
class QTcpSocket; | ||
class QNetworkSession; | ||
|
||
/*Parameters used as Type in outgoing packets*/ | ||
#define SOCKET_TIMESTAMP 0 | ||
#define SOCKET_START 1 | ||
#define SOCKET_STOP 2 | ||
#define SOCKET_FILENAME 3 | ||
#define SOCKET_TRACKINGRESULT 4 | ||
|
||
class SocketClient : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit SocketClient(QWidget *parent = Q_NULLPTR); | ||
void connectToHost(); | ||
|
||
private slots: | ||
void onReadData(); | ||
void onConnected(); | ||
void onDisconnected(); | ||
|
||
void onSocketError(); | ||
|
||
private: | ||
QTcpSocket *tcpSocket; | ||
QString hostname; | ||
int port; | ||
void readMax(QIODevice *io, int n); | ||
QBuffer outBuffer; | ||
QBuffer inBuffer; | ||
QDataStream outStream; /*To serialize outgoing data*/ | ||
QDataStream inStream; /*To serialize incoming data*/ | ||
|
||
signals: | ||
void socketTimeStamp(quint64 timeStamp); | ||
void socketStartTimeStamp(quint64 timeStamp); | ||
void socketStopTimeStamp(quint64 timeStamp); | ||
void socketFileName(QString fileName); | ||
void socketTrackingResult(QVector<double> trackingResult); | ||
|
||
}; | ||
|
||
#endif // SOCKETCLIENT_H |