Nonsense no, on the key code
Header file
#include <QUdpSocket>#include<qtcpsocket.h>#ifndef vrudp#defineVrudp#definePlane_data_num 30structplaneposestruct{DoubleLon; Doublelat; Doubleheight; Doubleheading; Doublepitch; Doublerotate;};classJsbsimsocket: Publicqobject{Q_object Public: Jsbsimsocket (); ~Jsbsimsocket (); voidinitnet (); voidSendplanecontroldata (Char* Data,intlength);PrivateSlots:voidRecvplanepose (); voidRecvtcpback ();Private: Qtcpsocket*M_control_tcpsocket; Qudpsocket*M_get_udpsocket; Qhostaddress M_get_udphost; Quint16 M_get_udpport; Doublem_jsbsimdata[plane_data_num];};
source file
#include"vrUDP.h"Jsbsimsocket::jsbsimsocket () {}jsbsimsocket::~Jsbsimsocket () {}voidjsbsimsocket::initnet () {//for the control side, based on QT_TCP customer service: Aircraft control transmission, information feedbackQhostaddress tcp_host = qhostaddress::localhost;//please use XML data hereQuint16 Tcp_port =8009;//please use XML data hereM_control_tcpsocket =NewQtcpsocket; M_control_tcpsocket-connecttohost (Tcp_host, Tcp_port); M_control_tcpsocket-waitforconnected (); Connect (M_control_tcpsocket, SIGNAL (Readyread ()), This, SLOT (Recvtcpback ())); M_control_tcpsocket-Waitforreadyread (); //used to get flight posture, based on the QT_UDP server. M_get_udphost = Qhostaddress::any;//please use XML data hereM_get_udpport =8008;//please use XML data hereM_get_udpsocket =NewQudpsocket; M_get_udpsocket-bind (M_get_udphost,m_get_udpport); Connect (m_get_udpsocket,signal (readyread)), This, SLOT (Recvplanepose ()));}voidJsbsimsocket::sendplanecontroldata (Char* Data,intlength) { //Send control information//The key to communication is the organization of this data.//refer to the data structure of JSBSim for specific communication contents intRe = m_control_tcpsocket->write (data); if(Re = =-1) {printf ("Send Error"); }}voidJsbsimsocket::recvtcpback () {Charbuffer[4096]; Qint64 size= M_control_tcpsocket->read (buffer,4096); if(Size >0) { //This gets the feedback from the TCP, which can be later interactively manipulatedBuffer[size] =' /'; printf ("recvtcpback:%s", buffer); }}voidJsbsimsocket::recvplanepose () {Charbuffer[4096]; Qint64 size= M_get_udpsocket->readdatagram (buffer,sizeof(planeposestruct)); if(Size >0) {Buffer[size]=' /'; memcpy (&m_jsbsimdata[0], buffer, size); M_planepose.lon= m_jsbsimdata[0]; M_planepose.lat= m_jsbsimdata[1]; M_planepose.height= m_jsbsimdata[2] /3.2808; M_planepose.rotate= m_jsbsimdata[3] /3.14* the; M_planepose.pitch= m_jsbsimdata[4] /3.14* the; M_planepose.heading= m_jsbsimdata[5] /3.14* the;··············· }}···············
To put it simply:
My function is to control the plane's driving and to tell JSBSim with TCP.
JSBSim The current plane posture, then tells me the attitude of the plane via UDP.
As for, why not use TCP one-time fix, because ... I just wanted to try tcp|. Can UDP ...
About the JSBSim end how to achieve, this look at its source code of their own research can be!
Finally, please reprint of friends, the [original] word removed, or, I see will laugh dead
[OSG] [Osgearth] based on QT code implementation: tcp| UDP and flight simulation software JSBSim communication, realistic model flight!