Configuration storage method of command line and corresponding configuration reading method thereof

By parsing the command string and storing its variable parameters and callback function identifiers, it solves the problem of command line configuration storage space occupation in embedded operating systems, achieves efficient storage and reading, and reduces development complexity.

CN118796129AActive Publication Date: 2024-10-18WUXI TONGXIN HENGTONG TECH
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411010295.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-26
Publication Date
2024-10-18
Estimated Expiration
2044-07-26

AI Technical Summary

Technical Problem

In embedded operating systems, the storage method of command line configuration takes up a lot of storage space, especially complex command strings. The traditional method directly stores the entire command string, resulting in a waste of resources and redundant data.

Method used

By parsing the command string, extracting variable parameters and callback function identifiers as configuration data, only storing these data instead of the entire command string, and using an overlay storage method during storage, optimizes the storage sector allocation and reading process.

Benefits of technology

It reduces the storage space occupied, avoids the time and resource consumption caused by repeated parsing, improves the efficiency of configuration storage and reading, and reduces the difficulty of development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118796129A_ABST
    Figure CN118796129A_ABST
Patent Text Reader

Abstract

The invention discloses a configuration storage method of a command line and a corresponding configuration reading method, and relates to the technical field of command lines, the method does not directly store a whole command character string during configuration storage, but firstly performs analysis according to a target command line format corresponding to a target software module to which the command character string belongs, and then performs configuration reading according to the target command line format corresponding to the target software module to which the command character string belongs. The data of the variable parameters and the callback function identification in the command character string are extracted to serve as configuration data to be stored, and the data of the fixed parameters are not stored any more; the data of the variable parameters of the to-be-read command character string is transmitted to the callback function corresponding to the callback function identifier of the to-be-read command character string to obtain the execution result, so that the method can reduce the occupation of the storage space on the basis of ensuring correct configuration reading.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of command lines, and in particular to a command line configuration storage method and a corresponding configuration reading method. Background Art

[0002] In the field of embedded operating systems, the command line interface (CLI) is a text-based command interface between users and operating systems or applications. It provides the most basic human-computer interaction technology. Users can enter command strings through the command line interface to send instructions to the operating system, allowing the embedded operating system to perform specific tasks. Although the command line interface is not as convenient as the graphical user interface in terms of human-computer interaction, it saves more system resources of the embedded operating system and runs faster, so it is still a commonly used interaction method.

[0003] In the process of developing and applying embedded devices, it is often necessary to store the command string input by the user in the storage space of the embedded device. When needed later, it can be read from the storage space again, execute the stored command string and call the corresponding callback function to get the execution result, so that the corresponding task can be directly executed without repeatedly entering the command string every time. For example, during the operation of the switch device, sometimes there will be some problems or the user requires a new function to be added. At this time, the developer can write and store the command string of the corresponding function in the flash of the switch device. Even after the switch device is powered off or restarted, the corresponding command string can be directly read from the flash to execute to achieve the required function. At present, when storing command strings, the entire command string is generally saved in a string array, and then the string number is stored in the storage space. However, with the development of command line technology, the functions and complexity implemented by command strings are getting higher and higher. For example, currently storing a single command string may take up to 50-60 characters, so this storage method will take up a lot of storage space. Summary of the invention

[0004] In view of the above problems and technical requirements, this application proposes a command line configuration storage method. The technical solution of this application is as follows:

[0005] A command line configuration storage method, the configuration storage method comprising:

[0006] Get the input command string to be processed;

[0007] Parsing the command string to be processed according to the target command line format corresponding to the target software module to which the command string to be processed belongs in the defined and registered software module, extracting the data of the variable parameters in the command string to be processed and determining the callback function identifier corresponding to the target function of the command string to be processed as the callback function identifier of the command string to be processed; wherein the variable parameter is a parameter with different data content in different command strings belonging to the same software module, and each callback function identifier is used to uniquely identify a callback function;

[0008] The configuration data of the command string to be processed is stored in the storage space accordingly. The configuration data includes the data of the variable parameters of the command string to be processed and the callback function identifier. The data of the variable parameters of the command string to be processed is used to pass the callback function corresponding to the callback function identifier of the command string to be processed when the configuration is read to obtain the execution result of the command string to be processed.

[0009] A further technical solution is that the configuration storage method further includes:

[0010] When defining each software module, define the storage sector size of each function included in the software module;

[0011] When registering each software module, a storage sector in the storage space is allocated to each function according to the storage sector size of each function included in the software module, and the storage sector of each function is used to store configuration data of a command string having the function;

[0012] Storing the configuration data of the command string to be processed in the storage space accordingly includes: storing the configuration data of the command string to be processed in the storage sector of the target function accordingly.

[0013] A further technical solution is that the storage sectors in the storage space are allocated to each function according to the storage sector size of each function included in the software module, including:

