Communication protocol parsing code automatic generation method, application, system and storage medium

By automatically generating communication protocol parsing code, the problem of repetitive work and high error rate caused by manual reading of Excel tables in the existing technology of protocol parsing is solved, efficient protocol parsing code generation is achieved, and development efficiency is improved.

CN116126302BActive Publication Date: 2025-09-26HUIZHOU DESAY SV AUTOMOTIVE
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310054349.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-03
Publication Date
2025-09-26
Estimated Expiration
2043-02-03

AI Technical Summary

Technical Problem

In the existing technology, communication protocol parsing relies on manual reading of Excel spreadsheets, which leads to duplication of work, high error rate and low development efficiency, and fails to effectively simplify the protocol parsing process.

Method used

The communication protocol source data in the Excel document is parsed by the main program code, and the communication protocol parsing code is automatically generated, including constant definition, generation of the first parsing function and the second parsing function, and output as a C++ source file.

Benefits of technology

It simplifies the writing of protocol parsing code, eliminates manual coding errors, and improves development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116126302B_ABST
    Figure CN116126302B_ABST
Patent Text Reader

Abstract

The present invention provides a method, application, system and storage medium for automatically generating communication protocol parsing code. The method comprises: inputting source data of each communication protocol into a sheet of a blank Excel document, obtaining the Excel document, and generating a header file of the communication protocol parsing code; then generating constant definition code, traversing a column of English descriptions of structures in the sheet to generate a corresponding first parsing function, and generating a corresponding second parsing function based on the first parsing function; further defining a main function, and sequentially calling the constant definition code, the first parsing function and the second parsing function, thereby completing the automatic generation of the communication protocol parsing code. The present invention simplifies the tedious work of writing proofreading protocols and parsing codes, eliminates errors that may be introduced by manual coding, and improves development efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication protocol technology, and in particular to a method, application, system and storage medium for automatically generating communication protocol parsing code. Background Art

[0002] A communication protocol is a network communication language that supports communication between networks with different operating systems and hardware architectures. A communication protocol, also known as a communication protocol, is an agreement between two communicating parties on how to control data transmission. This agreement includes unified regulations on data format, synchronization method, transmission speed, transmission steps, error detection and correction methods, and control character definitions. Both parties must comply with this agreement, and therefore it is also called a link control protocol.

[0003] Under the existing framework, parsing communication protocols mainly relies on manual reading of Excel spreadsheets to understand the communication protocols. Code is then written for parsing based on the protocol format and content described in the Excel spreadsheets. Similar code needs to be written for different products to implement protocol parsing. For each product, a large Excel spreadsheet needs to be read, and the contents in the Excel spreadsheet need to be read one by one to write code to parse the instructions. If the instructions are long, more code needs to be written. If a field in the instruction represents multiple types, more code will be generated. Writing these codes is repetitive work, and errors are easily introduced during manual proofreading, resulting in low development efficiency. In addition, the person who wrote this protocol has already proofread it once, and the user of this protocol needs to proofread it again when implementing the parsing, resulting in a waste of manpower. Summary of the Invention

[0004] In order to solve the above technical problems, the present invention provides a method, application, system and storage medium for automatically generating communication protocol parsing code, which parses the communication protocol source data in an Excel document through a main program code to automatically generate its corresponding communication protocol parsing code for the communication protocol parsing program to call.

[0005] Specifically, the present invention provides a method for automatically generating communication protocol parsing code, comprising the following steps:

[0006] S100: Input the source data of each communication protocol into a sheet of a blank Excel document according to the preset format requirements.

[0007] S200: Acquire the Excel document, and automatically generate corresponding communication protocol parsing code according to the communication protocol source data.

[0008] S300: Output the communication protocol parsing code for calling by the communication protocol parsing program.

[0009] The communication protocol source data in step S100 at least includes a number, a Chinese description of the structure, an English description of the structure, a transmission direction of the structure, an instruction id, an instruction id byte length, parameters, an attribute id, an attribute value type, a constant and a constant value.

