Automatic data storage method and device adaptive to multiple protocols and electronic equipment
Through data automation storage methods adapted to multiple protocols, SQL statements are generated according to the communication protocol, which solves the problem of manual participation in storage in different communication scenarios, realizes automatic storage of communication data, and improves storage efficiency.
Patent Information
- Application Number
- CN202410005563.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-02
- Publication Date
- 2025-07-04
AI Technical Summary
In the prior art, data storage requires manual participation for different communication scenarios and protocols, resulting in inconvenience in stored procedures.
It provides an automated data storage method adapted to multiple protocols, and realizes automatic storage of communication data by generating database storage and table building SQL statements based on signal configuration information of communication protocols.
It realizes adaptability to multiple communication protocols, automatically stores communication data, reduces manual participation, and improves storage efficiency.
Smart Images

Figure CN120256499A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data storage, and particularly to a method, device and electronic device for automatically storing data adaptable to multiple protocols. Background Art
[0002] A communication protocol refers to the rules and agreements that both entities must follow to complete communication or services. The protocol defines the format of data units used, the information and meaning that information units should contain, the connection method, and the timing of information sending and receiving, thereby ensuring that data in the network is successfully transmitted to a determined place.
[0003] Currently, for different communication scenarios (different protocols, different protocol body structures), traditional manual table building operations are often used to implement the storage of communication data, and manual participation is required in the storage process, which is rather inconvenient.
[0004] Therefore, there is an urgent need for an automatic data storage method adaptable to multiple protocols to solve the above problems. Summary of the Invention
[0005] In view of the above problems, the present invention provides an automatic data storage method, device and electronic device adaptable to multiple protocols, which are adaptable to multiple different types of communication protocols and can automatically store communication data corresponding to multiple communication protocols.
[0006] The present invention provides a method for automatically storing data adaptable to multiple protocols, and the method includes:
[0007] According to the communication protocol corresponding to the received communication data, determine the signal configuration information corresponding to the communication data from the signal configuration information corresponding to various pre-configured communication protocols; wherein, the signal configuration information corresponding to each communication protocol is obtained by performing signal type configuration on the protocol body content of the communication protocol;
[0008] Generate a database storage SQL statement for the communication data according to the signal configuration information;
[0009] Execute the database storage SQL statement to store the communication data into the database.
[0010] Further, if an error message indicating that the database has not been built is returned after executing the database storage SQL statement, generate a database table creation SQL statement for the communication data according to the signal configuration information;
[0011] Execute the database table creation SQL statement to create a table in the database, and then execute the database storage SQL statement again after the table is created.
[0012] Further, the signal configuration information includes digital quantity signal configuration information and analog quantity signal configuration information.
[0013] Further, the digital signal configuration information includes the signal name, port, port size, byte offset, number of bits occupied, and database table name of the digital signal.
[0014] Further, the default field type of the digital signal includes character type or boolean type.
[0015] Further, the analog signal configuration information includes the signal name, signal type, signal length, port, port size, byte offset, and database table name of the analog signal.
[0016] Further, one communication protocol corresponds to one database table name.
[0017] Further, according to the signal configuration information, generate the database table creation SQL statement or the database storage SQL statement for communication data, including:
[0018] Obtain the information required for database table creation or the information required for database storage from the signal configuration information corresponding to the communication data; wherein, the information required for database table creation includes: database table name, field name, and field type, and the information required for database storage includes: database table name, field name, field type, byte offset of the signal, and bit offset of the signal;
[0019] Generate the database table creation SQL statement according to the information required for database table creation, or generate the database storage SQL statement according to the information required for database storage.
[0020] The present invention also provides an adaptive multi - protocol data automatic storage device, and the device includes:
[0021] A configuration information determination module, configured to determine the signal configuration information corresponding to the communication data from the signal configuration information corresponding to various pre - configured communication protocols according to the communication protocol corresponding to the received communication data; wherein, the signal configuration information corresponding to each communication protocol is obtained by dividing the protocol body content of the communication protocol.
[0022] A generation module, configured to generate the database storage SQL statement for the communication data according to the signal configuration information.
[0023] An execution module, configured to execute the database storage SQL statement to store the communication data into the database.
[0024] The present invention also provides a computer - readable storage medium, and the computer program stored in the computer - readable storage medium, when executed by one or more processors, implements the steps of the above - mentioned method.
[0025] The present invention also provides an electronic device, including a memory and one or more processors. A computer program is stored on the memory. When the computer program is executed by the one or more processors, the steps of the above method are performed.
[0026] The data automatic storage method, device and electronic device for adapting to multiple protocols provided by the present invention can generate database storage SQL statements according to the signal configuration information corresponding to communication data, and thus automatically store the communication data into the database by executing the database storage SQL statements, which is adaptable to multiple different types of communication protocols and realizes the automatic storage of communication data corresponding to multiple communication protocols. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0028] Figure 1 It is a schematic diagram of the software system structure;
[0029] Figure 2 It is a flowchart of the steps of the data automatic storage method for adapting to multiple protocols provided in an embodiment of the present invention;
[0030] Figure 3 It is a schematic diagram of the database table creation SQL statement code provided in an embodiment of the present invention;
[0031] Figure 4 It is a schematic diagram of the database storage SQL statement code provided in an embodiment of the present invention;
[0032] Figure 5 It is a schematic diagram of the data processing flow provided in an embodiment of the present invention;
[0033] Figure 6 It is a schematic diagram of the DCU table creation SQL statement code provided in an embodiment of the present invention;
[0034] Figure 7 It is a schematic diagram of the DCU storage SQL statement code provided in an embodiment of the present invention;
[0035] Figure 8 It is a schematic diagram of the BCU table creation SQL statement code provided in an embodiment of the present invention;
[0036] Figure 9 It is a schematic diagram of the BCU storage SQL statement code provided in an embodiment of the present invention;
[0037] Figure 10 Schematic diagram of the structure of an adaptive multi - protocol data automatic storage device provided in an embodiment of the present invention;
[0038] Figure 11 Schematic diagram of the structure of an electronic device provided in an embodiment of the present invention;
[0039] Reference numerals:
[0040] Figure 10 Among them: 1001 - configuration information determination module, 1002 - generation module, 1003 - execution module;
[0041] Figure 11 Among them: 1100 - electronic device, 1101 - processor, 1102 - communication bus, 1103 - user interface, 1104 - communication interface, 1105 - memory. Detailed implementation manners
[0042] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the drawings in the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0043] As Figure 1 shown, it is a schematic diagram of the software system structure. Among them, the entire system structure is divided into three layers. In the communication interface layer, multiple clients transmit communication data to the server through communication methods such as UDP (User Datagram Protocol) and TCP (Transmission Control Protocol); in the business logic layer, the application software on the server encapsulates and processes the received data for business logic; in the persistence layer, database operations (such as creating tables, saving, etc.) are performed on the encapsulated data.
[0044] In an embodiment of the present invention, an adaptive multi - protocol data automatic storage method is provided. This method is applied to the server. As Figure 2 shown, the method includes the following steps:
[0045] Step S201: Determine the signal configuration information corresponding to the communication data from the signal configuration information corresponding to various pre - configured communication protocols according to the communication protocol corresponding to the received communication data.
[0046] Step S202: Generate a database storage SQL statement for the communication data according to the signal configuration information;
[0047] Step S203: Execute the database storage SQL statement to store the communication data in the database.
[0048] Furthermore, the method further includes:
[0049] Step S204: If a database table creation error message is returned after executing the database storage SQL statement, generate a database table creation SQL statement for the communication data according to the signal configuration information;
[0050] Step S205: Execute the database table creation SQL statement to create a table in the database, and then execute the database storage SQL statement again after the table is created.
[0051] It can be understood that a database is actually composed of multiple tables, and data is stored in the tables. To store data in the database, a table needs to be created first (create a table in the database for storing the data), and then execute the database storage SQL statement to store the data in the corresponding table.
[0052] In this embodiment, if a table for storing the communication data has been created in the database, after executing Step S203, the communication data can be stored in the database; if a table for storing the communication data has not been created in the database, a database table creation error message will be returned after executing the database storage SQL statement. Furthermore, according to Step S204 and Step S205, first generate and execute the database table creation SQL statement to create a table in the database, and then execute the database storage SQL statement again after the table is created to store the communication data in the corresponding table of the database.
[0053] In Step S201, the signal configuration information corresponding to each communication protocol is obtained by performing signal type configuration on the protocol body content of the communication protocol. Specifically, the signal configuration information corresponding to each communication protocol is obtained by performing signal type configuration on the protocol body content of the communication protocol. Among them, according to the protocol body structure, the signal types can be divided into two types: digital quantity signals (occupying 1 BIT) and analog quantity signals (more than 1 BIT). The signal configuration information includes digital quantity signal configuration information and analog quantity signal configuration information.
[0054] More specifically, the digital quantity signal configuration information includes the signal name, port, port size, byte offset, occupied bit, and database table name of the digital quantity signal; the default field type of the digital quantity signal includes character type or boolean type; the analog quantity signal configuration information includes the signal name, signal type, signal length, port, port size, byte offset, and database table name of the analog quantity signal. One communication protocol corresponds to one database table name, that is, the communication data sent through the same communication protocol is stored in one table.
[0055] Before step S201, the user can configure the signal type for the protocol body content of the communication protocol, so as to pre-configure the signal configuration information corresponding to various communication protocols in the server.
[0056] Among them, the communication protocol types can include RS485, RS422, RS232, UDP (User Datagram Protocol), TCP (Transmission Control Protocol), Modbus, MVB (Multifunction Vehicle Bus), WTB (Wire Train Bus), etc.
[0057] Exemplarily, taking two communication protocols (protocol name 1, protocol name 2) as an example, the protocol body content of the communication protocol can be basically represented in the following table form:
[0058] Table 1 Protocol Name 1 (Port Number: XXX1)
[0059]
[0060] Table 2 Protocol Name 2 (Port Number: XXX2)
[0061]
[0062] After configuring the signal type for the protocol body content of the communication protocol, the obtained signal configuration information corresponding to the communication protocol includes digital quantity signal configuration information and analog quantity signal configuration information, which can be represented in the following table form:
[0063] Table 3 Digital Quantity Signal Configuration Information
[0064]
[0065] Configuration description: The port corresponds to the communication port number in the original protocol, the port size corresponds to the protocol body length, the byte offset is the byte offset of the digital quantity signal in the protocol, the DB (database) table name is the table name where the digital quantity signal is stored in the database (the database table name can be specifically set according to actual needs), and signal name 1, signal name 2, signal name 3, and signal name 6 are the field names stored in the database table name, and the default field type is character type or boolean type.
[0066] Table 4 Analog Quantity Signal Configuration Information
[0067] Serial number Signal length Port Port size Byte offset Signal name Signal type DB table name 1 1 XXX1 Y1 2 Signal name 4 Integer type DB_Name1 2 4 XXX1 Y1 3 Signal name 5 String type DB_Name1 3 5 XXX2 Y2 1 Signal name 7 String type DB_Name2
[0068] Configuration instructions: The signal length is the number of bytes occupied by the analog signal. The port corresponds to the port number in the original protocol. The port size corresponds to the protocol body length. The byte offset is the byte offset of the analog signal in the protocol. The signal name is the field name stored in the database table named DB_Name. The signal type is the database field type corresponding to the analog signal. The DB (database) table name is the table name in which the analog signal is stored in the database (set the database table name according to actual needs. In principle, one protocol corresponds to one database table name).
[0069] In step S204, according to the signal configuration information, the database table creation SQL statement for generating communication data includes:
[0070] Obtain the information required for database table creation from the signal configuration information corresponding to the communication data; among them, the information required for database table creation includes the database table name, field name, and field type.
[0071] Generate a database table creation SQL statement according to the information required for database table creation.
[0072] Exemplarily, taking the MySql database as an example, according to the signal configuration information (Table 3, Table 4) of the above two communication protocols (Protocol Name 1, Protocol Name 2), the generated database table creation SQL statement code can be referred to Figure 3 .
[0073] In step S202, according to the signal configuration information, generate a database storage SQL statement, including:
[0074] Obtain the information required for database storage from the signal configuration information corresponding to the communication data;
[0075] Generate a database storage SQL statement according to the information required for database storage.
[0076] Among them, the information required for database storage includes: the database table name, field name, field type, and the byte offset and bit offset of the signal. It can be understood that the byte offset and bit offset of the signal refer to the byte offset and bit offset corresponding to the analog signal and digital signal (which can be determined from the signal configuration information in Table 3 and Table 4).
[0077] Among them, the received communication data can be disassembled according to the byte offset and bit offset of the signal (analog signal, digital information) to obtain the signal values of each signal, and then a database storage SQL statement can be generated according to the database table name, field name, field type, and the signal values of each signal.
[0078] Exemplarily, taking the MySql database as an example, according to the signal configuration information (Table 3, Table 4) of the above two communication protocols (Protocol Name 1, Protocol Name 2), the generated database storage SQL statements can refer to Figure 4 .
[0079] It can be understood that in this embodiment, when storing communication data, the data processing flow can be referred to Figure 5 . For the received communication data, disassemble and locate the communication data to generate corresponding SQL statements, and by executing the corresponding SQL statements, the communication data is further stored in the database.
[0080] The data automatic storage method for adapting to multiple protocols provided in this embodiment can generate database storage SQL statements according to the signal configuration information corresponding to the communication data, so that by executing the database storage SQL statements, the communication data is automatically stored in the database, which has self - adaptability to multiple different types of communication protocols and realizes the automatic storage of communication data corresponding to multiple communication protocols.
[0081] In another embodiment of the present invention, an application example of the data automatic storage method for adapting to multiple protocols is provided.
[0082] Specifically, taking the MVB (Multifunction Vehicle Bus) protocol of the DCU (Drive Control Unit) and BCU (Brake Control Unit) as an example, the protocol body content of the DCU_MVB protocol and BCU_MVB protocol can be represented in the following table form:
[0083] Table 5 DCU_MVB protocol 0xB0 port
[0084]
[0085]
[0086] Table 6 BCU_MVB protocol 0xD0 port
[0087]
[0088] The first step: Protocol signal type division.
[0089] Table 7 Digital quantity signal configuration information
[0090]
[0091]
[0092] Table 8 Analog signal configuration information
[0093]
[0094] Step 2: Generate SQL statements according to the digital signal configuration information and the analog signal configuration information.
[0095] Among them, the code of the SQL statement for creating a table in the DCU can be found in Figure 6 , and the code of the SQL statement for storing in the DCU can be found in Figure 7 , and the code of the SQL statement for creating a table in the BCU can be found in Figure 8 , and the code of the SQL statement for storing in the BCU can be found in Figure 9 .
[0096] Step 3: Just execute the SQL statements using the application software.
[0097] In another embodiment of the present invention, as Figure 10 shown, the present invention also provides an adaptive data automation storage device for multiple protocols, and the device includes:
[0098] A configuration information determination module 1001, configured to determine the signal configuration information corresponding to the communication data from the signal configuration information corresponding to various pre-configured communication protocols according to the communication protocol corresponding to the received communication data; wherein, the signal configuration information corresponding to each communication protocol is obtained by dividing the protocol body content of the communication protocol;
[0099] A generation module 1002, configured to generate a database storage SQL statement for the communication data according to the signal configuration information;
[0100] An execution module 1003, configured to execute the database storage SQL statement to store the communication data in the database.
[0101] Optionally, the generation module 1002 is further configured to generate a database table creation SQL statement for the communication data according to the signal configuration information when the execution module 1003 returns an error message indicating that the database has not been created after executing the database storage SQL statement;
[0102] The execution module 1003 is further configured to execute the database table creation SQL statement to create a table in the database and execute the database storage SQL statement again after the table is created.
[0103] Optionally, the signal configuration information includes digital signal configuration information and analog signal configuration information.
[0104] Optionally, the digital signal configuration information includes the signal name, port, port size, byte offset, number of bits occupied, and database table name of the digital signal.
[0105] Optionally, the default field types of digital signals include character type or boolean type.
[0106] Optionally, the analog signal configuration information includes the signal name, signal type, signal length, port, port size, byte offset, and database table name of the analog signal.
[0107] Optionally, one communication protocol corresponds to one database table name.
[0108] Optionally, according to the signal configuration information, database table creation SQL statements or database storage SQL statements are generated, including:
[0109] Obtain the information required for database table creation or the information required for database storage from the signal configuration information corresponding to the communication data; among them, the information required for database table creation includes: database table name, field name, and field type, and the information required for database storage includes: database table name, field name, field type, byte offset of the signal, and bit offset of the signal;
[0110] Generate database table creation SQL statements according to the information required for database table creation, or generate database storage SQL statements according to the information required for database storage.
[0111] In another embodiment of the present invention, a computer program product is further provided. The computer program product includes a computer program or instruction, and when the computer program or instruction is executed by a processor, all or part of the steps of the method in the above method embodiment are implemented. This embodiment will not be repeated here.
[0112] Furthermore, the computer program product may include one or more computer-executable components configured to execute the embodiments when the program is running; the computer program product may also include a computer program tangibly embodied on a computer-readable medium, and the computer program includes program code for executing all or part of the steps of the method in the method embodiment of the present invention. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part, and / or installed from a removable medium.
[0113] In another embodiment of the present invention, a computer-readable storage medium is further provided. The computer program stored in the computer-readable storage medium, when executed by one or more processors, implements all or part of the steps of the method in the above method embodiment. This embodiment will not be repeated here.
[0114] In another embodiment of the present invention, an electronic device 1100 is further provided. Figure 11 It is a schematic diagram of the composition structure of the electronic device provided by the embodiment of the present invention, as Figure 11As shown in the figure, the electronic device 1100 includes: at least one processor 1101, at least one communication bus 1102, a user interface 1103, at least one external communication interface 1104, and a memory 1105. Among them, the communication bus 1102 is configured to implement connection communication between these components. Among them, the user interface 1103 may include a display screen, and the external communication interface 1104 may include a standard wired interface and a wireless interface. A computer program is stored on the memory 1105, and the memory 1105 and one or more processors 1101 are communicatively connected to each other. When the computer program is executed by one or more processors, the processor 1101 is configured to execute the computer program stored in the memory to implement all or part of the steps of the method in the above method embodiment, and this embodiment will not be repeated here.
[0115] The data automation storage method, device and electronic device for adapting to multiple protocols provided by the present invention can generate database storage SQL statements according to the signal configuration information corresponding to communication data, and thus automatically store the communication data into the database by executing the database storage SQL statements, which has self - adaptability to multiple different types of communication protocols and realizes the automatic storage of communication data corresponding to multiple communication protocols.
[0116] Each embodiment in the present invention is described in a progressive manner. The same or similar parts among the embodiments can be referred to each other, and the key point of each embodiment is to illustrate the differences from other embodiments.
[0117] The protection scope of the present invention is not limited to the above - mentioned embodiments. Obviously, those skilled in the art can make various changes and deformations to the present invention without departing from the scope and spirit of the present invention. If these changes and deformations belong to the scope of the claims of the present invention and their equivalent technologies, the intention of the present invention also includes these changes and deformations.
Claims
1. An adaptive data automated storage method for multiple protocols, characterized in that The method includes: Determine the signal configuration information corresponding to the communication data from the signal configuration information corresponding to various pre-configured communication protocols according to the communication protocol corresponding to the received communication data; wherein, the signal configuration information corresponding to each communication protocol is obtained by performing signal type configuration on the protocol body content of the communication protocol; Generate a database storage SQL statement for the communication data according to the signal configuration information; Execute the database storage SQL statement to store the communication data in the database.
2. The adaptive multi-protocol data automatic storage method according to claim 1, characterized in that The method further includes: If an error message indicating that the table has not been created in the database is returned after executing the database storage SQL statement, generate a database table creation SQL statement for the communication data according to the signal configuration information; Execute the database table creation SQL statement to create a table in the database, and execute the database storage SQL statement again after the table is created.
3. The data automatic storage method adaptable to multiple protocols according to claim 1, characterized in that, The signal configuration information includes digital quantity signal configuration information and analog quantity signal configuration information.
4. The data automatic storage method adaptable to multiple protocols according to claim 3, wherein The digital quantity signal configuration information includes the signal name, port, port size, byte offset, number of bits occupied, and database table name of the digital quantity signal.
5. The adaptive multi-protocol data automatic storage method according to claim 4, wherein The default field type of the digital quantity signal includes character type or boolean type.
6. The data automatic storage method adaptable to multiple protocols according to claim 3, wherein The analog quantity signal configuration information includes the signal name, signal type, signal length, port, port size, byte offset, and database table name of the analog quantity signal.
7. The adaptive multi-protocol data automatic storage method according to claim 4 or 6, characterized in that One communication protocol corresponds to one database table name.
8. The data automatic storage method adaptable to multiple protocols according to claim 2, characterized in that, Generating a database table creation SQL statement or a database storage SQL statement for the communication data according to the signal configuration information includes: Obtain the information required for database table creation or the information required for database storage from the signal configuration information corresponding to the communication data; wherein, the information required for database table creation includes: database table name, field name, and field type, and the information required for database storage includes: database table name, field name, field type, byte offset of the signal, and bit offset of the signal; Generate a database table creation SQL statement according to the information required for database table creation, or generate a database storage SQL statement according to the information required for database storage.
9. An adaptive data automated storage device for multiple protocols, characterized in that, The device includes: A configuration information determination module, configured to determine the signal configuration information corresponding to the communication data from the signal configuration information corresponding to various pre-configured communication protocols according to the communication protocol corresponding to the received communication data; wherein, the signal configuration information corresponding to each communication protocol is obtained by partitioning the protocol body content of the communication protocol; A generation module, configured to generate a database storage SQL statement for the communication data according to the signal configuration information; An execution module, configured to execute the database storage SQL statement to store the communication data in the database.
10. A computer-readable storage medium, characterized in that, The computer program stored in the computer-readable storage medium, when executed by one or more processors, implements the steps of the method according to any one of claims 1 to 8.
11. An electronic device, characterized in that, Including a memory and one or more processors, the sto red with a computer program, when the computer program is executed by the one or more processors, Perform the steps of the method according to any one of claims 1 to 8.