Data matching processing method, computer storage medium, and input / output device
By optimizing the matching of instruction protocols and input/output device information through double-string hashing and mean hashing algorithms, the problems of high resource consumption and low efficiency in embedded systems are solved, and efficient data parsing and flexible protocol management are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- UNICORE COMM INC
- Filing Date
- 2023-04-24
- Publication Date
- 2026-05-15
AI Technical Summary
Existing technologies suffer from high resource consumption, low computational efficiency, poor scalability, and wasted storage space when managing and processing a large number of different instruction protocols in embedded systems, especially when supporting thousands of instruction protocols.
The method employs a double-string hashing approach, which combines a pre-loaded first hash table file and a second hash table file with mean hashing and trisection processing to optimize the matching of instruction protocols and input/output device information, thereby reducing the probability of hash collisions and improving computational efficiency.
It improves the processing efficiency of data parsing and matching, reduces computational complexity and storage space requirements, and supports efficient management and flexible expansion of large-volume instruction protocols.
Smart Images

Figure CN116501699B_ABST
Abstract
Description
Technical Field
[0001] This application relates to, but is not limited to, embedded chip technology, including a data matching and processing method, a computer storage medium, and an input / output device. Background Technology
[0002] In applications that support numerous different instruction protocols and have multiple input / output interfaces, such as surveying and mapping, machine control, IoT, autonomous driving, and wearable devices, various input / output devices are used for multiple types of data interaction, requiring the system to support thousands of instruction protocols. Taking the UM960 embedded positioning module as an example, this chip is used in platforms that interact with various types of data through multiple input / output devices. It uses the FreeRTOS (a real-time operating system for microcontrollers and small microprocessors) embedded platform, but can also be applied to Linux, Windows, and other x86 platforms, as well as ARM-Linux, embedded configurable operating systems (ECOS), and uCOS (generally referring to a real-time multitasking operating system). Due to product design requirements, the system needs to support thousands of instruction protocols. Users can interact with the UM960 module through multiple serial ports or Ethernet ports. The user first inputs the instruction protocol string, which is then processed by the data parsing and matching program within the UM960 before outputting feedback data.
[0003] The following problems exist when applying related technologies to instruction protocols: 1. Using a database to store and manage instruction protocols; however, this adds an extra database system and corresponding database application interface, consuming more system resources (such as storage and CPU), making it particularly unsuitable for embedded systems. 2. Calculating hash values for different strings using modulo operations involves a traversal matching method, resulting in low efficiency in calculation and query matching, affecting data query and processing speed. The resulting hash table also suffers from uneven distribution of attribute values, increasing the complexity of hash value calculation. 3. Adding, deleting, or modifying existing input devices and instruction protocols affects the loading and use of other configurations, resulting in poor scalability. Ordinary string hash algorithms have low computational efficiency. 4. Large batches of instruction protocols (such as thousands of instruction protocols) are unsuitable for large-scale management, as the management and use of instruction protocols generate complex processing logic. 5. Due to the uncertainty of the number of subsequent instruction protocol expansions, a large amount of storage space is typically allocated initially, wasting storage resources.
[0004] In summary, managing and maintaining a large number of instruction protocols and different input / output (I / O) devices, and improving the processing efficiency of data parsing and matching, is a problem that needs to be solved in the process of supporting a large number of different instruction protocols. Summary of the Invention
[0005] The following is an overview of the subject matter described in detail in this application. This overview is not intended to limit the scope of the claims.
[0006] This application provides a data matching processing method, a computer storage medium, and an input / output device, which can improve the processing efficiency of data parsing and matching.
[0007] This application provides a data matching processing method, including:
[0008] Receive instruction protocol string;
[0009] When the received instruction protocol string exists in a pre-set static variable data structure, the binding process of the input / output device corresponding to the instruction protocol string is executed;
[0010] Based on the binding process performed, output the feedback data after the execution of the instruction protocol string;
[0011] The static variable data structure includes a pre-loaded first hash table file and a second hash table file; the first hash table file is a file obtained by performing a hash operation on a first text file, and the first text file includes instruction protocol information; the second hash table file is a file obtained by performing a hash operation on a second text file, and the second text file includes input / output device information.
[0012] On the other hand, embodiments of this application also provide a computer storage medium storing a computer program, which, when executed by a processor, implements the above-described data matching processing method.
[0013] Furthermore, embodiments of this application also provide an input / output device, including: a memory and a processor, wherein the memory stores a computer program; wherein,
[0014] The processor is configured to execute computer programs in memory;
[0015] When the computer program is executed by the processor, it implements the data matching processing method described above.
[0016] This application embodiment improves the processing efficiency of data parsing and matching by performing double-string hashing on instruction protocol information and input / output device information.
[0017] Other features and advantages of this application will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the description, claims and drawings. Attached Figure Description
[0018] The accompanying drawings are used to provide a further understanding of the technical solutions of this application and constitute a part of the specification. They are used together with the embodiments of this application to explain the technical solutions of this application and do not constitute a limitation on the technical solutions of this application.
[0019] Figure 1 This is a flowchart of a data matching processing method according to an embodiment of this application;
[0020] Figure 2 This is a block diagram of the input / output devices in an embodiment of this application. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in detail below with reference to the accompanying drawings. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be arbitrarily combined with each other.
[0022] The steps illustrated in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases the steps shown or described may be performed in a different order than that presented here.
[0023] Figure 1 This is a flowchart of the data matching processing method in an embodiment of this application, as shown below. Figure 1 As shown, it includes:
[0024] Step 101: Receive the instruction protocol string;
[0025] Step 102: When the received instruction protocol string exists in a pre-set static variable data structure, perform the binding process of the input / output device corresponding to the instruction protocol string;
[0026] Step 103: Based on the executed binding process, output the feedback data after the execution of the instruction protocol string;
[0027] The static variable data structure includes a pre-loaded first hash table file and a second hash table file; the first hash table file is obtained by performing a hash operation on a first text file, and the first text file includes instruction protocol information; the second hash table file is obtained by performing a hash operation on a second text file, and the second text file includes input / output device information.
[0028] In one exemplary instance, the above-described steps 101-103 can be performed by an input / output device in this embodiment of the application.
[0029] In one exemplary instance, before loading the first hash table file and the second hash table file into the static variable data structure, the method of this application embodiment refers to related technologies: associating the first hash table file and the second hash table file in the running code. When the program of this application embodiment runs, it includes a code segment, a stack segment, and a data segment; wherein, the data segment is used to store global variables and static variables, etc.; when compiling the program (referring to the running code in this application embodiment), memory has already been allocated for the global variables and static variables of the data segment; when allocating memory, this application embodiment configures a pre-set offset address for the first hash table file and the second hash table file, thereby realizing the processing of associating the first hash table file and the second hash table file in the running code. The compiled program is a binary file, also called a firmware file. Using a flashing tool, the firmware is written to the specified flash memory address on the embedded platform. When the embedded platform is working normally, it first loads the firmware from the specified address. Then, through the bootloader, it migrates the code segment (code part) and data segment (data part) into memory. The first and second hash table files are stored as static variable data structures in the data segment. Through preprocessing on the host (PC) side, the generated hash tables are compiled into the firmware as static variables. During program initialization and runtime, the first and second hash table files are read from the flash memory address based on the offset address and written into memory as static variables. These are then called by the relevant processing logic in the code segment for subsequent hash matching.
[0030] In one exemplary instance, the storage of the first text file and the second text file, and the generation of the first hash table file and the second hash table file in this application embodiment can be performed by the host that compiles the firmware code.
[0031] This application embodiment improves the efficiency of subsequent hash matching processing and enhances the processing efficiency of data parsing by performing double-string hashing on instruction protocol information and input / output device information.
[0032] In one exemplary instance, each line of instruction protocol information in the first text file may contain one or any combination of the following fields ordered according to a first preset order: initial value of the first hash address, unique identifier ID of the instruction protocol, instruction protocol string, name of instruction protocol processing function, instruction protocol type, instructions for use of the instruction protocol, and instruction protocol example;
[0033] Each line of input / output device information in the second text file may contain one or any combination of the following fields ordered according to a second preset order: initial value of the second hash address, input / output device ID, input / output device string, and input / output device description.
[0034] It should be noted that the first and second preset sorting can be set with reference to the experience and habits of those skilled in the art in coding, or can be uniformly adjusted according to subsequent applications.
[0035] In one exemplary instance, the static variable data structure of this application embodiment includes a pre-loaded first hash table file and a second hash table file, comprising:
[0036] An array of more than one hash list contains a pre-loaded first hash table file and a second hash table file.
[0037] In one exemplary instance, one or more hash list arrays in this application embodiment may include:
[0038] This is used to load the command hash list array containing the command protocol in the instruction protocol within the first hash table file;
[0039] An array of LOG hash lists used to load the LOG protocol containing the information (LOG) protocol in the instruction protocol within the first hash table file;
[0040] A device hash array used to load input / output device information contained in the second hash table file.
[0041] This application's embodiments further improve data matching and processing efficiency by distinguishing between command protocols and LOG protocols.
[0042] It should be noted that the information protocol in this application embodiment may include measurement and mapping related information such as UTC time information and location information, which are well known to those skilled in the art. This information is output at preset intervals (e.g., 1 second). After inputting the LOG protocol command, the board responds and outputs the corresponding LOG information. For example, GNGGA COM1 1 mentioned in this application embodiment means that one GNGGA message is output through COM1 every second.
[0043] In one exemplary instance, this application embodiment determines whether the received instruction protocol string exists in the static variable data structure through the following steps:
[0044] The first and second hash table files in the static variable data structure are recursively divided into three equal parts to obtain the corresponding equally divided hash tables.
[0045] In addition, the received instruction protocol string is hashed to obtain the corresponding instruction protocol hash value;
[0046] The instruction protocol hash value is matched with the equally divided hash table to determine whether the instruction protocol string exists in the static variable data structure;
[0047] The minimum length of the equal hash table obtained by dividing the first hash table file into three equal parts is greater than or equal to the preset first maximum length, and the minimum length of the equal hash table obtained by dividing the second hash table file into three equal parts is greater than or equal to the preset second maximum length.
[0048] It should be noted that the recursive trisection process is a well-known trisection method in the art. Taking the first hash table file as an example, the basic operations of the trisection process may include: firstly dividing the first hash table file into three equal parts, assuming the three files obtained are the first trisection file, determining whether the first trisection file is greater than the first maximum length; if the first trisection file is greater than the first maximum length, dividing the first trisection file into three equal parts, assuming the three files obtained are the second trisection file, determining whether the second trisection file is greater than the first maximum length; if the second trisection file is less than the first maximum length, then the first trisection file is the trisection hash table obtained by splitting the first hash table file; if the second trisection file is greater than the first maximum length, continuing to split the second trisection file until the nth trisection file obtained by splitting is less than the first maximum length, then determining the (n-1)th trisection file obtained by the (n-1)th trisection as the trisection hash table obtained by splitting the first hash table file.
[0049] In one exemplary instance, the hash operation processing in this application embodiment may include:
[0050] Hash operations are performed based on the mean hash algorithm.
[0051] In this application embodiment, both the first hash table file and the second hash table file are obtained by the mean hash algorithm, and are uniformly distributed hash tables, which can further improve the efficiency of subsequent hash matching processing and improve the processing efficiency of data parsing and matching.
[0052] In one exemplary instance, the mean hash algorithm of this application is implemented based on binary bitwise operations.
[0053] In one exemplary instance, the hash operation processing based on the mean hash algorithm in this application embodiment may include:
[0054] Using a preset prime number seed as the coefficient of the mean hash algorithm, hashing is performed on the first and second text files. In one exemplary embodiment, the selection of the prime number seed in this application can be determined by those skilled in the art based on experience. In one exemplary embodiment, after determining the binding process of the input / output device corresponding to the execution instruction protocol string, this application embodiment refers to related technologies to execute the binding process of the input / output device corresponding to the instruction protocol string.
[0055] In one exemplary instance, when the instruction protocol string does not exist in the static variable data structure, the method of this application embodiment may further include: outputting preset feedback prompt information. In one exemplary instance, outputting preset feedback prompt information may include: outputting feedback prompt information through a pre-set human-computer interaction window; wherein, the feedback prompt information may include: a prompt information indicating that the instruction protocol string failed to match.
[0056] In one exemplary instance, before matching the instruction protocol hash value with the equally divided hash table, the method of this application embodiment may further include:
[0057] Determine the maximum length of the instruction protocol string contained in the first hash table file, and set the maximum length of the instruction protocol string as the first maximum length;
[0058] Determine the maximum length of the strings for input / output devices in the second hash table file, and set the maximum length of the strings for those input / output devices as the second maximum length.
[0059] Write the first and second maximum lengths into the header file.
[0060] In one exemplary instance, this application embodiment includes writing the first maximum length and the second maximum length into the header file, specifically into the header file of the code being executed. By writing the determined first and second maximum lengths into the header file of the program code, this application embodiment dynamically implements the maximum length of the stored hash table. This facilitates the allocation of the actual required storage space during program initialization, avoiding the allocation of excessive storage space and operational anomalies due to insufficient allocated storage space.
[0061] In one exemplary instance, before outputting the feedback data after the execution of the instruction protocol string, the method of this application embodiment may further include:
[0062] In the LOG protocol included in the instruction protocol information of the first text file, add the output device for output feedback data.
[0063] When this application embodiment receives an instruction protocol string, it determines whether an output device is specified in the instruction protocol string. If no output device is specified, the input device is determined as the output device by referring to the relevant protocol. When an output device is specified in the instruction protocol string, the feedback data output after processing the instruction protocol string is output through the specified output device.
[0064] In one exemplary instance, when the instruction protocol information in the first text file contains a unique identifier (ID) for the instruction protocol, the input / output device information in the second text file contains an input / output device ID, and the received instruction protocol string exists in a static variable data structure, the method of this application embodiment further includes:
[0065] The instruction protocol string is processed according to a pre-defined string processing function that corresponds to the input / output device ID and the unique identification number ID of the instruction protocol.
[0066] In one exemplary instance, considering the different number and types of command parameters, the command instruction string in this embodiment of the application is pre-set with corresponding splitting processing functions. These splitting processing functions respectively determine the validity of the number of parameters, the validity of the parameter type, and the validity of the parameter value or character length. After processing by the splitting processing functions, a processing result is returned. The returned result includes: concatenating an error message for invalid input or a feedback for correct input into an output string. The output string is also bound to the input / output device for later feedback to the user via an output function.
[0067] This application also provides a computer storage medium storing a computer program, which, when executed by a processor, implements the above-described data matching processing method.
[0068] Figure 2 This is a block diagram of the input / output devices in an embodiment of this application, such as... Figure 2 As shown, it includes: a memory and a processor, wherein the memory stores the computer program; wherein,
[0069] The processor is configured to execute computer programs in memory;
[0070] When a computer program is executed by a processor, it implements the data matching process described above.
[0071] The following application examples briefly illustrate the embodiments of this application. These application examples are only used to describe the embodiments of this application and are not intended to limit the scope of protection of this application.
[0072] The data matching process in this application embodiment includes:
[0073] Step 201: The host stores the instruction protocol information as a first text file and the input / output device information as a second text file;
[0074] In one exemplary instance, the fields in the first and second text files of this application embodiment are arranged in a pre-defined order. In another exemplary instance, the fields contained in each line of instruction protocol information in the first text file, from left to right, are: initial value of the first hash address, unique identifier ID of the instruction protocol, instruction protocol string, name of the instruction protocol processing function, instruction protocol type, instruction protocol usage description, and instruction protocol example. In another exemplary instance, the fields contained in each line of input / output device information in the second text file, from left to right, are: initial value of the second hash address, input / output device ID, input / output device string, and input / output device description.
[0075] It should be noted that the initial values of the first hash address and the second hash address mentioned above in the embodiments of this application are not the final hash values actually used. The hash values used in the program are generated through subsequent uniform hashing.
[0076] In one exemplary instance, in this application embodiment, whether it is instruction protocol information or input / output device information, each piece of information may include the corresponding instruction protocol unique identification number (ID) and input / output device ID, which are used for logical processing in the program; the instruction protocol unique identification number (ID) and input / output device ID can be expanded and added in the order of addition according to a preset rule, and the instruction protocol unique identification number (ID) and input / output device ID will also be written into the user manual for easy query and use by the user.
[0077] In this embodiment, when adding, deleting, or modifying instruction protocol information or input / output device information, the first and second text files can be processed directly. These files, along with the project program files, can be managed and maintained using a configuration management tool (SVN). To ensure scalability and maintainability, there are instances where the name strings of stored input / output devices and instruction protocol strings need to be modified. Adding strings involves appending new lines to existing strings; deleting strings involves directly deleting the corresponding lines from the text files. In this embodiment, whether adding, modifying, or deleting unused instruction protocols, or adding, modifying, or deleting unused input / output devices, only the corresponding text files need to be modified, improving management flexibility.
[0078] Step 202: When the host compiles the firmware code, it performs hash operations on the stored first text file and second text file using a pre-defined mean hash algorithm to obtain a first hash table file corresponding to the first text file and a second hash table file corresponding to the second text file; wherein, the mean hash algorithm is implemented based on binary bitwise operations;
[0079] This application's embodiments reduce computational complexity and improve computational efficiency by using binary bitwise operations instead of the modulo operation in the general hash algorithm. The following example compares the modulo operation with 4 and the "#" character: the ASCII decimal value of the "#" character is 35, and the modulo operation is: 35 % 4 = 3; in this application's embodiment, the binary bitwise operation is: 35 & 3 = 00100011 & 0011 = 3.
[0080] This application embodiment reduces the probability of hash collisions by combining double-string hashing of the first hash table file and the second hash table file; it dynamically generates a uniform hash table file when compiling firmware code, which reduces resource consumption during program initialization and provides support for improving the hit rate of instruction protocol string matching.
[0081] In one exemplary instance, adding and / or deleting command protocols in related technologies can lead to uneven distribution of hash tables in existing configuration text. In this application embodiment, when compiling firmware code on a PC platform, a tool using the mean hash algorithm is called to process the first and second text files, generating a first hash table file (HashList_CommandLog.txt) and a second hash table file (HashList_Device.txt). The first and second hash table files contain the hash values of different strings obtained from the first and second text files using the mean hash algorithm. The first and second hash table files are uniformly distributed hash tables, thereby improving the efficiency of subsequent hash matching processing.
[0082] In one exemplary embodiment, to achieve a uniform distribution between the first hash table file and the second hash table file, a prime number seed is introduced as a coefficient for hashing calculation. Using prime numbers avoids cycles and allows for a more even distribution of data in the hash table. In one exemplary embodiment, 131 is selected as the prime number seed. The hash value of a string is calculated using the selected prime number seed. The formula for calculating the hash value of a string containing N characters is as follows:
[0083] Hash value = 131^(N-1) * P(N-1) + 131^(N-2) * P(N-2) + ... + 131^1 * P(1) + P(0)
[0084] Where P(N-1) represents the ASCII value corresponding to each character.
[0085] The following BKDRHash function can be used to calculate the hash value of a string:
[0086] INT BKDRHash(const CHAR *str)
[0087] {
[0088] UINT seed = 131; / / Select 131 as the prime number seed
[0089] UINT hash = 0;
[0090] while (*str) / / Calculate the hash value of the input string str using a loop.
[0091] {
[0092] hash = hash * seed + (*str);
[0093] str++;
[0094] }
[0095] return (hash & 0x7FFFFFFFL); / / Returns the number of valid bits in the calculated hash value.
[0096] }
[0097] Step 203: The input / output device associates the obtained first hash table file and second hash table file in the running code, and loads the generated first hash table file and second hash table file into a static variable data structure; wherein, the static variable data structure includes one or more hash list arrays;
[0098] In one exemplary instance, this application embodiment loads the generated first hash table file and second hash table file into a static variable data structure, including: when running a program on an embedded device, performing the following initialization operations: reading the first hash table file through the initialization function of the instruction protocol management class, storing all instruction protocols in a hash list; according to the instruction protocol type, storing the command protocols contained in the instruction protocols in the hash list into a command hash list array, and storing the LOG protocols contained in the instruction protocols in the hash list into a LOG hash list array, the hash list array storing the hash values (i.e., valid hash addresses) obtained by calculating the initial values of the first and second hash addresses using a uniform hash algorithm. The second hash table file is loaded through the initialization function of the device management class, storing all input / output device information in a device hash array; each device has a unique input / output device ID and hash value. This application embodiment improves matching processing efficiency by distinguishing between command protocols and LOG protocols.
[0099] In one exemplary instance, the embodiments of this application can store the above-mentioned LOG protocol in a preset format; for example, the LOG protocol can be stored in order of LOG name, device name and output frequency; taking LOG protocol as RANGEA COM1 1 as an example, the LOG protocol indicates: requesting the output of RANGEA with an output frequency of 1Hz through COM1.
[0100] Step 204: When the input / output device receives an externally input instruction protocol string, it verifies whether the received instruction protocol string exists in the loaded static variable data structure, and determines whether to perform the binding process between the instruction protocol string and the input / output device based on the verification result.
[0101] In one exemplary instance, the program loaded in the input / output device of this application verifies the existence of the instruction protocol string of external input (user input) in the static variable data structure, i.e., whether it exists in the previously initialized instruction hash list array or LOG hash list array, by calling a string parsing program, and completes the binding of the instruction protocol string to the input / output device. In another exemplary instance, each input / output device of this application can implement the verification of the input instruction protocol string through the input string verification function in the DeviceIO class.
[0102] This application embodiment provides information support for managing and maintaining the correspondence between each input / output device and the input instruction protocol string through double string hashing.
[0103] In one exemplary instance, this application embodiment verifies whether the received instruction protocol string exists in the loaded static variable data structure, including:
[0104] The first hash table file and the second hash table file in the loaded static variable data structure are recursively divided into three equal parts to obtain the corresponding equal-part hash tables. The minimum length of the equal-part hash table obtained by dividing the first hash table file into three equal parts is greater than the first maximum length, and the minimum length of the equal-part hash table obtained by dividing the second hash table file into three equal parts is greater than the second maximum length.
[0105] The received instruction protocol string is hashed using the mean hash algorithm to obtain the instruction protocol hash value corresponding to the instruction protocol string; the mean hash algorithm is implemented based on binary bit operations.
[0106] The obtained instruction protocol hash value is matched with the obtained equally divided hash table to determine whether the received instruction protocol string exists in the loaded static variable data structure.
[0107] In one exemplary instance, this application embodiment processes the input instruction protocol string according to the ASCII decimal value corresponding to each character, and generates a corresponding hash value based on a hash operation that includes binary bitwise operations. The generated hash value is then matched with the hash values in the command hash list array and the LOG hash list array, respectively.
[0108] In one exemplary instance, before performing matching processing on the input instruction protocol string, the method of this application embodiment further includes:
[0109] Determine the first maximum length of the instruction protocol string in the first hash table file and the second maximum length of the input / output devices in the second hash table file, respectively.
[0110] The determined first and second maximum lengths are written into the header file of the program code.
[0111] In one exemplary instance, the determination of the first and second maximum lengths in this application embodiment can be performed when generating the first and second hash table files. By writing the determined first and second maximum lengths into the header file of the program code, the maximum length of the stored hash table is dynamically implemented, facilitating the allocation of the actual required storage space during program initialization and avoiding excessive allocation of storage space or runtime exceptions due to insufficient allocated storage space. Through uniform hash preprocessing and related calculations on the PC, it is not necessary to calculate the hash values of a large number of strings during program initialization, thus reducing resource consumption during program initialization.
[0112] In one exemplary instance, after obtaining the instruction protocol hash value and the equally divided hash table, this embodiment of the application determines whether the received instruction protocol string exists in the loaded static variable data structure through a hash matching function. If the received instruction protocol string exists in the loaded static variable data structure, the match is considered successful. At this point, it is confirmed whether the hash address generated based on the instruction protocol string is valid. If the generated hash address is confirmed to be valid, the subsequent processing flow includes binding the input / output device corresponding to the instruction protocol string and outputting feedback data after the instruction protocol string is executed. If the received instruction protocol string does not exist in the loaded static variable data structure, the match is considered to have failed. In this case, the hash address is invalid, the processing flow is exited, and feedback is sent to the user: the instruction protocol string match failed, or an instruction protocol string that does not conform to the protocol specification was input. This embodiment of the application performs matching processing based on the first maximum length and the second maximum length, reducing the algorithm complexity from O(N) * O(N) to O(N / )* O(N / The overall complexity is O(N)O(N / ).
[0113] In this application embodiment, the device names, i.e. the names of the input / output devices used for user interaction, vary. Some physical input / output devices have a fixed number, such as serial ports, while the number of others dynamically expands and changes according to actual application needs, such as network ports. For each network connection, a virtual network device name is generated, and the number of network connections can reach thousands. To better manage and maintain these network devices, this application embodiment introduces string hashing for input / output devices. To match device names, the user input command protocol string is processed, and the feedback data is output as a string to the input / output device the user wants to output to.
[0114] In one exemplary instance, the input and output devices are assumed to be the same in this application embodiment. For example, if a user inputs the command VERSIONA through serial port 1, the feedback string of the command will be output through serial port 1 by default if no output device is specified. The following is the feedback data from serial port 1:
[0115] $command,versiona,response: OK*45;
[0116] #VERSIONA,37,GPS,FINE,2253,442308000,0,0,18,844;"UB4B0","R5.00Build22875","B123G125 R12E15a5bS1Z125-HRBMDF0011N1-S20-P20-A3P","-","1953506740603","2023 / 02 / 17"*66656294;
[0117] The input and output devices in this application embodiment may be different. In one exemplary instance, the LOG protocol in this application embodiment includes information about the output device, that is, the output device for outputting feedback data can be specified through the LOG protocol; for example, if the LOG protocol is input as GNGGA COM2 1 through serial port 1 (i.e. COM1), it means that GNGGA is output through output serial port 2 (i.e. COM2) at an output frequency of 1Hz. After processing the input information, the feedback data is output through serial port 2 in the form of a string.
[0118] When this application embodiment receives an instruction protocol string, it determines whether an output device is specified in the instruction protocol string. If no output device is specified, the output device is determined to be an input device. When an output device is specified in the instruction protocol string, the feedback data output after processing the instruction protocol string is output through the specified output device.
[0119] In one exemplary instance, the matching process of the instruction protocol string in this application embodiment is as follows:
[0120] For command protocol strings, whether it's a command protocol or a LOG protocol, the matching is done on the pure string; the string before the first space is the string to be recognized. For example, the command string for configuring coordinates: mode base40.078993938 116.236612846 58.0388, only the mode needs to be recognized; similarly, for a request to output a 1Hz GNGGA frequency: GNGGA COM1 1, only the GNGGA needs to be recognized.
[0121] This application embodiment can mark the input / output device of the input instruction protocol string, and the LOG protocol output will specify the corresponding IO device. In one example, the method of this application embodiment further includes hash matching between the IO device string and the device hash array. When the embedded system contains multiple IO device ports (i.e., input / output ports), this application embodiment, when identifying the input string, simultaneously determines the IO device from which the input comes, and binds the input string with the IO device identifier, so that when outputting feedback corresponding to the input, it can output to the correct IO device.
[0122] In one exemplary instance, the method of this application embodiment further includes the processing of performing step 205;
[0123] Step 205: For the instruction protocol string that has successfully matched the hash, the input / output device obtains the device ID and the unique identification number ID of the instruction protocol according to the first hash table file and the second hash table file, and processes the instruction protocol string according to the pre-set string processing function corresponding to the input / output device ID and the unique identification number ID of the instruction protocol.
[0124] In one exemplary instance, the string in the LOG protocol in this application embodiment can be fixed. In another exemplary instance, the string in the LOG protocol can be stored according to the LOG name, input / output device, and LOG frequency. In yet another exemplary instance, this application embodiment can use a splitting function to uniformly process the LOG protocol.
[0125] Considering the different numbers and types of command parameters, the command instruction strings in this embodiment are pre-set with corresponding splitting processing functions. These functions perform checks on the validity of the number of parameters, the validity of the parameter type, and the validity of the parameter value or character length. After processing by the splitting functions, a processing result is returned. This result includes concatenating an error message for invalid input or a response to correct input into an output string. This output string is also bound to the input / output device for later feedback to the user via an output function.
[0126] This application's embodiments introduce a dual-string hashing approach, combining multiple input / output device names and various instruction protocol strings input by each device, managing and maintaining the data from both the device name and input string dimensions. When compiling the embedded software firmware on the PC, a mean hashing algorithm is used to ensure the first and second hash table files are distributed as evenly as possible. During program initialization, the evenly distributed first and second hash table files are directly loaded. A trisection algorithm is introduced in the input / output device name string matching and instruction protocol string matching stages to improve matching efficiency; thus, efficient management of multiple different I / O devices and the corresponding input instruction protocol strings for each device is achieved.
[0127] In this embodiment, the string hash can be a constructed number that uniquely represents the string. The characters in this embodiment can be ASCII characters, each with a corresponding value in the ASCII table. This embodiment calculates the hash value of each string, ensuring that the hash value is unique and thus avoiding hash collisions and achieving efficient string matching. Furthermore, the string hash value enables the management and maintenance of instruction protocols and I / O devices.
[0128] The embodiments of this application improve the management efficiency of instruction protocols and enhance the flexibility of adding, deleting and modifying instruction protocols; through experimental verification, it can support the management of more than 8,000 instruction protocols.
[0129] It will be understood by those skilled in the art that all or some of the steps, systems, or apparatuses disclosed above, and their functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof. In hardware implementations, the division between functional modules / units mentioned above does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed collaboratively by several physical components. Some or all components may be implemented as software executed by a processor, such as a digital signal processor or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit (ASIC). Such software may be distributed on a computer-readable medium, which may include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.
Claims
1. A method for data matching and processing, comprising: Receive instruction protocol string; When the received instruction protocol string exists in a pre-set static variable data structure, the binding process of the input / output device corresponding to the instruction protocol string is executed; Based on the binding process performed, output the feedback data after the execution of the instruction protocol string; The static variable data structure includes a pre-loaded first hash table file and a second hash table file; the first hash table file is a file obtained by performing a hash operation on a first text file, and the first text file includes instruction protocol information; the second hash table file is a file obtained by performing a hash operation on a second text file, and the second text file includes input / output device information.
2. The method according to claim 1, characterized in that: Each line of instruction protocol information in the first text file contains one or any combination of the following fields ordered according to a first preset order: initial value of the first hash address, unique identifier ID of the instruction protocol, instruction protocol string, name of instruction protocol processing function, instruction protocol type, instructions for use of the instruction protocol, and instruction protocol example; Each line of input / output device information in the second text file contains one or any combination of the following fields ordered according to a second preset order: initial value of the second hash address, input / output device ID, input / output device string, and input / output device description.
3. The method according to claim 2, characterized in that, When the instruction protocol information in the first text file contains a unique identifier (ID) for the instruction protocol, the input / output device information in the second text file contains the input / output device ID, and the received instruction protocol string exists in a static variable data structure, the method further includes: The instruction protocol string is processed according to a pre-defined string processing function that corresponds to the input / output device ID and the unique identification number ID of the instruction protocol.
4. The method according to claim 1, characterized in that, The static variable data structure includes a pre-loaded first hash table file and a second hash table file, including: An array of more than one hash list contains a pre-loaded first hash table file and a second hash table file.
5. The method according to claim 4, characterized in that, The array of one or more hash lists includes: This is used to load the command hash list array containing the command protocol in the instruction protocol within the first hash table file; An array of LOG hash lists used to load the LOG protocol information contained in the instruction protocol within the first hash table file; A device hash array used to load the input / output device information contained in the second hash table file.
6. The method according to any one of claims 1 to 5, characterized in that, Determining whether the received instruction protocol string exists in the static variable data structure is achieved through the following steps: The first hash table file and the second hash table file in the static variable data structure are recursively divided into three equal parts to obtain the corresponding equally divided hash table; and the received instruction protocol string is hashed to obtain the corresponding instruction protocol hash value. The instruction protocol hash value is matched with the equally divided hash table to determine whether the instruction protocol string exists in the static variable data structure; Wherein, the minimum length of the equally divided hash table obtained by the first hash table file being divided into three equal parts is greater than or equal to a pre-set first maximum length, and the minimum length of the equally divided hash table obtained by the second hash table file being divided into three equal parts is greater than or equal to a pre-set second maximum length.
7. The method according to any one of claims 1 to 5, characterized in that, The hash operation process includes: Hash operations are performed based on the mean hash algorithm.
8. The method according to claim 7, characterized in that, The mean hash algorithm is implemented based on binary bitwise operations.
9. The method according to claim 7, characterized in that, The hash operation processing based on the mean hash algorithm includes: A preset prime number seed is used as the coefficient for the mean hash algorithm to perform hashing calculations.
10. The method according to claim 6, characterized in that, Before matching the instruction protocol hash value with the equally divided hash table, the method further includes: Determine the maximum length of the instruction protocol string contained in the first hash table file, and set the maximum length of the instruction protocol string as the first maximum length; Determine the maximum length of the string for the input / output device in the second hash table file, and set the maximum length of the string for the input / output device as the second maximum length; Write the first maximum length and the second maximum length into the header file.
11. The method according to any one of claims 1 to 5, characterized in that, Before outputting the feedback data after executing the instruction protocol string, the method further includes: In the instruction protocol information contained in the first text file, add an output device for output feedback data.
12. A computer storage medium storing a computer program that, when executed by a processor, implements the data matching processing method as described in any one of claims 1 to 11.
13. An input / output device, comprising: A memory and a processor, wherein the memory stores a computer program; wherein, The processor is configured to execute computer programs in memory; When the computer program is executed by the processor, it implements the data matching processing method as described in any one of claims 1 to 11.