[0010] The automatic generation of the corresponding communication protocol parsing code in step S200 is specifically as follows:

[0011] S210: Generate constant definition code.

[0012] S220: Traverse a column of English descriptions of structures in the sheet, use the column as a standard to distinguish different instruction IDs, and generate a corresponding first parsing function according to the instruction ID.

[0013] S230: Generate a second parsing function corresponding to the sheet form according to the first parsing function.

[0014] S240: Define a main function, and call the constant definition code, the first parsing function, and the second parsing function in sequence.

[0015] S250: Complete automatic generation of communication protocol parsing code.

[0016] The step S210 is specifically as follows: reading the first sheet in the Excel document; traversing the three columns of attribute ID, constant and constant value in the sheet, and generating constant definition code.

[0017] The step S220 is specifically as follows:

[0018] S221: traverse a column of English descriptions of structures in the sheet form, and based on this column, traverse all rows containing the instruction ID, convert the parameters in each row into constant values, and call the callback function to return the constant values ​​to the client.

[0019] S222: Determine whether there is communication protocol source data in the sheet. If yes, go to S221; otherwise, read the next sheet.

[0020] S223: Complete the generation of the first analytical function.

[0021] The step S230 specifically includes: traversing a column of instruction IDs and a column of structure English descriptions in the sheet, and generating a second parsing function according to the first parsing function.

[0022] Before step S210 , the method further includes: generating a header file of the communication protocol parsing code so that the compiler can find the function library corresponding to each referenced function in the communication protocol parsing code.

[0023] As another preferred embodiment, the present invention also provides an application based on the method for automatically generating communication protocol parsing code, comprising the following steps: opening the main program code, the program generates the corresponding communication protocol parsing code by parsing the Excel document, and outputs it as a C++ source file.

[0024] As another preferred embodiment, the present invention also provides a communication protocol parsing code automatic generation system, which includes: an input unit: used to input each communication protocol source data into a sheet form of a blank Excel document; an acquisition unit: used to acquire the Excel document; a generation unit: used to automatically generate corresponding communication protocol parsing code based on the communication protocol source data for call by the communication protocol parsing program.

[0025] As another preferred embodiment, the present invention further provides a storage medium, which is a computer-readable storage medium and stores a computer program thereon. When the computer program is executed by a processor, the method for automatically generating communication protocol parsing code is implemented.

[0026] Compared with the prior art, the present invention has the following beneficial effects:

[0027] The present invention uses a main program code written in C++ to traverse the communication protocol source data in an Excel document to automatically generate the corresponding communication protocol parsing code and output it as a C++ source file. This allows the main program code to parse the data in the Excel document according to the format established by the communicating parties and generate a C++ source file for the parsing protocol. This simplifies the tedious work of proofreading the protocol and writing the parsing code, eliminates errors that may be introduced by manual coding, and improves development efficiency. This solves the problems in the prior art of requiring different codes to be written for different products, as well as the high error rate and low development efficiency caused by manual proofreading and parsing. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 This is a flow chart of the method for automatically generating communication protocol parsing code according to the present invention.

[0029] Figure 2 for Figure 1 The automatically generated communication protocol parsing code flow chart.

[0030] Figure 3 for Figure 2 The generating first analytical function flow chart.

[0031] Figure 4 for Figure 1 System framework diagram of the method for automatically generating communication protocol parsing code. Implementation Method

[0032] The following is a further detailed description of a method, application, system and storage medium for automatically generating communication protocol parsing codes according to the present invention in conjunction with specific embodiments and accompanying drawings.

[0033] Specifically, such as Figure 1 As shown, the present invention provides a method for automatically generating communication protocol parsing code, comprising the following steps:

[0034] S100: Input the source data of each communication protocol into a sheet of a blank Excel document according to the preset format requirements.

[0035] The communication protocol source data in step S100 at least includes a number, a Chinese description of the structure, an English description of the structure, a transmission direction of the structure, an instruction id, an instruction id byte length, parameters, an attribute id, an attribute value type, a constant and a constant value.

