A multi-physical layer adaptive communication method and device
By adopting a multi-physical-layer adaptive communication method, the problem of redundant development caused by the differences between CAN and serial communication protocols is solved, a unified communication processing flow is achieved, development and maintenance costs are reduced, and code reusability is improved.
Patent Information
- Application Number
- CN202611078640.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-20
- Publication Date
- 2026-11-27
AI Technical Summary
In existing technologies, due to the differences in protocol stack architecture between CAN and serial communication, the host computer and the host machine need to be developed separately, which consumes a lot of development time and increases the difficulty of maintenance.
A multi-physical-layer adaptive communication method is adopted, which simultaneously initializes the CAN and serial communication modules through the protocol adaptation layer, defines a unified protocol data unit format, dynamically locks the current communication channel, realizes a unified sending interface and receiving processing, and shields the differences in underlying physical media.
This allows application layer code to be unaware of the underlying physical media type, reducing development difficulty and maintenance costs, improving code reusability, and simplifying the physical media switching process.
Smart Images

Figure CN123185282A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communication technology, and in particular to a multi-physical-layer adaptive communication method and apparatus. Background Technology
[0002] In existing technologies, automated communication between the host computer and the upper-level computer mainly relies on the CAN bus or serial communication interfaces (such as RS232 / RS485). Due to significant differences in protocol stack architecture and data processing flow between CAN and serial communication, developers need to write separate protocol processing code for the upper-level computer and host computer sides for both CAN and serial media during the development of automated functions. This includes modules for data encapsulation, decapsulation, error handling, and flow control. This "one machine, two protocols" development model results in low software code reusability. The same automated function needs to be repeatedly developed on different physical links, consuming significant development time and increasing the difficulty of product maintenance and upgrades. Summary of the Invention
[0003] The purpose of this invention is to disclose a multi-physical-layer adaptive communication method and device, which solves the technical problem that existing CAN and serial ports use different protocols, resulting in the need for separate development of the host computer and the host machine, which consumes a lot of development time.
[0004] To achieve the above objectives, this invention discloses a multi-physical-layer adaptive communication method, comprising: Step S1: The protocol adaptation layer simultaneously initializes the CAN diagnostic communication module and the serial communication module, so that both physical channels are in the receiving ready state, and simultaneously listens for data from the host computer through the two physical channels, and locks the current communication channel based on the first frame of valid data received. Step S2: The protocol adaptation layer provides a unified sending interface to receive protocol data units sent by the application layer. The protocol data units are generated according to a unified protocol format. Step S3: The protocol adaptation layer obtains the type of the current communication channel. a. If the current communication channel is in CAN diagnostic mode, the protocol data unit is encapsulated as the data payload of the UDS diagnostic service and sent through the CAN bus; b. If the current communication channel is in serial port mode, the protocol data unit will be sent directly through the serial port driver.
[0005] Furthermore, it also includes a receiving step: Step S4: When the underlying physical channel receives data, the protocol adaptation layer determines the physical channel type for receiving the data. a. If it is in CAN mode, the CAN diagnostic communication module performs ISO-TP multi-frame reassembly on the received CAN message to restore the complete UDS diagnostic response message, and extracts the original protocol data unit from the diagnostic response message. b. If it is in serial port mode, the serial communication module receives the raw byte stream and identifies and extracts the complete protocol data unit from the byte stream according to the predefined frame header, frame tail or length field; Step S5: The protocol adaptation layer transmits the extracted protocol data unit to the protocol parsing layer. The protocol parsing layer parses the protocol data unit according to the unified protocol format and performs corresponding automated function operations.
[0006] Specifically, locking the current communication channel based on the received first frame of valid data includes: The protocol adaptation layer performs validity checks on the data received by a certain physical channel to determine whether it conforms to the predefined unified protocol data frame format; If the verification is successful, the physical channel will be locked as the current communication channel. If the verification fails, the data is discarded, and subsequent data will continue to be monitored through the two physical channels.
[0007] Specifically, in the CAN diagnostic mode, the protocol data unit is used as the data payload of the UDS diagnostic service, and a dedicated data identifier is assigned to the payload to uniquely identify the payload type; the UDS diagnostic service includes reading data service via identifier (0x22) or writing data service via identifier (0x2E).
[0008] Specifically, in the CAN diagnostic mode, the steps for encapsulating the protocol data unit as the data payload of the UDS diagnostic service and transmitting it via the CAN bus include: Determine whether the data length of the protocol data unit is greater than 7 bytes; If it is less than or equal to 7 bytes, then directly construct a single-frame diagnostic request message and send it; If the data is greater than 7 bytes, the ISO-TP protocol is invoked for segmented transmission. First, the first frame is sent, and then the receiver replies with a flow control frame. Then, multiple consecutive frames are sent continuously according to the parameters specified in the flow control frame until all data has been sent.
[0009] On the other hand, in order to achieve the above objectives, the present invention discloses a multi-physical-layer adaptive communication device, comprising: The bus interface module, located at the physical layer, is used to provide an interface for physical connection with the host computer. The interface is either a CAN interface or a serial communication interface. The CAN diagnostic communication module, located at the transmission link layer, is used to implement the UDS diagnostic protocol stack and the ISO-TP transmission layer protocol. The serial communication module, located at the transmission link layer, is used to implement the underlying driver for serial communication and transparent data transmission and reception. The protocol adaptation module, located at the protocol layer, is connected to both the CAN diagnostic communication module and the serial communication module. It is used to initialize both the CAN diagnostic communication module and the serial communication module simultaneously when the system starts up, so that both physical channels are in a receive-ready state, and to lock the current communication channel based on the first frame of valid data received. The protocol adaptation module is also used to provide a unified sending and receiving interface to shield the upper layer from the differences in the underlying physical medium. The protocol parsing module, located above the protocol adaptation module, is used to define a unified automated communication protocol format and to package or parse data according to the unified protocol format.
[0010] Specifically, the protocol adaptation module is used to enable the receiving functions of both the CAN diagnostic communication module and the serial communication module during system initialization, and to perform validity verification on the data received from any channel after receiving the data, locking the channel that has been successfully verified as the current working channel; when sending data, it selectively sends the data to the CAN diagnostic communication module or the serial communication module according to the currently locked channel type.
[0011] Specifically, the CAN diagnostic communication module is configured to: in the transmitting direction, use the protocol data unit issued by the protocol adaptation module as the data payload of the UDS diagnostic service, and send data exceeding the single frame length limit in segments according to the ISO-TP protocol; in the receiving direction, perform ISO-TP reassembly on the received CAN message to restore the complete diagnostic response message and extract the data payload.
[0012] Specifically, the protocol parsing module is unaware of the underlying physical medium and is configured to: in the sending direction, package application layer data into protocol data units according to the unified protocol format and send them to the protocol adaptation module; in the receiving direction, parse the protocol data units uploaded by the protocol adaptation module according to the unified protocol format, extract instruction codes and / or data fields, and trigger the execution of corresponding automated functions.
[0013] Specifically, the protocol adaptation module is bidirectionally connected to both the CAN diagnostic communication module and the serial communication module, and the protocol parsing module is bidirectionally connected to the protocol adaptation module; the bus interface module is physically connected to either the CAN diagnostic communication module or the serial communication module.
[0014] The beneficial effects of this invention are as follows: By adding a protocol adaptation layer on the host side and defining a unified protocol data unit format, this protocol adaptation layer initializes both CAN and serial physical channels simultaneously during system initialization and listens to data from the host computer. Based on the first valid frame of data received, it dynamically locks the current communication channel to automatically identify the actual physical medium type. In the transmission direction, it performs differentiated processing based on the locked channel type. In the reception direction, it extracts data from different channel sources into protocol data units and then passes them to the protocol parsing layer for unified parsing. This allows the application layer code to be completely unaware of the underlying physical medium type, achieving complete decoupling between the upper-layer business logic and the lower-layer transmission protocol. When switching physical media, only the hardware interface needs to be changed without modifying the application layer code. This significantly reduces the joint development time and difficulty of the host computer and host computer, greatly improves code reusability, and reduces maintenance costs. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a flowchart illustrating the multi-physical-layer adaptive communication method of the present invention; Figure 2 This is a schematic diagram of the structure of the multi-physical-layer adaptive communication device of the present invention. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. 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.
[0018] In this invention, the terms "upper," "lower," "left," "right," "front," "rear," "top," "bottom," "inner," "outer," "middle," "vertical," "horizontal," "lateral," and "longitudinal" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. These terms are primarily for the purpose of better describing the invention and its embodiments, and are not intended to limit the indicated devices, elements, or components to having a specific orientation, or to be constructed and operated in a specific orientation.
[0019] Furthermore, in addition to indicating direction or positional relationship, some of the aforementioned terms may also have other meanings. For example, the term "above" may also be used in certain situations to indicate a dependency or connection. Those skilled in the art can understand the specific meaning of these terms in this invention based on the specific circumstances.
[0020] Furthermore, the terms "installation," "setup," "equipped with," "connection," and "linked" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral structure; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium, or an internal connection between two devices, components, or parts. Those skilled in the art can understand the specific meaning of these terms in this invention based on the specific circumstances.
[0021] Furthermore, the terms "first," "second," etc., are primarily used to distinguish different devices, components, or parts (which may be the same or different in specific type and construction), and are not intended to indicate or imply the relative importance or quantity of the indicated devices, components, or parts. Unless otherwise stated, "a plurality of" means two or more.
[0022] The technical solution of the present invention will be further described below with reference to the embodiments and accompanying drawings.
[0023] Example 1 like Figure 1 As shown, this embodiment provides a multi-physical-layer adaptive communication method applied to the host side (the tested end), which interacts with the host computer (the control end) via a physical connection. The physical connection includes either a CAN bus interface or a serial communication interface (such as RS232 / RS485). The host computer's interface is fixed as either a CAN interface or a serial port.
[0024] The host computer internally contains a protocol stack, which, from top to bottom, includes the application layer, protocol parsing layer, protocol adaptation layer, transport link layer, and physical layer. The method includes the following steps: Step 1: System initialization and communication channel determination.
[0025] This step specifically includes: Step 101: Power on or reset the host system and perform initialization operations on the underlying hardware and communication modules.
[0026] Step 102: The protocol adaptation layer simultaneously starts and initializes the CAN diagnostic communication module and the serial communication module, ensuring that both physical channels are in a receive-ready state. The CAN diagnostic communication module implements the UDS diagnostic protocol stack and the ISO-TP transport layer protocol, while the serial communication module enables transparent transmission and reception of underlying data from UART / RS232 / RS485.
[0027] Step 103: The protocol adaptation layer simultaneously listens to data from the host computer through two physical channels and waits to receive the first frame of valid data.
[0028] Step 104: When data is received on a physical channel, the protocol adaptation layer performs a validity check on the data to determine whether it conforms to the predefined unified protocol data frame format. If the check is successful, the physical channel is locked as the current communication channel; if the check fails, the data is discarded and listening continues. During the communication link maintenance period, all subsequent reply data is sent to the host computer through the locked current communication channel.
[0029] Step 2, Data Sending Process.
[0030] When the application layer of the host needs to send a frame of automation instructions or data to the host computer, the following sub-steps are executed: Step 201: The application layer packages the raw data according to a predefined unified protocol format to generate a complete Protocol Data Unit (PDU). The PDU includes a frame header, a length field, a command code field, a data field, and a checksum field.
[0031] Step 202: The application layer calls the unified sending interface provided by the protocol adaptation layer and passes the PDU as a parameter to the unified sending interface.
[0032] Step 203: The protocol adaptation layer obtains the type of the currently locked communication channel and performs the following branch operations based on the type: a. If the current communication channel is in CAN diagnostic mode, then perform the following steps: Step 203a1: The protocol adaptation layer uses the PDU as the data payload of the UDS diagnostic service and assigns a dedicated data identifier (DID) to the payload to uniquely identify the type of the PDU. The UDS diagnostic service includes reading data via the identifier (0x22) or writing data via the identifier (0x2E).
[0033] Step 203a2: Determine whether the data length of the PDU is greater than 7 bytes.
[0034] If the data length of the PDU is less than or equal to 7 bytes, a single-frame diagnostic request message is directly constructed and sent through the CAN bus interface.
[0035] If the data length of the PDU is greater than 7 bytes, the ISO-TP protocol is invoked for segmented transmission. Specifically, this includes: first, sending the first frame (FF), waiting for the receiving end to reply with a flow control frame (FC), and then continuously sending multiple consecutive frames (CF) according to the parameters specified in the flow control frame until all data has been sent.
[0036] Step 203a3: Send the constructed diagnostic request message to the host computer through the CAN bus interface.
[0037] b. If the current communication channel is in serial port mode, then perform the following steps: Step 203b: The protocol adaptation layer sends the PDU directly through the driver of the serial communication module without performing any additional protocol encapsulation on the PDU.
[0038] Step 3: Data Reception Process.
[0039] When the underlying physical channel receives data from the host computer, the following sub-steps are executed: Step 301: The protocol adaptation layer determines the physical channel type for receiving data and performs the following branch operations based on the type: a. If the physical channel is in CAN mode, then perform the following steps: Step 301a1: The CAN diagnostic communication module receives CAN messages and reassembles the received ISO-TP multi-frame messages to restore the complete UDS diagnostic response message.
[0040] Step 301a2: Extract the data payload from the UDS diagnostic response message. This data payload is the original PDU.
[0041] Step 301a3: Pass the extracted PDU to the protocol adaptation layer.
[0042] b. If the physical channel is in serial port mode, then perform the following steps: Step 301b1: The serial communication module receives the raw byte stream and identifies and extracts the complete PDU from the byte stream according to the predefined frame header, frame tail identifier or length field.
[0043] Step 301b2: Pass the extracted PDU to the protocol adaptation layer.
[0044] Step 302: After receiving a PDU from any physical channel, the protocol adaptation layer calls the unified parsing interface of the protocol parsing layer.
[0045] Step 303: The protocol parsing layer parses the PDU according to the predefined unified protocol format, extracts the instruction code and / or data field, and executes the corresponding automated function operation based on the parsing result.
[0046] Example 2 like Figure 2 As shown, this embodiment provides a multi-physical layer adaptive communication device for implementing the method described in Embodiment 1. The device is integrated inside the host and includes: a bus interface module, a CAN diagnostic communication module, a serial communication module, a protocol adaptation module, and a protocol parsing module.
[0047] The bus interface module, located at the physical layer, is used to provide an interface for physical connection with the host computer. This interface is either a CAN interface or a serial communication interface.
[0048] The CAN diagnostic communication module, located at the transmission link layer, is used to implement the UDS diagnostic protocol stack and the ISO-TP transport layer protocol. It is configured to: in the transmitting direction, encapsulate the data payload sent from the application layer into a diagnostic request message conforming to the ISO 14229 standard, and segment and send data exceeding the single-frame length limit according to the ISO 15765-2 protocol; in the receiving direction, perform ISO-TP reassembly on the received CAN message to restore the complete diagnostic response message and extract the data payload.
[0049] The serial communication module, located at the transmission link layer, is used to implement the underlying driver for UART / RS232 / RS485. It is configured to transmit data directly and transparently in the transmitting direction and to identify and extract complete protocol data frames from the raw byte stream in the receiving direction.
[0050] The protocol adaptation module, located at the protocol layer, is connected to both the CAN diagnostic communication module and the serial communication module. This module provides a unified send and receive interface to shield the upper application layer from differences in the underlying physical media. The protocol adaptation module is configured to: enable the receive functions of both the CAN diagnostic communication module and the serial communication module simultaneously during device initialization; upon receiving data from any channel, verify the validity of the data and lock the successfully verified channel as the current working channel; and selectively send data to either the CAN diagnostic communication module or the serial communication module based on the currently locked channel type when sending data.
[0051] The protocol parsing module, located above the protocol adaptation module, defines a unified automated communication protocol, including instruction sets, data frame formats, handshake rules, and error handling rules. The protocol parsing module is unaware of the underlying physical medium and is configured to: in the sending direction, package application layer data into protocol data units according to a unified protocol format; and in the receiving direction, parse the data uploaded by the protocol adaptation layer according to a unified protocol format and execute corresponding automated functions.
[0052] The technical means disclosed in this invention are not limited to those disclosed in the above embodiments, but also include technical solutions composed of any combination of the above technical features. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of this invention, and these improvements and modifications are also considered within the scope of protection of this invention.
Claims
1. A multi-physical-layer adaptive communication method, characterized in that, include: Step S1: The protocol adaptation layer simultaneously initializes the CAN diagnostic communication module and the serial communication module, so that both physical channels are in the receiving ready state, and simultaneously listens for data from the host computer through the two physical channels, and locks the current communication channel based on the first frame of valid data received. Step S2: The protocol adaptation layer provides a unified sending interface to receive protocol data units sent by the application layer. The protocol data units are generated according to a unified protocol format. Step S3: The protocol adaptation layer obtains the type of the current communication channel, including: a. If the current communication channel is in CAN diagnostic mode, the protocol data unit is encapsulated as the data payload of the UDS diagnostic service and sent through the CAN bus; b. If the current communication channel is in serial port mode, the protocol data unit will be sent directly through the serial port driver.
2. The method according to claim 1, characterized in that, It also includes the receiving step: Step S4: When the underlying physical channel receives data, the protocol adaptation layer determines the physical channel type for receiving the data, including: a. If it is in CAN mode, the CAN diagnostic communication module performs ISO-TP multi-frame reassembly on the received CAN message to restore the complete UDS diagnostic response message, and extracts the original protocol data unit from the diagnostic response message. b. If it is in serial port mode, the serial communication module receives the raw byte stream and identifies and extracts the complete protocol data unit from the byte stream according to the predefined frame header, frame tail or length field; Step S5: The protocol adaptation layer transmits the extracted protocol data unit to the protocol parsing layer. The protocol parsing layer parses the protocol data unit according to the unified protocol format and performs corresponding automated function operations.
3. The method according to claim 1, characterized in that, The step of locking the current communication channel based on the received first frame of valid data includes: The protocol adaptation layer performs validity checks on the data received by a certain physical channel to determine whether it conforms to the predefined unified protocol data frame format; If the verification is successful, the physical channel will be locked as the current communication channel. If the verification fails, the data is discarded, and subsequent data will continue to be monitored through the two physical channels.
4. The method according to claim 1, characterized in that, In the CAN diagnostic mode, the protocol data unit is used as the data payload of the UDS diagnostic service, and a dedicated data identifier is assigned to the payload to uniquely identify the payload type. The UDS diagnostic service includes a data reading service via identifier (0x22) or a data writing service via identifier (0x2E).
5. The method according to claim 4, characterized in that, In the CAN diagnostic mode, the specific steps for encapsulating the protocol data unit as the data payload of the UDS diagnostic service and transmitting it via the CAN bus include: Determine whether the data length of the protocol data unit is greater than 7 bytes; If it is less than or equal to 7 bytes, then directly construct a single-frame diagnostic request message and send it; If the data is greater than 7 bytes, the ISO-TP protocol is invoked for segmented transmission. First, the first frame is sent, and then the receiver replies with a flow control frame. Then, multiple consecutive frames are sent continuously according to the parameters specified in the flow control frame until all data has been sent.
6. A multi-physical-layer adaptive communication device, characterized in that, include: The bus interface module, located at the physical layer, is used to provide an interface for physical connection with the host computer. The interface is either a CAN interface or a serial communication interface. The CAN diagnostic communication module, located at the transmission link layer, is used to implement the UDS diagnostic protocol stack and the ISO-TP transmission layer protocol. The serial communication module, located at the transmission link layer, is used to implement the underlying driver for serial communication and transparent data transmission and reception. The protocol adaptation module, located at the protocol layer, is connected to both the CAN diagnostic communication module and the serial communication module. It is used to initialize both the CAN diagnostic communication module and the serial communication module simultaneously when the system starts up, so that both physical channels are in a receive-ready state, and to lock the current communication channel based on the first frame of valid data received. The protocol adaptation module is also used to provide a unified sending and receiving interface to shield the upper layer from the differences in the underlying physical medium. The protocol parsing module, located above the protocol adaptation module, is used to define a unified automated communication protocol format and to package or parse data according to the unified protocol format.
7. The apparatus according to claim 6, characterized in that, The protocol adaptation module is specifically used to enable the receiving functions of both the CAN diagnostic communication module and the serial communication module during system initialization, and to perform validity verification on the data received from any channel after receiving the data, locking the channel that passes the verification as the current working channel; when sending data, it selectively sends the data to the CAN diagnostic communication module or the serial communication module according to the currently locked channel type.
8. The apparatus according to claim 6, characterized in that, The CAN diagnostic communication module is configured to: in the transmitting direction, use the protocol data unit issued by the protocol adaptation module as the data payload of the UDS diagnostic service, and send data exceeding the single frame length limit in segments according to the ISO-TP protocol; in the receiving direction, perform ISO-TP reassembly on the received CAN message to restore the complete diagnostic response message and extract the data payload.
9. The apparatus according to claim 6, characterized in that, The protocol parsing module is unaware of the underlying physical medium and is configured to: in the sending direction, package application layer data into protocol data units according to the unified protocol format and send them to the protocol adaptation module; On the receiving side, the protocol data units uploaded by the protocol adaptation module are parsed according to the unified protocol format, the instruction code and / or data field are extracted, and the corresponding automated functions are triggered.
10. The apparatus according to claim 6, characterized in that, The protocol adaptation module is bidirectionally connected to the CAN diagnostic communication module and the serial communication module, respectively; the protocol parsing module is bidirectionally connected to the protocol adaptation module; the bus interface module is physically connected to the CAN diagnostic communication module and the serial communication module, respectively.