[0014] Starting from the initial storage address of the storage space, each function is allocated its own storage sector in the order of registration of the function. When registering each function, the storage offset address is determined based on the storage sectors that have been allocated to other function functions, and the storage sector starting from the storage offset address and with the storage sector size is allocated to the currently registered function.

[0015] A further technical solution is to define the storage sector size of each function included in the software module, including:

[0016] Define the number of storage mapping units of the function and the size of each storage mapping unit, the sum of the sizes of all storage mapping units is the storage sector size of the function;

[0017] Allocating storage sectors to the function functions according to the storage sector size of the function functions includes: allocating multiple storage mapping units as storage sectors to the function functions according to the number and size of the storage mapping units of the function functions.

[0018] A further technical solution is that the configuration data of the command string to be processed is stored in the storage space correspondingly, including:

[0019] When the storage mapping unit of the target function is one, the configuration data of the command string to be processed is stored in the storage mapping unit of the target function in an overwriting storage manner;

[0020] When there are multiple storage mapping units of the target function, the configuration data of the command string to be processed is stored in one of the storage mapping units of the target function in an overwriting storage manner, and the storage mapping unit used to store the configuration data of the command string to be processed matches the configuration data of the command string to be processed.

[0021] A further technical solution is that when the function function is a first type of command with command storage requirements, the storage sector size of the defined function function is greater than 0; when the function function is a second type of command without command storage requirements, the storage sector size of the defined function function is 0; and the configuration storage method further includes:

[0022] When the target function of the command string to be processed is a first-class command, after executing the command string to be processed, a step of storing the configuration data of the command string to be processed in the storage space is performed;

[0023] When the target function of the command string to be processed is a second-category command, the process ends after the command string to be processed is executed.

[0024] A further technical solution is that the variable parameters in the command string to be processed include option parameters and value parameters, the data content of the option parameters is used to identify the target function, and the data content of the value parameters is the function parameter of the target function;

[0025] The configuration data of the command string to be processed is stored in the storage space, including:

[0026] The data of the option parameters encoded in numerical form, the data of the value-containing parameters, and the callback function identifier are stored in the storage space.

[0027] Its further technical solution is that the method for defining each software module includes: writing a command definition macro of the software module, the command definition macro of the software module includes the command line format of the software module, the callback functions of each function contained in the software module and their corresponding callback function identifiers and the storage sector size, the command line format of the software module indicates a linear linked list structure of multiple command nodes included in the command string belonging to the software module, and the node type of each command node is one of a common node, an option node and a value-containing node; in the command line format, each common node has a unique value, each option node has a plurality of different preset optional options, and the first command node of the command line format of each software module is a common node;

[0028] The configuration storage method also includes: when registering each software module, merging the command nodes in the command line format of the software module with the command nodes in the already formed command tree to update the command tree, the command tree is a tree structure formed by connecting the command nodes in the command line formats of multiple registered software modules, and the command line format of each registered software module corresponds to a command node path formed by connecting multiple command nodes in sequence in the command tree.

[0029] A further technical solution is to parse the command string to be processed according to the target command line format, including:

[0030] Taking the command node in the command tree that matches the first command node in the command string to be processed as the root node, traverse the command nodes connected to the root node in the command tree in turn to determine the command node path that matches the command string to be processed, and determine that the command node path obtained by sequentially passing through each command node from the root node matches each command node in the command string to be processed one by one; wherein, for any command node in the command string to be processed, when the value of the command node is the same as the value of an ordinary node in the command tree, it matches the ordinary node, or, when the value of the command node is the same as one of the preset optional options of the option node in the command tree, it matches the option node, or, when the value of the command node conforms to the predetermined data format of the value-containing node, it matches the value-containing node;

[0031] Extracting the value of the command node that matches the option node in the command string to be processed to obtain the data of the option parameter of the command string to be processed, and extracting the value of the command node that matches the value-containing node in the command string to be processed to obtain the data of the value-containing parameter of the command string to be processed;

[0032] The target function of the command string to be processed is determined according to the extracted data of the option parameter, and the data containing the value parameter is determined to be the function parameter of the target function, and the callback function identifier of the target function is used as the callback function identifier of the command string to be processed.

[0033] A command line configuration reading method, the configuration reading method comprising:

[0034] Obtain the data of the variable parameters of the command string to be read and the corresponding callback function identifier from the storage space;

[0035] The data of the variable parameters of the command string to be read are transmitted to the callback function corresponding to the callback function identifier of the command string to be read, so as to obtain the execution result of the command string to be read.

[0036] The beneficial technical effects of this application are:

[0037] The present application discloses a configuration storage method of a command line and a corresponding configuration reading method. The method does not directly store the entire command string, but first parses the target command line format corresponding to the target software module to which the command string belongs, so as to extract the data of the variable parameters and the callback function identifier in the command string as configuration data, and then only stores the configuration data in the command string without storing the data of the fixed parameters. Based on this configuration storage method, the occupation of storage space can be reduced on the basis of ensuring correct configuration reading. In addition, the method directly stores the configuration data obtained after parsing, so that there is no need to repeat the parsing when reading the configuration. When the configuration reading needs to be performed multiple times, the time consumption and memory resource consumption caused by repeated parsing are avoided, and the efficiency of configuration storage reading can be improved.