[0036] Preferably, the communication protocol source data is written into a blank Excel document sheet in the order of the communication protocol source data to ensure that the subsequent function can accurately traverse the data. Each communication protocol source data corresponds to column AK in the sheet.

[0037] Taking the structure whose Chinese description is air conditioning switch as an example, its English description is HvacOnOff, the transmission direction is from MCU system to SOC system, the instruction ID is 0x7350, the byte length of the instruction ID is 2, the parameters include 0x00 and 0x01, the property ID is PROP_HVAC_AC, the property value type is int32_t, the constants include AC_OFF and AC_ON, and their corresponding constant values ​​are 1 and 2 respectively.

[0038] Taking the structure with the Chinese description of air conditioning air volume as an example, its English description is HvacFanSpeed, the transmission direction is from the MCU system to the SOC system, the instruction ID is 0x7351, the byte length of the instruction ID is 2, the parameters include 0x00, 0x01 and 0x02, the property ID is PROP_HVAC_FAN_SPEED, the property value type is int32_t, and the constants include FAN_SPEED_LEVEL_1, FAN_SPEED_LEVEL_2 and FAN_SPEED_LEVEL_3, and their corresponding constant values ​​are 1, 2 and 3 respectively.

[0039] S200: Acquire the Excel document, and automatically generate corresponding communication protocol parsing code according to the communication protocol source data.

[0040] S300: Output the communication protocol parsing code for calling by the communication protocol parsing program.

[0041] like Figure 2 As shown, the automatic generation of the corresponding communication protocol parsing code in step S200 is specifically:

[0042] S210: Generate constant definition code.

[0043] The step S210 specifically includes: reading the first sheet in the Excel document; traversing the three columns of attribute id, constant and constant value in the sheet, and generating constant definition code.

[0044] Preferably, in the code representation, the three columns H, J and K are traversed to generate constant definition codes; once a constant is defined, it cannot be modified or redefined.

[0045] Specifically, AC_OFF=1, AC_ON=2.

[0046] FAN_SPEED_LEVEL_1=1, FAN_SPEED_LEVEL_2=2, FAN_SPEED_LEVEL_3=3.

[0047] Before step S210 , the method further includes: generating a header file of the communication protocol parsing code so that the compiler can find the function library corresponding to each referenced function in the communication protocol parsing code.

[0048] S220: Traverse a column of English descriptions of structures in the sheet, use the column as a standard to distinguish different instruction IDs, and generate a corresponding first parsing function according to the instruction ID.

[0049] like Figure 3 As shown, the step S220 is specifically as follows:

[0050] S221: traverse a column of English descriptions of structures in the sheet form, and based on this column, traverse all rows containing the instruction ID, convert the parameters in each row into constant values, and call the callback function to return the constant values ​​to the client.

[0051] S222: Determine whether there is communication protocol source data in the sheet. If yes, go to S221; otherwise, read the next sheet.

[0052] Preferably, the sheet form only contains two structures, namely, the air conditioning switch and the air conditioning air volume. After traversing their corresponding English descriptions, the parameters in the two rows of the air conditioning switch and the air conditioning air volume are converted into constant values, and the callback function is called to return the constant values ​​to the client. At this time, there is no other communication protocol source data in the sheet form, and the next sheet form is automatically read to generate the communication protocol parsing code corresponding to the sheet form.

[0053] S223: Complete the generation of the first analytical function.

[0054] S230: Generate a second parsing function corresponding to the sheet form according to the first parsing function.

[0055] The step S230 specifically includes: traversing a column of instruction IDs and a column of structure English descriptions in the sheet, and generating a second parsing function according to the first parsing function.

[0056] S240: Define a main function, and call the constant definition code, the first parsing function, and the second parsing function in sequence.

[0057] S250: Complete automatic generation of communication protocol parsing code.

