diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-12-03 22:23:08 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-12-04 12:19:26 +0100 |
commit | b256886a5cb9f2ae3ebda70a2045b19ed9f4233e (patch) | |
tree | 4fa1e46de224cf834a05824dc1eb86001bdb3300 /proto-udp/ftnoir_protocol_ftn.cpp | |
parent | e89709a801e7874bc02c66848c638c6a0ccc85c1 (diff) |
api: add status check for modules
Diffstat (limited to 'proto-udp/ftnoir_protocol_ftn.cpp')
-rw-r--r-- | proto-udp/ftnoir_protocol_ftn.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
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) |