[0038] This method also provides a new command line integration framework, which optimizes the command line process into a convenient and unified module. By pre-defining the storage sector size of the software module, the storage sector of each software module can be automatically planned, without the need to manually calculate the specified storage address, which is more convenient and accurate. And the use of a linear linked list structure to represent the target command line format of the software module can clearly express the hierarchical structure of the command node of the software module. This method can be applied to various occasions in embedded devices that require a command line interface, and the optimization of the command line integration framework allows software developers to not care about the underlying implementation details, reducing the difficulty of development. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 It is a method flow chart of a configuration storage method according to an embodiment of the present application.

[0040] Figure 2 It is a method flow chart of a configuration reading method according to an embodiment of the present application.

[0041] Figure 3 This is a linear linked list structure diagram of the target command line format of a software module in an example.

[0042] Figure 4The diagram is a partial structural diagram of a command tree composed of target command line formats of multiple software modules in an example. DETAILED DESCRIPTION

[0043] The specific implementation of the present application is further described below in conjunction with the accompanying drawings.

[0044] This application discloses a command line configuration storage method, please refer to Figure 1 As shown in the flowchart, the configuration storage method includes the following contents:

[0045] Step 1: Get the input command string to be processed.

[0046] Step 2, parse the command string to be processed according to the target command line format corresponding to the target software module to which the command string to be processed belongs in the defined and registered software module, extract the data of the variable parameters in the command string to be processed and determine the callback function identifier corresponding to the target function function of the command string to be processed as the callback function identifier funcid of the command string to be processed. Each callback function identifier funcid is used to uniquely identify a callback function, and the corresponding callback function can be quickly obtained according to the callback function identifier funcid.

[0047] Any command string is used to implement a function. If the function belongs to a software module, then the command string belongs to the software module. The same software module can implement multiple different functions. The specific contents of the command strings belonging to the same software module but implementing different functions are different. For example, a software module is "transferring files with a TFTP server". One of the functions implemented by the software module is "downloading file source1 from TFTP server host1 and transferring it to destination1 on the local computer". The command string to implement this function can be written as tftp host1get source1 destination1. Another function implemented by the software module is "transferring file source2 on the local computer to destination2 on TFTP server host2". The command string to implement this function is tftp host2 put source2 destination2.

[0048] It can be seen from this that the specific contents of different command strings belonging to the same software module may be different, but the formats are similar. The parameters in each command string belonging to the same software module can be divided into two categories, namely fixed parameters and variable parameters. Fixed parameters are parameters with the same data content in different command strings belonging to the software module, and variable parameters are parameters with different data content in different command strings belonging to the software module. For example, in the above example, in the command string tftp host1 get source1 destination1, "tftp" is a fixed parameter, and its data content is the same in other command strings belonging to the software module. However, "host1", "get", "source1", and "destination1" are variable parameters, and their data content in other command strings belonging to the software module may be different.

[0049] Further, the variable parameters in the command string can be divided into option parameters and value-containing parameters, wherein the data content of the option parameters is used to distinguish different function functions, and each command string belonging to the software module contains one or more option parameters. The data content of the option parameters in multiple command strings belonging to the same software module and realizing the same function function is the same, and the data content of at least one option parameter in multiple command strings belonging to the same software module but realizing different function functions is different. Option parameters generally have multiple different preset optional options, and the data content of the option parameters in each command string belonging to the software module can only be one of the preset optional options. Value-containing parameters are function parameters that need to be passed to the function function implemented by the command string. The function parameters of a function function generally also have a specific value range or numerical format. Therefore, although the value-containing parameters do not have clear preset optional options like option parameters, the data content of the value-containing parameters also has a predetermined data format. Therefore, the data of the option parameters in the command strings belonging to the same software module but realizing different function functions are different, and the data of the option parameters in the command strings realizing the same function function are the same, but the value-containing parameters can be different.

[0050] For example, in the above example, for the four variable parameters "host1", "get", "source1", and "destination1", "get" is an option parameter, which has two different preset optional options, get and put, which are used to distinguish two different function functions belonging to the software module. The data content of the option parameter in different command strings belonging to the software module is either get or put, and not the other way around. "host1", "source1", and "destination1" are value-containing parameters.

[0051] Step 3: store the configuration data of the command string to be processed in the storage space accordingly. The configuration data of the command string to be processed includes the data of the variable parameters of the command string to be processed and the callback function identifier.

