A mapping method between UDP datagram and text interpretation based on XML

Through the XML-based UDP datagram and text interpretation mapping method, the status information of each device is parsed, and the problem of lack of universality and rapid portability of UDP datagram and text mapping in the prior art is solved, thereby realizing the code simplification and improvement of development efficiency.

CN115185902BActive Publication Date: 2025-04-29TIANJIN NAVIGATION INSTR RES INST
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210716599.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-23
Publication Date
2025-04-29
Estimated Expiration
2042-06-23

AI Technical Summary

Technical Problem

In the prior art, UDP datagram and text mapping methods lack universality and rapid portability, resulting in bloated software code, difficult to maintain, and slow development efficiency.

Method used

The mapping method of UDP datagrams and text interpretation based on XML is adopted. By reading the text interpretation content defined by the XML file, the status information of each device is parsed, and there is no need to design the status information mapping function separately according to different devices.

Benefits of technology

It reduces the amount of code, improves the stability and maintainability of equipment software, and improves the efficiency of software development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115185902B_ABST
    Figure CN115185902B_ABST
Patent Text Reader

Abstract

The present invention relates to a mapping method between UDP datagram and text interpretation based on XML, which is based on the set XML file structure; the XML file content is read to obtain the sub-nodes related to the interpretation content; the text state information of the sub-nodes related to the interpretation content is parsed by byte or by bit to complete the mapping between UDP datagram and text interpretation. The present invention can write the text interpretation into the XML file according to a specific rule, and the equipment software reads the XML file under a specific directory. When receiving the real-time network message, the software automatically completes the mapping work of the real-time data message according to the defined interpretation content in the XML file, which makes up for the deficiency of writing the enumeration type mapping function in the software and can improve the software development efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of software data management, in particular to a mapping method between UDP datagram and text interpretation based on XML. Background Art

[0002] The status information is mostly in text form. To achieve the mapping between network data and text, a specific mapping function needs to be written in the software. To achieve the mapping process, all situations need to be enumerated, which makes the software code bloated and difficult to maintain. In the prior art, the UDP datagram and text mapping method is mostly implemented in a dedicated parsing mapping function, which is not universal and fast to transplant. Software personnel have to do a lot of repetitive work and the development efficiency is low. Summary of the invention

[0003] The purpose of the present invention is to overcome the shortcomings of the prior art and propose a mapping method between UDP datagrams and text interpretations based on XML. The method of reading the text interpretation content defined in the XML file is used to parse the status information of each device. There is no need to design different status information mapping functions according to different devices, which reduces the amount of code and achieves the purpose of enhancing the stability and maintainability of equipment software.

[0004] The present invention solves the technical problem by adopting the following technical solutions:

[0005] A method for mapping UDP datagrams and text interpretations based on XML, comprising the following steps:

[0006] Step 1. Set up the XML file structure;

[0007] Step 2: Read the XML file content according to the XML file structure and obtain the child nodes related to the interpretation content;

[0008] Step 3: Determine the XML file structure, and parse the text status information of the sub-nodes related to the interpretation content by byte or by bit, and complete the mapping between UDP datagram and text interpretation.

[0009] Moreover, the XML document structure in step 1 includes interpretation content in bytes and interpretation content in bits.

[0010] Moreover, the interpretation content in bytes includes tag information colname, length and data, wherein tag information colname is status information, tag information length is byte length, tag information data is status information interpretation, and data includes three lines of information: the first line is text status information parsed in byte form, the second line is code 0x0001 indicating normal operation, and the third line is code 0x0002 indicating faulty operation.

[0011] Moreover, the status information in the interpretation content in bit units is represented by two bytes of data content, and the Chinese status information is represented by a free combination of the lower 3 bits, wherein the 0th bit B0 represents the status information of mode 1, and the 2nd and 1st bits B2B1 represent the status information of mode 2.

[0012] Moreover, the use of the lower 3 bits to freely combine to represent the Chinese status information includes: bit 000 represents mode 2: state 1, mode 1 state 1; bit 001 represents mode 2: state 1, mode 1 state 2; bit 010 represents mode 2: state 2, mode 1 state 1; bit 011 represents mode 2: state 2, mode 1 state 2; bit 110 represents mode 2: state 3, mode 1 state 1; bit 111 represents mode 2: state 3, mode 1 state 2; bit 100 represents mode 2: unknown state, mode 1 state 1; bit 101 represents mode 2: unknown state, mode 1 state 2.

[0013] Furthermore, the step 2 comprises the following steps:

[0014] Step 2.1, determine whether the XML file is open, if it is open, proceed to step 2.2, otherwise end;

[0015] Step 2.2, read the XML file content through the QDomDocument tool class and generate a file tree in the software;

