Protocol conversion method and device, protocol converter and storage medium
By storing the message field values in the database and performing protocol conversion, the problem of insufficient CPU processing power is solved and the message conversion efficiency is improved.
Patent Information
- Application Number
- CN202510867346.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-26
- Publication Date
- 2025-09-19
AI Technical Summary
When converting between multiple protocols, the CPU processing capacity of existing protocol converters is limited, resulting in data backlog and affecting the efficiency of message conversion.
The received message field values are stored in the database, protocol conversion is performed through the database, field value conversion is performed using the field mapping table, and the message is completed according to the target protocol structure and sent to the corresponding port.
By caching message data in the database, CPU data backlog is avoided and message conversion efficiency is improved.
Smart Images

Figure CN120676058A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a protocol conversion method, device, protocol converter and storage medium. Background Art
[0002] With the rapid development of technologies like the Internet of Things, smart grids, and cloud computing, the number of various terminal devices has exploded. These devices come from different manufacturers and follow different communication protocols. Different protocols have different message structures during data transmission, and protocol conversion is necessary to achieve data interoperability.
[0003] In order to meet the requirements of multi-protocol conversion, existing protocol converters are configured with a large number of ports to send and receive messages of different protocols. At the same time, multiple ports receive messages at the same time, but the CPU processing power is limited, resulting in CPU data backlog and affecting message conversion efficiency. Summary of the Invention
[0004] In view of this, the present invention provides a protocol conversion method, device, protocol converter and storage medium, which can improve the message conversion efficiency.
[0005] In a first aspect, the present invention provides a protocol conversion method that supports message conversion between multiple communication protocols, including: After receiving the first message to be converted from the first protocol port, the field values of each field of the first message are stored in a database, the database being used to store the field values of all fields involved in the messages of the multiple communication protocols that can be converted; Obtaining the field value of each field of the first message from the database, and converting the field value of each field of the first message into the field value of each field of the second message; Completing each field according to the message structure of the second message to obtain a complete second message; Send the complete second message to the corresponding second protocol port.
[0006] Optionally, storing the field value of each field of the first message in a database includes: Determining the first protocol followed by the first message based on the information of the first protocol port; Parsing the first message according to the first protocol to obtain a field name and a field value of each field of the first message; Write the field value to the database according to the field name.
[0007] Optionally, the field values of each field of the first message are converted into the field values of each field of the second message by querying a field mapping table, and the field mapping table is used to store the mapping relationship between all fields involved in messages of multiple convertible communication protocols.
[0008] Optionally, the mapping relationship between all fields involved in messages of multiple communication protocols includes: One-to-one mapping; One-to-many mapping; Many-to-one mapping; Direct mapping means that the field value of a field in the second message can directly use the field value of the corresponding field in the first message; Indirect mapping means that the field value of a field in the second message cannot directly use the field value of the corresponding field in the first message, and the corresponding field value can only be queried through the field mapping table.
[0009] Optionally, the steps of storing the field values of each field of the first message into a database and obtaining the field values of each field of the first message from the database and converting the field values of each field of the first message into field values of each field of the second message are parallel processing steps.
[0010] Optionally, the database adopts a first-in-first-out working mode.
[0011] In a second aspect, the present invention provides a protocol conversion device that supports message conversion between multiple communication protocols, including: a writing module configured to, after receiving a first message to be converted from a first protocol port, store the field values of each field of the first message in a database, the database being configured to store the field values of all fields involved in messages of multiple convertible communication protocols; A field conversion module, configured to obtain field values of each field of the first message from a database, and convert the field values of each field of the first message into field values of each field of the second message; A field completion module, configured to complete each field according to the message structure of the second message to obtain a complete second message; The sending module is used to send the complete second message to the corresponding second protocol port.
[0012] Optionally, the writing module and the field conversion module work in parallel.
[0013] In a third aspect, the present invention provides a protocol converter, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and when the at least one processor executes the instructions, the protocol conversion method provided in the first aspect is implemented.
[0014] In a fourth aspect, the present invention provides a non-transitory computer-readable storage medium having instructions stored thereon, which, when executed, implement the protocol conversion method provided in the first aspect.
[0015] The protocol conversion method, device, protocol converter, and storage medium provided by the present invention first store the field values of each field of a received first message in a database. Then, during the protocol conversion process, the field values of each field of the first message are obtained from the database and converted into the field values of each field of a second message. Each field is then completed according to the message structure of the second message to obtain a complete second message. The complete second message is then sent to the corresponding second protocol port. Compared to existing technologies, the database caches message data once. This prevents CPU data backlogs in the event of excessive message data volume, thus reducing the CPU burden and improving message conversion efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 1 is a flow chart of a protocol conversion method according to an embodiment; Figure 2 Schematic diagram of the structure of a protocol conversion device in one embodiment; Figure 3 FIG. 1 is a schematic structural diagram of a protocol converter in one embodiment. DETAILED DESCRIPTION
[0017] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying 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. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0018] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0019] The following embodiments of the present invention are described in detail with reference to the accompanying drawings. In the absence of conflict, the following embodiments and features in the embodiments may be combined with each other.
[0020] An embodiment of the present invention provides a protocol conversion method that supports message conversion between multiple communication protocols, such as Figure 1 As shown, the protocol conversion method includes the following steps: S101, after receiving a first message to be converted from a first protocol port, storing the field values of each field of the first message in a database, the database being used to store the field values of all fields involved in messages of multiple convertible communication protocols; S102, obtaining the field value of each field of the first message from the database, and converting the field value of each field of the first message into the field value of each field of the second message; S103, completing each field according to the message structure of the second message to obtain a complete second message; S104: Send the complete second message to the corresponding second protocol port.
[0021] In this embodiment, the first message is the original message before conversion, and the first protocol followed by the original message can be called the original protocol. The second message is the target message after conversion, and the second protocol followed by the target message can be called the target protocol.
[0022] It is also noted that the first protocol port and the second protocol port predefine the correspondence between the port and the communication protocol. Based on the port information, such as the port number, the communication protocol followed by the messages received and sent by the port can be known.
[0023] An embodiment of the present invention provides a protocol conversion method that first stores the field values of each field of a received first message in a database. Then, during the protocol conversion process, the field values of each field of the first message are obtained from the database, and the field values of each field of the first message are converted into the field values of each field of a second message. Each field is completed according to the message structure of the second message to obtain a complete second message. The complete second message is sent to the corresponding second protocol port. Compared to the existing technology, the database caches the message data once. In the case of excessive message data volume, it will not cause CPU data backlog, which helps to reduce the burden on the CPU and improve message conversion efficiency.
[0024] Each step is discussed in detail below.
[0025] In step S101, the field values of each field of the first message are stored in a database, which may specifically include: Determining the first protocol followed by the first message based on the information of the first protocol port; Parsing the first message according to the first protocol to obtain a field name and a field value of each field of the first message; Write the field value to the database according to the field name.
[0026] As an embodiment, the field names and field values of each field in the first message are stored in the database in JSON format. It is understood that the field names of each field are pre-stored in the database and do not need to be written here. It is only necessary to find the corresponding field name and write the field value. In actual applications, the field values in the database are updated in real time.
[0027] In step S102, as an implementation method, the field values of each field of the first message are converted into the field values of each field of the second message by querying a field mapping table, and the field mapping table is used to store the mapping relationship between all fields involved in the messages of multiple convertible communication protocols.
[0028] The mapping relationship between fields in the field mapping table is a bidirectional mapping, and the mapping relationship is reflected by the correspondence between field names and field values. As for how to construct the field mapping table, it is not within the scope of protection of this application and will not be described in detail here. The following example illustrates the mapping relationship between protocols.
[0029] As shown in Table 1 below, the mapping relationship between some fields of the HTTP protocol and the CoAP protocol is shown, which reflects one-to-one mapping, one-to-many mapping, many-to-one mapping, direct mapping and indirect mapping.
[0030] Table 1 HTTP and CoAP field mapping table (partial)
[0031] Note: "*" indicates that the mapping value needs to be obtained during the conversion process of the protocol message.
[0032] Refer to Table 1 for the mapping relationships between all fields involved in messages of various communication protocols, including: 1) One-to-one mapping: For example, the Accept field.
[0033] 2) One-to-many mapping: For example, the Code field with a Co AP field value of 2.02 can be mapped to the Status-Code field with an HTTP field value of 200 or 204.
[0034] 3) Many-to-one mapping: For example, the Status-Code field with an HTTP field value of 400 or 500 can be mapped to the Code field with a CoAP field value of 4.02; together with the one-to-many mapping relationship, it constitutes a many-to-many mapping relationship.
[0035] 4) Direct mapping: This indicates that the field of the second message (i.e., the mapping field) can directly use the value of the field of the first message (i.e., the mapped field) as its own field value. In this case, the specific field value can only be known during the protocol conversion process. Therefore, the symbol * is used in Table 1 to replace the mapping value, such as the Uri-Path and Payload fields of HTTP in the table.
[0036] 5) Indirect mapping: This means that the field of the second message (i.e., the mapping field) cannot directly use the field value of the field of the first message (i.e., the mapped field). Instead, the corresponding field value must be queried through the field mapping table. For example, when the Method field is mapped to the Code field and the Method value is GET, GET cannot be directly used as the value of the Code field. Instead, the table query obtains 0.01 as the value of the Code field.
[0037] In step S103, how to complete the field depends on the field type, which is explained below with an example.
[0038] First, for mapped default fields and mapped calculated fields whose values cannot be found in the field mapping table, if the field is optional, they are discarded. If the field is fixed, the default or calculated value is used. If there is no default value or specified calculation method, an error message is displayed. Second, for default and calculated fields, the default or calculated value is used directly. If the field is optional, it can also be discarded. If the field is fixed and there is no default value or specified calculation method, an error message is displayed. Finally, the complete target message data is stored in JSON format.
[0039] For instructions on mapping default fields, mapping calculated fields, default fields, and calculated fields, see Table 2.
[0040] Table 2 Field Type Description
[0041] It is further explained that step S101 and step S102 may be parallel processing steps, which are implemented by a processor in a multi-threaded manner. The parallel processing mode helps to further improve the efficiency of message conversion.
[0042] As an implementation method, the database may adopt a first-in-first-out (FIFO) working mode.
[0043] As an implementation manner, the various communication protocols supported by the embodiment of the present invention include but are not limited to the following: Modbus, Profibus, TCP / IP, HTTP, and CoAP.
[0044] On the other hand, the embodiment of the present invention also provides a protocol conversion device that supports message conversion between multiple communication protocols, such as Figure 2As shown, the protocol conversion device includes: The writing module 201 is configured to store the field values of each field of the first message into a database after receiving the first message to be converted from the first protocol port. The database is configured to store the field values of all fields involved in the messages of the multiple communication protocols that can be converted; A field conversion module 202 is configured to obtain field values of each field of the first message from a database, and convert the field values of each field of the first message into field values of each field of the second message; A field completion module 203 is configured to complete each field according to the message structure of the second message to obtain a complete second message; The sending module 204 is configured to send the complete second message to the corresponding second protocol port.
[0045] According to an embodiment of the present invention, the writing module 201 is specifically configured to: Determining the first protocol followed by the first message based on the information of the first protocol port; Parsing the first message according to the first protocol to obtain a field name and a field value of each field of the first message; According to the field name, the field value is written into the database.
[0046] According to one embodiment of the present invention, the field conversion module 202 is used to convert the field values of each field of the first message into the field values of each field of the second message by querying the field mapping table, and the field mapping table is used to save the mapping relationship between all fields involved in the messages of multiple convertible communication protocols.
[0047] Furthermore, the mapping relationship between all fields involved in the messages of multiple communication protocols includes: One-to-one mapping; One-to-many mapping; Many-to-one mapping; Direct mapping means that the field value of a field in the second message can directly use the field value of the corresponding field in the first message; Indirect mapping means that the field value of a field in the second message cannot directly use the field value of the corresponding field in the first message, and the corresponding field value can only be queried through the field mapping table.
[0048] Furthermore, the writing module 201 and the field conversion module 202 work in parallel.
[0049] The protocol conversion device provided in the embodiment of the present invention is used to execute the above method embodiment and has the same technical effect. Its specific process and detailed content please refer to the above embodiment and will not be repeated here.
[0050] Figure 3 Schematic diagram of the protocol converter structure provided by the embodiment of the present invention. Figure 3 As shown, the protocol converter may include: at least one processor 301 and a memory 302 communicatively connected to the processor 301, wherein the processor 301 and the memory 302 communicate with each other via a communication bus 303. The memory 302 stores instructions executable by the processor 301, and when the processor 301 executes the instructions, the protocol conversion methods provided in the above embodiments are implemented. Of course, the protocol converter may also include other components, for example, multiple protocol ports, each of which is used to receive and send messages of a corresponding communication protocol.
[0051] On the other hand, an embodiment of the present invention further provides a non-transitory computer-readable storage medium having instructions stored thereon, which, when executed by a processor, implement the protocol conversion methods provided in the above embodiments.
[0052] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0053] Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented using software plus a necessary general-purpose hardware platform, or of course, hardware. Based on this understanding, the essence of the above technical solution, or the portion that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, or an optical disk, and includes a number of instructions for causing a computer device (such as a personal computer, server, or network device) to execute the methods described in each embodiment or certain portions of the embodiments.
[0054] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A protocol conversion method, characterized in that: Supports message conversion between multiple communication protocols, and the protocol conversion method includes: After receiving a first message to be converted from a first protocol port, storing the field values of each field of the first message in a database, the database is used to store the field values of all fields involved in messages of multiple convertible communication protocols; Acquire the field value of each field of the first message from the database, and convert the field value of each field of the first message into the field value of each field of the second message; Completing each field according to the message structure of the second message to obtain a complete second message; Send the complete second message to the corresponding second protocol port.
2. The protocol conversion method according to claim 1, wherein: Storing the field value of each field of the first message in a database includes: Determining the first protocol followed by the first message based on the information of the first protocol port; Parsing the first message according to the first protocol to obtain a field name and a field value of each field of the first message; According to the field name, the field value is written into the database.
3. The protocol conversion method according to claim 1, wherein: The field values of each field of the first message are converted into the field values of each field of the second message by querying a field mapping table, wherein the field mapping table is used to store the mapping relationship between all fields involved in messages of multiple convertible communication protocols.
4. The protocol conversion method according to claim 3, wherein: The mapping relationship between all fields involved in the messages of the multiple communication protocols includes: One-to-one mapping; One-to-many mapping; Many-to-one mapping; Direct mapping, indicating that the field value of a field of the second message can directly use the field value of the corresponding field of the first message; Indirect mapping means that the field value of a field of the second message cannot directly use the field value of the corresponding field of the first message, and the corresponding field value can only be queried through the field mapping table.
5. The protocol conversion method according to claim 1, wherein: The steps of storing the field values of each field of the first message into a database and obtaining the field values of each field of the first message from the database and converting the field values of each field of the first message into the field values of each field of the second message are parallel processing steps.
6. The protocol conversion method according to claim 1, wherein: The database adopts a first-in-first-out working mode.
7. A protocol conversion device, characterized in that: Supporting message conversion between multiple communication protocols, the protocol conversion device includes: a writing module configured to, after receiving a first message to be converted from a first protocol port, store the field values of each field of the first message in a database, wherein the database is configured to store the field values of all fields involved in messages of multiple convertible communication protocols; a field conversion module, configured to obtain field values of each field of the first message from the database, and convert the field values of each field of the first message into field values of each field of the second message; A field completion module, configured to complete each field according to the message structure of the second message to obtain a complete second message; A sending module is used to send the complete second message to the corresponding second protocol port.
8. The protocol conversion device according to claim 7, characterized in that: The writing module and the field conversion module work in parallel.
9. A protocol converter, characterized in that: The protocol converter comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the at least one processor implements the protocol conversion method according to any one of claims 1 to 6 when executing the instructions.
10. A non-transitory computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed, the protocol conversion method according to any one of claims 1 to 6 is implemented.