Embodiment
Embodiment one: a kind of method that realizes HIT-TENA middleware of present embodiment, it specifically should comprise following two parts:
Step 1, the data structure of transmitting according to interface type, data element type, message header form, the message body formal definition of the difference service of HIT-TENA system.
Step 2, middleware is divided into network thread, data processing thread and data assembling thread, wherein network thread comprises UDP receiving thread and send-thread, TCP receiving thread and send-thread, and thread dividing situation as shown in Figure 1.
In concrete step 2, the network thread of required realization is separated in different threads receiving and sending, and can remove influencing each other of receiving and send, and realizes data receiver and data and sends concurrent carrying out.Middleware only need to be announced UDP to other members of pilot system and receive the port numbers of socket and the port numbers that TCP receives socket, it is served by system modelling adds notifications message bag, to other members of pilot system, announce these port numbers with the system operation notification message bag that adds of system operation service, for further communicating by letter and lay the foundation.Its network thread comprising is as follows:
Concrete, the packet of its UDP assembles corresponding API design, it is characterized in that middleware has exposed a series of API to operation interface software, while sending instructions such as adding system, statement are ordered, startup operation in web page operation interface, these API of CGI thread dispatching, assembling request message bag or notification message bag, complete operation requirement.Its api interface comprises all objects of adding pilot system, obtaining system member issue, orders attribute, orders object, order cancellation attribute, order cancellation object, adds pilot system operation, adds pilot system operation, exits pilot system.Its implementation is as follows:
Concrete, the UDP message bag parsing of middleware and dispatch thread, heartbeat packet assembling thread, tcp data packing distribution journey, tcp data bag processing threads, its detailed design is as follows:
The advantage of present embodiment:
By the in-depth analysis to the research of middleware communication mechanism and packet, and the applying in a flexible way of DSP/BIOS thread communication technology and thread synchronization, realized middleware system modeling service, declaration management service, system operation service, lookup service and Object Management group service, solved resource access device and independently participated in the significant problem of pilot system.
Utilize this DSP of DM642 to realize the basic function of HIT-TENA middleware.Owing to supporting the operating system layer of the ACE network library of HIT-TENA not support DSP/BIOS real time operating system, therefore, need the middleware software of development support DSP/BIOS to reach this object.Owing to only need to realize the transmission of data in DSP, conversion, so can carry out the most basic service of cutting realization complete service.
Embodiment two: present embodiment is different from embodiment one: the difference service in described step 1 specifically comprises following five kinds of services: system modelling service, declaration management service, system operation service, Object Management group service and lookup service; Wherein, described system modelling service, declaration management service, system operation service and lookup service belong to static modeling process.Other step and parameter are identical with embodiment one.
Embodiment three: present embodiment is different from embodiment one or two: be specially according to the data structure of the interface type of the difference service of HIT-TENA system, data element type, message header form and the transmission of message body formal definition in described step 1:
First, the packet transmitting in static modeling process consists of message header and message body, and the form of described message header comprises message numbering, service name length, service name, type of message length, type of message, message name length, message name, member Name's length, member Name, message body length and message body totally 11 parts;
Described service name, type of message and message name are the identification strings for static modeling process service configuration, by different service names, compartment system modeling service, declaration management service, system operation service and discovery take four kinds of different services, according to different type of messages and message name, distinguish different operations;
The second, Object Management group service comprises polytype packet, and after the packet that the equipment that crops does not need to support, the type of message that resource access device Object Management group services package contains has 2 kinds, is respectively property value renewal and object value and upgrades;
The message format that described property value upgrades comprises total length of data packets, message type code, source member's title length, source member's title, source object title length, source object title, source Property Name length, source Property Name, timestamp sign, timestamp, property value length and attribute value data totally 12 parts;
Described object value is upgraded and is comprised total length of data packets, message type code, source member's title length, source member's title, source object title length, source object title, timestamp sign, timestamp, object value length and object value data totally 10 parts, the timestamp field of property value updating message and object value updating message is a structure, and size is 28 bytes.
Other step and parameter are identical with embodiment one or two.
Embodiment four: present embodiment is different from one of embodiment one to three: 5 kinds of described services are organized polytype packet according to certain rules by middleware, realize respective services and function, the whole process that member participates in pilot system can be divided into three states: exited pilot system, in pilot system and off-duty state with in pilot system running status, by sending the packet of certain type, the state of realizing switches;
When being in the state of " having exited pilot system ", when transmission adds the message of system requirements and adds the reply message of system, can send the message that adds system, now, system enters " at pilot system and off-duty " state, when system is in " at pilot system and off-duty " state, receive while nullifying system directive, system can forward the state state that " exited pilot system " to, and receives while carrying out instruction, can enter " in experimental system operation " state; When system is in " in pilot system operation " state, receive when cancellation system is carried out instruction, can return to the state of " at system and off-duty "; While being in " at pilot system and off-duty " state or " in pilot system operation " state, member needs timed sending heartbeat packet; While being in " at pilot system and off-duty " state, member can send declaration management service message bag, wraps and receives corresponding response, or send a notification message, thereby realize the order of object or attribute as sent a request message; While being in " in pilot system operation " state, member can move Object Management group service, receives and processing attribute value updating message or object value updating message bag, or sends property value updating message or object value updating message bag.
Other step and parameter are identical with one of embodiment one to three.
Embodiment five: present embodiment is different from one of embodiment one to four: in described step 2, all threads design according to the following steps:
Step 1, according to service request, design middleware related data structures;
Step 2, according to service request, design middleware network of relation thread;
Step 3, according to service request, the parsing of UDP message bag and the dispatch thread of design middleware, heartbeat packet assembling thread, tcp data are packed distribution journey and tcp data bag processing threads.
Other step and parameter are identical with one of embodiment one to four.
Embodiment six: present embodiment is different from one of embodiment one to five: the data structure of the transmission of definition described in step 1 comprises design member list, member orders list, issue list, responds data structure, the data structure of UDP transmit queue queue nodes, data structure and input queue and the output queue of TCP transmit queue queue nodes of waiting for structure UDP receiving queue node;
(1) member's list: the every terms of information that member's list comprises member, comprise IP address that member Name, middleware send static modeling process service data bag with the IP address of port numbers, transmission Object Management group service data bag with port numbers, the time, the member's running status that receive recently heartbeat packet be connected socket with TCP;
(2) member orders list: resource access device is ordered object or attribute by declaration management service to other members of pilot system;
Wherein, described order list is for storing these order relations, ordering list comprises object number, attribute number, member, title is resembled to title and Property Name, storage object order record and attribute order record, for object order record, the number field that sets a property is FFFFH, and Property Name is null character string, and object number and attribute number are object and the storage numbering of attribute information in resource access device;
(3) order list: the situation that the object of issue list storage resource access device or attribute are ordered by other members, comprises object number, attribute number and member's list node pointer in list;
(4) respond and wait for structure: this structure is waited for the process of replying message after sending and asking structure body for intermediary message; It comprises message numbering, message body length and message first address;
(5) data structure of UDP receiving queue node: the first address that the node of UDP receiving queue comprises packet and length;
(6) data structure of UDP transmit queue queue nodes: first address and length that the data structure of UDP transmit queue node comprises packet to be sent, and object member's IP address and port numbers;
(7) data structure of TCP transmit queue queue nodes: the first address data that the data structure of TCP transmit queue node comprises packet to be sent and length l ength, and be connected socket with object member's TCP; TCP send-thread, according to the difference of length field value in this queue nodes, is distinguished packet and different orders, specific as follows:
When length is greater than 0, for general data node, send it;
When length is-1, sets up TCP with all member and be connected;
When length is-2, sets up TCP with mandatory member and be connected;
When length is-3, closes all TCP and connect;
When length is-4, the TCP that closes mandatory member connects;
When length field is-2 or-4, first address pointer data points to the node of member's list
(8) input queue and output queue: the node of input queue and output queue comprises object number information, the object number of the object that storage is updated.
Other step and parameter are identical with one of embodiment one to five.
Embodiment seven: present embodiment is different from one of embodiment one to six: the related thread of step 2 is to be separated in different threads receiving and sending, can remove influencing each other of receiving and send, realize data receiver and data and send concurrent carrying out; Middleware only need to be announced UDP to other members of pilot system and receive the port numbers of socket and the port numbers that TCP receives socket, it is served by system modelling adds notifications message bag, to other members of pilot system, announce these port numbers with the system operation notification message bag that adds of system operation service, its network thread comprising is as follows:
(1) synchronizeing of middleware network thread and NDK protocol stack event scheduler thread: middleware network thread is operation after NDK protocol stack event scheduler thread starts; Utilize the NC_NetStart of NDK to call, in this parameter of calling, comprise Start call back function pointer, scheduler thread calls this call back function after protocol stack is ready, therefore can in this call back function is realized, create and start the some network thread that need, reach desired synchronized relation;
Use semaphore SEM0, each network thread need to wait for that SEM0 effectively could start further flow process; On the other hand, in the Start of NC_NetStart call back function, make the counting of semaphore SEM0 add four (post tetra-times, each network thread consumes a counting)
(2) UDP receiving thread: the process flow diagram that Figure 2 shows that UDP receiving thread.UDP receiving thread receives after data, first carries out nested word binding, then adds data to receiving queue, and transmits reception semaphore, and to activate, UDP message bag is resolved and dispatch thread is processed packet;
(3) UDP send-thread: UDP send-thread wait-semaphore as shown in Figure 3, when pend success, from transmit queue, obtain first packet and send to object member (the IP address and the port number information that comprise object member in transmit queue node);
(4) TCP receiving thread: TCP receiving thread needs a plurality of members of supportive test system to connect simultaneously and sends data, by being used socket select to call realization.The process flow diagram of TCP receiving thread as shown in Figure 4.The variable declaration that this process flow diagram relates to is as follows:
Rdfs_keep:fd_set type, preserves all sockets in thread.
Rdfs:fd_set type, the socket of activity in storage thread.Before calling fdSelect, rdfs_keep is copied to rdfs.
Maxfd:int type, the maximum socket descriptor of thread adds 1.Using maxfd and rdfs as parameter call fdSelect API, i.e. fdSelect (maxfd, & rfds, NULL, NULL, NULL).
Fig. 5 is the process flow diagram of traversal rfds, adjusts the process flow diagram of maxfd and sees Fig. 6 (a) and Fig. 6 (b).Wherein comprise the grand of two self-defining operation fd_set structures, be defined as follows:
#define FD_ISALLCLR(p) ((p)->fds_bits[0]==0)
#define FD_RSHIFT_TEMP(n,p)((p)->fds_bits[0]>>(n))
TCP receiving thread is used fdSelect to monitor and monitors socket and the activity that is connected socket, and process, thereby obtain new connection socket, or receive to obtain tcp data bag, or close the connection of disconnection, receive after data, add data to receiving queue QUE_RcvTcp, and post semaphore SEM_RcvTcp, activation of TCP processing data packets thread is processed packet;
(5) TCP send-thread: the design of this thread need to support to be connected with a plurality of operation of pilot system member and to send data; In resource access device Middleware implementation, this realizes by integrated data in the node of tcp data transmit queue and order.The process flow diagram of TCP send-thread as shown in Figure 7; TCP send-thread wait-semaphore SEM_SndTcp, when pend success, from transmit queue QUE_SndTcp, obtain a node, if packet sends to it object member (in queue nodes, targetsock field is object member socket information); If order, newly-built or close connection; The socket that newly-built connection obtains is stored in the tcpsock field of corresponding member node in member's list;
In TCP send-thread, if newly-built successful connection, post semaphore SEM_Connected; And after closing connection, post semaphore SEM_Done.
Other step and parameter are identical with one of embodiment one to six.
The packet of UDP assembles corresponding interface function design, it is characterized in that middleware has exposed a series of interface functions to operation interface software, while sending instructions such as adding system, statement are ordered, startup operation in web page operation interface, these functions of CGI thread dispatching, assembling request message bag or notification message bag, complete operation requirement; Its interface function comprises all objects of adding pilot system, obtaining system member issue, orders attribute, orders object, order cancellation attribute, order cancellation object, adds pilot system operation, adds pilot system operation and exit pilot system; Its implementation is as follows:
Add pilot system, obtain system member issue all objects, order attribute, order these functions of object and send a request message, wait-for-response message further processing then; Because all UDP message bags are all received by UDP receiving thread, so need extra information that the response message of coupling is sorted out; Just because of this, when the static modeling process service data packet format design of middleware, be provided with message numbering field; Transmit leg guarantees that the every request message sending has unique message numbering, is assumed to be N; Take over party, when replying response message, is also set to N by the message numbering of response message bag; Transmit leg receives after response message, offers the thread of waiting for this message;
During specific implementation, a WaitingReply structure variable that the overall situation is unique is set, SEM_Reply, two semaphores of SEM_SendRequest are set again, wherein SEM_Reply semaphore is for sending request the thread of packet and synchronizeing of the parsing of UDP message bag and dispatch thread, SEM_SendRequest semaphore is used for guaranteeing the mutual exclusion of WaitingReply structure variable, guarantee before receiving response message, the value of variable is not covered by another request.The flow process of this process as shown in Figure 8.
The UDP message bag parsing of related middleware and dispatch thread, heartbeat packet assembling thread, tcp data packing distribution journey, tcp data bag processing threads, its detailed design is as follows:
1) UDP message bag is resolved and dispatch thread: UDP message bag is resolved packet UDP receiving thread being received with dispatch thread and resolved, and does different processing according to the type of packet, and the process flow diagram of this thread as shown in Figure 9; Receive after notification message, upgrade the data of middleware; Receive after request message, need to reply response message bag, and the message numbering that the message numbering of response message bag is request message is set;
2) heartbeat packet assembling thread: add after pilot system at resource access device, heartbeat packet assembling thread sends M_MemberOnline notification message every 50s to each member in member's list. the process flow diagram of this thread is as shown in figure 10;
3) tcp data packing distribution journey: after tcp data packing distribution journey activates, determine the object upgrading, then traversal issue list, sends to by the data after upgrading the member who has ordered this object or association attributes; If detect not yet and connect before transmission packet, first to TCP send-thread, sending and create bind command. Figure 11 has described the execution flow process of tcp data packing distribution journey;
Tcp data packing distribution journey arranges resource object buffer zone, the content in resource object instantiation district is copied to this region, make during issue object value or property value updating message, up protocol conversion process is renewable instantiation region still, and issuing process and renewal process are independent of each other; When operating resource object-instantiated district, follow and obtain and releasing resource lock, thereby guarantee the atomicity to instantiation region operation.Send after bind command, when SEM_Connected semaphore is effective, show successfully to connect;
4) tcp data bag processing threads is resolved the packet receiving, if object value updating message bag, list upgating object instantiation region are ordered in inquiry, then add the object number of object to QUE_Out queue, reactivation descending protocol conversion thread is converted to hardware protocol packet by object; If property value updating message bag, according to the part instantiation region of ordering the Query Result upgating object of list, then remove the more corresponding bits position of new state, when more each bit of new state is all eliminated, add the object number of object to QUE_Out queue, and activate descending protocol conversion thread execution.During upgating object instantiation region, need to use resource lock LCK_ObjOut to protect.Carry out flow process as shown in figure 12;
Thread sends SEM_Out semaphore and activates after descending protocol conversion thread, resets the target update state that more new state is object, for next round object renewal process ready.
Emulation experiment:
For the practical function of five services, carry out five groups of different experiments respectively, verify that whether its service operation is normal, meets HIT-TENA standard.
System modelling service testing: intercept and capture communication data packet in resource access device adds or exits pilot system process, Figure 13 has shown the M_Request_JoinSystem request message bag of intercepting and capturing, Figure 14 and Figure 15 have shown the M_JoinSystem notification message bag intercepted and captured and M_ResignSystem notification message bag (shown in since 2AH byte to latter end, be useful load in message bag, the stem of all the other agreements such as be UDP).Through comparison, these message Bao Jun that resource access device sends meet HIT-TENA requirement (.Sent after M_JoinSystem notification message bag, until send M_ResignSystem notification message bag, other members of system can find resource access device, and resource access device also can view other members.This shows that system modelling service operation is normal.
Declaration management service testing: Figure 16 has shown M_Request_GetMemberObjects request message bag, and Figure 17 has shown the M_Reply_GetMemberObjects message bag of device replied; Figure 18 is M_Request_SubscribeObject request message bag, and Figure 19 is that M_Reply_SubscribeObject replys message bag (shown in be useful load since 2AH byte to latter end in message bag, the stem of all the other agreements such as be UDP).These message Bao Jun meets the requirement of HIT-TENA.By the processing of these packets, the object of other member's issues of pilot system can be checked and order to resource access device, also can process other members' subscription request.Visible, resource access device can normally move declaration management service.
System operation service test: Figure 20 has shown M_JoinSystemExecution notification message bag, Figure 21 shown M_ResignSystemExecution notification message bag (shown in since 2AH byte to latter end, be useful load in message bag, all the other are the stem of the agreements such as UDP), all meet the requirement of HIT-TENA.By these two kinds of packets, resource access device has been ready to move Object Management group service to other member's statements, can start data subscription issuing process.System operation service normal operation.
Object Management group service testing: resource access device sends or process object value updating message bag and property value updating message bag in operation Object Management group service process.Test shows object value or the property value updating message bag that resource access device can acceptance test system member sends, also can normally to each, order member and send object value or property value updating message bag, resource access device and pilot system member can carry out data subscription issuing process.Figure 22 has shown the object value updating message bag that resource access device sends (being wherein useful load since 36H byte to latter end, the stem of all the other agreements such as be TCP), meets the requirement of HIT-TENA.Object Management group service operation is normal.
Lookup service test: the M_MemberOnline message bag that resource access device sends is (shown in be useful load since 2AH byte to latter end in message bag, the stem of all the other agreements such as be UDP) as shown in figure 23, conforms to the requirement of HIT-TENA.Equipment energy timed sending heartbeat data packets, points out other member device normal operations.Lookup service normal operation.
By test, show, resource access device Middleware implementation minimum service function collection, i.e. system modelling service, declaration management service, system operation service, Object Management group service, and lookup service.Resource access device possesses the independent pilot system that participates in and carries out mutual ability.