Multi-master control communication method, device, equipment, medium and product
By adopting unified communication protocol and feature identification in multi-master communication, the problems of high latency and low stability between multi-masters are solved, efficient and reliable communication is achieved, and system response efficiency and fault tolerance are improved.
Patent Information
- Application Number
- CN202510417858.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-03
- Publication Date
- 2025-07-25
AI Technical Summary
The existing multi-master communication scheme has high latency and low stability when handling interactions between multi-masters, resulting in data loss or transmission interruption, affecting system response speed and data reliability.
Using a unified communication protocol and feature identifier, the feature identifier is obtained by receiving external terminal data packets and analyzing header data, determining the timeout detection time based on the priority identifier, selecting the target master and transmitting the data packet. If the timeout does not respond, a timeout error code will be sent.
It improves communication response efficiency in multi-main control scenarios, reduces protocol conversion delay, enhances the system's fault tolerance and scalability, and ensures timely response of key instructions.
Smart Images

Figure CN120378513A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of device communication, and particularly to a multi-master communication method, apparatus, device, medium, and product. Background Art
[0002] With the improvement of the intelligence level and the increase in functional complexity of electronic devices, the multi-master architecture is widely used to enhance the flexibility and reliability of the system. However, there is a significant defect in existing communication solutions when dealing with the interaction between multiple masters: high latency and low stability caused by data parsing and forwarding during the protocol conversion process, especially in cases where multiple independent communication links need to be crossed or protocol conversion is required. This not only increases the processing time but also easily leads to the risk of data loss or transmission interruption, seriously affecting the overall system response speed and data reliability. Summary of the Invention
[0003] The main purpose of this application is to provide a multi-master communication method, apparatus, device, medium, and product, aiming to improve the response efficiency of communication in a multi-master scenario.
[0004] To achieve the above object, this application proposes a multi-master communication method, which is applied to a first master. The first master is communicatively connected to a second master and an external terminal. The communication protocol between the first master and the second master is the same as the communication protocol between the first master and the external terminal. The multi-master communication method includes:
[0005] Receiving a data packet sent by an external terminal and parsing the header data of the data packet to obtain a feature identifier, where the feature identifier includes a first target receiving identifier and a priority identifier;
[0006] Determining a timeout detection time according to the priority identifier;
[0007] Determining a second master from at least one preset master according to the first target receiving identifier, and transmitting the data packet to the second master, where the second master is used to receive a first data packet transmitted by the first master, generate a response packet according to the first data packet, and send the response packet to the first master;
[0008] If a response packet sent by the second master is received within the timeout detection time, then sending the response packet to the external terminal;
[0009] If a response packet sent by the second master is not received within the timeout detection time, then sending a preset timeout error code to the external terminal.
[0010] In an embodiment, the feature identifier further includes a packet type identifier and a transaction identifier. Before the step of receiving a response packet sent by the second master within the timeout detection time, it includes:
[0011] If the packet type identifier is a two-way request packet or a response packet, store the mapping relationship between the first transaction identifier and the external terminal in the mapping table, where the first transaction identifier is the transaction identifier of the data packet.
[0012] Determine a second master from at least one preset master according to the first target receiving identifier, and transmit the data packet to the second master.
[0013] Before the step of sending the response packet to the external terminal, it includes:
[0014] Obtain the second transaction identifier and the second target receiving identifier in the response packet.
[0015] If the mapping table queries the mapping relationship between the second transaction identifier and the second target receiving identifier, send the response packet to the terminal corresponding to the second target receiving identifier according to the mapping relationship.
[0016] Delete the mapping relationship between the second transaction identifier and the second target receiving identifier in the mapping table.
[0017] In an embodiment, applied to the second master, the second master is communicatively connected to the first master, the first master is communicatively connected to the external terminal, the communication protocol between the first master and the second master is the same as the communication protocol between the first master and the external terminal, and the multi-master communication method includes:
[0018] Receive the first data packet transmitted by the first master, where the first master is used to receive the data packet sent by the external terminal, parse the header data of the data packet to obtain the feature identifier, determine whether to perform timeout detection according to the packet type identifier in the feature identifier, determine the timeout detection time according to the priority identifier in the feature identifier, determine a second master from at least one preset master according to the first target receiving identifier in the feature identifier, and transmit the data packet to the second master.
[0019] Generate a response packet according to the first data packet, and send the response packet to the first master, where the first master is used to send the response packet to the external terminal when receiving the response packet sent by the second master within the timeout detection time, and send a preset timeout error code to the external terminal when not receiving the response packet sent by the second master within the timeout detection time.
[0020] In an embodiment, the step of generating a response packet according to the first data packet further includes:
[0021] If the total data length in the first data packet is greater than the valid length of the data in this packet, store the checksum of the first data packet as the first checksum.
[0022] Use a preset checksum algorithm to calculate the first data packet to obtain a second checksum.
[0023] Compare the first verification code with the second verification code. If the first verification code is inconsistent with the second verification code, encapsulate a preset verification error code into a response packet. Among them, after receiving the response packet forwarded by the first master, the external terminal determines whether to resend the data packet as needed.
[0024] In an embodiment, after the step of comparing the first verification code with the second verification code, it includes:
[0025] If the first verification code is consistent with the second verification code, determine a second data packet that is consistent with the header information of the first data packet;
[0026] Judge whether the sum of the data valid lengths of all second data packets and the data valid length of the first data packet is equal to the total data length of the first data packet;
[0027] If it is equal to the total data length of the first data packet, merge the first data packet with all second data packets to obtain a complete data packet;
[0028] Generate a response packet according to the complete data packet and send the response packet to the first master.
[0029] In addition, to achieve the above object, the present application also proposes a multi-master communication device, which is applied to the first master. The first master is communicatively connected to the second master, and the first master is communicatively connected to the external terminal. The communication protocol between the first master and the second master is the same as the communication protocol between the first master and the external terminal. The multi-master communication device includes:
[0030] An acquisition identification module, configured to receive a data packet sent by an external terminal and parse the header data of the data packet to obtain a feature identification, where the feature identification includes a first target receiving identification and a priority identification;
[0031] A timeout detection module, configured to determine a timeout detection time according to the priority identification;
[0032] A determination target module, configured to determine a second master from at least one preset master according to the first target receiving identification, and transmit the data packet to the second master, where the second master is configured to receive a first data packet transmitted by the first master, generate a response packet according to the first data packet, and send the response packet to the first master;
[0033] An information sending module, configured to send the response packet to the external terminal if the response packet sent by the second master is received within the timeout detection time;
[0034] A timeout error reporting module, configured to send a preset timeout error code to the external terminal if the response packet sent by the second master is not received within the timeout detection time.
[0035] In addition, to achieve the above object, the present application further provides a medium, which is a computer-readable storage medium, and a computer program is stored on the medium. When the computer program is executed by a processor, the steps of the multi-master communication method as described above are implemented.
[0036] In addition, to achieve the above object, the present application further provides a product, which is a computer program product. The computer program product includes a computer program. When the computer program is executed by a processor, the steps of the multi-master communication method as described above are implemented.
[0037] One or more technical solutions proposed by the present application have at least the following technical effects:
[0038] The present application is applied to a first master. The first master is communicatively connected to a second master and communicatively connected to an external terminal. The communication protocol between the first master and the second master is the same as the communication protocol between the first master and the external terminal. Efficient and reliable communication between multiple masters is achieved through a unified communication protocol and characteristic identifiers. It not only reduces the latency and instability problems caused by protocol conversion, but also enhances the fault tolerance and scalability of the system. Receive a data packet sent by an external terminal, and parse the header data of the data packet to obtain a characteristic identifier, where the characteristic identifier includes a first target receiving identifier and a priority identifier; determine the timeout detection time according to the priority identifier; determine the second master from at least one preset master according to the target receiving identifier, and transmit the data packet to the second master. The second master receives the first data packet transmitted by the first master, generates a response packet according to the first data packet, and sends the response packet to the first master; if the response packet sent by the second master is received within the timeout detection time, the response packet is sent to the external terminal; if the response packet sent by the second master is not received within the timeout detection time, a preset timeout error code is sent to the external terminal. Through precise timeout management and priority control, it is ensured that critical instructions can be responded to in a timely manner, and the response efficiency of communication in a multi-master scenario is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The drawings herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0040] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0041] Figure 1 It is a schematic flowchart of the first embodiment of the multi-master communication method of the present application;
[0042] Figure 2 Schematic diagram of the scenario where an external terminal requests the second master version number in the multi-master communication method of this application;
[0043] Figure 3 Schematic diagram of the process of integrity verification in the multi-master communication method of this application;
[0044] Figure 4 Schematic diagram of the module structure of the multi-master communication device in the embodiment of this application;
[0045] Figure 5 Schematic diagram of the device structure of the hardware operating environment involved in the multi-master communication method in the embodiment of this application.
[0046] The realization of the purpose, functional features and advantages of this application will be further described with reference to the accompanying drawings in combination with the embodiments. Specific implementation manners
[0047] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of this application and are not used to limit this application.
[0048] For a better understanding of the technical solutions of this application, the following will be described in detail in combination with the drawings in the specification and specific implementation manners.
[0049] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device, a terminal system, etc. that can implement the above functions. The following takes the system as an example to illustrate this embodiment and the following embodiments.
[0050] Based on this, this embodiment provides a multi-master communication method, which is applied to the first master. The first master is communicatively connected to the second master and communicatively connected to an external terminal. The communication protocol between the first master and the second master is the same as the communication protocol between the first master and the external terminal.
[0051] It should be noted that this embodiment is applicable to multi-master scenarios with two or more masters. The first and the second are only used to distinguish concepts and do not limit the quantity. In this embodiment, the master (or master processor) can be a single-chip microcomputer or other chips for data processing. The first master is the first master processor of the multi-master communication device, and the second master is the second master processor of the multi-master communication device. The multi-master communication device can include multiple master processors.
[0052] To simplify the system design and improve compatibility and efficiency, the communication protocol between the first master controller and the second master controller is designed to be the same as the communication protocol between the first master controller and the external terminal. This means that whether communicating with an external terminal or with other master controllers, parameters such as the data format, verification rules, transmission rate, etc. used are the same. The compatibility method in this embodiment is to transplant the core elements independent of the physical layer of the HID (Human Interface Device) protocol to the implementation method of the UART (Universal Asynchronous Receiver / Transmitter) interface. For this purpose, we designed the mapping rules of the HID descriptor in serial communication, the extended design of the flow control field (the binding mechanism of RTS / CTS (Request to Send / Clear to Send) and the HID report index), and the UART (Universal Asynchronous Receiver / Transmitter) data encapsulation method based on the HID standard frame structure. This enables data exchange to use a similar protocol framework whether between the external terminal and the first master controller or between the first master controller and the second master controller, reducing the need for protocol conversion, lowering the possibility of errors, and improving the overall system response speed and reliability.
[0053] Refer to Figure 1 , Figure 1 is a schematic flowchart of the multi-master communication method of this application. The multi-master communication method includes steps S10 to S50:
[0054] Step S10, receive the data packet sent by the external terminal, and parse the header data of the data packet to obtain the feature identifier, where the feature identifier includes the first target receiving identifier and the priority identifier;
[0055] Step S20, determine the timeout detection time according to the priority identifier;
[0056] Step S30, determine the second master controller from at least one preset master controller according to the first target receiving identifier, and transmit the data packet to the second master controller, where the second master controller is used to receive the first data packet transmitted by the first master controller, generate a response packet according to the first data packet, and send the response packet to the first master controller;
[0057] Step S40, if the response packet sent by the second master controller is received within the timeout detection time, then send the response packet to the external terminal;
[0058] Step S50, if the response packet sent by the second master controller is not received within the timeout detection time, then send the preset timeout error code to the external terminal.
[0059] It should be noted that a data packet is an information unit sent by an external terminal, and its header data contains feature identifiers, which include a target receiving identifier, a packet type identifier, and a priority identifier. The target receiving identifier is used to specify the target master processor of the data packet; the priority identifier determines the urgency of processing the data packet and the timeout detection time. The timeout detection is determined based on the packet type identifier whether to execute, and the specific waiting time is determined according to the priority identifier. The response packet is the feedback information after the second master processor processes the data packet. The timeout error code is a notification returned to the external terminal when the expected response is not received. In this embodiment, the timeout error code can be 0xEF, indicating that the target device has no response, and the first master needs to record a log and notify the external terminal.
[0060] In this embodiment, first, the first master receives a data packet from an external terminal, and extracts the feature identifiers including the target receiving identifier, the packet type identifier, and the priority identifier from the header of the data packet. The packet type identifier differentiates different types of communication requirements, such as a request packet or a request packet that requires a response, etc. It can be determined whether to start the timeout detection mechanism according to the packet type identifier. If it is a request packet or a response packet that needs to return an answer packet, the priority identifier is used to determine the specific timeout detection time. If it is a request packet that does not need to return an answer packet. Subsequently, the second master responsible for processing the data packet is identified through the target receiving identifier, and the data packet is forwarded. The second master receives the first data packet transmitted by the first master, generates a response packet according to the first data packet, and sends the response packet to the first master. During this process, if the response packet sent back by the second master is received within the set timeout detection time, the response packet is immediately passed to the external terminal. On the contrary, if the response packet is not received on time, a preset timeout error code is sent to the external terminal to inform its current communication status.
[0061] The core of this embodiment is to achieve efficient and reliable communication between multiple masters through a unified communication protocol and feature identifiers.
[0062] Exemplarily, in this embodiment, the format of the data packet sent by the external terminal can be as shown in Table 1:
[0063] Table 1
[0064]
[0065]
[0066] Furthermore, each master in this embodiment can maintain a local cache to store the recently accessed data packets and their processing results. In this way, when a repeated request arrives, the result can be directly obtained from the cache, reducing unnecessary communication overhead.
[0067] This embodiment is applied to the first master controller. The first master controller is communicatively connected to the second master controller and the external terminal. The communication protocol between the first master controller and the second master controller is the same as that between the first master controller and the external terminal. Through the unified communication protocol and feature identifier, efficient and reliable communication between multiple master controllers is achieved. It not only reduces the delay and instability problems caused by protocol conversion, but also enhances the fault tolerance and scalability of the system. Receive the data packet sent by the external terminal, and parse the header data of the data packet to obtain the feature identifier, where the feature identifier includes the target receiving identifier, packet type identifier, and priority identifier; determine whether to perform timeout detection according to the packet type identifier. If timeout detection is performed, determine the timeout detection time according to the priority identifier; determine the second master controller from at least one preset master controller according to the target receiving identifier, and transmit the data packet to the second master controller. The second master controller receives the first data packet transmitted by the first master controller, generates a response packet according to the first data packet, and sends the response packet to the first master controller; if the response packet sent by the second master controller is received within the timeout detection time, send the response packet to the external terminal; if the response packet sent by the second master controller is not received within the timeout detection time, send the preset timeout error code to the external terminal. Through precise timeout management and priority control, it ensures that critical instructions can be responded to in a timely manner, and improves the response efficiency of communication in the multi-master scenario.
[0068] In a feasible implementation manner, the steps in step S40 may include steps T10 to T50:
[0069] Step T10, if the packet type identifier is a two-way request packet or a response packet, store the mapping relationship between the first transaction identifier and the external terminal in the mapping table, where the first transaction identifier is the transaction identifier of the data packet;
[0070] Step T20, determine the second master controller from at least one preset master controller according to the first target receiving identifier, and transmit the data packet to the second master controller;
[0071] Before the step of sending the response packet to the external terminal, it includes:
[0072] Step T30, obtain the second transaction identifier and the second target receiving identifier in the response packet;
[0073] Step T40, if there is a mapping relationship between the second transaction identifier and the second target receiving identifier in the mapping table query, send the response packet to the terminal corresponding to the second target receiving identifier according to the mapping relationship;
[0074] Step T50, delete the mapping relationship between the second transaction identifier and the second target receiving identifier in the mapping table.
[0075] It should be noted that the feature identifier not only includes the target receiving identifier, packet type identifier, and priority identifier, but also includes the transaction identifier. The transaction identifier is used to precisely match requests and responses to ensure the accurate transmission and processing of data packets. The mapping table stores the mapping relationship between the transaction identifier and the external terminal. When the packet type identifier is a two-way request packet (requiring a response packet) or a response packet, the transaction identifier and its corresponding external terminal information are recorded in the mapping table. The second transaction identifier is a field in the response packet used to identify the specific request corresponding to the response packet. The second target receiving identifier indicates to which terminal the response packet should be sent.
[0076] In this embodiment, the first master processor receives a data packet from an external terminal and parses its header data to obtain the feature identifier including the transaction identifier. If the packet type identifier indicates that this is a two-way request packet or a response packet, the mapping relationship between the transaction identifier and the external terminal is stored in the mapping table, and the transaction identifier in the data packet is updated. Then, according to the target receiving identifier, the second master processor responsible for processing the data packet is determined, and the updated data packet is forwarded to the second master. When the second master completes the processing and returns a response packet containing the target receiving identifier and the transaction identifier, the first master processor extracts the second transaction identifier and the second target receiving identifier from the response packet. By querying the mapping table, if a record matching the second transaction identifier and the second target receiving identifier is found, the response packet is sent to the corresponding terminal, and the relevant mapping relationship in the mapping table is deleted.
[0077] This embodiment realizes efficient and reliable communication between multiple masters through the transaction identifier and the mapping table, ensuring the precise matching of requests and responses. Through precise transaction management and mapping relationship processing, key instructions can be promptly responded to, improving the user experience.
[0078] Based on Embodiment 1 of the present application, in Embodiment 2 of the present application, the same or similar content as that in the above Embodiment 1 can be referred to the above introduction and will not be elaborated hereinafter. On this basis, this embodiment provides a multi-master communication method applied to the second master. The multi-master communication method includes steps A10 to A20:
[0079] Step A10, receiving the first data packet transmitted by the first master;
[0080] Step A20, generating a response packet according to the first data packet and sending the response packet to the first master.
[0081] Exemplarily, referring to Figure 2 , Figure 2This is a schematic diagram of the scenario in which an external terminal requests the version number of the second master control. The external terminal (PC) first sends a request packet to the first master control (master control 1), which contains the header information of target ID (target receiving identifier) = 0x02, packet type = 0x01, transaction ID (transaction identifier) = 0x0101, and priority = 0x00. After receiving the request packet, master control 1 performs protocol processing. If it is found that it does not meet the current requirements, the packet is discarded. Then, after confirming that the packet type is not equal to 0x01, the transaction ID mapping is recorded and the timeout timer is started, and then the request packet is forwarded to the second master control (master control 2). After master control 2 parses the request and obtains the version information, it generates a response packet, which contains target ID = PC, transaction ID = 0x0101, data + version number, and sends it back to master control 1. After receiving the response packet, master control 1 verifies the validity of the response by matching the transaction ID. If it is valid, it forwards the version information to the external terminal and clears the mapping record; if it times out, it sends the error code 0xEF and also clears the mapping record. In this way, the whole process ensures the accuracy and integrity of data transmission from the PC to the two main controllers, and realizes effective communication and response processing.
[0082] In a feasible implementation manner, step A20 further includes steps B10 to B30:
[0083] Step B10, generating response information according to the first data packet;
[0084] Step B20, generating a target receiving identifier according to the processing object of the response information, and updating the target receiving identifier to the response information;
[0085] Step B30: If the packet type identifier in the first data packet is a response packet, the transaction identifier in the first data packet is bound to the updated response information, and the bound response information is encapsulated into a response packet.
[0086] It should be noted that the second target receiving identifier is determined when the response information is generated, and it indicates to which device or terminal the response information should be sent, which can be the terminal that encapsulates the data packet or the terminal specified in the data packet. When the packet type identifier in the first data packet is a reply packet, it means that the second transaction identifier in the data packet needs to be bound to the updated response information to ensure that the response can be correctly returned to the device that initiated the request.
[0087] First, after receiving the first data packet forwarded by the first master control, the second master control generates a corresponding response message according to its content. This step involves parsing the header data of the first data packet to obtain feature identifiers, including target reception identifiers, packet type identifiers, and priority identifiers. Next, the second master control generates a second target reception identifier according to the processing object of the response information, and updates it to the response information. If the packet type identifier in the first data packet indicates that this is a reply packet, the second master control extracts the second transaction identifier from the first data packet and binds it to the updated response information. In this way, it can be ensured that the response information can be accurately returned to the correct device that initiated the request. Finally, the response information containing the second transaction identifier is encapsulated into a response packet and is ready to be sent back to the first master control, which is then forwarded to the external terminal by the first master control.
[0088] Furthermore, in this embodiment, each main control processor can maintain a dynamically updated transaction log to record the state changes of all transactions. In this way, in the case of network failure or main control restart, unfinished transactions can be recovered from the log to avoid data loss.
[0089] This embodiment realizes efficient and reliable multi-master communication through precise transaction management and target receiving identification update, which not only reduces the delay and instability caused by protocol conversion, but also enhances the fault tolerance and scalability of the system.
[0090] Based on the first or second embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those in the first or second embodiment can be referred to the above description, and will not be described in detail later. Step A20 also includes steps C10 to C30:
[0091] Step C10, if the total length of the data in the first data packet is greater than the valid length of the data in the present packet, the check code of the first data packet is stored as the first check code;
[0092] Step C20, using a preset verification algorithm to calculate the first data packet to obtain a second verification code;
[0093] Step C30, compare the first check code with the second check code, if the first check code is inconsistent with the second check code, encapsulate the preset check error code into a response packet, wherein the external terminal determines whether to resend the data packet as needed after receiving the response packet forwarded by the first master control.
[0094] It should be noted that when the total data length in the first data packet is greater than the effective length of the data in this packet, it means that the data packet may be fragmented for transmission. At this time, the checksum of the first data packet (i.e., the first checksum) will be extracted and stored. The preset checksum algorithm refers to a specific algorithm used to calculate data integrity. In this embodiment, the CRC-16 algorithm is used. The result obtained by recalculating the first data packet through this algorithm is called the second checksum. If the first checksum is inconsistent with the second checksum, it indicates that an error may have occurred during data transmission. At this time, a response packet containing a preset checksum error code will be generated. The checksum error code can be 0xEE, representing that the data packet check fails. The second master will discard the current fragment and forward it to the external terminal through the first master, so that the external terminal can decide whether to resend the data packet.
[0095] In this embodiment, when the second master receives the first data packet forwarded by the first master, it first checks whether the total data length of the data packet is greater than the effective length of the data in this packet. If so, the second master will extract the existing checksum from the first data packet and store it as the first checksum. Next, the second master uses the preset CRC-16 checksum algorithm to recalculate the data packet to obtain a new checksum, that is, the second checksum. Subsequently, the second master compares the first checksum with the second checksum. If the two do not match, it means that the data has been damaged or lost during transmission. The second master will then encapsulate a response packet containing a preset checksum error code. This response packet is then sent back to the first master and finally forwarded to the external terminal by the first master. After receiving the response packet containing the checksum error code, the external terminal can determine whether to resend the original data packet according to the specific situation.
[0096] This embodiment can further improve the stability and efficiency of the system through an adaptive retransmission mechanism. Specifically, when a checksum error is detected, the second master can not only return an error code but also attach a recommended retransmission strategy, such as recommending which specific fragments to retransmit or adjusting the fragment size to adapt to the current network conditions.
[0097] This embodiment ensures the accuracy and integrity of data transmission through the method of checksum comparison, reducing misoperations caused by data damage. It not only improves the communication reliability in a multi-master architecture but also enhances the fault tolerance of the system.
[0098] In a feasible implementation, referring to Figure 3 , the steps of step C30 further include steps D10 to D40:
[0099] Step D10, if the first checksum is consistent with the second checksum, determine the second data packet that is consistent with the header information of the first data packet;
[0100] Step D20, determine whether the sum of the data valid lengths of all second data packets and the data valid length of the first data packet is equal to the total data length of the first data packet;
[0101] Step D30, if it is equal to the total data length of the first data packet, then merge the first data packet and all second data packets to obtain a complete data packet;
[0102] Step D40, generate a response packet according to the complete data packet, and send the response packet to the first master controller.
[0103] It should be noted that if the first check code is consistent with the second check code, it indicates that the data packet has not been damaged during transmission. The second data packet refers to a data packet that has the same header information as the first data packet but may contain different fragments. The data valid length refers to the length of the actual payload data contained in each data packet, while the total data length is the total number of bytes of the entire data packet (including all fragments). The complete data packet is the original data packet formed by merging all fragments. The response packet is the feedback information generated according to the complete data packet and sent to the first master controller.
[0104] When the second master controller receives the first data packet, it first compares the first check code and the second check code. If the two are consistent, it indicates that the data packet has not been damaged. Next, the second master controller determines all second data packets that are consistent with the header information of the first data packet. Then, the second master controller determines whether the sum of the data valid lengths of all second data packets plus the data valid length of the first data packet is equal to the total data length of the first data packet. This step is to ensure that all fragments have been correctly received and there is no loss. If the verification result is true, that is, the total valid length of all data packets is equal to the total data length, then the first data packet and all second data packets are merged to form the original complete data packet. Finally, a response packet is generated according to this complete data packet and sent to the first master controller.
[0105] Exemplarily, assume that an external terminal sends a data packet containing a 100-byte control instruction to the first master control. Since the maximum packet size limit of a single transmission interface is 64 bytes, this instruction is split into two fragments for transmission: the first fragment has a packet sequence number of 0, a valid data length of 52 bytes, and is accompanied by a CRC-16 checksum as the first checksum; the second fragment has a packet sequence number of 1, a valid data length of 48 bytes, and also has the same characteristic identifiers such as the transaction ID, target receiving identifier, packet type identifier, etc. and the first checksum. These fragments are forwarded by the first master control to the second master control. After receiving the first fragment, the second master control extracts the first checksum from its header information and recalculates to obtain the second checksum using the CRC-16 algorithm. If the two are consistent, it continues to process, determines all the second data packets (i.e., the second fragments) with the same header information, and checks whether the sum of the data valid lengths of all relevant fragments is equal to the total data length of the original data packet (100 bytes). After confirming that the total length matches, the second master control merges the first data packet with all the second data packets to form a complete 100-byte control instruction, generates a response packet according to the content of the complete data packet, which includes the transaction ID to ensure the accurate matching of the request and the response, and finally sends this response packet back to the first master control.
[0106] Through the precise checksum comparison and data packet recombination process in this embodiment, the accuracy and integrity of data transmission are ensured. It not only reduces errors caused by data corruption or loss but also improves the communication reliability in a multi-master control architecture.
[0107] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the multi-master control communication method of this application. Based on this technical concept, more forms of simple transformations are within the protection scope of this application.
[0108] This application also provides a multi-master control communication device. Please refer to Figure 4 , which is applied to the first master control. The first master control is communicatively connected to the second master control, and the first master control is communicatively connected to the external terminal. The communication protocol between the first master control and the second master control is the same as the communication protocol between the first master control and the external terminal. The multi-master control communication device includes:
[0109] An acquisition identification module 10, configured to receive a data packet sent by an external terminal and parse the header data of the data packet to obtain characteristic identifiers, where the characteristic identifiers include a first target receiving identifier and a priority identifier;
[0110] A timeout detection module 20, configured to determine the timeout detection time according to the priority identifier;
[0111] Determine the target module 30, which is used to determine the second master from at least one preset master according to the first target reception identifier, and transmit the data packet to the second master. The second master is used to receive the first data packet transmitted by the first master, generate a response packet according to the first data packet, and send the response packet to the first master;
[0112] The information sending module 40 is used to send the response packet to the external terminal if the response packet sent by the second master is received within the timeout detection time;
[0113] The timeout error reporting module 50 is used to send the preset timeout error code to the external terminal if the response packet sent by the second master is not received within the timeout detection time.
[0114] The multi-master communication device provided in this application adopts the multi-master communication method in the above embodiment, which can improve the response efficiency of communication in the multi-master scenario. Compared with the prior art, the beneficial effects of the multi-master communication device provided in this application are the same as those of the multi-master communication method provided in the above embodiment, and other technical features in the multi-master communication device are the same as the features disclosed in the above embodiment method, which will not be elaborated here.
[0115] This application provides a multi-master communication device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the multi-master communication method in the first embodiment above.
[0116] Next, refer to Figure 5 , which shows a schematic structural diagram of a multi-master communication device suitable for implementing the embodiments of this application. The multi-master communication device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The multi-master communication device shown is only an example and should not impose any limitations on the functions and usage scope of the embodiments of this application.
[0117] As Figure 5As shown, the multi-master communication device may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which may perform various appropriate actions and processes according to the program stored in the read-only memory 1002 or the program loaded from the storage device 1003 into the random access memory 1004. In the random access memory 1004, various programs and data required for the operation of the multi-master communication device are also stored. The processing device 1001, the read-only memory 1002, and the random access memory 1004 are connected to each other through a bus 1005. The input / output interface 1006 is also connected to the bus. Generally, the following systems may be connected to the input / output interface 1006. Generally, the following systems may be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 may allow the multi-master communication device to communicate with other devices wirelessly or wiredly to exchange data. Although the figure shows a multi-master communication device with various systems, it should be understood that it is not required to implement or have all the shown systems. Instead, more or fewer systems may be implemented or had.
[0118] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from the network through the communication device, or installed from the storage device 1003, or installed from the read-only memory 1002. When the computer program is executed by the processing device 1001, the above functions defined in the methods of the embodiments disclosed in the present application are executed.
[0119] The multi-master communication device provided by the present application adopts the multi-master communication method in the above embodiment, and can improve the response efficiency of communication in the multi-master scenario. Compared with the prior art, the beneficial effects of the multi-master communication device provided by the present application are the same as those of the multi-master communication method provided by the above embodiment, and other technical features in the multi-master communication device are the same as those disclosed in the method of the previous embodiment, and will not be elaborated here.
[0120] It should be understood that each part disclosed in this application can be implemented by hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in a suitable manner in any one or more embodiments or examples.
[0121] The above is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in this application, and all such changes or substitutions should be covered by the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.
[0122] This application provides a medium, which is a computer-readable storage medium with computer-readable program instructions (i.e., computer programs) stored thereon. The computer-readable program instructions are used to execute the multi-master communication method in the above embodiments.
[0123] The computer-readable storage medium provided by this application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM) or flash memory, optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this embodiment, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system or device. The program code contained on the computer-readable storage medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0124] The above computer-readable storage medium can be included in the multi-master communication device; or it can exist separately and not be assembled into the multi-master communication device.
[0125] The above computer-readable storage medium carries one or more programs. When the above one or more programs are executed by the multi-master communication device, the multi-master communication device is caused to:
[0126] Receive data packets sent by an external terminal, and parse the header data of the data packets to obtain feature identifiers, where the feature identifiers include a first target receiving identifier and a priority identifier;
[0127] Determine the timeout detection time according to the priority identifier;
[0128] Determine a second master from at least one preset master according to the first target receiving identifier, and transmit the data packet to the second master, where the second master is used to receive a first data packet transmitted by the first master, generate a response packet according to the first data packet, and send the response packet to the first master;
[0129] If a response packet sent by the second master is received within the timeout detection time, send the response packet to the external terminal;
[0130] If a response packet sent by the second master is not received within the timeout detection time, send a preset timeout error code to the external terminal.
[0131] Computer program code for performing the operations of this application can be written in one or more programming languages or combinations thereof. The above programming languages include object-oriented programming languages - such as Java, Smalltalk, C++, and also include conventional procedural programming languages - such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network - including a local area network (LAN: Local Area Network) or a wide area network (WAN: Wide Area Network), or can be connected to an external computer (for example, by using an Internet service provider to connect through the Internet).
[0132] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a portion of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions noted in the blocks may occur in a different order than that noted in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system that performs the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.
[0133] The modules involved in the embodiments described in the present application can be implemented in software or in hardware. In some cases, the name of the module does not constitute a limitation on the unit itself.
[0134] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above multi-master communication method, and can improve the response efficiency of communication in a multi-master scenario. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as those of the multi-master communication method provided by the above embodiments, and will not be elaborated here.
[0135] The present application also provides a product, which is a computer program product, including a computer program. When the computer program is executed by a processor, it implements the steps of the multi-master communication method as described above.
[0136] The computer program product provided by the present application can improve the response efficiency of communication in a multi-master scenario. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as those of the multi-master communication method provided by the above embodiments, and will not be elaborated here.
[0137] The above are only some embodiments of the present application, and do not limit the patent scope of the present application. All equivalent structural transformations made under the technical concept of the present application by using the content of the specification and drawings of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A multi-master communication method, characterized in that, Applied to the first master controller, the first master controller is communicatively connected to the second master controller, and the first master controller is communicatively connected to an external terminal. The communication protocol between the first master controller and the second master controller is the same as the communication protocol between the first master controller and the external terminal. The multi-master communication method includes: Receiving a data packet sent by the external terminal, and parsing the header data of the data packet to obtain a feature identifier, where the feature identifier includes a first target receiving identifier and a priority identifier; Determining a timeout detection time according to the priority identifier; Determining a second master controller from at least one preset master controller according to the first target receiving identifier, and transmitting the data packet to the second master controller, where the second master controller is configured to receive a first data packet transmitted by the first master controller, generate a response packet according to the first data packet, and send the response packet to the first master controller; If the response packet sent by the second master controller is received within the timeout detection time, sending the response packet to the external terminal; If the response packet sent by the second master controller is not received within the timeout detection time, sending a preset timeout error code to the external terminal.
2. The multi-master communication method according to claim 1, wherein The feature identifier further includes a packet type identifier and a transaction identifier. Before the step of if the response packet sent by the second master controller is received within the timeout detection time, it includes: If the packet type identifier is a two-way request packet or a response packet, storing the mapping relationship between the first transaction identifier and the external terminal in a mapping table, where the first transaction identifier is the transaction identifier of the data packet; Determining a second master controller from at least one preset master controller according to the first target receiving identifier, and transmitting the data packet to the second master controller; Before the step of sending the response packet to the external terminal, it includes: Obtaining a second transaction identifier and a second target receiving identifier in the response packet; If the mapping relationship between the second transaction identifier and the second target receiving identifier exists in the mapping table query, sending the response packet to the terminal corresponding to the second target receiving identifier according to the mapping relationship; Deleting the mapping relationship between the second transaction identifier and the second target receiving identifier in the mapping table.
3. A multi-master communication method, characterized in that, Applied to the second master controller, the second master controller is communicatively connected to the first master controller, and the first master controller is communicatively connected to an external terminal. The communication protocol between the first master controller and the second master controller is the same as the communication protocol between the first master controller and the external terminal. The multi-master communication method includes: Receiving a first data packet transmitted by the first master controller, where the first master controller is configured to receive a data packet sent by the external terminal, parse the header data of the data packet to obtain a feature identifier, determine whether to perform timeout detection according to the packet type identifier in the feature identifier, determine a timeout detection time according to the priority identifier in the feature identifier, determine a second master controller from at least one preset master controller according to the first target receiving identifier in the feature identifier, and transmit the data packet to the second master controller; Generate a response packet according to the first data packet and send the response packet to the first master. The first master is configured to send the response packet to the external terminal when the response packet sent by the second master is received within the timeout detection time, and send a preset timeout error code to the external terminal when the response packet sent by the second master is not received within the timeout detection time.
4. The multi-master communication method according to claim 3, characterized in that, The step of generating a response packet according to the first data packet includes: Generate response information according to the first data packet; Generate a second target receiving identifier according to the processing object of the response information and update the second target receiving identifier to the response information; If the packet type identifier in the first data packet is an acknowledgment packet, bind the second transaction identifier in the first data packet to the updated response information and encapsulate the bound response information into a response packet.
5. The multi-master communication method according to claim 3, characterized in that, The step of generating a response packet according to the first data packet further includes: If the total data length in the first data packet is greater than the effective data length of this packet, store the checksum of the first data packet as the first checksum; Calculate the first data packet using a preset checksum algorithm to obtain a second checksum; Compare the first checksum with the second checksum. If the first checksum is inconsistent with the second checksum, encapsulate a preset checksum error code into a response packet. The external terminal determines whether to retransmit the data packet as needed after receiving the response packet forwarded by the first master.
6. The multi-master communication method according to claim 5, wherein After the step of comparing the first checksum with the second checksum includes: If the first checksum is consistent with the second checksum, determine a second data packet that is consistent with the header information of the first data packet; Judge whether the sum of the effective data lengths of all the second data packets and the effective data length of the first data packet is equal to the total data length of the first data packet; If it is equal to the total data length of the first data packet, merge the first data packet with all the second data packets to obtain a complete data packet; Generate a response packet according to the complete data packet and send the response packet to the first master.
7. A multi-master communication device, characterized in that, Applied to the first master, the first master is communicatively connected to the second master, the first master is communicatively connected to the external terminal, and the communication protocol between the first master and the second master is the same as the communication protocol between the first master and the external terminal. The multi-master communication device includes: An acquisition identification module, configured to receive a data packet sent by the external terminal and parse the header data of the data packet to obtain a feature identifier, where the feature identifier includes a first target receiving identifier and a priority identifier; A timeout detection module, configured to determine a timeout detection time according to the priority identifier; A target determination module, configured to determine a second master from at least one preset master according to the first target receiving identifier and transmit the data packet to the second master. The second master is configured to receive a first data packet transmitted by the first master, generate a response packet according to the first data packet, and send the response packet to the first master; An information sending module, configured to send the response packet to the external terminal if the response packet sent by the second master is received within the timeout detection time; A timeout error reporting module, configured to send a preset timeout error code to the external terminal if the response packet sent by the second master is not received within the timeout detection time.
8. A multi-master communication device, characterized in that, The multi-master communication device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, where the computer program is configured to implement the steps of the multi-master communication method according to any one of claims 1 to 6.
9. A computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the multi-master communication method according to any one of claims 1 to 6 are implemented.
10. A computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the multi-master communication method according to any one of claims 1 to 6 are implemented.