[0052] For any command string, the command string must contain fixed parameters and variable parameters respectively, and the variable parameters contained therein may be at least one of option parameters and value-containing parameters. When the command string to be processed contains both option parameters and value-containing parameters, when extracting the data of the variable parameters in the command string to be processed, the data of the option parameters and the data of the value-containing parameters in the command string to be processed are extracted and stored respectively. In addition, in one embodiment, since the data of the option parameters are often in the form of strings, when storing the data of the option parameters in the command string to be processed, the data of the option parameters are encoded into a numerical form before being stored.

[0053] According to the traditional configuration storage method, the entire command string to be processed will be stored in the storage space, that is, the data of the fixed parameters and the data of the variable parameters in the command string to be processed will be stored in the storage space, which will occupy more storage space. According to the configuration storage method of the present application, only the callback function identifier of the command string to be processed and the data of the more important variable parameters are stored in the storage space, and the data of the fixed parameters in the command string to be processed are no longer stored, which greatly reduces the occupation of the storage space, avoids the repeated storage of the fixed parameter data, and reduces the redundancy of data storage.

[0054] Corresponding to the configuration storage method of this application, this application also provides a command line configuration reading method, please refer to Figure 2 As shown in the flowchart, the configuration reading method includes the following steps:

[0055] Step 1: Obtain the data of the variable parameters of the command string to be read and the corresponding callback function identifier from the storage space.

[0056] Step 2: The variable parameter data of the command string to be read is passed into the callback function corresponding to the callback function identifier of the command string to be read to obtain the execution result of the command string to be read.

[0057] Based on the traditional configuration storage method, each time the configuration is read, the entire stored command string to be processed needs to be read out, and then the key information in the command string is extracted through command parsing and passed into the corresponding callback function to obtain the execution result. The data that needs to be passed into the callback function each time the configuration is read is mainly the data of the variable parameters in the command string to be processed. However, the present application has already completed the parsing of the command string to be processed and extracted the data of the variable parameters for storage in the configuration storage stage. Therefore, when the configuration is read later, the data of the variable parameters of the command string to be processed is directly read from the storage space and passed into the callback function corresponding to the callback function identifier funcid of the command string to be processed, and the execution result of the command string to be processed can also be obtained. Therefore, the method of the present application can reduce the occupation of storage space on the basis of ensuring accurate execution results and realizing configuration reading. In addition, in actual application, the command string to be processed may need to be configured and read multiple times. Based on the traditional configuration storage method, each time the configuration is read, it is necessary to repeatedly extract the required data from the command string to be processed and pass it into the corresponding callback function. The present application completes the parsing operation in the configuration storage stage. Each time the configuration is read, what is read directly from the storage space is the data of the variable parameters in the command string to be processed, without the need for additional parsing. In the scenario of multiple configuration readings, this method can also reduce the time consumption and memory resource consumption of configuration reading.

[0058] It can be seen from the above introduction that the configuration storage method of the present application needs to use the command line format of the software module that has been defined and registered. Therefore, the present application does not simply optimize the method of the configuration storage process, but also needs to adaptively optimize the definition and registration process of the software module before the configuration storage. Therefore, the present application actually designs a new command line integration framework. The command framework design process is introduced in order in the following embodiments:

[0059] 1. Definition of Software Module

[0060] When defining, write the command definition macro CLI_ITEM of the software module for unified definition. One software module only needs to define one command definition macro CLI_ITEM to complete the development. Use C language macro to uniformly define each software module, which is easy to use and has a simple interface.

[0061] The command definition macro CLI_ITEM of a software module at least includes the command line format of the software module, the callback functions of each function contained in the software module and their corresponding callback function identifiers funcid. In addition, the command definition macro CLI_ITEM of the software module can also include the name of the software module and some reserved fields for subsequent information expansion.

[0062] The command line format of a software module indicates a linear linked list structure of multiple command nodes included in a command string belonging to the software module. The linear linked list structure indicates the order of arrangement between the command nodes. The operation of dividing a command string into multiple command nodes can be completed using existing methods, and this embodiment will not be repeated. The node type of each command node in the command line format of the software module is one of a common node, an option node, and a value-containing node. In the command line format, each common node has a unique value, each option node has multiple different preset optional options and the preset optional options can be empty. Each function implemented by the software module corresponds to a combination of preset optional options of all option nodes, and the value-containing node has a predetermined data format. The first command node in the command line format of each software module is a common node.

[0063] For example, in the above example, for the software module "transfer files with TFTP server", the command line format of the software module is defined as tftp[host](GET|PUT)[source](destination|NULL), where () represents option nodes and "|" separates multiple preset optional options, [] represents value-containing nodes, and NULL indicates that the data content of the option node can be empty. The linear linked list structure indicated by the command line format is as follows: Figure 3 As shown, different command nodes are connected in series in the order of arrangement, including the common node tftp, the value node host, the option node GET|PUT, the value node source, and the option node destination|NULL. Figure 3 Ordinary nodes are represented by circular solid-line frames, option nodes are represented by square frames, and value-containing nodes are represented by circular dotted-line frames.