[0058] As another preferred embodiment, the present invention also provides an application based on the method for automatically generating communication protocol parsing code, comprising the following steps: opening the main program code, the program generates the corresponding communication protocol parsing code by parsing the Excel document, and outputs it as a C++ source file.

[0059] Taking the air conditioner switch as an example, the output C++ source file code is:

[0060] #include "Receiver.h"

[0061] #include "PropValue.h"

[0062] Receiver receiver;

[0063] enum class PropConstant : uint32_t {

[0064] AC_OFF = 1,

[0065] AC_ON = 2,

[0066] FAN_SPEED_LEVEL_1 = 1,

[0067] FAN_SPEED_LEVEL_2 = 2,

[0068] FAN_SPEED_LEVEL_3 = 3,

[0069] };

[0070] void parseCmdHvacOnOff(uint8_t* data) {

[0071] PropValue propValue;

[0072] switch (data[0]) {

[0073] case 0x00:

[0074] propValue.propId = (int)PropertyId::PROP_HVAC_AC;

[0075] propValue.value = PropConstant::AC_OFF;

[0076] receiver.callback(propValue);

[0077] break;

[0078] case 0x01:

[0079] propValue.propId = (int)PropertyId::PROP_HVAC_AC;

[0080] propValue.value = PropConstant::AC_ON;

[0081] receiver.callback(propValue);

[0082] break;

[0083] }

[0084] }

[0085] void parseCmdHvacFanSpeed(uint8_t* data) {

[0086] PropValue propValue;

[0087] switch (data[0]) {

[0088] case 0x00:

[0089] propValue.propId = (int)PropertyId::PROP_HVAC_FAN_SPEED;

[0090] propValue.value = PropConstant::FAN_SPEED_LEVEL_1;

[0091] receiver.callback(propValue);

[0092] break;

[0093] case 0x01:

[0094] propValue.propId = (int)PropertyId::PROP_HVAC_FAN_SPEED;

[0095] propValue.value = PropConstant::FAN_SPEED_LEVEL_2;

[0096] receiver.callback(propValue);

[0097] break;

[0098] case 0x02:

[0099] propValue.propId = (int)PropertyId::PROP_HVAC_FAN_SPEED;

[0100] propValue.value = PropConstant::FAN_SPEED_LEVEL_3;

[0101] receiver.callback(propValue);

[0102] break;

[0103] }

[0104] }

[0105] void parseComponentHVAC(uint8_t* data) {

[0106] switch(data[0]) {

[0107] case 0x7350:

[0108] parseCmdHvacOnOff(&data[2]);

[0109] break;

[0110] case 0x7351:

[0111] parseCmdHvacFanSpeed(&data[2]);

[0112] break;

[0113] }

[0114] }

[0115] As another preferred embodiment, Figure 4 As shown, the present invention also provides a communication protocol parsing code automatic generation system, which includes: an input unit: used to input each communication protocol source data into a sheet form of a blank Excel document; an acquisition unit: used to obtain the Excel document; a generation unit: used to automatically generate corresponding communication protocol parsing code according to the communication protocol source data, for call by the communication protocol parsing program.

[0116] As another preferred embodiment, the present invention further provides a storage medium, which is a computer-readable storage medium and stores a computer program thereon. When the computer program is executed by a processor, the method for automatically generating communication protocol parsing code is implemented.

[0117] In summary, the present invention provides a method, application, system and storage medium for automatically generating communication protocol parsing code; by inputting each communication protocol source data into a sheet form of a blank Excel document and obtaining the Excel document, a header file of the communication protocol parsing code is generated; then, a constant definition code is generated, a column of English descriptions of structures in the sheet form is traversed to generate a corresponding first parsing function, and a corresponding second parsing function is generated based on the first parsing function; a main function is further defined, and the constant definition code, the first parsing function and the second parsing function are called in sequence, and the communication protocol parsing code is automatically generated. The present invention implements parsing of the data in the Excel document according to the format established by the communicating parties through the main program code, generates a C++ source file of the parsing protocol, simplifies the tedious work of proofreading the protocol and writing the parsing code, eliminates errors that may be introduced by manual coding, and improves development efficiency.