[0016] Step 2.3, obtain the root node information in the file tree through the QDomElement tool class;

[0017] Step 2.3, obtain the child nodes related to the interpretation content in the root node through the QDomNodeList tool class;

[0018] Step 2.4: Traverse step 2.3 and store the child node content in the vector.

[0019] Moreover, parsing the text status information by byte in step 3 includes the following steps:

[0020] Step 3.1.1, read the content of the data child node, and determine whether the first line of content is true. If it is true, parse it in the form of status information and proceed to step 3.1.2. Otherwise, parse it in the form of non-status information and end;

[0021] Step 3.1.2: Determine two things: whether the middle content is bit, if it is bit, parse it in bit form and proceed to step 3.2.1; if the content is byte, parse it in byte form and proceed to step 3.1.3; if it is other content, parse it in non-state information form and end;

[0022] Step 3.1.3, determine whether the interpretation content in the second line of the data child node is normal operation. If it is normal operation, output the Chinese interpretation of normal operation and end. Otherwise, determine whether the interpretation content in the third line of the content is faulty operation. If it is faulty operation, output the Chinese interpretation of faulty operation and end. Otherwise, output the unknown working status and end.

[0023] Furthermore, the bit-by-bit parsing of the text status information comprises the following steps:

[0024] Step 3.2.1, read the original value in the data subnode content;

[0025] Step 3.2.2, determine whether the original value is equal to 0, if the original value is equal to 0, then mode 1 outputs state 1, otherwise mode 1 outputs state 2;

[0026] Step 3.2.3, perform right shift operation on the original value, shift right 1 bit, and determine whether the values ​​of the two lowest bits of the original value are equal to 0. If they are equal to zero, mode 2 outputs state 1. Otherwise, determine whether the values ​​of the two lowest bits of the original value are equal to 1. If they are equal to 1, mode 2 outputs state 2. Otherwise, determine whether the values ​​of the two lowest bits of the original value are equal to 3. If they are equal to 3, mode 2 outputs state 3. Otherwise, mode 2 outputs unknown and ends.

[0027] The advantages and positive effects of the present invention are:

[0028] The present invention is based on the set XML file structure; reads the XML file content, obtains the sub-nodes related to the interpretation content; parses the text state information of the sub-nodes related to the interpretation content by byte or by bit, and completes the mapping between UDP datagram and text interpretation. The present invention can write the text interpretation into the XML file according to a specific rule, and the equipment software reads the XML file under a specific directory. When receiving the real-time network message, the software automatically completes the mapping work of the real-time data message according to the defined interpretation content in the XML file, which makes up for the deficiency of writing enumeration type mapping functions in the software and can improve the software development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 is a flow chart of the present invention;

[0030] Figure 2 Reading XML content flow chart for the present invention;

[0031] Figure 3 This is a flow chart of the present invention parsing text status information in byte form;

[0032] Figure 4 This is a flow chart of parsing status information in bit form according to the present invention. DETAILED DESCRIPTION

[0033] The present invention is further described in detail below with reference to the accompanying drawings.

[0034] A mapping method between UDP datagrams and textual interpretations based on XML, such as Figure 1 As shown, the following steps are included:

[0035] Step 1: Set the XML file structure: interpretation content in bytes and interpretation content in bits.

[0036] The original data of the status information in the message is generally transmitted in two forms. One is that the minimum unit is bytes, and the status information can be parsed by comparing bytes; the other minimum unit is bits, and the combination of several bits is used to realize the combined transmission of status information. According to the above two different forms, the present invention designs two different fields in the XML file according to the byte interpretation and the bit interpretation respectively.

[0037] The interpretation in bytes is:

[0038] <colname> Status Information< / colname>

[0039] <length> 2< / length>

[0040] <data>true:byte: ;

[0041] 0x0001: normal operation; ;

[0042] 0x0002: Faulty operation; ;< / data>

[0043] The above content includes three tag information colname, length and data, among which the tag information colname is the status information, the tag information length is the byte length, the tag information data is the status information interpretation, and data includes three lines of information: the first line is the text status information parsed in byte form, the second line indicates the normal working code 0x0001, and the third line indicates the faulty working code 0x0002.

[0044] The interpretation in bits is:

[0045] <colname> Status Information< / colname>

[0046] <length> 2< / length>

[0047] <data>true:bit: ;

[0048] "B0" mode 1;

[0049] '0' state 1;

[0050] '1' state 2;

[0051] "B2B1" mode 2;

[0052] '00' state 1;

[0053] '01' state 2;

[0054] '11' status 3; ;< / data>

[0055] The above content status information is represented by two bytes of data content, and the Chinese status information is represented by a free combination of the lower 3 bits, wherein the 0th bit B0 represents the status information of mode 1, and the 2nd and 1st bits B2B1 represent the status information of mode 2.

