diff options
Diffstat (limited to 'proto-udp/ftnoir_protocol_ftn.cpp')
| -rw-r--r-- | proto-udp/ftnoir_protocol_ftn.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/proto-udp/ftnoir_protocol_ftn.cpp b/proto-udp/ftnoir_protocol_ftn.cpp index b659e3b5..c67c39b8 100644 --- a/proto-udp/ftnoir_protocol_ftn.cpp +++ b/proto-udp/ftnoir_protocol_ftn.cpp @@ -14,21 +14,37 @@ udp::udp() { + set_dest_address(); + + QObject::connect(&*s.b, &bundle_::changed, + this, &udp::set_dest_address, + Qt::DirectConnection); +} + +void udp::pose(const double *headpose, const double*) +{ + QMutexLocker l(&lock); + + outSocket.writeDatagram((const char *) headpose, sizeof(double[6]), dest_ip, dest_port); } -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); +void udp::set_dest_address() +{ + QMutexLocker l(&lock); + + dest_port = (unsigned short)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 ); } -bool udp::correct() -{ - return outSocket.bind(QHostAddress::Any, 0, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); +module_status udp::initialize() +{ + if (outSocket.bind(QHostAddress::Any, 0, QUdpSocket::DontShareAddress)) + return status_ok(); + else + return error(tr("Can't bind socket: %1").arg(outSocket.errorString())); } -OPENTRACK_DECLARE_PROTOCOL(udp, FTNControls, udpDll) +OPENTRACK_DECLARE_PROTOCOL(udp, FTNControls, udp_sender_dll) |
