“Flight simulation system is an indispensable technical equipment for modern aviation scientific research, teaching, experiment and so on. It has high economic value and military value in aspects of flight performance research, flight quality evaluation and flight training. Under normal circumstances, the flight simulation system uses distributed computing technology, and the entire system is composed of multiple computers. Data transmission between the computers needs to be completed by data communication technology. Data communication technology requires the use of network protocols, and the current protocol used by the Internet is the IPv4 protocol.
Flight simulation system is an indispensable technical equipment for modern aviation scientific research, teaching, experiment and so on. It has high economic value and military value in aspects of flight performance research, flight quality evaluation and flight training. Under normal circumstances, the flight simulation system uses distributed computing technology, and the entire system is composed of multiple computers. Data transmission between the computers needs to be completed by data communication technology. Data communication technology requires the use of network protocols, and the current protocol used by the Internet is the IPv4 protocol.
IPv4 is the fourth version of the Internet Protocol (IP). It defines IP data communication methods including unicast, network-wide broadcast, and multicast. Unicast refers to the data communication carried out between two IP addresses; the whole network broadcast refers to the sending of data packets to all the IP addresses in the network in the IP subnet, and all the IP stations in the subnet can receive the whole network Broadcast; Multicast means that when an individual sends data to a group of people, he does not need to send the data to everyone, but only needs to send the data to a specific reservation group address, and all people who join the group can receive this Copies of data.
In order to allow multiple hosts in the network to receive the same data packet at the same time, if unicast is used, the source host must send the same data packet separately. It is also a big burden for a host to send the same data packets continuously at the same time. If the broadcast method is adopted, the data packet is transmitted to every host in the LAN, regardless of whether the host is interested in the data packet or not, this will result in a waste of bandwidth and a waste of resources of the host. If the multicast method is adopted, the source host can reach each host that needs to be received by sending only one data packet, which depends on the router’s maintenance and selection of group members and group relations. Multicast has a mechanism for maintaining the relationship between group members and groups. It can be clearly known whether there are hosts in a certain subnet that are interested in such multicast packets. If not, the packets will not be forwarded. And will notify the upstream router not to forward such data packets to the downstream router. In InternetNIC’s regulations on IP addresses, IP addresses are divided into 5 types of AE, and Class D addresses are multicast addresses, ranging from 18.104.22.168-22.214.171.124. Class D addresses are transient addresses that are dynamically allocated and restored. Each multicast group corresponds to a dynamically allocated class D address; when the multicast group ends multicast, the corresponding class D address will be recycled and used for future multicast.
According to the above, using multicast technology, for the sender, the data can be sent to all receivers only once. Therefore, for the receivers, the multicast technology is to receive the same data at the same time. The synchronization of the data received by the computer is well controlled, and the time period for sending is shortened, thereby greatly reducing the burden on the sender and the load on the network, and saving a lot of resources.
1 The composition and communication mechanism of the flight simulation system
A typical flight simulation system includes: flight system, fire control system, sound system, motion system, instructor station system, navigation system, instrument system, control system, multiple visual computers, etc., as shown in Figure 1. The flight system controls the entire flight simulation system, which is the core of the entire system; the instrument system displays the various instrument panels in the aircraft cockpit, and displays the flight status of the aircraft through the instrument panel; the control system controls the flight attitude of the aircraft; multiple visual scenes The computer shows the different angles of the plane when it is in the same position.
Figure 1 The communication structure of the flight simulation system (the solid line represents the network)
According to Figure 1, you can see the data transmission process of the entire system. If unicast communication is used, the flight system computer will repeatedly send the same data to multiple visual computers, increasing the transmission time period, which will lead to the duplication of the flight system computer’s work tasks and the waste of network resources, and When unicast sends data, there is precedent, so the five visual Display computers do not receive the data from the flight system computer at the same time. This will cause the frames of multiple visual computers to be out of synchronization between frames, which is not compatible with real-time Display. Requirements. If the broadcast communication method is adopted, the control system computer will also receive the data of the control computer, but in fact the control system computer does not use the information of the flight system computer, which will lead to a waste of network resources. If a multicast communication method is adopted, all the computers in the flight simulation system are in the same multicast group, so that the flight system computer sends data once, and the relevant computers will receive the same data at the same time, and multiple visual computers can be real-time Shows the flying attitude of the aircraft without the problem of frame-to-frame synchronization. So based on the above analysis, we use multicast technology to realize network communication in the experimental system.
2 Realization of Multicast Technology
This section introduces how to use winsock to implement multicast communication programming on the VC6.0 platform.
2.1 Method of Realizing Multicast with Winsock
This system uses VC6.0 as the development tool. For network programming, multi-threading technology is needed. In the VC6.0 development environment, the AfxBeginThread() function is used to start a thread, AfxBeginThread (RecvThread, &m_mysock); the RecvThread() function is the thread function, mainly used to receive and send data; m_mysock is a self-encapsulated one An object of class CMySocket, this class encapsulates all the information about multicast communication, such as: the data received in the thread function is stored in the variables of this class.
For Socket programming, the sockaddr_in structure must be initialized first, that is, the multicast address and port number are assigned to s_addr and sin_port in sockaddr_in, and the specific implementation is as follows:
Local.sin_family = AF_INET;
Local.sin_port = htons (2007);
Among them, Local is a sockaddr_in structure variable, the multicast address is: 126.96.36.199, and the port number is 2007.
Then it is the initialization of the socket, and the variable of SOCKET is defined as sock,
sock = socket (AF_INET, SOCK_DGRAM, 0); where SOCK_DGRAM represents the use of UDP protocol (SOCK_STREAM represents TCP protocol).
After initialization, use the bind() function to bind the socket to the IP address and port number, bind (sock, (sockaddr*) & (Local), sizeof (Local));
The definition of sock and Local is the same as above.
The multicast technology is set by the socket function option of the setsockopt() function. The multicast technology options of the setsockopt() function are shown in the following table:
Table 1 setsockopt() multicast option description
Sending data uses the sendto() function, which is used to send data to the multicast address, sendto(sock, buffer, sizeof(buffer), 0, (sockaddr*)&Local, sizeof(Local));
What the buffer stores is the data to be sent. Here is an introduction to the form of storing data in the buffer. The buffer is an array of characters. The first four digits of it are the computer name of the machine; the 5 to 8 digits are the commands. This command refers to what you want the receiver to do. ; From 9 digits onwards, all are data, and these data are for the receiver to use these data to complete their tasks. This is mainly because after the sender sends data to the multicast address, all receivers will fetch data from the network multicast address. For each receiver, it is possible that the received data is useless to itself, so when sending data , The data header adds the 1 to 8 bits of identification information mentioned above, and the receiver can obtain useful data for itself based on this information. The recvfrom() function is used to receive data, this function is to receive data on the network, recvfrom (sock, recvBuff, 1024, 0, (sockaddr*) & clientsock, & sizeof (clientsock)); recvBuff is an array of characters, which is received The data is stored in this array. Then, we have to parse this data, which is the information of the data packet header added when sending. After the data is received, the first four bits of the data packet are judged, and the computer from which the information is sent is judged. Then judge the 5 to 8 digits to determine what information it is, that is, what command. According to the information of the first 8 bits of the data packet, if it is the data that the machine will use, the data after the first 8 bits of the data packet will be extracted; otherwise, the received data will be discarded.
2.2 Validity of data transmission
As mentioned earlier, the main disadvantage of multicast is that there is no error correction mechanism, and it is difficult to make up for packet loss and wrong packet. That is to say, in the process of data transmission, it is impossible to guarantee that the received data is consistent with the sent data. This can cause the real-time simulation to be out of synchronization, and even multiple visual computers cannot observe the different angles of the aircraft in real time. In order to solve this problem, two measures are taken. Kinds of programs to make up for it.
2.2.1 Adopt time waiting
The time and other methods are to use the select() function. The use of select() function is that if the program wants to check whether there is data coming in the set time range (timeout = 5ms) on the socket, it first needs to add the socket handle to the readability monitoring collection, and then call select ()function. If no data arrives, wait for the next 5ms until there is data on the network. The select() function specifically implements the following code:
if(select(NULL, NULL, &fds, NULL, &timeout) == -1)
else if (select(NULL, NULL, &fds, NULL, &timeout)==0)
else if (FD_ISSET (sock, & fds))
However, this method also has certain drawbacks. If some of all the viewing computers wait for a long time during the process of receiving data, then all the viewing machines will not obtain the same data at the same time. As a result, the views of multiple visual computers are out of sync.
2.2.2 How to send a copy
When sending data at the sending end, one or more copies of this data must be sent at the same time. When receiving data at the receiving end, if the received data is found to be incorrect, the data will be fetched from other copies, which will make up for the unreliability of the received data .
3 concluding remarks
Since the multicast technology uses the UDP protocol, the main feature of the UDP protocol is the fast data transmission speed, so the data transmission speed problem in the flight simulation system can be solved. In the flight simulation system, the visual display is the focus of the system. If multiple viewing cameras are not displayed simultaneously, the observer will not be able to effectively control the flight of the aircraft, and then the entire system will not be able to control. Multicast technology is to send data only once, and computers in the same multicast address will receive these data. According to Figure 1, after the flight system computer sends data to the visual computer, the visual computer will receive the same data at the same time. In this way, the visual computer will perform the corresponding actions of the aircraft according to the received data. Therefore, the use of multicast technology can solve the problem of synchronization of visual computer displays. In the flight simulation system, by using the select() function and sending a copy, the reliability of the data in the transmission process can be compensated. Using the above methods, in the flight simulation system, the speed of data transmission, the synchronization of the visual computer and the reliability of data transmission have all been well verified.