[0064] For another example, the command line format defined for another software module is written as ethtrunk 1 (trunkport | lacp) interface [ge1]. The software module uses two preset optional options trunkport and lacp of the option node (trunkport | lacp) to distinguish two different functions implemented by the software module. One function implemented by the software module is "adding port ge1 to static aggregation group 1" and the command string format is ethtrunk1trunkport interface ge1. Another function implemented by the software module is "adding port ge1 to dynamic aggregation group 1" and the command string format is ethtrunk 1lacp interface ge1.

[0065] In another embodiment, when defining each software module, the storage sector size corresponding to each function included in the software module is also defined, and the command definition macro CLI_ITEM written into the software module also includes the storage sector size of each function implemented by the software module. Different functions have different characteristics and different storage requirements. When the function is a first-class command with command storage requirements, the storage sector size of the function is defined to be greater than 0. The first-class command needs to be stored after execution, so it is necessary to allocate a storage sector of a corresponding size to it for storing the configuration data of the command string. When the function is a second-class command that does not have a command storage requirement, the storage sector size of the function is defined to be 0. For example, for display commands such as display and show, it does not need to store records after execution, so there is no need to allocate an area for storage.

[0066] Even for the function functions belonging to the first category of commands, different function functions have different storage requirements. Some function functions can only store one function parameter, while some function functions can store multiple function parameters at the same time. Based on this, in one embodiment, when defining the storage sector size of a function function, it includes defining the number cmdnum of storage mapping units of the function function and the size cmdsize of each storage mapping unit. The sum of the sizes of all storage mapping units allocated to the function function is the storage sector size of the function function. In actual application, the number cmdnum of storage mapping units for a function function is generally defined to be equal to the number of function parameters of the function function, and also equal to the number of values ​​of the value-containing parameters, that is, a storage mapping unit is defined and allocated to different function parameters of a function function respectively, so that different function parameters of a function function can be stored in their respective storage mapping units. For example, if a function is vlan[INT], the value of the value node INT can be any one of 1, 2, 3, 4, and 5, then the number of storage mapping units cmdnum defined for the function is 5, and each storage mapping unit corresponds to a value of the value node INT. One storage mapping unit is used to store vlan 1, and another storage mapping unit is used to store vlan 2. The same applies to other storage mapping units. Based on the above content, the command definition macro CLI_ITEM of a software module defines the following content:

[0067] (1)cliname##_help[] string array: This string array is used to store help information for command strings.

[0068] (2)cli##cliname: A command structure of type cli_item_t, which contains the command line format, the callback function identifier funcid of each function, the pointer of the callback function and help information. Cliname is the name of the command structure and also the name of the software module.

[0069] (3) conf_set##funcid[] character array: This character array is used to record the storage sector size of each function contained in the software module.

[0070] (4) Init##funcid() constructor, used to register the function functions contained in the software module and set the storage sector of the function functions when the program starts.

[0071] By only defining the command definition macro CLI_ITEM of the software module and implementing the corresponding callback function, the development of a function contained in the software module can be realized, avoiding the concern for the underlying implementation details.

[0072] 2. Registration of software modules

[0073] Refer to the definition of the command definition macro CLI_ITEM of the software module. The command structure is defined as cli_item_tcli##cliname. Through the function cli_register(&cli##cliname), all cli_item_t are stored and represented in a linked list. cli_register is used as a registration function to add all cli_item_t to the function entry.

[0074] The function definition of the software module does not have a registration entry. By taking advantage of the characteristics of the compiler, the registration function does not need to be called separately at the entrance of the main function for initialization. __attribute__((constructor)) is a feature in GCC and compatible compilers, which is used to instruct the compiler to mark a function as an initialization function that is automatically executed when the program starts. This embodiment uses this feature to allow the marked related initialization function to run automatically before the main function, avoiding the need to explicitly add a registration function similar to cli_register to the program initialization process.

[0075] As defined in the command definition macro CLI_ITEM of the software module above, the corresponding storage sector size is defined for each function included in the software module. Therefore, when registering each software module, the storage sector in the storage space can be automatically allocated to each function implemented by the software module according to the storage sector size of the function. The storage sector of each function is used to store the configuration data of the command string with the function. That is, when the configuration data of the command string to be processed is stored in the storage space, it can be stored in the storage sector of the target function of the command string to be processed.

[0076] In one embodiment, the method of allocating a storage sector in a storage space to each function includes: starting from the initial storage address of the storage space, allocating respective storage sectors to each function in turn according to the registration order of the function. When registering each function, the current storage offset address is determined according to the storage sectors already allocated to other functions, and then the storage sector starting from the storage offset address and having the storage sector size is allocated to the currently registered function.

[0077] When the number cmdnum of storage mapping units of a function and the size cmdsize of each storage mapping unit are defined, when allocating storage sectors to the function, multiple storage mapping units are allocated to the function as storage sectors according to the number and size of the storage mapping units of the function, that is, starting from a determined storage offset address, each storage mapping unit has a storage sector consisting of multiple storage mapping units of corresponding size allocated to the function.

