Implementation method of serialized extensible control system communication protocol based on Qt
By introducing Qt-based serialization and universal message structure into the communication protocol, the problems of low data serialization and deserialization efficiency and poor scalability in existing protocols are solved, achieving efficient communication and strong scalability.
Patent Information
- Application Number
- CN202411453121.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2025-01-24
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing communication protocols have low efficiency and poor scalability in data serialization and deserialization, and cannot meet the needs of complex control systems.
Adopt a serialized and extensible control system communication protocol based on Qt, introduce a common message structure and efficient serialization and deserialization methods, including the definition and processing of message headers and message bodies.
It improves data transmission efficiency and communication stability, realizes high -efficiency communication between control systems, and has strong scalability, suitable for communication needs between various control systems.
Smart Images

Figure CN119363840A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of communication protocols, and in particular to a method for implementing a serialized and extensible control system communication protocol based on Qt. Background Art
[0002] The communication protocol provides a set of standardized communication rules and formats, so that different devices and systems can transmit and interact with each other according to the same rules. This consistency ensures the reliability of communication and avoids communication failure or data loss caused by format mismatch or inconsistent rules.
[0003] Standardized communication protocols enable devices or systems from different manufacturers and models to communicate with each other, share information and work together. This interoperability is essential for building complex systems because it allows the system to integrate a variety of different types of devices and software to meet diverse needs.
[0004] In data exchange and communication between control systems, the design of communication protocols is crucial to the performance and scalability of the system. However, the communication protocols provided in the prior art often have problems such as low efficiency of data serialization and deserialization and poor scalability, which cannot meet the needs of complex control systems. In existing protocols, data serialization and deserialization operations are usually completed by their own implementations, lacking unified standards and efficient implementation methods. Therefore, there is an urgent need for a new type of communication protocol that can overcome the shortcomings of traditional protocols and provide a more flexible and efficient serialization and deserialization mechanism. Summary of the invention
[0005] In view of the shortcomings of the prior art, the purpose of the present invention is to provide a method for implementing a serialized and extensible control system communication protocol based on Qt to solve the problems raised in the above background technology. The present invention introduces a universal message structure, and cooperates with efficient serialization and deserialization methods to achieve efficient communication between control systems, improve data transmission efficiency and communication stability, and has strong scalability.
[0006] In order to achieve the above object, the present invention is implemented by the following technical solution: a method for implementing a serialized and extensible control system communication protocol based on Qt, and the method for implementing the communication protocol includes the following steps:
[0007] Step 1: The communication protocol refers to a general message structure, and the message structure includes a message header and a message body. The message header consists of a frame header, a timestamp, a frame sequence number, a message body length, a number of data segments, a message body CRC checksum, and a reserved field; the message body consists of one or more data segments;
[0008] Step 2: Serialize the message header and message body, and splice them into a QByteArray type message data based on the serialized message header and message body;
[0009] Step 3: Efficient deserialization processing, which includes parsing message header data, receiving message body data and deserializing data segments.
[0010] Furthermore, the frame header is used to identify the starting position of the message so that the receiving end can correctly identify the beginning of the message; the timestamp is used to record the timestamp of message generation so that the receiving end can understand the time information of the message; the frame sequence number is used to identify the order of the message in the message stream so that the receiving end can correctly process the messages in sequence.
[0011] Furthermore, the message body length is used to record the length of the message body so that the receiving end can correctly parse the message body; the number of data segments in the message body is used to record the number of data segments contained in the message body so that the receiving end can correctly parse the data in the message body; the message body CRC check is used to perform CRC check on the message body to ensure the integrity and correctness of the message body; the reserved field is used to reserve the field for future expansion or other purposes. If it is not used temporarily, it is reserved as 0.
[0012] Furthermore, the message body may include one or more data segments according to specific application requirements, and each data segment includes data of a specific type.
[0013] Furthermore, the number of data segments in the message body is specified by the "number of data segments in the message body" in the message header, and the structure of each data segment can be defined according to application requirements.
[0014] Furthermore, in the process of serializing the message header in step 2, a message header structure variable including a frame header, a timestamp, a frame number, a message body length, the number of data segments in the message body, a message body CRC checksum and a reserved field is first defined according to the description of the message header in step 1, and then the message header structure is filled according to actual application requirements, and finally the message header structure is serialized using the constructor.
[0015] Furthermore, in the process of serializing the message body in step 2, the message structure variable that needs to be sent to the recipient in the communication and the corresponding data segment ID variable are first defined, and then the data segment ID is assigned a value according to the message structure type, and the message structure variable is serialized into QByteArray type data using the QByteArray constructor, and finally the data segment ID, data length and QByteArray type message data are serialized together into QByteArray type data using QDataStream.
[0016] Furthermore, in step 3, after receiving the message, the receiving end first checks whether the message header is received completely. If it is complete, the data of each field of the message header is parsed according to the definition of the message header.
[0017] Furthermore, according to the data length field in the message header, the receiving end receives the complete message body data consistent with the length and performs verification processing.
[0018] Furthermore, after receiving the message, the receiving end first checks whether the message header is received completely. If it is complete, it parses the data of each field of the message header according to the definition of the message header.
[0019] Beneficial effects of the present invention:
[0020] 1. This Qt-based serialized and extensible control system communication protocol implementation method introduces a universal message structure that can be flexibly used in communications between various control systems, improves the flexibility and versatility of the communication protocol, realizes efficient communication between control systems, is suitable for communication needs between various control systems, and has broad application prospects and promotion value.
[0021] 2. The implementation method of the Qt-based serialized and extensible control system communication protocol adopts efficient serialization and parsing methods, which improves data transmission efficiency and communication stability.
[0022] 3. The message structure design of the implementation method of the Qt-based serialized extensible control system communication protocol is flexible, supports the addition of new data segments, meets the communication needs in different application scenarios, and has strong scalability. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 A general message structure diagram of a method for implementing a serialized and extensible control system communication protocol based on Qt according to the present invention;
[0024] Figure 2 It is a flow chart of message transmission and processing between the sending end and the receiving end in the present invention. DETAILED DESCRIPTION
[0025] In order to make the technical means, creative features, objectives and effects achieved by the present invention easy to understand, the present invention is further explained below in conjunction with specific implementation methods.
[0026] See also Figure 1 to Figure 2 The present invention provides the following technical solution: a method for implementing a serialized and extensible control system communication protocol based on Qt.
[0027] Example 1
[0028] This embodiment introduces a general message structure:
[0029] This communication protocol introduces a common message structure, which consists of a message header and a message body. Figure 1 As shown. The message header consists of the frame header, timestamp, frame sequence number, message body length, number of data segments, message body CRC checksum and reserved fields. The message body consists of one or more data segments. The following is a detailed description of the message header and message body:
[0030] Message header structure:
[0031] ⑴ Frame header (4 bytes): used to identify the starting position of the message. Usually a fixed identifier is used so that the receiving end can correctly identify the beginning of the message.
[0032] (2) Timestamp (8 bytes): records the timestamp when the message is generated so that the receiving end can understand the time information of the message. It usually uses a standard time format, such as UNIX timestamp.
[0033] (3) Frame sequence number (2 bytes): used to identify the order of messages in the message stream so that the receiving end can process the messages correctly in sequence.
[0034] (4) Message body length (2 bytes): records the length of the message body so that the receiving end can correctly parse the message body.
[0035] ⑸ Number of data segments in the message body (2 bytes): records the number of data segments contained in the message body so that the receiving end can correctly parse the data in the message body.
[0036] (6) Message body CRC check (2 bytes): used to perform CRC check on the message body to ensure the integrity and correctness of the message body.
[0037] ⑺Reserved field (2 bytes in total): The reserved field is used for future expansion or other purposes. If it is not used temporarily, it will be reserved as 0.
[0038] Message body structure:
[0039] The message body can contain one or more data segments, depending on the specific application requirements. Each data segment contains a specific type of data. The number of data segments in the message body is specified by the "Number of data segments in the message body" in the message header. The structure of each data segment can be defined according to application requirements, and usually includes a data segment ID, data length, and data content.
[0040] ⑴Data type identifier (4 bytes), used to identify the type of data,
[0041] ⑵Data length (4 bytes), the size of the serialized data.
[0042] ⑶Data content (number of bytes is variable), the actual data after serialization.
[0043] Example 2
[0044] This embodiment also provides an efficient serialization method:
[0045] ⑴Message body serialization
[0046] ① First, according to the description of the message header in step 1, define a message header structure variable that includes a frame header, timestamp, frame sequence number, message body length, number of data segments in the message body, message body CRC checksum, and reserved fields. The message header structure definition example is as follows.
[0047] Message header structure definition:
[0048]
[0049] ②Then, fill in the message header structure according to actual application requirements: fill in the value 0xEA5B3C67 for the frame header (FRM_HEAD::head), fill in the current time in seconds for the timestamp (FRM_HEAD::timeTag), fill in the cumulative value of the sequence number (FRM_HEAD::seq), fill in the length of the message body (FRM_HEAD::len), fill in the number of data segments contained in the message body (FRM_HEAD::subFrmCount), and fill in the CRC checksum of the message body (FRM_HEAD::crc).
[0050] ③Finally, use the QByteArray constructor to serialize the message header structure into QByteArray type data: QByteArray((char*)&Frm.frmHead,sizeof(FRM_HEAD)).
[0051] ⑵Message body serialization
[0052] ① First, define the message structure variable that needs to be sent to the receiving party in the communication, and the corresponding data segment ID variable. The following are examples of message structure variable definition and data segment ID definition.
[0053] Example of message structure variable definition
[0054]
[0055] Example of segment ID definition
[0056] #define ID_SYS1_STATE 0x01 / / Subsystem 1 status
[0057] #define ID_SYS1_STATE 0x02 / / Subsystem 2 status
[0058] ②Then, assign a value to the data segment ID according to the message structure type: id = ID_SYS1_STATE, and fill in the data of each field in the structure variable: SYS1_STATE: dev10nlineState = 1, ...; ③Then, use the QByteArray constructor to serialize the message structure variable into QByteArray type data: QByteArray((char*)&sys1STATE, sizeof(SYS1_STATE)). ④Finally, use QDataStream to serialize the data segment ID, data length and QByteArray type message data into QByteArray type data: QDataStreamdataStream, fill in ID: dataStream <<id, fill in the message body data length: dataStream <<data.size(), fill in the message body data: dataStream <<data.
[0059] ⑶Message serialization
[0060] The serialized message header and message body are concatenated into a QByteArray type message data: frmHead+datastream.
[0061] Example 3
[0062] This embodiment also provides an efficient deserialization method:
[0063] ⑴Parse message header data
[0064] After receiving the message, the receiver first checks whether the message header is received completely. If it is complete, it parses the data of each field of the message header according to the message header definition: frame header (FRM_HEAD::head), timestamp (FRM_HEAD::timeTag), sequence number (FRM_HEAD::seq), message body length (FRM_HEAD::len), number of data segments (FRM_HEAD::subFrmCount), and message body CRC check (FRM_HEAD::crc).
[0065] ⑵Receive message body data
[0066] According to the "data length" field (FRM_HEAD::len) in the message header, the receiving end receives the complete message body data (FRM_BODY::data) that is consistent with the length, and verifies that the crc of the complete message body data (FRM_BODY::data) is consistent with the crc in the message header (FRM_HEAD::crc).
[0067] ⑶ Data segment deserialization
[0068] According to the "number of data segments" field in the message header, the receiving end uses QDataStream to extract the serialized data one by one, and deserializes each data segment to restore the original data message: QDataStreamdataStream, extract the ID: dataStream>>id, extract the message body data length: dataStream>>data.size(), extract the message body data: dataStream>>data.
[0069] The basic principles and main features of the present invention and the advantages of the present invention are shown and described above. For those skilled in the art, it is obvious that the present invention is not limited to the details of the above-mentioned exemplary embodiments, and the present invention can be implemented in other specific forms without departing from the spirit or basic characteristics of the present invention.
[0070] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.
Claims
1. A method for implementing a serialized and extensible control system communication protocol based on Qt, characterized in that: The implementation method of the communication protocol includes the following steps: Step 1: The communication protocol refers to a general message structure, and the message structure includes a message header and a message body. The message header consists of a frame header, a timestamp, a frame sequence number, a message body length, a number of data segments, a message body CRC checksum, and a reserved field; the message body consists of one or more data segments; Step 2: Serialize the message header and message body, and splice them into a QByteArray type message data based on the serialized message header and message body; Step 3: Efficient deserialization processing, which includes parsing message header data, receiving message body data and deserializing data segments.
2. The method for implementing a Qt-based serialized and extensible control system communication protocol according to claim 1, characterized in that: The frame header is used to identify the starting position of the message so that the receiving end can correctly identify the beginning of the message; the timestamp is used to record the timestamp of message generation so that the receiving end can understand the time information of the message; The frame sequence number is used to identify the order of the messages in the message stream so that the receiving end can correctly process the messages in order.
3. The method for implementing a Qt-based serialized and extensible control system communication protocol according to claim 2, characterized in that: The message body length is used to record the length of the message body so that the receiving end can correctly parse the message body; the number of data segments in the message body is used to record the number of data segments contained in the message body so that the receiving end can correctly parse the data in the message body; the message body CRC check is used to perform CRC check on the message body to ensure the integrity and correctness of the message body; the reserved field is used to reserve the field for future expansion or other purposes. If it is not used temporarily, it is reserved as 0.
4. The method for implementing a Qt-based serialized and extensible control system communication protocol according to claim 1, characterized in that: The message body may include one or more data segments according to specific application requirements, and each data segment includes data of a specific type.
5. The method for implementing a Qt-based serialized and extensible control system communication protocol according to claim 4, characterized in that: The number of data segments in the message body is specified by the "number of data segments in the message body" in the message header, and the structure of each data segment can be defined according to application requirements.
6. The method for implementing a Qt-based serialized and extensible control system communication protocol according to claim 1, characterized in that: During the message header serialization process in step 2, first define a message header structure variable including a frame header, a timestamp, a frame sequence number, a message body length, the number of data segments in the message body, a message body CRC checksum, and a reserved field according to the description of the message header in step 1, then fill in the message header structure according to actual application requirements, and finally use the constructor to serialize the message header structure.
7. A method for implementing a Qt-based serialized and extensible control system communication protocol according to claim 6, characterized in that: In the message body serialization process in step 2, first define the message structure variable that needs to be sent to the recipient in the communication and the corresponding data segment ID variable, then assign a value to the data segment ID according to the message structure type, use the QByteArray constructor to serialize the message structure variable into QByteArray type data, and finally use QDataStream to serialize the data segment ID, data length and QByteArray type message data together into QByteArray type data.
8. The method for implementing a Qt-based serialized and extensible control system communication protocol according to claim 1, characterized in that: In the step 3, after receiving the message, the receiving end first checks whether the message header is received completely. If it is complete, the data of each field of the message header is parsed according to the definition of the message header.
9. The method for implementing a Qt-based serialized and extensible control system communication protocol according to claim 8, characterized in that: According to the data length field in the message header, the receiving end receives the complete message body data consistent with the length and performs verification processing.
10. The method for implementing a Qt-based serialized and extensible control system communication protocol according to claim 8, characterized in that: After receiving the message, the receiver first checks whether the message header is received completely. If it is complete, it parses the data of each field of the message header according to the message header definition.
Citation Information
Patent Citations
Big data encoding and decoding method and device based on time sequence
CN113094346A
Rocket test equivalent device data processing method, computer equipment and storage medium
CN114490654A
Data transmission method and device between heterogeneous devices of intelligent network connection automobile
CN117118574A
Multi-device access upper computer software system
CN117785586A
Cited By
Communication method and system based on conventional communication protocol and QT
CN121547503A