TRDP data frame real-time processing method based on blocking mode combined with timeout mechanism
By employing a data frame processing method with blocking mode and timeout mechanism in TRDP data transmission, the problems of untimely data reception, data loss, and data corruption are solved, achieving real-time and synchronous data transmission while reducing resource consumption.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XIAN XIANGXUN TECH
- Filing Date
- 2026-03-10
- Publication Date
- 2026-07-31
AI Technical Summary
Existing data transmission based on the TRDP communication protocol suffers from problems such as untimely TRDP data frame reception, easy loss, reception errors, and data overwriting.
A real-time data frame processing method combining blocking mode and timeout mechanism is adopted. By setting UDP sockets and timeout mechanism through data receiving thread, the data receiving cycle is synchronized with the sending cycle. A circular buffer is used to store data frames, and a signal wake-up mechanism is used to process data frames.
It achieves real-time, consistent, and synchronous data reception, solves the problems of untimely, lost, and disordered data frame reception, reduces CPU resource consumption, improves processing efficiency, and effectively controls memory increase.
Smart Images

Figure CN122496136A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to rail communication, and more specifically to a real-time processing method for TRDP data frames based on a blocking mode combined with a timeout mechanism. Background Technology
[0002] With the continuous improvement of train intelligence, real-time performance monitoring of trains places higher demands on the stability and timeliness of train communication systems. In the driver's cab, the display screen and other onboard hardware devices such as the train control unit (CCU) need to conduct high-speed and reliable real-time data communication in order to monitor the train's operating status, control its operation, and thus ensure the safety of train operation and the timeliness of system response.
[0003] TRDP (Train Real-Time Data Protocol) is a real-time Ethernet communication protocol for train control networks. It is commonly used for data transmission between the display screen and the train control unit. This protocol features high real-time communication performance, low data transmission latency, and flexible configuration, and can meet the needs of train control systems for high-speed, deterministic data exchange.
[0004] When transmitting data based on the TRDP communication protocol, a circular polling method is often used to receive TRDP data frames. After receiving the TRDP data frames, they are returned to the application layer of the TRDP protocol for packet assembly. However, due to the asynchronous transmission and reception frequencies of the CCU device's data receiving threads, problems such as untimely reception of TRDP data frames, loss of TRDP data frames, and disordered reception of multiple TRDP data frames can easily occur. In addition, when too many TRDP data frames are received at any given time, data overwriting can easily occur during storage. Summary of the Invention
[0005] To address the technical problems of existing technologies, such as untimely reception of TRDP data frames, easy loss of TRDP data frames, disordered reception of multiple TRDP data frames, and easy data overwriting during storage, this invention provides a real-time processing method for TRDP data frames based on blocking mode combined with a timeout mechanism.
[0006] To achieve the above objectives, the present invention adopts the following technical solution:
[0007] A real-time processing method for TRDP data frames based on blocking mode combined with a timeout mechanism, characterized by the following steps:
[0008] S1. Create a data receiving thread and a data management thread;
[0009] S2. The external CCU device sends TRDP data frames to the data receiving thread. After receiving the TRDP data frames, the data receiving thread calls the data management thread to send the TRDP data frames to the data management thread. The data receiving thread uses a blocking mode combined with a timeout mechanism to receive the TRDP data frames sent by the CCU device. The blocking mode is configured with a UDP socket for the data receiving thread to ensure that the data receiving thread is in a waiting state when it has not received TRDP data frames. The timeout mechanism is configured with a receive timeout time and a timeout interval for the data receiving thread. The receive timeout time is used to ensure that the data receiving cycle of the data receiving thread is synchronized with each transmission cycle of the CCU device. The timeout interval is used to ensure that within each transmission cycle of the CCU device, the data receiving cycle of the data receiving thread is synchronized with the transmission cycle of the TRDP data frames.
[0010] S3. The data management thread uses a circular buffer to store the received TRDP data frames. After storing a complete frame of data, it packages the complete frame of data into a data packet and pushes it to the application layer of the TRDP protocol. The complete frame of data is a group of continuously received TRDP data frames without timeout.
[0011] The S4 and TRDP protocols process the received data packets to complete the real-time processing of TRDP data frames.
[0012] Furthermore, the timeout mechanism for the data receiving thread in step S2 is as follows:
[0013] a.1. Setting the data transmission cycle of the CCU device includes Zhou, among them Send within each sending cycle TRDP data frames, of which Define the first sending period as , ;
[0014] a.2. Set the current time as the start time Set the data receiving thread's receive timeout to The This refers to the time during which the CCU device transmits TRDP data frames in each transmission cycle. ;by Based on this, determine the first [stage / phase] of the CCU device. Within each sending cycle, the data receiving thread has a timeout period. If a TRDP data frame has been received, proceed to step a.3; otherwise, proceed to step a.4.
[0015] a.3 After receiving the TRDP data frame, the data receiving thread calls the data management thread to store the TRDP data frame in the data management thread and executes step a.5;
[0016] a.4. After obtaining the current time, return to step a.2;
[0017] a.5. Set the timeout interval between TRDP data frames to... Determine the CCU device in the first... The remaining data sent within each sending cycle Is the interval between TRDP data frames greater than the timeout interval? If yes, then all TRDP data frames before the Cth TRDP data frame that timed out are stored in the data management thread. The data management thread encapsulates the stored TRDP data frames into data packets. After obtaining a complete frame of data, step a.6 is executed. If no, then all the remaining N-1 data frames are stored in the data management thread. The data management thread encapsulates the stored TRDP data frames into data packets. After obtaining a complete frame of data, step a.7 is executed.
[0018] a.6 Judgment Is it equal to 0? If not, proceed to step a.9; if yes, proceed to step a.7.
[0019] a.7. Set the current time as the end time. Calculate the time taken to receive, store, and encapsulate the data frame. Then set the timeout interval. ;
[0020] a.8, Order ,judge If the condition is not met, proceed to step a.9; if it is met, the data receiving thread completes the reception of the TRDP data frame sent by the CCU device.
[0021] a.9. Set the current time as the start time ,by Based on this, determine the first [stage / phase] of the CCU device. Within each sending cycle, the data receiving thread operates within the timeout interval. Has a TRDP data frame been received? If yes, proceed to step a.10; otherwise, let... Then, proceed to step a.6;
[0022] a.10 After receiving a TRDP data frame, the data receiving thread calls the data management thread to store the TRDP data frame in the data management thread.
[0023] a.11. Set the timeout interval between TRDP data frames. , Determine if the remaining data frames sent by the CCU device exceed the timeout interval. If so, all TRDP data frames received before the timeout will be stored in the data management thread. The data management thread will then encapsulate the stored TRDP data frames into data packets. After obtaining a complete data frame, it will... If the current TRDP data frame has timed out, return to step a.6; otherwise, store the remaining TRDP data frames into the data management thread. The data management thread will encapsulate the stored TRDP data frames into data packets. After obtaining a complete frame of data, return to step a.7.
[0024] Furthermore, in step a.2, when the data receiving thread reaches the reception timeout period... If no TRDP data frame is received from the CCU device, the data receiving thread sends a wake-up request to the data management thread.
[0025] In steps a.5, a.9, and a.11, when the data receiving thread is within the timeout interval... If no TRDP data frame is received from the CCU device, the data receiving thread sends a wake-up request to the data management thread.
[0026] Upon receiving a wake-up request, the data management thread encapsulates the stored TRDP data frames into data packets and pushes them to the application layer of the TRDP protocol.
[0027] Furthermore, in step S3, the process by which the data management thread stores the received TRDP data frames using a circular buffer is as follows:
[0028] b.1 The data management thread creates a circular buffer and allocates memory space within the circular buffer according to the TRDP data frame structure; the TRDP data frame structure includes the comID and the payload data corresponding to the comID.
[0029] b.2. Divide the memory space into A storage cells and define the input position index of each storage cell. Output position index Define the number of data packets. Where A≥1;
[0030] b.3 When the data management thread receives a TRDP data frame, it maps the TRDP data frame to the corresponding storage cell according to the comID and stores the corresponding payload data in the corresponding storage cell.
[0031] b.4. Determine if the data management thread has received a wake-up request from the data receiving thread. If so, then... ,judge Is it true? If so, then let Perform step b.5; otherwise, let If not, proceed to step b.5; otherwise, return to step b.3.
[0032] b.5, based on The value encapsulates the payload data stored in the cell into a data packet and pushes it to the application layer, enabling... Proceed to step b.6;
[0033] b.6 Judgment and Are they all equal to A? If yes, return to step b.2; otherwise, return to step b.3.
[0034] Furthermore, in step a.7, when hour, .
[0035] Furthermore, in step S2, the process of setting the blocking mode of the data receiving thread is as follows:
[0036] c.1. Create a UDP socket and bind it to the listening port of the data receiving thread; the listening port is used to receive TRDP data frames.
[0037] c.2 Set the UDP socket to blocking mode and set the receive timeout. Complete the setting of the blocking mode for the data receiving thread.
[0038] Furthermore, in steps a.3, a.5, a.10, and a.11, after receiving the TRDP data frame, the data receiving thread parses the TRDP data frame to obtain the communication identifier comID and the payload data corresponding to the comID, and stores the payload data into the data management thread according to the comID.
[0039] Furthermore, in step b.2, a valid identifier is also set. The application layer is used to... The value determines whether to parse the TRDP data frame within the data packet;
[0040] When the storage cell contains payload data, a valid identifier is established. The value is the actual length of the effective payload data; otherwise, it is a valid identifier. The value is -1;
[0041] When valid identifier When the value is the actual length of the payload data, the application layer parses the TRDP data frame within the data packet. When the value is -1, the application layer does not perform any processing on the TRDP data frames in the data packet.
[0042] The beneficial effects of this invention are:
[0043] 1. This invention provides a real-time processing method for TRDP data frames based on a blocking mode combined with a timeout mechanism. A data receiving thread is created and configured with a timeout mechanism to receive TRDP data frames sent by a CCU device. The set timeout period ensures that the data receiving cycle of the data receiving thread is synchronized with each transmission cycle of the CCU device. The set timeout interval ensures that within each transmission cycle of the CCU device, the data receiving cycle of the data receiving thread is synchronized with the transmission cycle of the TRDP data frames, thereby ensuring the real-time performance, consistency, and synchronization of data reception. This solves the problems of untimely TRDP data frame reception, easy loss of TRDP data frames, and disordered reception of multiple TRDP data frames in existing data reception methods.
[0044] 2. The present invention provides a real-time processing method for TRDP data frames based on blocking mode combined with timeout mechanism. The data receiving thread adopts blocking mode and is in a waiting state when the CCU device does not actively send data. This avoids the problems of frequent checks that consume CPU resources and slow response caused by the traditional loop polling method of periodically checking whether the CCU device has data. This improves the data processing efficiency and reduces resource consumption.
[0045] 3. The present invention provides a real-time processing method for TRDP data frames based on blocking mode combined with timeout mechanism. It adopts a circular buffer mechanism for storing and managing data, which solves the problem of data blocking caused by excessive data volume in a short period of time. After the blocking is restored, the data management thread receives too much data at once, causing data loss and overwriting. It not only effectively controls the increase of memory, but also provides an effective buffer for the application processing of TRDP protocol.
[0046] 4. The present invention provides a real-time processing method for TRDP data frames based on blocking mode combined with timeout mechanism. The data receiving thread and the data management thread adopt a signal wake-up mechanism. Compared with the traditional timer polling mode, it effectively reduces the CPU usage, reduces hardware dependence, ensures the flexibility and portability of the code, and is easy to integrate and extend. Attached Figure Description
[0047] Figure 1 This is a flowchart illustrating an embodiment of a real-time processing method for TRDP data frames based on a blocking mode combined with a timeout mechanism according to the present invention.
[0048] Figure 2This is a schematic diagram of step S4, the data receiving process, in an embodiment of a real-time processing method for TRDP data frames based on blocking mode and timeout mechanism according to the present invention. Detailed Implementation
[0049] The technical solution of the present invention will be clearly and completely described below with reference to the accompanying drawings and embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0050] This embodiment provides a real-time processing method for TRDP data frames based on blocking mode combined with a timeout mechanism, such as... Figure 1 As shown, it includes the following steps:
[0051] S1. Check the network connection status of the CCU device, initialize the program, and create a main window object instance. The main window object instance is used to create the data receiving thread and the data management thread, as well as the main window elements, child window elements, fault handling thread, and sub-interface processing thread required during program execution, and to initialize variables. The main window elements are used to display the output data after application layer processing via the TRDP protocol. The child window elements are used to classify and display the output data according to importance within the main window elements. Importance data includes train speed, fault data, etc. The fault handling thread is used to handle various exceptions during program execution, and the sub-interface processing thread is used to control the classification and display of output data by the child window elements.
[0052] S2. Set the blocking mode for the data receiving thread, including creating a UDP socket, binding the port, setting multicast, setting the blocking mode, and setting the receive timeout. The process of creating a UDP socket is as follows:
[0053] a. Create a UDP socket and bind it to the listening port of the data receiving thread; the listening port is used to receive TRDP data frames.
[0054] b. Set the UDP socket to blocking mode and set the receive timeout. This completes the setting of the blocking mode for the data receiving thread, as described in this embodiment. .
[0055] Multicast is set up on the data receiving thread, and the IP of the CCU device is registered to the corresponding multicast IP segment address. This method allows for flexible setting and detection of the number of CCU devices, as well as flexible control of the number of display and control terminals, which facilitates fault analysis. The display and control terminals are the display platforms corresponding to the main window elements and child window elements.
[0056] S3. The data management thread creates a circular buffer for TRDP data frames. The circular buffer is a two-dimensional array. The first dimension represents the size of the buffer, and the second dimension represents the location index of the comID corresponding to the CCU device. It creates a mapping relationship between the TRDP data frame communication identifier comID and the index of the second-dimensional buffer of the data management thread. It also establishes a signal connection between the data management thread and the application layer of the TRDP protocol.
[0057] S4, the CCU device sends a TRDP data frame to the data receiving thread. After receiving the TRDP data frame, the data receiving thread calls the data management thread to store the TRDP data frame in the data management thread. After receiving the TRDP data frame, the data receiving thread parses the TRDP data frame to obtain the communication identifier comID and the payload data corresponding to the comID, and stores the payload data in the data management thread according to the comID.
[0058] The data receiving thread uses a blocking mode combined with a timeout mechanism to receive TRDP data frames sent by the CCU device. In blocking mode, a UDP socket is configured for the data receiving thread to ensure that it remains in a waiting state if no TRDP data frames are received. The timeout mechanism sets a receive timeout period and a timeout interval for the data receiving thread. The receive timeout period ensures that the data receiving thread's data receiving cycle is synchronized with each sending cycle of the CCU device. The timeout interval ensures that within each sending cycle of the CCU device, the data receiving thread's data receiving cycle is synchronized with the TRDP data frame sending cycle. Figure 2 As shown, the process of the data receiving thread receiving TRDP data frames using a timeout mechanism is as follows:
[0059] S4.1 Setting the data transmission cycle of the CCU device includes Zhou, among them Send within each sending cycle TRDP data frames, of which Define the first sending period as , ;
[0060] S4.2, Set the current time as the start time Set the data receiving thread's receive timeout to The This refers to the time during which the CCU device transmits TRDP data frames in each transmission cycle. ;by Based on this, determine the first [stage / phase] of the CCU device. Within each sending cycle, the data receiving thread has a timeout period. If a TRDP data frame is received, proceed to step S4.3; otherwise, proceed to step S4.4.
[0061] S4.3 After receiving the TRDP data frame, the data receiving thread calls the data management thread to store the TRDP data frame in the data management thread and executes step S4.5.
[0062] S4.4 After obtaining the current time, return to step S4.2;
[0063] S4.5, Set the timeout interval between TRDP data frames to... Determine the CCU device in the first... The remaining data sent within each sending cycle Is the interval between TRDP data frames greater than the timeout interval? If yes, then all TRDP data frames before the Cth TRDP data frame that timed out are stored in the data management thread. The data management thread encapsulates the stored TRDP data frames into data packets. After obtaining a complete frame of data, step S4.6 is executed. If no, then all the remaining N-1 data frames are stored in the data management thread. The data management thread encapsulates the stored TRDP data frames into data packets. After obtaining a complete frame of data, step S4.7 is executed.
[0064] S4.6, Judgment Is it equal to 0? That is, determine whether the received C-th TRDP data frame is the last one in the current cycle. If not, proceed to step S4.9. If yes, it means that all the data in a cycle has been received, and proceed to step S4.7.
[0065] S4.7 Set the current time as the end time , calculate reception Time taken per data frame Then set the timeout interval. That is, using the next cycle time Subtract the time consumed in the current cycle. Assign a value to Proceed to step S4.8;
[0066] S4.8, Order ,judge If the condition is not met, proceed to step S4.9; if it is met, the data receiving thread completes the reception of the TRDP data frame sent by the CCU device.
[0067] S4.9, Set the current time to the start time. ,by Based on this, determine the first [stage / phase] of the CCU device. Within each sending cycle, the data receiving thread operates within the timeout interval. If a TRDP data frame has been received, proceed to step S4.10; otherwise, set... Then, proceed to step S4.6;
[0068] S4.10 After receiving a TRDP data frame, the data receiving thread calls the data management thread to store the TRDP data frame in the data management thread.
[0069] S4.11 Setting the timeout interval between TRDP data frames In this embodiment =2ms, determine if the remaining data frames sent by the CCU device are greater than the timeout interval. If yes, then all TRDP data frames received before the timeout will be stored in the data management thread. The data management thread will encapsulate the stored TRDP data frames into data packets. After obtaining a complete data frame, let C be the TRDP data frame that has timed out, and return to step S4.6. If no, then all remaining TRDP data frames will be stored in the data management thread. The data management thread will encapsulate the stored TRDP data frames into data packets. After obtaining a complete data frame, return to step S4.7.
[0070] In step S4.2, when the data receiving thread reaches the reception timeout period... If no TRDP data frame is received from the CCU device, the data receiving thread sends a wake-up request to the data management thread.
[0071] In steps S4.5, S4.9, and S4.11, when the data receiving thread is within the timeout interval... If no TRDP data frame is received from the CCU device, the data receiving thread sends a wake-up request to the data management thread.
[0072] After receiving the wake-up request, the data management thread encapsulates the stored TRDP data frames into data packets and pushes them to the application layer of the TRDP protocol.
[0073] In step S4.7, when hour, .
[0074] In step S4.2, it is determined that the data receiving thread has exceeded the reception timeout period. The method for determining whether a TRDP data frame has been received is as follows: A temporary received data variable is set within the data receiving thread. This variable is used to determine whether a TRDP data frame has been received. The received length of the temporary received data variable is calculated to determine whether a TRDP data frame has been received. If a TRDP data frame has been received, the received length is greater than 0; otherwise, the received length is 0. Simultaneously, the IP address of the CCU device is saved to the multicast IP segment address. In steps S4.5, S4.9, and S4.11, it is determined that the data receiving thread has reached the timeout interval. The method for determining whether a TRDP data frame sent by the CCU is received is similar.
[0075] S5. The data management thread uses a circular buffer to store the received TRDP data frames. After storing a complete frame, it packages the complete frame into a data packet and pushes it to the application layer of the TRDP protocol. A complete frame is a group of continuously received TRDP data frames without timeout. The process of the data management thread storing the received TRDP data frames using a circular buffer is as follows:
[0076] S5.1 The data management thread creates a circular buffer and allocates memory space within the circular buffer according to the TRDP data frame structure; the TRDP data frame structure includes a comID and the payload data corresponding to the comID.
[0077] S5.2. Divide the memory space into A storage cells and define the input position index of each storage cell. Output position index Define the number of data packets. Where A≥1, and in this embodiment, A=20;
[0078] S5.3 When the data management thread receives a TRDP data frame, it maps the IP source and comID passed in by the data receiving thread, generates a mapping index, and stores the comID, the corresponding payload data, and the payload data size in a storage cell; the storage cell is indexed by the input position. The specified one-dimensional position is determined by combining the two-dimensional position specified by the mapping index;
[0079] S5.4. Determine whether the data management thread has received a wake-up request from the data receiving thread. If so, then... Next, calculate the number of valid packets in the circular buffer, considering two cases: when... The number of valid packets is
[0080] ,when Then let The payload data stored in the storage cell is encapsulated into a data packet and pushed to the application layer, enabling... , If not, return to step S5.3;
[0081] S5.5, Judgment and Are they all equal to A? If yes, return to step S5.2; otherwise, return to step S5.3.
[0082] In step 5.2, a valid identifier is also set. The application layer is used to... The value determines whether to parse the TRDP data frame within the data packet;
[0083] When the storage cell contains payload data, a valid identifier is established. The value is the actual length of the effective payload data; otherwise, it is a valid identifier. The value is -1;
[0084] When valid identifier When the value is the actual length of the payload data, the application layer parses the TRDP data frame within the data packet. When the value is -1, the application layer does not perform any processing on the TRDP data frames in the data packet.
[0085] The S6 and TRDP protocols analyze and process the received data packets and display the processing results on the display and control terminal, thereby completing the real-time processing of TRDP data frames.
[0086] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present invention should be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for real-time processing of TRDP data frames based on blocking mode combined with timeout mechanism, characterized in that, Includes the following steps: S1. Create a data receiving thread and a data management thread; S2. The external CCU device sends TRDP data frames to the data receiving thread. After receiving the TRDP data frames, the data receiving thread calls the data management thread to send the TRDP data frames to the data management thread. The data receiving thread uses a blocking mode combined with a timeout mechanism to receive the TRDP data frames sent by the CCU device. The blocking mode is configured with a UDP socket for the data receiving thread to ensure that the data receiving thread is in a waiting state when it has not received TRDP data frames. The timeout mechanism is configured with a receive timeout time and a timeout interval for the data receiving thread. The receive timeout time is used to ensure that the data receiving cycle of the data receiving thread is synchronized with each transmission cycle of the CCU device. The timeout interval is used to ensure that within each transmission cycle of the CCU device, the data receiving cycle of the data receiving thread is synchronized with the transmission cycle of the TRDP data frames. S3. The data management thread uses a circular buffer to store the received TRDP data frames. After storing a complete frame of data, it packages the complete frame of data into a data packet and pushes it to the application layer of the TRDP protocol. A complete frame of data is a group of continuously received TRDP data frames without timeout. The S4 and TRDP protocols process the received data packets to complete the real-time processing of TRDP data frames.
2. The real-time processing method for TRDP data frames based on blocking mode combined with timeout mechanism according to claim 1, characterized in that: The timeout mechanism for the data receiving thread in step S2 is as follows: a.1, the data sending period of the CCU device is set to have one week, wherein , in each sending period, a number of TRDP data frames are sent, wherein the number of TRDP data frames is defined as ; the first sending period is defined as , ; a.2, set the current time as the start time , set the receiving timeout time of the data receiving thread as , the is the time for the CCU device to send the TRDP data frame in each sending cycle, ; based on , judge whether the data receiving thread receives the TRDP data frame within the receiving timeout time in the first sending cycle of the CCU device, if yes, execute step a.3, if no, execute step a.4; a.3 After receiving the TRDP data frame, the data receiving thread calls the data management thread to store the TRDP data frame in the data management thread and executes step a.5; a.
4. After obtaining the current time, return to step a.2; a.
5. Set the timeout interval between TRDP data frames to... Determine the CCU device in the first... The remaining data sent within each sending cycle Is the interval between TRDP data frames greater than the timeout interval? If yes, then all TRDP data frames before the Cth TRDP data frame that timed out are stored in the data management thread. The data management thread encapsulates the stored TRDP data frames into data packets. After obtaining a complete frame of data, step a.6 is executed. If no, then all the remaining N-1 data frames are stored in the data management thread. The data management thread encapsulates the stored TRDP data frames into data packets. After obtaining a complete frame of data, step a.7 is executed. a.6 Judgment Is it equal to 0? If not, proceed to step a.9; if yes, proceed to step a.
7. a.
7. Set the current time as the end time. Calculate the time taken to receive, store, and encapsulate the data frame. Then set the timeout interval. ; a.8, Order ,judge If the condition is not met, proceed to step a.9; if it is met, the data receiving thread completes the reception of the TRDP data frame sent by the CCU device. a.
9. Set the current time as the start time ,by Based on this, determine the first [stage / phase] of the CCU device. Within each sending cycle, the data receiving thread operates within the timeout interval. Has a TRDP data frame been received? If yes, proceed to step a.10; otherwise, let... Then, proceed to step a.6; a.10 After receiving a TRDP data frame, the data receiving thread calls the data management thread to store the TRDP data frame in the data management thread. a.
11. Set the timeout interval between TRDP data frames. , Determine if the remaining data frames sent by the CCU device exceed the timeout interval. If so, all TRDP data frames received before the timeout will be stored in the data management thread. The data management thread will then encapsulate the stored TRDP data frames into data packets. After obtaining a complete data frame, it will... If the current TRDP data frame has timed out, return to step a.6; otherwise, store the remaining TRDP data frames into the data management thread. The data management thread will encapsulate the stored TRDP data frames into data packets. After obtaining a complete frame of data, return to step a.
7.
3. The real-time processing method for TRDP data frames based on blocking mode combined with timeout mechanism according to claim 2, characterized in that: In step a.2, when the data receiving thread reaches the reception timeout period... If no TRDP data frame is received from the CCU device, the data receiving thread sends a wake-up request to the data management thread. In steps a.5, a.9, and a.11, when the data receiving thread is within the timeout interval... If no TRDP data frame is received from the CCU device, the data receiving thread sends a wake-up request to the data management thread. Upon receiving a wake-up request, the data management thread encapsulates the stored TRDP data frames into data packets and pushes them to the application layer of the TRDP protocol.
4. The real-time processing method for TRDP data frames based on blocking mode combined with timeout mechanism according to claim 3, characterized in that: In step S3, the data management thread stores the received TRDP data frames using a circular buffer as follows: b.1 The data management thread creates a circular buffer and allocates memory space within the circular buffer according to the TRDP data frame structure; the TRDP data frame structure includes the comID and the payload data corresponding to the comID. b.
2. Divide the memory space into A storage cells and define the input position index of each storage cell. Output position index Define the number of data packets. Where A≥1; b.3 When the data management thread receives a TRDP data frame, it maps the TRDP data frame to the corresponding storage cell according to the comID and stores the corresponding payload data in the corresponding storage cell. b.
4. Determine if the data management thread has received a wake-up request from the data receiving thread. If so, then... ,judge Is it true? If so, then let Perform step b.5; otherwise, let If not, proceed to step b.5; otherwise, return to step b.
3. b.5, based on The value encapsulates the payload data stored in the cell into a data packet and pushes it to the application layer, enabling... Proceed to step b.6; b.6 Judgment and Are they all equal to A? If yes, return to step b.2; otherwise, return to step b.
3.
5. The real-time processing method for TRDP data frames based on blocking mode combined with timeout mechanism according to claim 4, characterized in that: In step a.7, when hour, .
6. The real-time processing method for TRDP data frames based on blocking mode combined with timeout mechanism according to claim 5, characterized in that: In step S2, the process of setting the blocking mode of the data receiving thread is as follows: c.
1. Create a UDP socket and bind it to the listening port of the data receiving thread; the listening port is used to receive TRDP data frames. c.2 Set the UDP socket to blocking mode and set the receive timeout. Complete the setting of the blocking mode for the data receiving thread.
7. The real-time processing method for TRDP data frames based on blocking mode combined with timeout mechanism according to claim 6, characterized in that: In steps a.3, a.5, a.10, and a.11, after receiving a TRDP data frame, the data receiving thread parses the TRDP data frame, obtains the communication identifier comID and the payload data corresponding to the comID, and stores the payload data into the data management thread according to the comID.
8. The real-time processing method for TRDP data frames based on blocking mode combined with timeout mechanism according to claim 7, characterized in that: In step b.2, a valid identifier is also set. The application layer is used to... The value determines whether to parse the TRDP data frame within the data packet; When the storage cell contains payload data, a valid identifier is established. The value is the actual length of the effective payload data; otherwise, it is a valid identifier. The value is -1; When valid identifier When the value is the actual length of the payload data, the application layer parses the TRDP data frame within the data packet. When the value is -1, the application layer does not perform any processing on the TRDP data frames in the data packet.