[0078] In traditional practices, when a command string needs to be stored, one approach is to manually specify the storage address of each command string, and then store the command string at its corresponding storage address. However, in reality, there are a large number of command strings, and it is difficult and error-prone to manually specify the storage address of each command string. Another approach is to not fix the storage address of each command string, and then store each command string in sequence. This approach does not require manual specification of the storage address of each command string, but in actual operation, the same command string may be obtained multiple times. According to this method, it will be stored multiple times, resulting in the problem of repeated storage and it is actually difficult to determine whether there is duplication.

[0079] The present application defines the storage sector of each function in the definition stage, and then can automatically calculate and determine the storage sector of each function in the registration stage, thereby fixing the storage address of the command string of each function without the need for manual calculation and specification, which is conducive to improving storage accuracy and efficiency.

[0080] In addition, in the command line integration framework, there is not only one software module, and each software module has its own command line format. In one embodiment, a command tree is generated according to the command line format of the registered software module. The command tree is a tree structure formed by connecting the command nodes in the command line formats of multiple registered software modules. The command line format of each registered software module corresponds to a command node path formed by connecting multiple command nodes in sequence in the command tree.

[0081] In actual use, there will be common command nodes in the command line formats of different software modules. When registering each software module, the command nodes in the command line format of the currently registered software module will be automatically merged with the command nodes in the command tree that has been formed to update the command tree. The same command nodes will be merged, and the command line format of each registered software module corresponds to a command node path in the command tree, and this correspondence is known.

[0082] For example, Figure 4 In the command tree, the command line format of the registered software module 1 is A(B|C)[INT], the command line format of the registered software module 2 is A(B|C)D[INT], and the command line format of the registered software module 3 is ABDE. These three software modules share the common node A. In addition, software module 1 and software module 2 also share the option node (B|C). The partial structure of these three software modules in the command tree is as follows: Figure 4 As shown, the three command node paths starting from the common node A correspond to three different software modules. In fact, when more software modules are defined, the structure of the command tree is more complicated, and there will be more command nodes shared between different software modules, but they are all constructed in the same way. Therefore, developers only need to use command node paths to represent a software module and execute it. Different software modules can be directly represented by different command node paths, and the command tree can be automatically merged and updated without manually adding and setting the relationship between different command nodes in the command tree.

[0083] 3. Command string parsing and configuration storage

[0084] After obtaining any input command string to be processed, first match the command string to be processed with the command node path in the command tree, including:

[0085] The command node in the command tree that matches the first command node in the command string to be processed is taken as the root node, and the first command node in the command string to be processed is always a common node. Then, each command node connected to the root node in the command tree is traversed in sequence to determine the command node path that matches the command string to be processed, and each command node that the command node path determined in this way passes through in sequence from the determined root node is matched one by one with each command node in the command string to be processed.

[0086] Among them, for any command node in the command string to be processed, when the value of the command node in the command string to be processed is the same as the value of the ordinary node in the command tree, it matches the ordinary node; or, when the value of the command node in the command string to be processed is the same as one of the preset optional options of the option node in the command tree, it matches the option node; or, when the value of the command node in the command string to be processed conforms to the predetermined data format of the value-containing node, it matches the value-containing node.

[0087] For example, based on Figure 4 The command tree partial structure shown, when a pending command string is received as AB D123, the value of the first command node of the pending command string is A, which matches the common node A in the command tree, so the common node A is used as the root node. Then the command nodes under the root node are traversed in sequence. The value of the second command node of the pending command string is B, which is the same as the common node B in the command tree and therefore matches, and it is the same as a preset optional option in the option node B|C in the command tree and therefore matches. The value of the third command node that continues to traverse the pending command string is D, which is the same as the common node D in the command tree and therefore matches. Finally, the value of the fourth command node that traverses the pending command string is 123, and the command node conforms to the predetermined data format of the value-containing node INT and therefore matches the value-containing node INT. Thus, it can be finally determined that the command node path matched by the pending command string is A(B|C)D[INT], so the target software module corresponding to the pending command string is software module 2. In the above matching process, it can be determined that the second command node in the command string to be processed matches the option node, and the fourth command node in the command string to be processed matches the value-containing node according to the target command line format indicated by the command node path A(B|C)D[INT].

[0088] Then, the value of the command node matching the option node in the command string to be processed is extracted to obtain the data of the option parameter of the command string to be processed, and the value of the command node matching the value-containing node in the command string to be processed is extracted to obtain the data of the value-containing parameter of the command string to be processed.

[0089] Since the data of the option parameter is used to identify the function, the target function of the command string to be processed can be determined based on the extracted data of the option parameter, and the data containing the value parameter is determined to be the function parameter of the target function. Each function defines a callback function and a callback function identifier funcid when it is defined, so the callback function identifier of the target function can be determined as the callback function identifier of the command string to be processed.

