Automatic generation method of WORD format communication protocol interface function code
By setting feature points in the WORD protocol design and automatically supplementing the data packet table information, the problem of errors in word sequence numbers/byte sequence numbers in traditional designs is solved, and efficient automatic generation of interface function codes and automatic processing of protocol changes is realized.
Patent Information
- Application Number
- CN202411716122.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-05-06
AI Technical Summary
In the traditional communication protocol design, word number/byte number and word number/byte number in the data packet table are prone to errors, and it is difficult to achieve automatic reordering and synchronous changes in interface function codes when the protocol changes, resulting in large workload and error-prone.
By setting the eleven feature points of the WORD protocol packet, the modified WORD protocol packet table is generated, and the information content of word sequence number/byte sequence number and word count/byte count are automatically supplemented, and the interface function code is automatically generated to reduce manual operations.
It realizes automatic filling of word sequence numbers/byte sequence numbers and word counts/byte counts, reducing error occurrence, and automatically generating interface function codes greatly reduces manual workload, and supports automatic reordering and code synchronization when protocol changes.
Smart Images

Figure CN119938023A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of communication protocols and relates to a method for automatically generating a communication protocol interface function code in a WORD format. Background Art
[0002] A communication protocol refers to an agreement between two communicating parties on data transmission control. The communication protocol stipulates the process information and data packet definition (word sequence number / byte sequence number, physical name, number of words / bytes, data type, scale (equivalent), etc.) of the two communicating parties, and is generally recorded and saved in a WORD document.
[0003] The traditional communication protocol design and corresponding software development solution specifies the data packet content through a table in a WORD document. The software developers of both communicating parties manually fill in the table information according to the table content. The filled table is shown in Table 1, and then completes the variable definition, dimensionless data multiplication (division) scale conversion into physical quantities and other tasks. When writing the protocol in the table information, it is very easy to make mistakes in filling in the word sequence number / byte sequence number and the number of words / bytes in the data packet table. If one of the physical quantities is deleted (that is, a whole row of data in Table 1 is deleted), manual operation is required to re-sort all the word sequence numbers / byte sequence numbers in Table 1. The work is repetitive, cumbersome, and the workload is huge, and it is very easy to make mistakes in this process.
[0004] Table 1 Traditional WORD protocol data packet table information
[0005]
[0006] In the past two years, a technology has emerged that manually rearranges the data packet table in the WORD protocol in a specific format in EXCEL, and then automatically generates interface functions based on the EXCEL file information. This technology reduces the workload of developers to a certain extent, but still faces two problems:
[0007] 1) Usually, there are multiple data packet tables in a WORD protocol. This technology only supports one EXCEL file corresponding to one data packet table, so multiple EXCEL files need to be created. The process of creating EXCEL is still a manual process, which is difficult to avoid errors and the work is also repetitive and cumbersome;
[0008] 2) When the WORD protocol changes frequently (i.e., deleting or adding physical quantities), it is impossible to directly reorder the word sequence number / byte sequence number and synchronously change the interface function code required for software operation. It is necessary to manually change EXCEL, resulting in problem 1), which causes this technology to be mostly used in the initial development of software. When the WORD protocol changes, this technology is abandoned and instead returns to the traditional way of modifying the software by comparing the WORD protocol, which does not have the ability to be redeveloped. Summary of the invention
[0009] The present invention aims to solve at least one of the problems existing in the prior art.
[0010] To this end, the present invention provides a method for automatically generating a communication protocol interface function code in a WORD format, which can realize automatic filling of word sequence number / byte sequence number and word number / byte number to prevent errors, and can automatically generate an interface function code to reduce the workload of manual operation.
[0011] The technical solution of the present invention is:
[0012] A method for automatically generating a communication protocol interface function code in WORD format, the specific steps of the method are as follows:
[0013] Step 1, setting eleven characteristic points of the WORD protocol data packet, and generating a modified WORD protocol data packet table according to the eleven characteristic points, wherein the modified WORD protocol data packet table information has been filled with information content of the eleven characteristic points and information content of the physical quantity name, but has not been filled with information content of the word sequence number / byte sequence number and word number / byte number;
[0014] Step 2: Automatically supplement the word sequence number / byte sequence number and word count / byte count information in the modified WORD protocol data packet table information according to the feature points set in step 1, and automatically generate the interface function codes of all physical quantities of the modified WORD protocol data packet in batches.
[0015] Furthermore, the eleven feature points are:
[0016] Feature point 1 is the protocol interface function automatic generation tool configuration. If a table in a word document has information content configured by the protocol interface function automatic generation tool, it means that the table needs the interface function code to be automatically generated.
[0017] Feature point 2 is the starting position, i.e., the starting number of the word sequence number / byte sequence number specified in the table;
[0018] The third characteristic point is the unit, which is the data unit type specified in the table. The data unit types include: byte, word and double word;
[0019] Feature point 4 is the name of the structure variable, that is, the structure name of the code corresponding to the table;
[0020] Feature point five is the array variable name, that is, the name of the array corresponding to the data storage of the table;
[0021] Feature point six is the array offset, that is, the offset between the index position of a physical quantity in the array and the word number / byte number in the table;
[0022] Feature point seven is big endian / little endian, that is, big endian means the byte order is high first and low later, and little endian means the byte order is low first and high later;
[0023] Feature point eight is the sender and receiver, that is, the data flow information;
[0024] Feature point nine is the data type, which includes UINT16, UINT8, INT16 and INT32;
[0025] The characteristic point ten is the scale, and the dimensionless data is converted into a physical quantity with physical meaning by multiplying or dividing the scale;
[0026] The eleventh characteristic point is the physical quantity variable name, which specifies the variable name of the physical quantity in the structure definition.
[0027] Furthermore, in step 2, the process of automatically supplementing the information content of the word sequence number / byte sequence number and the word number / byte number is as follows:
[0028] Step 1, read the word document and get all the tables in the word document;
[0029] Step 2, traverse the table set A, and determine whether the current table T1 satisfies feature point 1 one by one. If it does, execute step 3; if not, skip the current table T1, and determine whether the next table satisfies feature point 1, until all tables in the table set A are processed;
[0030] Step 3, extract feature point 2, feature point 3 and feature point 9, and obtain the starting position, unit, and data type of each physical quantity of the current table T1;
[0031] Step 4, based on the information obtained in step 3, regenerate the information content of the word sequence number / byte sequence number and word count / byte count in the current table T1:
[0032] (1) Assuming that the starting position of the current table T1 is a, the unit is byte, and the data type of the selected physical quantity is UINT16, the calculation process for calculating the byte sequence number and number of bytes corresponding to the physical quantity is as follows:
[0033] ① Number of bytes = number of units corresponding to the data type. UINT16 represents two byte units, that is, number of bytes = 2;
[0034] ② Before calculating the byte number, first calculate the total number of bytes b of the physical quantity in all rows before the row where the physical quantity is located; at this time, the upper and lower limits of the byte number range are:
[0035] The lower limit of the byte number range = a + b;
[0036] The upper limit of the byte number range = a + b + the number of bytes of the physical quantity - 1;
[0037] (2) Assuming that the starting position of the current table T1 is a, the unit is word, and the data type of a physical quantity is UINT16, the calculation process for calculating the byte sequence number and number of bytes corresponding to the physical quantity is as follows:
[0038] ① Number of words = number of units corresponding to the data type, UINT16 represents 1 word unit, that is, number of words = 1;
[0039] ② Before calculating the word sequence number, first calculate the total number of words b of the physical quantity in all rows before the row where the physical quantity is located; at this time, the upper and lower limits of the word sequence number range are:
[0040] The lower limit of the word number range = a + b;
[0041] The upper limit of the word number range = a + b + the number of words of the physical quantity - 1;
[0042] Therefore, the information content of the calculated word sequence number / byte sequence number and word count / byte count is added to the modified WORD protocol data packet table.
[0043] Furthermore, when the protocol in the WORD protocol data packet changes, that is, when the physical quantity increases or decreases, the word sequence number / byte sequence number in the WORD protocol data packet table needs to be reordered. By repeating steps 3 and 4, the word sequence number / byte sequence number in the WORD protocol data packet table can be automatically refilled.
[0044] Further, the process of automatically generating the interface function codes of all physical quantities of the modified WORD protocol data packets in batches is as follows:
[0045] Step 5, extract feature point 4, feature point 5, feature point 6, feature point 7, feature point 8, feature point 10 and feature point 11, and obtain the structure variable name S1, array variable name G2, array offset c, big and small end type, sender and receiver information, scale d and physical quantity variable name V3 of the selected physical quantity in turn;
[0046] Step 6: According to the information obtained in step 5, the interface function code corresponding to the physical quantity is automatically generated. The specific process of generation is as follows:
[0047] (1) According to the type of big and small ends, distinguish whether the physical quantity is high first and then low or low first and then high:
[0048] If it is low first and high later, the upper limit of the range of the word number / byte number corresponding to the physical quantity is used as the big end of the data, and the lower limit of the range of the word number / byte number corresponding to the physical quantity is used as the little end of the data. The big end of the data and the little end of the data are spliced to obtain the spliced 16-bit data;
[0049] If it is high first and then low, the lower limit of the range of the word number / byte number corresponding to the physical quantity is used as the big end of the data, and the upper limit of the range of the word number / byte number corresponding to the physical quantity is used as the little end of the data. The big end of the data and the little end of the data are spliced to obtain the spliced 16-bit data;
[0050] (2) determining a data stream according to a sender, a receiver, and an input local device name, where the data stream includes an input stream and an output stream;
[0051] The interface function code for the input stream is expressed as follows: the 16-bit data after the previous step is multiplied by the scale d to convert it into a structure variable, wherein the value of the structure variable is expressed as S1.V3, S1 is the name of the structure variable, and V3 is the name of the physical quantity variable;
[0052] The interface function code for the output stream is expressed as follows: Divide the structure variable S1.V3 by the scale d to convert it into the 16-bit data after the previous step;
[0053] Repeat steps 5 and 6 to obtain the interface function codes for all physical quantities.
[0054] Furthermore, when 16-bit data is combined, the byte numbers are set to be M to N, and N is greater than M;
[0055] If it is low first and high later, the Qth byte of the array variable name G2 is used as the high 8 bits, and the Pth byte of the array variable name G2 is used as the low 8 bits, and the two are combined to form 16-bit data;
[0056] If high first and low later, the Qth byte of array variable name G2 is used as the lower 8 bits, and the Pth byte of array variable name G2 is used as the upper 8 bits, and the two are combined to form 16-bit data.
[0057] Q=N-array offset c, P=M-array offset c.
[0058] By applying the above technical solution, the present invention has the following beneficial effects:
[0059] The present invention adds eleven characteristic points to each data packet table based on the traditional WORD communication protocol design. With the help of these characteristic points, the following can be achieved:
[0060] (1) In the process of WORD protocol design, the word sequence number / byte sequence number and word count / byte count in the WORD protocol data packet are automatically generated, which reduces the protocol design time and avoids the error of manually writing the word sequence number / byte sequence number and word count / byte count;
[0061] (2) With the WORD protocol as the input file and the application program that parses the protocol, the interface function code corresponding to all the data packet tables in the WORD protocol can be directly and automatically generated, and the code can be generated in batches with high efficiency. Taking a project with 8 protocols as an example, 5,000 lines of code can be generated within 1 minute. The more protocols there are, the more obvious the advantage. It can also ensure that the generated code is completely consistent with the protocol regulations and has reliable quality. It can effectively avoid errors such as array index misalignment and incorrect scale implementation that may be caused by manual coding. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] The included drawings are used to provide a further understanding of the embodiments of the present invention, which constitute a part of the specification, are used to illustrate the embodiments of the present invention, and together with the text description, explain the principles of the present invention. Obviously, the drawings in the following description are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0063] Figure 1 A logic diagram automatically generated by the interface function code of the present invention;
[0064] Figure 2 This is an application layer relationship diagram. DETAILED DESCRIPTION
[0065] It should be noted that, in the absence of conflict, the embodiments in this application and the features in the embodiments can be combined with each other. The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and is by no means intended to limit the present invention and its application or use. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0066] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0067] Unless otherwise specifically stated, the relative arrangement of the parts and steps described in these embodiments, numerical expressions and numerical values do not limit the scope of the present invention. At the same time, it should be understood that, for ease of description, the sizes of the various parts shown in the accompanying drawings are not drawn according to the actual proportional relationship. The technology, method and equipment known to ordinary technicians in the relevant field may not be discussed in detail, but in appropriate cases, the technology, method and equipment should be regarded as a part of the authorization specification. In all examples shown and discussed here, any specific value should be interpreted as being merely exemplary, rather than as a limitation. Therefore, other examples of exemplary embodiments may have different values. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once a certain item is defined in an accompanying drawing, it does not need to be further discussed in subsequent drawings.
[0068] Embodiment 1:
[0069] This embodiment provides a method for automatically generating a communication protocol interface function code in WORD format, and the specific steps of the method are as follows:
[0070] Step 1: Change the data packet table format in the traditional WORD protocol, set eleven characteristic points of the data packet in the traditional WORD protocol, and generate the standard format of the WORD protocol data packet table, as shown in Table 2:
[0071] Table 2 WORD protocol data packet table after setting feature points
[0072]
[0073]
[0074] Among them, the eleven feature points are:
[0075] Feature point 1 is the configuration of the protocol interface function automatic generation tool. If a table in the word document has the information content of the protocol interface function automatic generation tool configuration, it means that the table needs the interface function code to be automatically generated, as shown in (1) in Table 2;
[0076] Feature point 2 is the starting position, i.e., the starting number of the word sequence number / byte sequence number specified in the table (i.e., the table with feature point 1), as shown in (2) of Table 2;
[0077] The characteristic point three is the unit, that is, the data unit type specified in the table, and the data unit types include: byte, word and double word, as shown in (3) of Table 2;
[0078] Feature point 4 is the name of the structure variable, that is, the structure name of the code corresponding to the table, as shown in Table 2 (4);
[0079] Feature point five is the name of the array variable, that is, the name of the array corresponding to the data storage in the table, as shown in Table 2 (5);
[0080] Feature point six is the array offset, that is, the offset between the index position of a physical quantity in the array and the word number / byte number in the table. For example, if the byte number of a physical quantity is 4 to 5 and the index position of the array is 2 to 3, the offset is 2, as shown in Table 2 (6);
[0081] Feature point seven is big endian / little endian, the definition of byte order, such as low first then high or high first then low, that is, big endian means the byte order is high first then low, and little endian means the byte order is low first then high, as shown in Table 2 (7);
[0082] Feature point eight is the sender and receiver, that is, the data flow information, which stipulates that the sender and receiver are XX devices, as shown in Table 2 (8);
[0083] Feature point nine is the data type, which includes UINT16, UINT8, INT16 and INT32, as shown in Table 2 (9);
[0084] Feature point 10 is the scale, and dimensionless data is multiplied or divided by the scale to be converted into physical quantities with physical meanings, as shown in Table 2 (⑽);
[0085] Feature point 11 is the name of the physical quantity variable, which specifies the variable name of the physical quantity in the structure definition, such as ⑾ in Table 2;
[0086] Step 2: According to the standard format of the WORD protocol data packet table generated in step 1, the data packet in the traditional WORD protocol is modified, and the modified WORD protocol data packet table information has been filled with the information content of the eleven feature points and the information content of the physical quantity name, but the information content of the word sequence number / byte sequence number and the number of words / bytes has not been filled;
[0087] This embodiment uses the information in Table 1 as a reference, and the modified WORD protocol data packet table information is shown in Table 3:
[0088] Table 3 Modified WORD protocol data packet table information
[0089]
[0090]
[0091] Step 3: Automatically supplement the word sequence number / byte sequence number and word count / byte count information in the modified WORD protocol data packet table information according to the feature points set in step 1, and automatically generate the interface function codes of all physical quantities of the modified WORD protocol data packet in batches, see Appendix Figure 1 , the specific process is:
[0092] Step 3-1, read the word document, obtain all the tables in the word document, and let all the tables be a table set A; the table set A includes: tables in several frame formats (such as Table 5), tables of several types (such as Table 4), modified WORD protocol data packet tables (such as Table 3), etc.;
[0093] Table 4
[0094] Data Types illustrate UINT8 Unsigned 8-bit integer data UINT16 Unsigned 16-bit integer data UINT32 Unsigned 32-bit integer data … …
[0095] Table 5
[0096] Byte Sequence Number name content 1 Frame Header 55H 2 Frame Header AAH 3 Data length N-4 … … …
[0097] Step 3-2, traverse the table set A, determine whether the current table T1 satisfies feature point 1 one by one, and if so, execute step 3-3; if not, skip the current table T1, and determine whether the next table satisfies feature point 1, until all tables in the table set A are processed; in this embodiment, table 3 satisfies feature point 1, and step 3-3 is executed for table 3; tables 4 and 5 do not satisfy feature point 1, and tables 4 and 5 are skipped;
[0098] Step 3-3, extract feature point 2, feature point 3 and feature point 9, and obtain the starting position, unit, and data type of each physical quantity of the current table T1 (this process is a prior art and will not be described in detail in this embodiment);
[0099] Step 3-4, based on the information obtained in step 3-3, regenerate (there may be word sequence number / byte sequence number and word number / byte number in the previous table, and the original word sequence number / byte sequence number and word number / byte number will be deleted) the word sequence number / byte sequence number and word number / byte number information content in the current table T1:
[0100] (1) Assuming that the starting position of the current table T1 is a, the unit is byte, and the data type of a physical quantity is UINT16 (corresponding to 2 bytes), the calculation process of the byte sequence number and number of bytes corresponding to the physical quantity is as follows:
[0101] ① Number of bytes = the number of units corresponding to the data type. UINT16 represents two byte units, which is 2.
[0102] ② Before calculating the byte number, first calculate the total number of bytes b of the physical quantity in all rows before the row where the physical quantity is located; in addition, the byte number can be a range, that is, when the data type of the physical quantity is more than one unit, for example, the byte number can be 14 to 15; at this time, the upper and lower limits of the byte number range are:
[0103] The lower limit of the byte number range = a + b;
[0104] The upper limit of the byte number range = a + b + 2 (2 is the number of bytes of the physical quantity) - 1;
[0105] (2) Assuming that the starting position of the current table T1 is a, the unit is word, and the data type of a physical quantity is UINT16 (corresponding to 1 word), the calculation process of the byte sequence number and number of bytes corresponding to the physical quantity is as follows:
[0106] ① Number of words = the number of units corresponding to the data type, UINT16 represents 1 word unit, that is, 1;
[0107] ② Before calculating the word sequence number, first calculate the total number of words b of the physical quantity in all rows before the row where the physical quantity is located; in addition, the word sequence number can be a range, that is, when the data type of the physical quantity is more than one unit, for example, the word sequence number can be 14 to 15. At this time, the upper and lower limits of the word sequence number range are:
[0108] The lower limit of the word number range = a + b;
[0109] The upper limit of the range of the word sequence number = a+b+1 (1 is the number of words of the physical quantity, which may also be equal to 2)-1;
[0110] In this embodiment, after the word sequence number / byte sequence number and word count / byte count information content are supplemented, Table 3 becomes Table 6:
[0111] Table 6
[0112]
[0113] In addition, when the protocol in the WORD protocol data packet changes, that is, when the physical quantity is increased or decreased, the word sequence number / byte sequence number in the WORD protocol data packet table needs to be reordered, and the word sequence number / byte sequence number in the WORD protocol data packet table can be automatically refilled by repeating steps 3-3 and 3-4;
[0114] Step 3-5, extract feature point 4, feature point 5, feature point 6, feature point 7, feature point 8, feature point 10 and feature point 11, and obtain the structure variable name S1, array variable name G2, array offset c, big and small end type, sender and receiver information, scale d and physical quantity variable name V3 where a certain physical quantity is located in sequence (this process is a prior art and will not be described in detail in this embodiment);
[0115] Step 3-6, based on the information obtained in step 3-5, automatically generate the interface function code corresponding to the physical quantity, and the specific process of generation is as follows:
[0116] (1) According to the big and small end types, data is stitched:
[0117] First distinguish whether the physical quantity is high first and then low or low first and then high. High first and then low or low first and then high represents the high and low byte order of the data stored in the array:
[0118] If it is low first and high later, the upper limit of the range of the word number / byte number corresponding to the physical quantity is used as the big end of the data, and the lower limit of the range of the word number / byte number corresponding to the physical quantity is used as the little end of the data, and the big end of the data and the little end of the data are spliced to obtain the spliced 16-bit data; in this embodiment, taking a physical quantity data type of UINT16, an array unit of byte, and a byte number of M to N (N is greater than M) as an example, the physical quantity corresponding to the byte number M to N is: the (N-array offset c)th byte of the array variable name G2 is used as the high 8 bits, and the (M-array offset c)th byte of the array variable name G2 is used as the low 8 bits, and the two are spliced into 16-bit data; if M=18, N=19, the 16-bit data is the (19-array offset c)th byte of the array variable name G2 as the high 8 bits, and the (18-array offset c)th byte of the array variable name G2 as the low 8 bits;
[0119] If it is high first and then low, the lower limit of the range of the word number / byte number corresponding to the physical quantity is used as the big end of the data, and the upper limit of the range of the word number / byte number corresponding to the physical quantity is used as the little end of the data, and the big end of the data and the little end of the data are spliced to obtain the spliced 16-bit data; in this embodiment, taking a physical quantity data type of UINT16, an array unit of byte, and a byte number of M to N as an example, the physical quantity corresponding to the byte number M to N is: the (N-array offset c)th byte of the array variable name G2 is used as the lower 8 bits, and the (M-array offset c)th byte of the array variable name G2 is used as the upper 8 bits, and the two are spliced into 16-bit data; if M=18, N=19, the 16-bit data is the (19-array offset c)th byte of the array variable name G2 as the lower 8 bits, and the (18-array offset c)th byte of the array variable name G2 as the upper 8 bits;
[0120] (2) determining a data stream according to a sender, a receiver, and an input local device name, where the data stream includes an input stream and an output stream;
[0121] The interface function code for the input stream is expressed as follows: the 16-bit data after the previous step is multiplied by the scale d to convert it into a structure variable, wherein the value of the structure variable is expressed as S1.V3, S1 is the name of the structure variable, and V3 is the name of the physical quantity variable;
[0122] The interface function code for the output stream is expressed as follows: Divide the structure variable (S1.V3) by the scale d to convert it into the 16-bit data after the previous step;
[0123] In addition, repeat steps 3-5 and 3-6 to obtain the interface function codes of all physical quantities;
[0124] At this point, the word sequence number / byte sequence number and word count / byte count of all tables in table set A that meet the requirements of feature point 1 are supplemented, and the interface function codes of all physical quantities of WORD protocol data packets are generated in batches. The interface function codes can convert dimensionless data (array storage, that is, the collected original data group) with data with physical meaning (structure storage), as shown in the attached figure. Figure 2 As shown, the interface function code can be used as part of the source code of the operating software of all communication devices.
[0125] Embodiment 2:
[0126] Based on Example 1, this example provides a supplementary process for the information content of word sequence number / byte sequence number and word count / byte count:
[0127] The first step is to list the name, data type, valid range, scale, physical quantity variable name and other information of the data package, as shown in Table 7:
[0128] Table 7 WORD protocol manual filling part
[0129]
[0130]
[0131] Step 2: Using the WORD file shown in the first step as input, after processing through step 3-3 and step 3-4 of step 3 of embodiment 1, the final WORD protocol data packet table information shown in Table 8 is obtained.
[0132] Table 8 WORD protocol automatically filled
[0133]
[0134] For ease of description, spatially relative terms such as "above", "above", "on the upper surface of", "above", etc. may be used here to describe the spatial positional relationship between a device or feature and other devices or features as shown in the figure. It should be understood that spatially relative terms are intended to include different orientations of the device in use or operation in addition to the orientation described in the figure. For example, if the device in the accompanying drawings is inverted, the device described as "above other devices or structures" or "above other devices or structures" will be positioned as "below other devices or structures" or "below other devices or structures". Thus, the exemplary term "above" can include both "above" and "below". The device can also be positioned in other different ways (rotated 90 degrees or in other orientations), and the spatially relative descriptions used here are interpreted accordingly.
[0135] In addition, it should be noted that the use of terms such as "first" and "second" to limit components is only for the convenience of distinguishing the corresponding components. If not otherwise stated, the above terms have no special meaning and therefore cannot be understood as limiting the scope of protection of the present invention.
[0136] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for automatically generating a WORD format communication protocol interface function code, characterized in that: The specific steps of this method are as follows: Step 1, setting eleven characteristic points of the WORD protocol data packet, and generating a modified WORD protocol data packet table according to the eleven characteristic points, wherein the modified WORD protocol data packet table information has been filled with information content of the eleven characteristic points and information content of the physical quantity name, but has not been filled with information content of the word sequence number / byte sequence number and word number / byte number; Step 2: Automatically supplement the word sequence number / byte sequence number and word count / byte count information in the modified WORD protocol data packet table information according to the feature points set in step 1, and automatically generate the interface function codes of all physical quantities of the modified WORD protocol data packet in batches.
2. The method for automatically generating a WORD format communication protocol interface function code as claimed in claim 1, characterized in that: The eleven characteristic points are: Feature point 1 is the protocol interface function automatic generation tool configuration. If a table in a word document has information content configured by the protocol interface function automatic generation tool, it means that the table needs the interface function code to be automatically generated. Feature point 2 is the starting position, i.e., the starting number of the word sequence number / byte sequence number specified in the table; The third characteristic point is the unit, which is the data unit type specified in the table. The data unit types include: byte, word and double word; Feature point 4 is the name of the structure variable, that is, the structure name of the code corresponding to the table; Feature point five is the array variable name, that is, the name of the array corresponding to the data storage of the table; Feature point six is the array offset, that is, the offset between the index position of a physical quantity in the array and the word number / byte number in the table; Feature point seven is big endian / little endian, that is, big endian means the byte order is high first and low later, and little endian means the byte order is low first and high later; Feature point eight is the sender and receiver, that is, the data flow information; Feature point nine is the data type, which includes UINT16, UINT8, INT16 and INT32; The characteristic point ten is the scale, and the dimensionless data is converted into a physical quantity with physical meaning by multiplying or dividing the scale; The eleventh characteristic point is the physical quantity variable name, which specifies the variable name of the physical quantity in the structure definition.
3. The method for automatically generating a WORD format communication protocol interface function code as claimed in claim 2, characterized in that: In step 2, the process of automatically supplementing the information content of the word sequence number / byte sequence number and the word number / byte number is as follows: Step 1, read the word document and get all the tables in the word document; Step 2, traverse the table set A, and determine whether the current table T1 satisfies feature point 1 one by one. If it does, execute step 3; if not, skip the current table T1, and determine whether the next table satisfies feature point 1, until all tables in the table set A are processed; Step 3, extract feature point 2, feature point 3 and feature point 9, and obtain the starting position, unit, and data type of each physical quantity of the current table T1; Step 4, based on the information obtained in step 3, regenerate the information content of the word sequence number / byte sequence number and word count / byte count in the current table T1: (1) Assuming that the starting position of the current table T1 is a, the unit is byte, and the data type of the selected physical quantity is UINT16, the calculation process for calculating the byte sequence number and number of bytes corresponding to the physical quantity is as follows: ① Number of bytes = number of units corresponding to the data type. UINT16 represents two byte units, that is, number of bytes = 2; ② Before calculating the byte number, first calculate the total number of bytes b of the physical quantity in all rows before the row where the physical quantity is located; at this time, the upper and lower limits of the byte number range are: The lower limit of the byte number range = a + b; The upper limit of the byte number range = a + b + the number of bytes of the physical quantity - 1; (2) Assuming that the starting position of the current table T1 is a, the unit is word, and the data type of a physical quantity is UINT16, the calculation process of the byte sequence number and number of bytes corresponding to the physical quantity is as follows: ① Number of words = number of units corresponding to the data type, UINT16 represents 1 word unit, that is, number of words = 1; ② Before calculating the word sequence number, first calculate the total number of words b of the physical quantity in all rows before the row where the physical quantity is located; at this time, the upper and lower limits of the word sequence number range are: The lower limit of the word number range = a + b; The upper limit of the word number range = a + b + the number of words of the physical quantity - 1; Therefore, the information content of the calculated word sequence number / byte sequence number and word count / byte count is added to the modified WORD protocol data packet table.
4. The method for automatically generating a WORD format communication protocol interface function code as claimed in claim 3, characterized in that: When the protocol in the WORD protocol data packet changes, that is, when the physical quantity is increased or decreased, the word sequence number / byte sequence number in the WORD protocol data packet table needs to be reordered. Repeat steps 3 and 4 to achieve automatic refilling of the word sequence number / byte sequence number in the WORD protocol data packet table.
5. The method for automatically generating a WORD format communication protocol interface function code as claimed in claim 3, characterized in that: The process of automatically generating the interface function codes of all physical quantities of the modified WORD protocol data packet in batches is as follows: Step 5, extract feature point 4, feature point 5, feature point 6, feature point 7, feature point 8, feature point 10 and feature point 11, and obtain the structure variable name S1, array variable name G2, array offset c, big and small end type, sender and receiver information, scale d and physical quantity variable name V3 of the selected physical quantity in turn; Step 6: According to the information obtained in step 5, the interface function code corresponding to the physical quantity is automatically generated. The specific process of generation is as follows: (1) According to the type of big and small ends, distinguish whether the physical quantity is high first and then low or low first and then high: If it is low first and high later, the upper limit of the range of the word number / byte number corresponding to the physical quantity is used as the big end of the data, and the lower limit of the range of the word number / byte number corresponding to the physical quantity is used as the little end of the data. The big end of the data and the little end of the data are spliced to obtain the spliced 16-bit data; If it is high first and then low, the lower limit of the range of the word number / byte number corresponding to the physical quantity is used as the big end of the data, and the upper limit of the range of the word number / byte number corresponding to the physical quantity is used as the little end of the data. The big end of the data and the little end of the data are spliced to obtain the spliced 16-bit data; (2) determining a data stream according to a sender, a receiver, and an input local device name, wherein the data stream includes an input stream and an output stream; The interface function code for the input stream is expressed as follows: the 16-bit data after the previous step is multiplied by the scale d to convert it into a structure variable, wherein the value of the structure variable is expressed as S1.V3, S1 is the name of the structure variable, and V3 is the name of the physical quantity variable; The interface function code for the output stream is expressed as follows: Divide the structure variable S1.V3 by the scale d to convert it into the 16-bit data after the previous step; Repeat steps 5 and 6 to obtain the interface function codes for all physical quantities.
6. A method for automatically generating a WORD format communication protocol interface function code as claimed in claim 5, characterized in that: When combining 16-bit data, let the byte numbers be M to N, and N is greater than M; If it is low first and high later, the Qth byte of the array variable name G2 is used as the high 8 bits, and the Pth byte of the array variable name G2 is used as the low 8 bits, and the two are combined to form 16-bit data; If high first and low later, the Qth byte of array variable name G2 is used as the lower 8 bits, and the Pth byte of array variable name G2 is used as the upper 8 bits, and the two are combined to form 16-bit data. Q=N-array offset c, P=M-array offset c.