[0118] Although example embodiments have been described herein with reference to the accompanying drawings, it should be understood that the above example embodiments are merely illustrative and are not intended to limit the scope of the present invention. Various changes and modifications may be made therein by those skilled in the art without departing from the scope and spirit of the present invention. All such changes and modifications are intended to be included within the scope of the present invention as claimed in the appended claims.

[0119] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.

[0120] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units described is merely a logical function division. In actual implementation, other division methods may be used, such as combining or integrating multiple units or components into another device, or ignoring or not performing some features.

[0121] The various component embodiments of the present invention can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It will be appreciated by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all of the functions of some modules according to embodiments of the present invention. The present invention can also be implemented as a device program (e.g., a computer program and a computer program product) for executing a part or all of the methods described herein. Such a program implementing the present invention can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

[0122] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0123] Although the present invention is described in conjunction with the above specific embodiments, it is obvious that those skilled in the art can make many substitutions, modifications and variations based on the above content. Therefore, all such substitutions, improvements and variations are included in the spirit and scope of the appended claims.

Claims

1. A method for automatically generating communication protocol parsing code, characterized in that: The following steps are involved: S100: Input each communication protocol source data into a blank Excel sheet according to a preset format requirement; wherein the communication protocol source data at least includes a number, a structure description in Chinese, a structure description in English, a structure transmission direction, an instruction ID, an instruction ID byte length, parameters, an attribute ID, an attribute value type, a constant, and a constant value; S200: Obtain the Excel document and automatically generate corresponding communication protocol parsing code based on the communication protocol source data; Wherein, the S200 includes: S210: Read the first sheet in the Excel document; traverse the three columns of attribute ID, constant, and constant value in the sheet to generate constant definition code; S220: Traverse a column of English descriptions of structures in the sheet, distinguish different instruction IDs based on the column, and generate a corresponding first parsing function according to the instruction ID; Wherein, the S220 includes: S221: traverse the English description column of the structure in the sheet, and based on this column, traverse all rows containing the instruction ID, convert the parameters in each row into constant values, and call the callback function to return the constant values ​​to the client; S222: Determine whether there is communication protocol source data in the sheet. If yes, go to S221; otherwise, read the next sheet. S223: Complete the generation of the first analytical function; S230: Generate a second analytic function corresponding to the sheet form according to the first analytic function; S240: defining a main function, and calling the constant definition code, the first parsing function, and the second parsing function in sequence; S250: completing automatic generation of communication protocol parsing code; S300: Output the communication protocol parsing code for calling by the communication protocol parsing program.

2. The method for automatically generating communication protocol parsing code according to claim 1, characterized in that: The step S230 specifically includes: traversing a column of instruction IDs and a column of structure English descriptions in the sheet, and generating a second parsing function according to the first parsing function.

3. The method for automatically generating communication protocol parsing code according to claim 1, characterized in that: Before step S210 , the method further includes: generating a header file of the communication protocol parsing code so that the compiler can find the function library corresponding to each referenced function in the communication protocol parsing code.

4. The method for automatically generating communication protocol parsing code according to claim 1, wherein: The following steps are also included: Open the main program code. The program parses the Excel document, generates the corresponding communication protocol parsing code, and outputs it as a C++ source file.

5. A system using the method for automatically generating communication protocol parsing code according to any one of claims 1 to 4, characterized in that: The system comprises: Input unit: used to input the source data of each communication protocol into a sheet of a blank Excel document; Acquisition unit: used for acquiring the Excel document; Generating unit: used for automatically generating corresponding communication protocol parsing code according to the communication protocol source data, so as to be called by the communication protocol parsing program.

6. A computer-readable storage medium, characterized in that A computer program is stored thereon, and when the computer program is executed by a processor, the method for automatically generating communication protocol parsing code according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Protocol configuration method and device

    CN107612919A

  • Data transmission method and device for upper computer and lower computer

    CN112242941A