[0090] After determining the target function of the command string to be processed, its command type can also be determined. One approach is to use the callback function identifier funcid to represent the command type, such as funcid>0 to represent the first type of command, and funcid<0 to represent the second type of command. Regardless of the representation method used, when it is determined that the target function of the command string to be processed is a first type of command, the configuration storage method of the present application can be executed, the command string to be processed is parsed according to the target command line format, and subsequent configuration storage operations are performed. When the target function of the command string to be processed is a second type of command, the execution of the command string to be processed ends, and the configuration storage operation is no longer performed.

[0091] When the target function is a first-class command, when the configuration data of the command string to be processed is stored in the storage sector corresponding to the target function, the implementation method is as follows: when the target function has one storage mapping unit, the configuration data of the command string to be processed is stored in the storage mapping unit of the target function by overwriting storage. When the target function has multiple storage mapping units, the configuration data of the command string to be processed is stored in one of the storage mapping units of the target function by overwriting storage, and the storage mapping unit for storing the configuration data of the command string to be processed matches the configuration data of the command string to be processed, specifically, corresponds to the function parameter of the data identifier of the value-containing parameter of the command string to be processed.

[0092] For example, a storage mapping unit A is allocated to the only function (the command string with the function is ABDE) contained in the software module 3 (the command line format is ABDE) in the example above. When a command string 11 that implements the software module 1 is obtained as ABDE, the configuration data of the command string 11 is stored in the storage mapping unit A. When another command string 12 that implements the software module 1 is obtained as ABDE next time, the configuration data of the command string 12 is stored in the storage mapping unit A to overwrite the configuration data of the command string 11.

[0093] For another example, a function function (a command string having the function function is ABD[INT]) of the software module 2 (the command line format is ABD[INT]) in the above example is allocated to the storage mapping unit B, and another function function (a command string having the function function is ACD[INT]) included in the software module is allocated to the storage mapping unit C and the storage mapping unit D respectively. Then, when a command string 21 of the software module 2 is obtained as ABD 123, the configuration data of the command string 21 is stored in the storage mapping unit B. When another command string 22 implementing the software module 2 is obtained as ACD 123, the configuration data of the command string 22 is stored in the storage mapping unit C. Next time, when another command string 23 implementing the software module 2 is obtained as ACD 234, the configuration data of the command string 23 is stored in the storage mapping unit D.

[0094] 4. Configuration reading of command strings stored in storage space

[0095] When it is necessary to configure and read a command string to be read, the configuration data of the command string to be read is read from the storage sector corresponding to the software module possessed by the command string to be read, and the read configuration data includes the data of the variable parameters and the corresponding callback function identifier funcid, and the data of the variable parameters includes the data of the option parameters and / or the data of the value-containing parameters. As described above, when the command string to be processed is stored, it will be stored in a storage mapping unit that matches the configuration data of the command string to be processed, so the configuration data can be read from the storage mapping unit corresponding to the command string to be read, and this embodiment will not be described in detail. Then, the callback function can be determined according to the callback function identifier funcid, and then the data of the variable parameters can be passed into the callback function to obtain the execution result of the command string to be read.

[0096] The above is only a preferred embodiment of the present application, and the present application is not limited to the above embodiments. It is understood that other improvements and changes directly derived or associated by those skilled in the art without departing from the spirit and concept of the present application should be considered to be included in the protection scope of the present application.

Claims

1. A command line configuration storage method, It is characterized in that The configuration storage method comprises: Get the input command string to be processed; Parsing the command string to be processed according to the target command line format corresponding to the target software module to which the command string to be processed belongs in the defined and registered software module, extracting the data of the variable parameters in the command string to be processed and determining the callback function identifier corresponding to the target function of the command string to be processed as the callback function identifier of the command string to be processed; wherein the variable parameter is a parameter with different data content in different command strings belonging to the same software module, and each callback function identifier is used to uniquely identify a callback function; The configuration data of the command string to be processed is stored in the storage space accordingly, and the configuration data includes the data of the variable parameters of the command string to be processed and the callback function identifier. The data of the variable parameters of the command string to be processed is used to pass the callback function corresponding to the callback function identifier of the command string to be processed when the configuration is read to obtain the execution result of the command string to be processed.

2. The configuration storage method according to claim 1, It is characterized in that The configuration storage method also includes: When defining each software module, define the storage sector size of each function included in the software module; When registering each software module, a storage sector in the storage space is allocated to each function according to the storage sector size of each function included in the software module, and the storage sector of each function is used to store configuration data of a command string having the function; Storing the configuration data of the command string to be processed in the storage space accordingly includes: storing the configuration data of the command string to be processed in the storage sector of the target function accordingly.