[0056] The text interpretations represented by the results of the free combination of bits are shown in Table 1.

[0057] Table 1 The text interpretation represented by the three-bit combination

[0058]

[0059]

[0060] Step 2: Read the XML file content according to the XML file structure and obtain the child nodes related to the interpretation content.

[0061] like Figure 2 As shown, this step includes the following steps:

[0062] Step 2.1, determine whether the XML file is open, if it is open, proceed to step 2.2, otherwise end;

[0063] Step 2.2, read the XML file content through the QDomDocument tool class and generate a file tree in the software;

[0064] Step 2.3, obtain the root node information in the file tree through the QDomElement tool class;

[0065] Step 2.3, obtain the child nodes related to the interpretation content in the root node through the QDomNodeList tool class;

[0066] Step 2.4: Traverse step 2.3 and store the child node content in the vector.

[0067] Step 3: Determine the XML file structure, and parse the text status information of the sub-nodes related to the interpretation content by byte or by bit, and complete the mapping between UDP datagram and text interpretation.

[0068] like Figure 3 As shown, parsing text status information by byte includes the following steps:

[0069] Step 3.1.1, read the content of the data child node, and determine whether the content before the ":" is "true" according to the content of the first line "true:byte:;". If it is "true", parse it in the form of status information and proceed to step 3.1.2, otherwise parse it in the form of non-status information and end.

[0070] Step 3.1.2: According to the content of the first line of the data child node, determine whether the content between the two ":" is "bit". If it is "bit", parse it in bit form and proceed to step 3.2.1. If the content is "byte", parse it in byte form and proceed to step 3.1.3. If it is other content, parse it in non-state information form and end.

[0071] Step 3.1.3, according to the three identifiers "0x", ":", ";" in the second and third lines of the data subnode, the interpretation content corresponding to the original message data "0001" can be intercepted, and it is determined whether the interpretation content in the second line of the data subnode is "0x0001: normal working; ;". If it is normal working, output the Chinese interpretation of normal working and end. Otherwise, determine whether the interpretation content in the third line is faulty working. If it is faulty working, output the Chinese interpretation of faulty working and end. Otherwise, output the unknown working status and end. Finally, the original message data set in XML format and its corresponding interpretation content set are obtained.

[0072] When the equipment software receives a network message, it compares the content of the field in the network message with the content in the original message data set obtained above. If the comparison is successful, the corresponding interpretation content is output. If the comparison is unsuccessful, "unknown" is output. At this point, the message parsing in byte form is completed.

[0073] If the message is parsed in bit form, the contents of lines 2 to 4 of the data field are:

[0074] "B0" mode 1;

[0075] '0' state 1;

[0076] '1' state 2;

[0077] The two different values ​​of the 0th bit in this byte in the network message represent two different states of mode 1.

[0078] The contents of lines 5 to 8 of the data field are:

[0079] "B2B1" mode 2;

[0080] '00' state 1;

[0081] '01' state 2;

[0082] '11' status 3; ;

[0083] The above content indicates that the values ​​of the 1st and 2nd bits in the byte of the network message represent three different states of mode 2. Through the information of the three bits 0, 1, and 2, multiple different state information representing mode 1 and mode 2 can be combined at the same time. Different information can be intercepted respectively through various identification numbers such as double quotes, single quotes, spaces, and line breaks. The software can automatically and intelligently parse the network message based on the read information.

[0084] The software determines the number of bits used in different modes based on the number of "B" in the double quotes in the 2nd and 5th lines. The number is recorded as n. The last digit in the double quotes is taken out as m. The last n binary bits of a numeric variable are set to 1, and the remaining binary bits are set to 0. The variable is recorded as H. The value of the field in the network message is shifted right by m bits and then ANDed with the variable H to obtain the value size of the field in the network message at different bits. The result is traversed with the interpretation content in the XML file. If the match is successful, the interpretation content is output, otherwise "unknown" is output.

[0085] like Figure 4 As shown, parsing text status information bit by bit includes the following steps:

[0086] Step 3.2.1, read the original value in the data subnode content;

[0087] Step 3.2.2, determine whether the original value is equal to 0, if the original value is equal to 0, then mode 1 outputs state 1, otherwise mode 1 outputs state 2;

[0088] Step 3.2.3, perform right shift operation on the original value, shift right 1 bit, and determine whether the values ​​of the two lowest bits of the original value are equal to 0. If they are equal to zero, mode 2 outputs state 1. Otherwise, determine whether the values ​​of the two lowest bits of the original value are equal to 1. If they are equal to 1, mode 2 outputs state 2. Otherwise, determine whether the values ​​of the two lowest bits of the original value are equal to 3. If they are equal to 3, mode 2 outputs state 3. Otherwise, mode 2 outputs unknown and ends.

