Method and apparatus for receiving and reorganizing protocol data based on a sliding window protocol over a can bus
By using a sliding window protocol for data reception and reassembly, the size of the receiving window is dynamically adjusted and acknowledgment response frames are generated. This solves the network congestion and data loss problems of CAN bus water control equipment under high-frequency interaction of multiple nodes, and achieves efficient and reliable data transmission.
Patent Information
- Application Number
- CN202511493343.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-20
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2045-10-20
AI Technical Summary
Existing CAN bus-based water control equipment suffers from network congestion, data delay, and data loss in scenarios with multiple nodes online simultaneously or high-frequency interaction. It lacks a mechanism for dynamically adjusting the receiving window size, resulting in low data transmission efficiency and unreliability.
The sliding window protocol is used for data reception and reassembly. Data frames are buffered to the receive buffer queue through an interrupt callback function, the receive window size is dynamically adjusted, an acknowledgment response frame is generated and the data frame is reassembled, and network conditions are monitored to generate congestion notification control frames, so as to ensure the integrity and accuracy of data frames.
It improves the efficiency and reliability of data frame reception, avoids network congestion, ensures the integrity and accuracy of data frames, and adapts to different network conditions and data transmission needs.
Smart Images

Figure CN120956675B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, specifically to a method and apparatus for receiving and reassembling data using a sliding window protocol based on a CAN bus. Background Technology
[0002] In the communication process of water control equipment based on CAN bus, the reliability and efficiency of data transmission are very important. In the existing technology, a frame-by-frame acknowledgment method can be used, that is, after sending a data frame, the receiver will be asked to acknowledge the data.
[0003] However, in scenarios where multiple nodes are online simultaneously or interact frequently, the existing frame response mechanism can cause network congestion and data delay, affecting performance. Furthermore, when a large amount of data needs to be sent or multiple terminals request or perform consumption operations simultaneously, the problems of network congestion, duplicate transmission, and data delay will be further aggravated. In addition, due to network delays or packet loss, the data frames received by the receiving end may be discontinuous, lacking the ability to dynamically adjust the receiving strategy to adapt to different network conditions. Summary of the Invention
[0004] To address the problems in the existing technology, this application provides a sliding window protocol data reception and reassembly method and apparatus based on CAN bus. It can effectively solve the shortcomings of traditional technology in that it lacks a congestion control mechanism when receiving data frames, cannot dynamically adjust the receiving window size according to network conditions, and cannot flexibly adapt to different data transmission needs, which leads to data loss and duplicate transmission. It significantly improves the reception efficiency of receiving data frames, ensures the integrity and accuracy of the received data frames, and avoids network congestion.
[0005] To solve at least one of the above problems, this application provides the following technical solution:
[0006] In a first aspect, this application provides a method for receiving and reassembling data using a sliding window protocol based on a CAN bus, including:
[0007] The data frame is buffered into the receive buffer queue based on the interrupt callback function, the current buffer status of the receive buffer queue is obtained, the size of the receive window is adjusted based on the buffer status, and the adjusted receive window is used to respond to and control the received data frame. The data frame includes data frame identifier, group number, frame number and service data.
[0008] Compare the group number and frame number of the current data frame with those of historical data frames. If the group number and frame number corresponding to the current data frame are not registered, register the group number and frame number of the current data frame, store the service data of the current data frame, generate an acknowledgment response frame based on the received data frame and the adjusted size of the receiving window, and send the acknowledgment response frame to the sending end.
[0009] Based on the total number of frames in the group and the registered frame numbers indicated in the current data frame, and after determining that all data frames in the current group have been received, the service data corresponding to the current group is reassembled according to the frame number order and submitted to the service layer. The size of the receiving window is increased, and the confirmation response frame includes a variable-length confirmation flag, which is used to indicate the reception status of each data frame in the current group.
[0010] Furthermore, it also includes: monitoring arrival signals of the controller LAN bus interface and triggering an interrupt based on the arrival signal;
[0011] Based on the interrupt callback function, the received data frame is completely copied to the receive buffer queue, and the storage position and timestamp of the data frame are recorded.
[0012] Furthermore, it also includes: when the remaining available space in the receive buffer queue is less than a preset buffer threshold, reducing the size of the receive window to the remaining available space;
[0013] When the remaining available space in the receive buffer queue is greater than the preset buffer threshold, the size of the receive window is increased according to the amount of business data included in a single data frame.
[0014] Furthermore, it also includes: obtaining the registered frame information table, which is used to store the group number and frame number of the data frames that have been successfully received;
[0015] Compare the group number and frame number of the current data frame with the registered frame information table. If the group number and frame number corresponding to the current data frame have already been registered, discard the current data frame.
[0016] If the group number and frame number corresponding to the current data frame are not registered, register the group number and frame number of the current data frame.
[0017] Furthermore, it also includes: determining the total number of frames within the group corresponding to the current data frame, and increasing the total number of frames within the group based on the current receiving window size;
[0018] After increasing the size of the receive window, it also includes:
[0019] The adjusted receive window size is sent to the sender so that the sender can send data frames based on the adjusted receive window.
[0020] Furthermore, it also includes: when multiple data frames are received consecutively with the same group number and frame number, determining that the current sending end should perform a retransmission step;
[0021] If the current data frame has been successfully received, resend the acknowledgment response frame corresponding to the current data frame to the sender.
[0022] If a data frame that has timed out is detected in the group corresponding to the group number of the data frame, all records of service data and received data frames in the group number are cleared, a reassembly failure notification is sent to the sender, and the receive window is reset to its initial value.
[0023] Furthermore, it also includes: monitoring the reception time interval of received data frames;
[0024] If the received interval exceeds a preset interval threshold, a congestion notification control frame is generated and sent to the sender so that the sender can adjust the size of the sending window based on the congestion notification control frame and reduce the size of the current receiving window to the size corresponding to the service data of a single data frame.
[0025] Secondly, this application provides a sliding window protocol data receiving and reassembly device based on a CAN bus, comprising:
[0026] The receiving module is used to buffer data frames into the receiving buffer queue based on the interrupt callback function, obtain the current buffer status of the receiving buffer queue, adjust the size of the receiving window based on the buffer status to obtain the adjusted receiving window, and respond to and control the received data frames through the adjusted receiving window. The data frame includes data frame identifier, group number, frame number and service data.
[0027] The storage module is used to compare the group number and frame number of the current data frame with those of historical data frames. If the group number and frame number corresponding to the current data frame are not registered, the module registers the group number and frame number of the current data frame, stores the service data of the current data frame, generates an acknowledgment response frame based on the received data frame and the adjusted size of the receiving window, and sends the acknowledgment response frame to the sending end.
[0028] The reassembly module is used to reassemble the service data corresponding to the current group according to the frame number order, based on the total number of frames in the group indicated in the current data frame and the registered frame numbers, and submit it to the service layer after determining that all data frames in the current group have been received. It also increases the size of the receiving window and confirms that the response frame includes a variable-length confirmation flag, which is used to indicate the reception status of each data frame in the current group.
[0029] Thirdly, this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the CAN bus-based sliding window protocol data reception and reassembly method.
[0030] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the CAN bus-based sliding window protocol data reception and reassembly method.
[0031] Fifthly, this application provides a computer program product, including a computer program / instructions, which, when executed by a processor, implement the steps of the CAN bus-based sliding window protocol data reception and reassembly method.
[0032] As can be seen from the above technical solution, this application provides a method and apparatus for receiving and reassembling data using a sliding window protocol based on a CAN bus. It innovatively buffers data frames into a receive buffer queue according to an interrupt callback function, obtains the current buffer state of the receive queue, adjusts the size of the receive window based on the buffer state, obtains the adjusted receive window, and responds to and controls the received data frames through the adjusted receive window. The data frame includes a data frame identifier, group number, frame number, and service data. The group number and frame number of the current data frame are compared with those of historical data frames. If the group number and frame number corresponding to the current data frame are not registered, they are registered. The service data of the current data frame is stored. An acknowledgment response frame is generated based on the received data frame and the adjusted receive window size, and the acknowledgment response frame is sent to the sending end. Based on the group indicated in the current data frame... The total number of frames and the registered frame numbers are used to reassemble the service data corresponding to the current group according to the frame number order, and submit it to the service layer. The size of the receiving window is also increased. The acknowledgment response frame includes a variable-length acknowledgment identifier, which indicates the reception status of each data frame in the current group. This allows the data reception rate to be controlled by adjusting the size of the receiving window, making data transmission more efficient. The variable-length acknowledgment identifier in the acknowledgment response frame can indicate the reception status of each data frame in the current group in detail, so as to clearly indicate to the sender the successfully received data frames and the data frames that need to be retransmitted, thereby reducing unnecessary retransmissions and improving transmission efficiency. At the same time, data frames can be reassembled according to the group number and frame number to ensure the integrity and order of service data in the data frames, thereby adapting to different data transmission needs and improving versatility. This method effectively solves the shortcomings of traditional technologies, such as the lack of congestion control mechanisms when receiving data frames, the inability to dynamically adjust the receiving window size according to network conditions, and the inability to flexibly adapt to different data transmission needs, which can easily lead to data loss and duplicate transmissions. It significantly improves the receiving efficiency of data frames, ensures the integrity and accuracy of received data frames, and avoids network congestion. Attached Figure Description
[0033] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0034] Figure 1 This is a flowchart illustrating the sliding window protocol data reception and reassembly method based on CAN bus in an embodiment of this application.
[0035] Figure 2 This is a structural diagram of the sliding window protocol data receiving and reassembly device based on the CAN bus in the embodiments of this application;
[0036] Figure 3 This is a schematic diagram of the structure of the electronic device in the embodiments of this application.
[0037] Figure label:
[0038] Electronic device 9600, central processing unit 9100, memory 9140, communication module 9110, input unit 9120, audio processor 9130, display 9160, power supply 9170, buffer memory 9141, application / function storage unit 9142, data storage unit 9143, driver storage unit 9144, antenna 9111, speaker 9131, microphone 9132. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0040] The acquisition, storage, use, and processing of data in this application all comply with the relevant provisions of national laws and regulations.
[0041] In existing technologies, water control terminals are widely deployed in campus bathhouses, hot water rooms, and other scenarios to meter and control water resource usage. Conventional water control systems rely on CAN bus for master-slave communication, which has advantages such as strong anti-interference and good real-time performance. However, when multiple nodes are online simultaneously or interact at high frequency, the traditional one-frame-one-response mechanism has communication bottlenecks and congestion problems. Especially when a large amount of data is sent (such as online upgrades of water control equipment) or multiple terminals request or perform consumption operations at the same time, network congestion, duplicate transmissions, and data delays will affect performance and result in a poor user experience.
[0042] In view of the problems existing in the prior art, this application provides a sliding window protocol data reception and reassembly method and apparatus based on CAN bus. It controls the data of water control equipment through a lightweight sliding window and congestion control mechanism similar to TCP (Lightweight IP, a resource-constrained embedded system and IoT device). Compared with the traditional CAN bus data transmission, it can respond in a timely manner according to the real-time control needs of water control terminals based on priority and fast response mechanisms. It can also dynamically adjust window parameters according to real-time network conditions to adapt to different industrial environments and application requirements. The receiving window status is identified by bitmap compression, realizing the adjustment of the sending window and control of data frame retransmission. At the same time, it has the ability to coordinate frame-level acknowledgment response frames and window status.
[0043] To effectively address the shortcomings of traditional technologies, such as the lack of congestion control mechanisms during data frame reception, the inability to dynamically adjust the receive window size based on network conditions, and the inability to flexibly adapt to different data transmission needs, leading to data loss and duplicate transmissions, this application provides an embodiment of a sliding window protocol data reception and reassembly method based on a CAN bus. See [link to relevant documentation]. Figure 1 The CAN bus-based sliding window protocol data reception and reassembly method specifically includes the following:
[0044] Step S101: Based on the interrupt callback function, buffer the data frame into the receive buffer queue, obtain the current buffer status of the receive buffer queue, adjust the size of the receive window based on the buffer status, obtain the adjusted receive window, and respond to and control the received data frame through the adjusted receive window.
[0045] The data frame includes a data frame identifier, group number, frame number, and service data.
[0046] Optionally, in this embodiment, the data frame is buffered to the receive buffer queue through an interrupt callback function. That is, when a data frame arrives on the CAN bus, the hardware triggers an interrupt signal to call the interrupt handler. In the interrupt callback function, the received data frame is completely copied to the receive buffer queue to ensure the integrity of the data frame. The receive buffer queue is generally a ring structure, which can realize efficient and continuous data temporary storage and reading. The size of the receive buffer queue can be a multiple of 8 of the length of the maximum packet of service data.
[0047] Additionally, the cache status of the current receive buffer queue is obtained, including but not limited to the used cache space and the remaining available space. The size of the receive window is dynamically adjusted according to the cache status to obtain the adjusted receive window.
[0048] Specifically, when the remaining available space in the receive buffer queue is tight, the size of the receive window is reduced to decrease the receive rate and prevent buffer overflow. When the remaining available space in the receive buffer queue is sufficient, the size of the receive window is increased to improve the receive rate and make full use of the buffer resources.
[0049] The initial size of the receive window is the size of the frames in the receive buffer queue.
[0050] In addition, the received data frames are responded to and controlled through an adjusted receiving window. The data frames include, but are not limited to, data frame identifiers, group numbers, frame numbers, and service data, so that the receiving end can flexibly adapt to different network conditions and data transmission requirements, ensuring the efficiency and reliability of data transmission.
[0051] The structure of the data frame is as follows:
[0052]
[0053] In this context, can_id represents a 4-byte configuration. Bits 0-20 are used to represent the ID address of the sending device, bits 21-26 are used to represent the group number, which is 6 bits in size, and bits 27-28 are used to represent the frame number, which ranges from 0 to 3.
[0054] Bits 0-3 of the can_dlc byte are used to indicate the actual length of the data. In the 7th bit, a value of 0 indicates a data frame and a value of 1 indicates a control frame. When the 7th bit is 0, bits 4-6 indicate the total number of actual data frames in the group, i.e., a maximum of 4 frames and a minimum of 1 data frame. When the 7th bit is 1, bits 4-6 are used to indicate the type of control frame: 000 indicates an ACK confirmation frame, i.e., an acknowledgment response frame; 001 indicates a frame returned by the receiver updating the receive window size; and 002 indicates a probe frame from the sender requesting the receive window size.
[0055] The 8-byte data represents the service data when the frame is a data frame, and the content of the control frame when the frame is a control frame.
[0056] That is, the format of a data frame can be represented as:
[0057] The frame header includes the data frame identifier, and the can_id includes the group number and the frame number.
[0058] Data content:
[0059]
[0060] This embodiment enables the receiver to flexibly control the data reception rate based on the current buffer state by dynamically adjusting the size of the receiving window, thus making data transmission more efficient.
[0061] Step S102: Compare the group number and frame number of the current data frame with those of historical data frames. If the group number and frame number corresponding to the current data frame are not registered, register the group number and frame number of the current data frame, store the service data of the current data frame, generate an acknowledgment response frame based on the received data frame and the adjusted receiving window size, and send the acknowledgment response frame to the sending end.
[0062] Optionally, in this embodiment, the receiving end compares the group number and frame number of the currently received data frame with those of historical data frames. If the group number and frame number of the current data frame have not yet been registered, the receiving end registers the group number and frame number of the current data frame and stores the service data of the current data frame in the receiving buffer queue.
[0063] Additionally, based on the received data frames and the adjusted receive window size, an acknowledgment frame is generated and sent to the sender. This acknowledgment frame includes a variable-length acknowledgment flag, which indicates the reception status of each data frame within the current group, including successfully received frames and frames yet to be received.
[0064] The data content of the confirmation response frame can be represented as follows:
[0065]
[0066] As can be seen from the above, the sequence numbers of the four data frames are incremented by 1. For a single acknowledgment response frame data packet, all four packet sequence numbers are within the range of [-4 + current packet sequence number, 4 + current packet sequence number]. Here, the packet sequence number = group number × 4 + frame number. When the current packet sequence number is within the range of [-4, 4], it can be represented by 8 bits of 1 byte. That is, each acknowledgment response frame data packet carries a 1-byte acknowledgment packet identifier. Each bit in the acknowledgment packet identifier represents the deviation value between the sequence numbers of other received packets and the current packet sequence number.
[0067] The confirmation packet identifier structure can be represented as:
[0068]
[0069] Where bit represents a byte, and Bit0 represents a sequence number that is 1 less than the current packet sequence number. A value of 1 indicates that the packet has been received, and a value of 0 indicates that the packet has not been received.
[0070] Bit1 represents a sequence number that is 2 less than the current packet sequence number. A value of 1 indicates that the packet has been received, and a value of 0 indicates that the packet has not been received.
[0071] Bit2 represents a sequence number that is 3 less than the current packet sequence number. A value of 1 indicates that the packet has been received, and a value of 0 indicates that the packet has not been received.
[0072] Bit3 represents a sequence number that is 4 less than the current packet sequence number. A value of 1 indicates that the packet has been received, and a value of 0 indicates that the packet has not been received.
[0073] Bit4 represents a sequence number that is one greater than the current packet sequence number. A value of 1 indicates that the packet has been received, and a value of 0 indicates that the packet has not been received.
[0074] Bit5 represents a sequence number that is 2 greater than the current packet sequence number. A value of 1 indicates that the packet has been received, and a value of 0 indicates that the packet has not been received.
[0075] Bit6 represents a sequence number that is 3 greater than the current packet sequence number. A value of 1 indicates that the packet has been received, and a value of 0 indicates that the packet has not been received.
[0076] Bit7 represents a sequence number that is 4 greater than the current packet sequence number. A value of 1 indicates that the packet has been received, while a value of 0 indicates that the packet has not been received.
[0077] For example, if the packet numbers of the sent data frames are 123, 124, 125, and 126, when the data packet of the acknowledgment data frame with packet number 124 is received, the binary representation of the acknowledgment response data packet is 10001100. That is, the receiver can confirm that packets 123, 124, 125, and 126 have been received by the ACK packet with sequence number 124.
[0078] This embodiment enables the sending end to accurately understand the receiving end's reception status by generating and sending an acknowledgment response frame and adjusting the size of the receiving window based on the acknowledgment response frame. This allows the sending end to perform targeted retransmission or continued transmission operations, thereby enhancing the reliability and efficiency of data transmission.
[0079] Step S103: Based on the total number of frames in the group indicated in the current data frame and the registered frame numbers, and after determining that all data frames in the current group have been received, reassemble the service data corresponding to the current group according to the frame number order and submit it to the service layer, and increase the size of the receiving window.
[0080] The acknowledgment response frame includes a variable-length acknowledgment identifier, which is used to indicate the reception status of each data frame in the current group.
[0081] Optionally, this embodiment determines whether all data frames in the current group have been received completely based on the total number of frames in the group indicated in the current data frame and the registered frame number. If it is confirmed that all data frames in the current group have been received completely, the received service data is reassembled in the order of the frame numbers to form complete service data.
[0082] In addition, the reconstructed business data is submitted to the business layer for further processing, and the size of the receiving window is increased so that the receiving end can receive subsequent data frames more efficiently.
[0083] This embodiment realizes the data reorganization of business data and submits the reorganized business data to the business layer, ensuring the integrity and order of business data, while improving overall performance and response speed.
[0084] This embodiment improves the efficiency and reliability of data reception and reassembly of the sliding window protocol based on the CAN bus by dynamically adjusting the size of the receiving window, registering and confirming data frames in detail, reassembling data, and submitting it to the service layer.
[0085] In some embodiments, buffering data frames into a receive buffer queue based on an interrupt callback function includes:
[0086] Monitor the arrival signal of the controller's local area network bus interface and trigger an interrupt based on the arrival signal;
[0087] Based on the interrupt callback function, the received data frame is completely copied to the receive buffer queue, and the storage position and timestamp of the data frame are recorded.
[0088] Optionally, in this embodiment, the receiving end monitors the CAN bus interface to detect the arrival signal of the data frame. When the arrival of the data frame is detected, the hardware triggers an interrupt signal. The interrupt signal is generated based on the physical arrival event of the data frame, so that the reception of the data frame can be processed in a timely manner.
[0089] In addition, in response to the interrupt signal, the interrupt callback function is called. The interrupt callback function is used to handle the interrupt event, that is, to copy the received data frame completely to the receive buffer queue. During the copying process, the content of the data frame is stored and the storage position and timestamp of the data frame are recorded. The timestamp is convenient for managing the timeliness and order of the received data.
[0090] Furthermore, before copying the data frame to the receive buffer queue, the integrity of the received data frame can be checked. If an error or corruption is found in the received data frame, a retransmission request can be triggered to ensure the integrity of the business data in the data frame and improve the response speed of the receiving end.
[0091] Furthermore, a multi-level caching mechanism can be added to the receive buffer queue. For example, the primary receive buffer queue is used to quickly store received data frames, while the secondary receive buffer queue can be used to temporarily store data frames to be processed, thereby improving the utilization rate of the receive buffer queue and reducing the risk of loss of business data.
[0092] This embodiment implements the buffering of data frames into the receive buffer queue according to the interrupt callback function, which improves the timeliness of data reception and the integrity and order of data, while optimizing resource utilization, reducing complexity, and improving overall performance and reliability.
[0093] In some embodiments, adjusting the size of the receive window based on the buffer state includes:
[0094] If the remaining available space in the receive buffer queue is less than the preset buffer threshold, the size of the receive window will be reduced to the remaining available space.
[0095] When the remaining available space in the receive buffer queue is greater than the preset buffer threshold, the size of the receive window is increased according to the amount of business data included in a single data frame.
[0096] Optionally, this embodiment monitors the remaining available space of the receive buffer queue. If the remaining available space is less than a preset buffer threshold, the receive window is adjusted to be the same as the remaining available space to prevent buffer overflow and ensure that the receiving end can stably process the received data frames.
[0097] Conversely, when the remaining available space in the receive buffer queue is greater than the preset buffer threshold, the size of the receive window increases according to the amount of business data included in a single data frame. In addition, the size of the receive window can be gradually increased according to the amount of business data carried by a single data frame to improve the data reception throughput.
[0098] Furthermore, a cache management algorithm can be used to enable the receiving end to dynamically allocate cache space according to different types of data frames. For example, cache space can be allocated first for high-priority data frames and then allocated for low-priority data frames, so that high-priority data frames can be processed quickly and the efficiency of cache resource utilization can be optimized.
[0099] Furthermore, the preset buffer threshold can be dynamically adjusted according to network conditions and data transmission needs. For example, under high load, the preset buffer threshold can be lowered to prevent buffer overflow, while under low load, the preset buffer threshold can be raised to improve receiving efficiency.
[0100] This embodiment adjusts the size of the receiving window based on the remaining available space in the receiving buffer queue, thereby preventing buffer overflow, improving data receiving efficiency, optimizing the utilization of buffer resources, and enhancing versatility.
[0101] In some embodiments, comparing the group number and frame number of the current data frame and historical data frames, and registering the group number and frame number of the current data frame if the group number and frame number corresponding to the current data frame are not registered, includes:
[0102] Obtain the registered frame information table, which stores the group number and frame number of data frames that have been successfully received;
[0103] Compare the group number and frame number of the current data frame with the registered frame information table. If the group number and frame number corresponding to the current data frame have already been registered, discard the current data frame.
[0104] If the group number and frame number corresponding to the current data frame are not registered, register the group number and frame number of the current data frame.
[0105] Optionally, in this embodiment, when processing the received data frame, a registered frame information table is obtained, wherein the registered frame information table is used to store the group number and frame number of the successfully received data frame.
[0106] The registered frame information table can be maintained in the memory of the receiving end, thus enabling fast access and updates.
[0107] In addition, the group number and frame number of the current data frame are compared with the records in the registered frame information table. If the group number and frame number of the current data frame already exist in the registered frame information table, it indicates that the current data frame is a duplicate data frame, and the receiving end discards the current data frame to avoid duplicate processing.
[0108] If the group number and frame number of the current data frame are not found in the registered frame information table, it indicates that the current data frame is a new data frame. The receiving end registers the group number and frame number of the current data frame in the registered frame information table and stores the service data of the data frame in the receiving buffer queue for subsequent processing.
[0109] Furthermore, during the registration of data frames, they can be classified and stored according to their priority, meaning that high-priority data frames can be processed first, ensuring the timeliness of high-priority data frames.
[0110] Furthermore, after all data frames in the group containing the current frame have been received and successfully submitted to the business layer, all registration items corresponding to that group can be marked as invalid or directly deleted to release storage resources and avoid overflow.
[0111] This embodiment achieves the uniqueness and integrity of data frames by comparing the group number and frame number of the current data frame with those of historical data frames, and registering them even when they are not registered. This improves the efficiency of data processing, optimizes resource utilization, and enhances the reliability of data transmission.
[0112] In some embodiments, increasing the size of the receiving window includes:
[0113] Determine the total number of frames within the group corresponding to the current data frame, and increase the total number of frames within the group based on the current receive window size;
[0114] After increasing the size of the receive window, it also includes:
[0115] The adjusted receive window size is sent to the sender so that the sender can send data frames based on the adjusted receive window.
[0116] Optionally, this embodiment determines the total number of frames within the group corresponding to the current data frame. The total number of frames within the group may be included in the header information of the data frame or negotiated in advance through other mechanisms.
[0117] In addition, based on the current receiving window, the receiving end increases the size of the receiving window by the total number of frames in the group to make full use of buffer resources and improve receiving efficiency.
[0118] In addition, after increasing the size of the receiving window, the adjusted receiving window size is sent to the sending end so that the sending end can adjust its sending strategy according to the new window size.
[0119] Furthermore, upon receiving a data frame and determining that the current data frame is one that has not been received before, the service data in the data frame is copied to the receive buffer queue, and the receive window size is reduced by 1.
[0120] Furthermore, the increase in the receiving window can be dynamically adjusted according to network conditions and data transmission needs. Under high load, the increase in the window can be appropriately reduced to avoid buffer overflow, while under low load, the increase in the window can be appropriately increased to improve receiving efficiency.
[0121] The size of the receiving window can also be gradually adjusted through a smooth transition, thereby avoiding the impact of drastic changes in window size, reducing the impact of window adjustment on data transmission, and improving stability.
[0122] This embodiment improves data reception efficiency, ensures data transmission reliability, optimizes resource utilization, and enhances adaptability by dynamically adjusting the size of the receiving window.
[0123] In some embodiments, it also includes:
[0124] If multiple data frames are received consecutively with the same group number and frame number, the current sending end is determined to perform a retransmission step.
[0125] If the current data frame has been successfully received, resend the acknowledgment response frame corresponding to the current data frame to the sender.
[0126] If a data frame that has timed out is detected in the group corresponding to the group number of the data frame, all records of service data and received data frames in the group number are cleared, a reassembly failure notification is sent to the sender, and the receive window is reset to its initial value.
[0127] Optionally, in this embodiment, during the processing of data frames, it is detected whether the group number and frame number of multiple data frames are consistent. If the group number and frame number of multiple data frames are received consecutively and are consistent, the receiving end determines that the sending end is currently performing a retransmission step.
[0128] If the current data frame has been successfully received, the corresponding acknowledgment response frame is resent to the sender, so that the sender can know the reception status of the data frame in a timely manner and avoid unnecessary retransmission.
[0129] If a data frame with a received timeout is detected in the group corresponding to the group number of the data frame, that is, if the service data of all frames in the group is not received within the preset time threshold, it is determined that the data reassembly of this group has failed. All records of service data and received data frames in the group number are cleared, a reassembly failure notification is sent to the sending end, and the receiving window is reset to the initial value. This can prevent the window state from being stagnant for a long time due to the loss of some data, and can also provide a stable initial environment for receiving data again.
[0130] Furthermore, the receiving end can dynamically adjust the size of the receiving window according to network conditions and data transmission requirements, improving adaptability and enabling efficient reception of data frames under different network conditions.
[0131] This embodiment enables the receiving end to determine whether the sending end is performing a retransmission step by detecting whether the group number and frame number of multiple consecutively received data frames are consistent, and to take corresponding measures to ensure the reliability of data transmission, improve the efficiency of data transmission, optimize resource utilization, and enhance adaptability.
[0132] In some embodiments, it also includes:
[0133] Monitor the time interval between received data frames;
[0134] If the received interval exceeds a preset interval threshold, a congestion notification control frame is generated and sent to the sender so that the sender can adjust the size of the sending window based on the congestion notification control frame and reduce the size of the current receiving window to the size corresponding to the service data of a single data frame.
[0135] Optionally, in this embodiment, when processing data frames, the receiving time interval of the received data frames is monitored, that is, the receiving time of each data frame is recorded, and the receiving time interval between adjacent data frames is calculated. The determination of the receiving time interval is performed in real time so as to understand the real-time status of data transmission in a timely manner.
[0136] If the received time interval exceeds a preset interval threshold, a congestion notification control frame is generated. The congestion notification control frame includes, but is not limited to, the current network congestion status information, and is used to notify the sending end of possible network congestion.
[0137] In addition, the generated congestion notification control frame is sent to the sending end so that after receiving the congestion notification control frame, the sending end can adjust the size of the sending window according to the congestion notification, thereby reducing the sending rate and alleviating network congestion.
[0138] Meanwhile, after sending the congestion notification control frame, the receiver reduces the size of its current receiving window to the size corresponding to the amount of service data in a single data frame. This can reduce the receiver's receiving rate and prevent further aggravation of network congestion.
[0139] Furthermore, the congestion notification control frame can include more detailed congestion status information, such as congestion level classification, so that the sender can adopt different adjustment strategies according to different congestion levels and control the transmission rate more finely.
[0140] Furthermore, after the sending end adjusts the sending window size based on the congestion notification, the receiving end can monitor changes in network status and gradually restore the receiving window size after congestion is relieved, enabling a rapid return to normal data transmission rates after congestion is alleviated.
[0141] This embodiment monitors the reception time interval of received data frames and generates and sends a congestion notification control frame when the reception time interval exceeds a preset threshold, thereby enabling timely detection of network congestion and the implementation of measures to alleviate it. Simultaneously, by adjusting the size of the reception window, the receiving rate at the receiving end is optimized, improving stability and adaptability.
[0142] To effectively address the shortcomings of traditional technologies, such as the lack of congestion control mechanisms during data frame reception, the inability to dynamically adjust the receive window size based on network conditions, and the inability to flexibly adapt to different data transmission needs, leading to data loss and duplicate transmissions, this application provides an embodiment of a CAN bus-based sliding window protocol data reception and reassembly device for implementing all or part of the aforementioned CAN bus-based sliding window protocol data reception and reassembly. See [link to embodiment]. Figure 2 The CAN bus-based sliding window protocol data receiving and reassembly device specifically includes the following components:
[0143] The receiving module 10 is used to buffer data frames into the receiving buffer queue based on the interrupt callback function, obtain the current buffer status of the receiving buffer queue, adjust the size of the receiving window based on the buffer status to obtain the adjusted receiving window, and respond to and control the received data frames through the adjusted receiving window. The data frame includes a data frame identifier, group number, frame number and service data.
[0144] The storage module 20 is used to compare the group number and frame number of the current data frame and the historical data frame. If the group number and frame number corresponding to the current data frame are not registered, the storage module 20 registers the group number and frame number of the current data frame, stores the service data of the current data frame, generates an acknowledgment response frame based on the received data frame and the adjusted receiving window size, and sends the acknowledgment response frame to the sending end.
[0145] The reassembly module 30 is used to reassemble the service data corresponding to the current group according to the number order of the frame numbers, based on the total number of frames in the group indicated in the current data frame and the registered frame numbers, and submit it to the service layer, and increase the size of the receiving window. The acknowledgment response frame includes a variable-length acknowledgment flag, which is used to indicate the reception status of each data frame in the current group.
[0146] As described above, the CAN bus-based sliding window protocol data receiving and reassembly device provided in this application can innovatively buffer data frames into a receiving buffer queue according to an interrupt callback function, obtain the current buffer status of the receiving queue, adjust the size of the receiving window according to the buffer status, obtain the adjusted receiving window, and respond to and control the received data frames through the adjusted receiving window. The data frame includes a data frame identifier, group number, frame number, and service data. The device compares the group number and frame number of the current data frame with those of historical data frames. If the group number and frame number corresponding to the current data frame are not registered, the device registers the group number and frame number of the current data frame, stores the service data of the current data frame, generates an acknowledgment response frame according to the received data frame and the adjusted receiving window size, and sends the acknowledgment response frame to the sending end. Based on the group indicated in the current data frame... The total number of frames and the registered frame numbers are used to reassemble the service data corresponding to the current group according to the frame number order, and submit it to the service layer. The size of the receiving window is also increased. The acknowledgment response frame includes a variable-length acknowledgment identifier, which indicates the reception status of each data frame in the current group. This allows the data reception rate to be controlled by adjusting the size of the receiving window, making data transmission more efficient. The variable-length acknowledgment identifier in the acknowledgment response frame can indicate the reception status of each data frame in the current group in detail, so as to clearly indicate to the sender the successfully received data frames and the data frames that need to be retransmitted, thereby reducing unnecessary retransmissions and improving transmission efficiency. At the same time, data frames can be reassembled according to the group number and frame number to ensure the integrity and order of service data in the data frames, thereby adapting to different data transmission needs and improving versatility. This method effectively solves the shortcomings of traditional technologies, such as the lack of congestion control mechanisms when receiving data frames, the inability to dynamically adjust the receiving window size according to network conditions, and the inability to flexibly adapt to different data transmission needs, which can easily lead to data loss and duplicate transmissions. It significantly improves the receiving efficiency of data frames, ensures the integrity and accuracy of received data frames, and avoids network congestion.
[0147] From a hardware perspective, in order to effectively address the shortcomings of traditional technologies, such as the lack of congestion control mechanisms when receiving data frames, the inability to dynamically adjust the receiving window size according to network conditions, and the inability to flexibly adapt to different data transmission needs, leading to data loss and duplicate transmissions, this application provides an embodiment of an electronic device for implementing all or part of the aforementioned CAN bus-based sliding window protocol data reception and reassembly method. The electronic device specifically includes the following components:
[0148] The system comprises a processor, memory, a communication interface, and a bus; wherein the processor, memory, and communication interface communicate with each other via the bus; the communication interface is used to realize information transmission between the CAN bus-based sliding window protocol data receiving and reassembly device and core business systems, user terminals, and related databases and other related devices; the logic controller can be a desktop computer, tablet computer, or mobile terminal, etc., and this embodiment is not limited to these. In this embodiment, the logic controller can be implemented with reference to the embodiments of the CAN bus-based sliding window protocol data receiving and reassembly method and the CAN bus-based sliding window protocol data receiving and reassembly device, the contents of which are incorporated herein, and repeated details will not be described again.
[0149] It is understood that the user terminal may include smartphones, tablet computers, network set-top boxes, portable computers, desktop computers, personal digital assistants (PDAs), in-vehicle devices, smart wearable devices, etc. Among these, the smart wearable devices may include smart glasses, smartwatches, smart bracelets, etc.
[0150] In practical applications, the data reception and reassembly method based on the CAN bus sliding window protocol can be partially executed on the electronic device side as described above, or all operations can be completed in the client device. The choice can be made based on the processing power of the client device and the limitations of the user's usage scenario. This application does not impose any limitations on this. If all operations are completed in the client device, the client device may further include a processor.
[0151] The aforementioned client device may have a communication module (i.e., a communication unit) that can communicate with a remote server to achieve data transmission with the server. The server may include a server on the task scheduling center side; in other implementation scenarios, it may also include a server on an intermediate platform, such as a server on a third-party server platform that has a communication link with the task scheduling center server. The server may include a single computer device, a server cluster consisting of multiple servers, or a distributed server structure.
[0152] Figure 3 This is a schematic block diagram illustrating the system configuration of the electronic device 9600 according to an embodiment of this application. Figure 3 As shown, the electronic device 9600 may include a central processing unit 9100 and a memory 9140; the memory 9140 is coupled to the central processing unit 9100. It is worth noting that... Figure 3This is an example; other types of structures can also be used to supplement or replace this structure to achieve telecommunications functions or other functions.
[0153] In one embodiment, the CAN bus-based sliding window protocol data reception and reassembly method can be integrated into the central processing unit 9100. The central processing unit 9100 can be configured to perform the following control:
[0154] Step S101: Based on the interrupt callback function, buffer the data frame into the receive buffer queue, obtain the current buffer status of the receive buffer queue, adjust the size of the receive window based on the buffer status, obtain the adjusted receive window, and respond to and control the received data frame through the adjusted receive window. The data frame includes data frame identifier, group number, frame number and service data.
[0155] Step S102: Compare the group number and frame number of the current data frame and the historical data frame. If the group number and frame number corresponding to the current data frame are not registered, register the group number and frame number of the current data frame, store the service data of the current data frame, generate an acknowledgment response frame based on the received data frame and the adjusted receiving window size, and send the acknowledgment response frame to the sending end.
[0156] Step S103: Based on the total number of frames in the group and the registered frame numbers indicated in the current data frame, and after determining that all data frames in the current group have been received, reassemble the service data corresponding to the current group according to the frame number order and submit it to the service layer, increase the size of the receiving window, and confirm that the response frame includes a variable-length confirmation flag, which is used to indicate the reception status of each data frame in the current group.
[0157] As described above, the electronic device provided in this application innovatively caches data frames to a receive buffer queue based on an interrupt callback function, obtains the current buffer state of the receive queue, adjusts the size of the receive window according to the buffer state to obtain an adjusted receive window, and responds to and controls the received data frames through the adjusted receive window. The data frame includes a data frame identifier, a group number, a frame number, and service data. The group number and frame number of the current data frame are compared with those of historical data frames. If the group number and frame number corresponding to the current data frame are not registered, the group number and frame number of the current data frame are registered. The service data of the current data frame is stored. An acknowledgment response frame is generated based on the received data frame and the adjusted receive window size, and the acknowledgment response frame is sent to the sending end. The total number of frames within the group indicated in the current data frame and the registered frame numbers are then used to determine the appropriate response. Once it is confirmed that all data frames in the current group have been received, the service data corresponding to the current group is reassembled according to the frame number order and submitted to the service layer. The size of the receiving window is increased. The acknowledgment response frame includes a variable-length acknowledgment identifier, which indicates the reception status of each data frame in the current group. This allows for control of the data reception rate by adjusting the receiving window size, making data transmission more efficient. The variable-length acknowledgment identifier in the acknowledgment response frame provides detailed information on the reception status of each data frame in the current group, clearly indicating to the sender which data frames have been successfully received and which need to be retransmitted, thereby reducing unnecessary retransmissions and improving transmission efficiency. Furthermore, data frames can be reassembled according to the group number and frame number, ensuring the integrity and order of service data within the data frames, thus adapting to different data transmission needs and improving versatility. This method effectively solves the shortcomings of traditional technologies, such as the lack of congestion control mechanisms when receiving data frames, the inability to dynamically adjust the receiving window size according to network conditions, and the inability to flexibly adapt to different data transmission needs, leading to data loss and duplicate transmissions. It significantly improves the reception efficiency of data frames, ensures the integrity and accuracy of received data frames, and avoids network congestion.
[0158] In another embodiment, the CAN bus-based sliding window protocol data receiving and reassembly device can be configured separately from the central processing unit 9100. For example, the CAN bus-based sliding window protocol data receiving and reassembly device can be configured as a chip connected to the central processing unit 9100, and the CAN bus-based sliding window protocol data receiving and reassembly method function can be implemented through the control of the central processing unit.
[0159] like Figure 3 As shown, the electronic device 9600 may further include: a communication module 9110, an input unit 9120, an audio processor 9130, a display 9160, and a power supply 9170. It is worth noting that the electronic device 9600 does not necessarily need to include these components. Figure 3All components shown; in addition, the electronic device 9600 may also include Figure 3 For components not shown, please refer to existing technologies.
[0160] like Figure 3 As shown, the central processing unit 9100, sometimes also referred to as a controller or operating control, may include a microprocessor or other processor device and / or logic device, which receives inputs and controls the operation of various components of the electronic device 9600.
[0161] The memory 9140 may be, for example, one or more of a cache, flash memory, hard drive, removable media, volatile memory, non-volatile memory, or other suitable devices. It may store the aforementioned failure-related information, and also store a program for executing that information. The central processing unit 9100 may execute the program stored in the memory 9140 to perform information storage or processing, etc.
[0162] Input unit 9120 provides input to central processing unit 9100. Input unit 9120 may be, for example, a keypad or touch input device. Power supply 9170 provides power to electronic device 9600. Display 9160 displays images and text. Display may be, for example, an LCD display, but is not limited thereto.
[0163] The memory 9140 can be a solid-state memory, such as a read-only memory (ROM), random access memory (RAM), a SIM card, etc. It can also be a memory that retains information even when power is off, can be selectively erased, and contains more data; examples of this type of memory are sometimes referred to as EPROMs. The memory 9140 can also be some other type of device. The memory 9140 includes a buffer memory 9141 (sometimes referred to as a buffer). The memory 9140 may include an application / function storage unit 9142 for storing application programs and function programs or processes for executing the operation of the electronic device 9600 via the central processing unit 9100.
[0164] The memory 9140 may also include a data storage unit 9143 for storing data, such as contacts, digital data, pictures, sounds, and / or any other data used by the electronic device. The driver storage unit 9144 of the memory 9140 may include various drivers for the electronic device for communication functions and / or for performing other functions of the electronic device (such as messaging applications, address book applications, etc.).
[0165] The communication module 9110 is a transmitter / receiver that sends and receives signals via the antenna 9111. The communication module 9110 (transmitter / receiver) is coupled to the central processing unit 9100 to provide input signals and receive output signals, which is the same as in a conventional mobile communication terminal.
[0166] Based on different communication technologies, multiple communication modules 9110 can be configured in the same electronic device, such as cellular network modules, Bluetooth modules, and / or wireless LAN modules. The communication module 9110 (transmitter / receiver) is also coupled to a speaker 9131 and a microphone 9132 via an audio processor 9130 to provide audio output via the speaker 9131 and receive audio input from the microphone 9132, thereby realizing typical telecommunications functions. The audio processor 9130 may include any suitable buffer, decoder, amplifier, etc. Additionally, the audio processor 9130 is coupled to a central processing unit 9100, enabling on-device recording via the microphone 9132 and on-device playback of stored audio via the speaker 9131.
[0167] Embodiments of this application also provide a computer-readable storage medium capable of implementing all steps of the CAN bus-based sliding window protocol data reception and reassembly method with a server or client as the execution subject in the above embodiments. The computer-readable storage medium stores a computer program that, when executed by a processor, implements all steps of the CAN bus-based sliding window protocol data reception and reassembly method with a server or client as the execution subject in the above embodiments. For example, when the processor executes the computer program, it implements the following steps:
[0168] Step S101: Based on the interrupt callback function, buffer the data frame into the receive buffer queue, obtain the current buffer status of the receive buffer queue, adjust the size of the receive window based on the buffer status, obtain the adjusted receive window, and respond to and control the received data frame through the adjusted receive window. The data frame includes data frame identifier, group number, frame number and service data.
[0169] Step S102: Compare the group number and frame number of the current data frame and the historical data frame. If the group number and frame number corresponding to the current data frame are not registered, register the group number and frame number of the current data frame, store the service data of the current data frame, generate an acknowledgment response frame based on the received data frame and the adjusted receiving window size, and send the acknowledgment response frame to the sending end.
[0170] Step S103: Based on the total number of frames in the group and the registered frame numbers indicated in the current data frame, and after determining that all data frames in the current group have been received, reassemble the service data corresponding to the current group according to the frame number order and submit it to the service layer, increase the size of the receiving window, and confirm that the response frame includes a variable-length confirmation flag, which is used to indicate the reception status of each data frame in the current group.
[0171] As described above, the computer-readable storage medium provided in this application innovatively caches data frames to a receive buffer queue according to an interrupt callback function, obtains the current buffer state of the receive queue, adjusts the size of the receive window according to the buffer state to obtain an adjusted receive window, and responds to and controls the received data frames through the adjusted receive window. The data frame includes a data frame identifier, a group number, a frame number, and service data. The group number and frame number of the current data frame are compared with those of historical data frames. If the group number and frame number corresponding to the current data frame are not registered, they are registered. The service data of the current data frame is stored. An acknowledgment response frame is generated based on the received data frame and the adjusted receive window size, and the acknowledgment response frame is sent to the sending end. The total number of frames in the group indicated in the current data frame and the registered... The method employs frame numbering. After confirming that all data frames within the current group have been received, the service data corresponding to the current group is reassembled according to the frame number order and submitted to the service layer. The size of the receiving window is increased. The acknowledgment response frame includes a variable-length acknowledgment identifier, which indicates the reception status of each data frame within the current group. This allows for control of the data reception rate by adjusting the receiving window size, making data transmission more efficient. The variable-length acknowledgment identifier in the acknowledgment response frame provides detailed information on the reception status of each data frame within the current group, clearly indicating to the sender which data frames have been successfully received and which need to be retransmitted, thereby reducing unnecessary retransmissions and improving transmission efficiency. Furthermore, it allows for reassembly of data frames based on group and frame numbers, ensuring the integrity and order of service data within the data frames, thus adapting to different data transmission needs and improving versatility. This method effectively addresses the shortcomings of traditional technologies, such as the lack of congestion control mechanisms during data frame reception, the inability to dynamically adjust the receiving window size according to network conditions, and the inability to flexibly adapt to different data transmission needs, leading to data loss and duplicate transmissions. It significantly improves the reception efficiency of data frames, ensures the integrity and accuracy of received data frames, and avoids network congestion.
[0172] Embodiments of this application also provide a computer program product capable of implementing all steps of the CAN bus-based sliding window protocol data reception and reassembly method, where the execution subject is a server or client, as described in the above embodiments. When executed by a processor, this computer program / instruction implements the steps of the CAN bus-based sliding window protocol data reception and reassembly method. For example, the computer program / instruction implements the following steps:
[0173] Step S101: Based on the interrupt callback function, buffer the data frame into the receive buffer queue, obtain the current buffer status of the receive buffer queue, adjust the size of the receive window based on the buffer status, obtain the adjusted receive window, and respond to and control the received data frame through the adjusted receive window. The data frame includes data frame identifier, group number, frame number and service data.
[0174] Step S102: Compare the group number and frame number of the current data frame and the historical data frame. If the group number and frame number corresponding to the current data frame are not registered, register the group number and frame number of the current data frame, store the service data of the current data frame, generate an acknowledgment response frame based on the received data frame and the adjusted receiving window size, and send the acknowledgment response frame to the sending end.
[0175] Step S103: Based on the total number of frames in the group and the registered frame numbers indicated in the current data frame, and after determining that all data frames in the current group have been received, reassemble the service data corresponding to the current group according to the frame number order and submit it to the service layer, increase the size of the receiving window, and confirm that the response frame includes a variable-length confirmation flag, which is used to indicate the reception status of each data frame in the current group.
[0176] As described above, the computer program product provided in this application innovatively caches data frames to a receive buffer queue based on an interrupt callback function, obtains the current buffer state of the receive queue, adjusts the size of the receive window according to the buffer state to obtain an adjusted receive window, and responds to and controls the received data frames through the adjusted receive window. The data frame includes a data frame identifier, group number, frame number, and service data. The group number and frame number of the current data frame are compared with those of historical data frames. If the group number and frame number corresponding to the current data frame are not registered, the group number and frame number of the current data frame are registered. The service data of the current data frame is stored. An acknowledgment response frame is generated based on the received data frame and the adjusted receive window size, and the acknowledgment response frame is sent to the sending end. The total number of frames in the group indicated in the current data frame and the registered frames are then used to determine the appropriate response. The method, after confirming that all data frames in the current group have been received, reassembles the corresponding service data of the current group according to the frame number order and submits it to the service layer, while increasing the size of the receiving window. The acknowledgment response frame includes a variable-length acknowledgment identifier, which indicates the reception status of each data frame in the current group. This allows for control of the data reception rate by adjusting the size of the receiving window, making data transmission more efficient. The variable-length acknowledgment identifier in the acknowledgment response frame provides detailed information on the reception status of each data frame in the current group, clearly indicating to the sender which data frames have been successfully received and which need to be retransmitted, thereby reducing unnecessary retransmissions and improving transmission efficiency. Furthermore, it can reassemble data frames according to the group number and frame number, ensuring the integrity and order of service data within the data frames, thus adapting to different data transmission needs and improving versatility. This method effectively solves the shortcomings of traditional technologies, such as the lack of congestion control mechanisms when receiving data frames, the inability to dynamically adjust the receiving window size according to network conditions, and the inability to flexibly adapt to different data transmission needs, leading to data loss and duplicate transmissions. It significantly improves the reception efficiency of data frames, ensures the integrity and accuracy of received data frames, and avoids network congestion.
[0177] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0178] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (devices), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0179] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0180] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0181] Specific embodiments have been used to illustrate the principles and implementation methods of this invention. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this invention. Therefore, the content of this specification should not be construed as a limitation of this invention.
Claims
1. A method for receiving and reassembling data using a sliding window protocol based on a CAN bus, characterized in that, The method includes: The system monitors the arrival signal of the Controller Area Network (CAN) bus interface, triggers an interrupt based on the arrival signal, copies the received data frame to the receive buffer queue based on the interrupt callback function, records the storage location and timestamp of the data frame, obtains the current buffer status of the receive buffer queue, adjusts the size of the receive window based on the buffer status to obtain the adjusted receive window, and responds to and controls the received data frame through the adjusted receive window. The data frame includes a data frame identifier, group number, frame number, and service data. Adjusting the size of the receive window based on the buffer status includes: reducing the size of the receive window to the remaining available space when the remaining available space of the receive buffer queue is less than a preset buffer threshold; and increasing the size of the receive window according to the amount of service data included in a single data frame when the remaining available space of the receive buffer queue is greater than the preset buffer threshold. Compare the group number and frame number of the current data frame with those of historical data frames. If the group number and frame number corresponding to the current data frame are not registered, register the group number and frame number of the current data frame, store the service data of the current data frame, generate an acknowledgment response frame based on the received data frame and the adjusted size of the receiving window, and send the acknowledgment response frame to the sending end. Based on the total number of frames in the group indicated in the current data frame and the registered frame numbers, if it is determined that all data frames in the current group have been received, the service data corresponding to the current group is reassembled according to the numbering order of the frame numbers and submitted to the service layer, and the size of the receiving window is increased. The acknowledgment response frame includes a variable-length acknowledgment identifier, which is used to indicate the reception status of each data frame in the current group.
2. The method according to claim 1, characterized in that, The step of comparing the group number and frame number of the current data frame and historical data frames, and registering the group number and frame number of the current data frame if the group number and frame number corresponding to the current data frame are not registered, includes: Obtain the registered frame information table, which is used to store the group number and frame number of the data frames that have been successfully received; The group number and frame number of the current data frame are compared with the registered frame information table. If the group number and frame number corresponding to the current data frame have been registered, the current data frame is discarded. If the group number and frame number corresponding to the current data frame are not registered, register the group number and frame number of the current data frame.
3. The method according to claim 1, characterized in that, Increasing the size of the receiving window includes: Determine the total number of frames within the group corresponding to the current data frame, and increase the total number of frames within the group based on the current size of the receiving window; After increasing the size of the receiving window, the method further includes: The adjusted size of the receiving window is sent to the sending end so that the sending end can send the data frame based on the adjusted receiving window.
4. The method according to claim 1, characterized in that, Also includes: When multiple data frames are received consecutively with the same group number and frame number, the current sending end is determined to perform a retransmission step. If the current data frame has been successfully received, the acknowledgment response frame corresponding to the current data frame is resent to the sending end. If a data frame that has timed out is detected in the group corresponding to the group number of the data frame, all service data and records of the received data frame in the group number are cleared, a reassembly failure notification is sent to the sending end, and the receiving window is reset to its initial value.
5. The method according to claim 1, characterized in that, Also includes: Monitor the time interval between receiving the data frames; If the receiving time interval is detected to exceed a preset interval threshold, a congestion notification control frame is generated and sent to the sending end, so that the sending end adjusts the size of the sending window based on the congestion notification control frame and reduces the current size of the receiving window to the size corresponding to the service data of a single data frame.
6. A sliding window protocol data receiving and reassembly device based on CAN bus, characterized in that, The device implements the steps of the sliding window protocol data reception and reassembly method based on CAN bus as described in any one of claims 1 to 5, including: A receiving module is used to monitor the arrival signal of the controller local area network bus interface, trigger an interrupt based on the arrival signal, copy the received data frame to the receive buffer queue based on the interrupt callback function, record the storage position and timestamp of the data frame, obtain the current buffer status of the receive buffer queue, and adjust the size of the receive window based on the buffer status to obtain the adjusted receive window, including: when the remaining available space of the receive buffer queue is less than a preset buffer threshold, reducing the size of the receive window to the remaining available space; when the remaining available space of the receive buffer queue is greater than the preset buffer threshold, increasing the size of the receive window according to the amount of service data included in a single data frame; and responding to and controlling the received data frame through the adjusted receive window, wherein the data frame includes a data frame identifier, group number, frame number, and service data. The storage module is used to compare the group number and frame number of the current data frame and the historical data frame. If the group number and frame number corresponding to the current data frame are not registered, the module registers the group number and frame number of the current data frame, stores the service data of the current data frame, generates an acknowledgment response frame based on the received data frame and the adjusted size of the receiving window, and sends the acknowledgment response frame to the sending end. The reassembly module is used to reassemble the service data corresponding to the current group according to the numbering order of the frame numbers, based on the total number of frames in the group indicated in the current data frame and the registered frame numbers, and submit it to the service layer, and increase the size of the receiving window, when it is determined that all data frames in the current group have been received. The acknowledgment response frame includes a variable-length acknowledgment identifier, which is used to indicate the reception status of each data frame in the current group.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the sliding window protocol data reception and reassembly method based on CAN bus as described in any one of claims 1 to 5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the CAN bus-based sliding window protocol data reception and reassembly method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
System and method for interfacing a can device and a peripheral device
EP1191747A2
TMO inter-process communication method based on can
KR1020110094853A