3. The configuration storage method according to claim 2, It is characterized in that The allocating storage sectors in the storage space to each function according to the storage sector size of each function included in the software module comprises: Starting from the initial storage address of the storage space, each function is allocated its own storage sector in turn according to the registration order of the function. When registering each function, the storage offset address is determined based on the storage sectors that have been allocated to other function functions, and the storage sector starting from the storage offset address and having the storage sector size is allocated to the currently registered function.

4. The configuration storage method according to claim 2, It is characterized in that Defining the storage sector size of each function included in the software module, including: The number of storage mapping units of the function and the size of each storage mapping unit are defined, and the sum of the sizes of all storage mapping units is the storage sector size of the function; Allocating storage sectors to the function function according to the storage sector size of the function function includes: allocating multiple storage mapping units as storage sectors to the function function according to the number and size of the storage mapping units of the function function.

5. The configuration storage method according to claim 4, It is characterized in that The configuration data of the command string to be processed is stored in the storage space correspondingly including: When the storage mapping unit of the target function is one, the configuration data of the command string to be processed is stored in the storage mapping unit of the target function in an overwriting storage manner; When there are multiple storage mapping units of the target function, the configuration data of the command string to be processed is stored in one of the storage mapping units of the target function in an overlay storage manner, and the storage mapping unit for storing the configuration data of the command string to be processed matches the configuration data of the command string to be processed.

6. The configuration storage method according to claim 2, It is characterized in that When the function is a first-class command with command storage requirements, the storage sector size of the function is defined to be greater than 0; when the function is a second-class command without command storage requirements, the storage sector size of the function is defined to be 0; The configuration storage method also includes: When the target function of the command string to be processed is a first-class command, after executing the command string to be processed, the step of storing the configuration data of the command string to be processed in the storage space is performed; When the target function of the command string to be processed is a second-category command, the process ends after executing the command string to be processed.

7. The configuration storage method according to claim 2, It is characterized in that The variable parameters in the command string to be processed include option parameters and value-containing parameters, the data content of the option parameters is used to identify the target function, and the data content of the value-containing parameters is the function parameter of the target function; The step of storing the configuration data of the command character string to be processed in the storage space includes: The data of the option parameters encoded in numerical form, the data of the value-containing parameters, and the callback function identifier are stored in the storage space.

8. The configuration storage method according to claim 7, It is characterized in that The method for defining each software module comprises: writing a command definition macro of the software module, wherein the command definition macro of the software module comprises a command line format of the software module, callback functions of various function functions contained in the software module and their corresponding callback function identifiers, and a storage sector size, wherein the command line format of the software module indicates a linear linked list structure of a plurality of command nodes included in a command string belonging to the software module, wherein the node type of each command node is one of a common node, an option node, and a value-containing node; in the command line format, each common node has a unique value, each option node has a plurality of different preset optional options, and the first command node of the command line format of each software module is a common node; The configuration storage method also includes: when registering each software module, merging the command node in the command line format of the software module with the command node in the already formed command tree to update the command tree, wherein the command tree is a tree structure formed by connecting the command nodes in the command line formats of multiple registered software modules, and the command line format of each registered software module corresponds to a command node path formed by connecting multiple command nodes in sequence in the command tree.

9. The configuration storage method according to claim 8, It is characterized in that Parsing the command string to be processed according to the target command line format includes: Taking the command node in the command tree that matches the first command node in the command string to be processed as the root node, traverse the command nodes in the command tree connected to the root node in turn to determine the command node path that matches the command string to be processed, and determine that the command node path obtained by sequentially passing through each command node from the root node matches each command node in the command string to be processed one by one; wherein, for any command node in the command string to be processed, when the value of the command node is the same as the value of an ordinary node in the command tree, it matches the ordinary node, or, when the value of the command node is the same as one of the preset optional options of the option node in the command tree, it matches the option node, or, when the value of the command node conforms to the predetermined data format of the value-containing node, it matches the value-containing node; Extracting the value of the command node that matches the option node in the command string to be processed to obtain the data of the option parameter of the command string to be processed, and extracting the value of the command node that matches the value-containing node in the command string to be processed to obtain the data of the value-containing parameter of the command string to be processed; The target function of the command string to be processed is determined based on the extracted data of the option parameters, and the data containing the value parameters is determined to be the function parameters of the target function, and the callback function identifier of the target function is used as the callback function identifier of the command string to be processed.

10. A command line configuration reading method, It is characterized in that The configuration reading method comprises: Obtain the data of the variable parameters of the command string to be read and the corresponding callback function identifier from the storage space; The data of the variable parameters of the command string to be read are transmitted to the callback function corresponding to the callback function identifier of the command string to be read, so as to obtain the execution result of the command string to be read.

Citation Information

Patent Citations

  • Command parameter transmission method and device, electronic equipment and storage medium

    CN116010124A

  • Method and apparatus for interacting with runnung software

    EP2634693A1

  • System and method for merging manual parameters with predefined parameters

    US20070078882A1