[0089] It should be emphasized that the embodiments described in the present invention are illustrative rather than restrictive. Therefore, the present invention includes but is not limited to the embodiments described in the specific implementation manner. Any other implementation manners derived by those skilled in the art based on the technical solution of the present invention also fall within the scope of protection of the present invention.

Claims

1. A method for mapping UDP datagrams and text interpretations based on XML, characterized in that: The following steps are involved: Step 1. Set up the XML file structure; Step 2: Read the XML file content according to the XML file structure and obtain the child nodes related to the interpretation content; Step 3, determine the XML file structure, and parse the text status information of the sub-nodes related to the interpretation content by byte or by bit, and complete the mapping between UDP datagram and text interpretation; Parsing the text status information by byte in step 3 includes the following steps: Step 3.1.1, read the content of the data child node, and determine whether the first line of content is true. If it is true, parse it in the form of status information and proceed to step 3.1.

2. Otherwise, parse it in the form of non-status information and end; Step 3.1.2: Determine two things: whether the middle content is bit, if it is bit, parse it in bit form and proceed to step 3.2.1; if the content is byte, parse it in byte form and proceed to step 3.1.3; if it is other content, parse it in non-state information form and end; Step 3.1.3, determine whether the interpretation content in the second line of the data child node is normal operation, if it is normal operation, output the Chinese interpretation of normal operation and end, otherwise determine whether the interpretation content in the third line of the content is faulty operation, if it is faulty operation, output the Chinese interpretation of faulty operation and end, otherwise output the unknown working state and end; Parsing text status information bit by bit includes the following steps: Step 3.2.1, read the original value in the data subnode content; Step 3.2.2, determine whether the original value is equal to 0, if the original value is equal to 0, then mode 1 outputs state 1, otherwise mode 1 outputs state 2; Step 3.2.3, perform right shift operation on the original value, shift right 1 bit, and determine whether the values ​​of the two lowest bits of the original value are equal to 0. If they are equal to zero, mode 2 outputs state 1. Otherwise, determine whether the values ​​of the two lowest bits of the original value are equal to 1. If they are equal to 1, mode 2 outputs state 2. Otherwise, determine whether the values ​​of the two lowest bits of the original value are equal to 3. If they are equal to 3, mode 2 outputs state 3. Otherwise, mode 2 outputs unknown and ends.

2. The method for mapping UDP datagrams and text interpretations based on XML according to claim 1, characterized in that: The XML file structure in step 1 includes interpretation content in bytes and interpretation content in bits.

3. The method for mapping UDP datagrams and text interpretations based on XML according to claim 2, characterized in that: The interpretation content in bytes includes the following tag information: colname, length and data, wherein the tag information colname is status information, the tag information length is the byte length, the tag information data is the status information interpretation, and data includes three lines of information: the first line is the text status information parsed in byte form, the second line is the code 0x0001 indicating normal operation, and the third line is the code 0x0002 indicating faulty operation.

4. The method for mapping UDP datagrams and text interpretations based on XML according to claim 2, characterized in that: The status information in the interpretation content in bit units is represented by two bytes of data content, and the Chinese status information is represented by a free combination of the lower 3 bits, wherein the 0th bit B0 represents the status information of mode 1, and the 2nd and 1st bits B2B1 represent the status information of mode 2.

5. The method for mapping UDP datagrams and text interpretations based on XML according to claim 4, characterized in that: The use of the lower 3 bits to freely combine to represent the Chinese status information includes: bit 000 represents mode 2: state 1, mode 1 state 1; bit 001 represents mode 2: state 1, mode 1 state 2; bit 010 represents mode 2: state 2, mode 1 state 1; bit 011 represents mode 2: state 2, mode 1 state 2; bit 110 represents mode 2: state 3, mode 1 state 1; bit 111 represents mode 2: state 3, mode 1 state 2; bit 100 represents mode 2: unknown state, mode 1 state 1; bit 101 represents mode 2: unknown state, mode 1 state 2.

6. The method for mapping UDP datagrams and text interpretations based on XML according to claim 1, characterized in that: The step 2 comprises the following steps: Step 2.1, determine whether the XML file is open, if it is open, proceed to step 2.2, otherwise end; Step 2.2, read the XML file content through the QDomDocument tool class and generate a file tree in the software; Step 2.3, obtain the root node information in the file tree through the QDomElement tool class; Step 2.3, obtain the child nodes related to the interpretation content in the root node through the QDomNodeList tool class; Step 2.4: Traverse step 2.3 and store the child node content in the vector.

Citation Information

Patent Citations

  • Analysis method and device for analyzing network data, electronic equipment and storage medium

    CN113347196A

  • Method and apparatus for decoding encoded structured data from a bit-stream

    US20120150828A1