summaryrefslogtreecommitdiffhomepage
path: root/proto-udp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-12-03 22:23:08 +0100
committerStanislaw Halik <sthalik@misaki.pl>2017-12-04 12:19:26 +0100
commitb256886a5cb9f2ae3ebda70a2045b19ed9f4233e (patch)
tree4fa1e46de224cf834a05824dc1eb86001bdb3300 /proto-udp
parente89709a801e7874bc02c66848c638c6a0ccc85c1 (diff)
api: add status check for modules
Diffstat (limited to 'proto-udp')
-rw-r--r--proto-udp/ftnoir_ftncontrols.ui399
-rw-r--r--proto-udp/ftnoir_protocol_ftn.cpp28
-rw-r--r--proto-udp/ftnoir_protocol_ftn.h13
-rw-r--r--proto-udp/ftnoir_protocol_ftn_dialog.cpp4
4 files changed, 215 insertions, 229 deletions
diff --git a/proto-udp/ftnoir_ftncontrols.ui b/proto-udp/ftnoir_ftncontrols.ui
index 28f8ccdf..d6a4dfce 100644
--- a/proto-udp/ftnoir_ftncontrols.ui
+++ b/proto-udp/ftnoir_ftncontrols.ui
@@ -9,15 +9,15 @@
<rect>
<x>0</x>
<y>0</y>
- <width>411</width>
- <height>169</height>
+ <width>372</width>
+ <height>106</height>
</rect>
</property>
<property name="windowTitle">
<string>UDP protocol settings</string>
</property>
<property name="windowIcon">
- <iconset resource="../gui/main-facetracknoir.qrc">
+ <iconset resource="../gui/opentrack-res.qrc">
<normaloff>:/images/facetracknoir.png</normaloff>:/images/facetracknoir.png</iconset>
</property>
<property name="layoutDirection">
@@ -26,222 +26,176 @@
<property name="autoFillBackground">
<bool>false</bool>
</property>
- <layout class="QVBoxLayout" name="_vertical_layout">
- <item>
- <layout class="QGridLayout" name="gridLayout">
- <item row="1" column="4">
- <widget class="QSpinBox" name="spinIPFourthNibble">
- <property name="maximumSize">
- <size>
- <width>60</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="maximum">
- <number>255</number>
- </property>
- <property name="singleStep">
- <number>1</number>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QSpinBox" name="spinIPFirstNibble">
- <property name="maximumSize">
- <size>
- <width>60</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="maximum">
- <number>255</number>
- </property>
- <property name="singleStep">
- <number>1</number>
- </property>
- </widget>
- </item>
- <item row="1" column="2">
- <widget class="QSpinBox" name="spinIPSecondNibble">
- <property name="maximumSize">
- <size>
- <width>60</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="maximum">
- <number>255</number>
- </property>
- <property name="singleStep">
- <number>1</number>
- </property>
- </widget>
- </item>
- <item row="1" column="3">
- <widget class="QSpinBox" name="spinIPThirdNibble">
- <property name="maximumSize">
- <size>
- <width>60</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="maximum">
- <number>255</number>
- </property>
- <property name="singleStep">
- <number>1</number>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_4">
- <property name="text">
- <string>IP-address remote PC</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>Port-number</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QSpinBox" name="spinPortNumber">
- <property name="minimum">
- <number>1000</number>
- </property>
- <property name="maximum">
- <number>10000</number>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="1" column="0">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
</property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
- </spacer>
- </item>
- <item>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Enter IP-address and port-number for the remote PC.</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>Remember: you may have to change firewall-settings too!</string>
- </property>
- </widget>
- </item>
- </layout>
+ </widget>
</item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <spacer name="horizontalSpacer_2">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <property name="sizeConstraint">
- <enum>QLayout::SetDefaultConstraint</enum>
- </property>
- <item>
- <widget class="QPushButton" name="btnOK">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>100</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize">
- <size>
- <width>100</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>OK</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="btnCancel">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
+ <item row="0" column="0">
+ <widget class="QFrame" name="frame">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="horizontalSpacing">
+ <number>22</number>
+ </property>
+ <item row="0" column="1">
+ <widget class="QFrame" name="frame_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="spacing">
+ <number>12</number>
</property>
- <property name="minimumSize">
- <size>
- <width>100</width>
- <height>0</height>
- </size>
+ <property name="leftMargin">
+ <number>0</number>
</property>
- <property name="maximumSize">
- <size>
- <width>100</width>
- <height>16777215</height>
- </size>
+ <property name="topMargin">
+ <number>0</number>
</property>
- <property name="text">
- <string>Cancel</string>
+ <property name="bottomMargin">
+ <number>0</number>
</property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>10</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
+ <item>
+ <widget class="QSpinBox" name="spinIPFirstNibble">
+ <property name="maximumSize">
+ <size>
+ <width>60</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="singleStep">
+ <number>1</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="spinIPSecondNibble">
+ <property name="maximumSize">
+ <size>
+ <width>60</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="singleStep">
+ <number>1</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="spinIPThirdNibble">
+ <property name="maximumSize">
+ <size>
+ <width>60</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="singleStep">
+ <number>1</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="spinIPFourthNibble">
+ <property name="maximumSize">
+ <size>
+ <width>60</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="singleStep">
+ <number>1</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QSpinBox" name="spinPortNumber">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimum">
+ <number>1024</number>
+ </property>
+ <property name="maximum">
+ <number>65535</number>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Remote IP address</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Port</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
</item>
</layout>
</widget>
@@ -251,13 +205,28 @@
<tabstop>spinIPThirdNibble</tabstop>
<tabstop>spinIPFourthNibble</tabstop>
<tabstop>spinPortNumber</tabstop>
- <tabstop>btnOK</tabstop>
- <tabstop>btnCancel</tabstop>
</tabstops>
<resources>
- <include location="../gui/main-facetracknoir.qrc"/>
+ <include location="../gui/opentrack-res.qrc"/>
</resources>
<connections/>
+ <designerdata>
+ <property name="gridDeltaX">
+ <number>5</number>
+ </property>
+ <property name="gridDeltaY">
+ <number>5</number>
+ </property>
+ <property name="gridSnapX">
+ <bool>true</bool>
+ </property>
+ <property name="gridSnapY">
+ <bool>true</bool>
+ </property>
+ <property name="gridVisible">
+ <bool>false</bool>
+ </property>
+ </designerdata>
<slots>
<slot>startEngineClicked()</slot>
<slot>stopEngineClicked()</slot>
diff --git a/proto-udp/ftnoir_protocol_ftn.cpp b/proto-udp/ftnoir_protocol_ftn.cpp
index b659e3b5..a1f445f0 100644
--- a/proto-udp/ftnoir_protocol_ftn.cpp
+++ b/proto-udp/ftnoir_protocol_ftn.cpp
@@ -14,21 +14,29 @@
udp::udp()
{
+ set_dest_address();
+ QObject::connect(s.b.get(), &bundle_::changed, this, &udp::set_dest_address);
}
void udp::pose(const double *headpose) {
- int destPort = s.port;
- QHostAddress destIP(QString("%1.%2.%3.%4").arg(
- QString::number(static_cast<int>(s.ip1)),
- QString::number(static_cast<int>(s.ip2)),
- QString::number(static_cast<int>(s.ip3)),
- QString::number(static_cast<int>(s.ip4))));
- outSocket.writeDatagram((const char *) headpose, sizeof( double[6] ), destIP, destPort);
+ outSocket.writeDatagram((const char *) headpose, sizeof(double[6]), dest_ip, dest_port);
}
-bool udp::correct()
-{
- return outSocket.bind(QHostAddress::Any, 0, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
+void udp::set_dest_address()
+{
+ dest_port = s.port;
+ dest_ip = QHostAddress((s.ip1.to<unsigned>() & 0xff) << 24 |
+ (s.ip2.to<unsigned>() & 0xff) << 16 |
+ (s.ip3.to<unsigned>() & 0xff) << 8 |
+ (s.ip4.to<unsigned>() & 0xff) << 0 );
+}
+
+module_status udp::check_status()
+{
+ if (outSocket.bind(QHostAddress::Any, 0, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint))
+ return status_ok();
+ else
+ return error(tr("Can't bind socket: %1").arg(outSocket.errorString()));
}
OPENTRACK_DECLARE_PROTOCOL(udp, FTNControls, udpDll)
diff --git a/proto-udp/ftnoir_protocol_ftn.h b/proto-udp/ftnoir_protocol_ftn.h
index b234cd89..7838f01a 100644
--- a/proto-udp/ftnoir_protocol_ftn.h
+++ b/proto-udp/ftnoir_protocol_ftn.h
@@ -31,11 +31,13 @@ struct settings : opts {
{}
};
-class udp : public IProtocol
+class udp : public QObject, public IProtocol
{
+ Q_OBJECT
+
public:
udp();
- bool correct();
+ module_status check_status() override;
void pose(const double *headpose);
QString game_name() {
return QCoreApplication::translate("udp_proto", "UDP over network");
@@ -43,12 +45,19 @@ public:
private:
QUdpSocket outSocket;
settings s;
+
+ QHostAddress dest_ip { 127u << 24 | 1u };
+ unsigned short dest_port = 65535;
+
+private slots:
+ void set_dest_address();
};
// Widget that has controls for FTNoIR protocol client-settings.
class FTNControls: public IProtocolDialog
{
Q_OBJECT
+
public:
FTNControls();
void register_protocol(IProtocol *) {}
diff --git a/proto-udp/ftnoir_protocol_ftn_dialog.cpp b/proto-udp/ftnoir_protocol_ftn_dialog.cpp
index 70416a69..51ce483c 100644
--- a/proto-udp/ftnoir_protocol_ftn_dialog.cpp
+++ b/proto-udp/ftnoir_protocol_ftn_dialog.cpp
@@ -21,8 +21,8 @@ FTNControls::FTNControls()
tie_setting(s.ip4, ui.spinIPFourthNibble);
tie_setting(s.port, ui.spinPortNumber);
- connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK()));
- connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel()));
+ connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &FTNControls::doOK);
+ connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &FTNControls::doCancel);
}
//