JSON-based parameter storage method, apparatus and device, and storage medium
Through the JSON-based parameter storage method, the system parameters are written into nonvolatile memory in JSON data format, which solves the problems of poor scalability and difficult development when storing system parameter variables in the prior art, and achieves higher readability and scalability, reducing maintenance costs.
Patent Information
- Application Number
- CN202411543838.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-02-28
AI Technical Summary
In the prior art, poor scalability and difficulty in developing when storing system parameter variables, resulting in strong coupling of storage structures and high maintenance costs.
The JSON-based parameter storage method is adopted, and the parameter data to be confirmed is obtained by receiving the write parameter command, and compared it with the system parameter data stored in the nonvolatile memory. If the parameter names are the same, it is written to the nonvolatile memory in the JSON data format.
It improves the readability and scalability of system parameters, reduces the coupling between storage structure and MCU system variables, and reduces the difficulty of development and maintenance costs.
Smart Images

Figure CN119537457A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of computer data storage, and in particular to a JSON-based parameter storage method, apparatus, device, and storage medium. Background Art
[0002] With the development of technology, the parameters stored in the embedded field are becoming more and more numerous and complex, and the readability of the parameters is required to be higher and higher. For the storage of microcontroller unit (MCU) parameters or other types of parameters, the existing solution is to store the original hexadecimal data directly into non-volatile memory (NVM). This method has poor readability and scalability, and adds additional costs to the later maintenance of the project. Figure 1 As shown in the figure, the order of parameter definitions in the MCU system and NVM must correspond one by one, which leads to a strong coupling between the stored MCU system variables and the storage structure. Developers need to have an in-depth understanding of the stored data to prevent data structure mismatches during version iteration, which increases the difficulty of development. Summary of the invention
[0003] The present invention provides a parameter storage method, device, equipment and storage medium based on JSON to solve the problems of poor scalability and difficult development when storing system parameter variables in the prior art.
[0004] According to one aspect of the present invention, a JSON-based parameter storage method is provided, the method comprising:
[0005] receiving a write parameter command, and obtaining parameter data to be confirmed according to the write parameter command;
[0006] Acquire first parameter data stored in a non-volatile memory; data in the first parameter data is a system parameter;
[0007] The data in the parameter data to be confirmed that is consistent with the parameter name of the first parameter data is written into the non-volatile memory in JSON data format.
[0008] According to another aspect of the present invention, a JSON-based parameter storage device is provided, the device comprising:
[0009] A receiving module, used for receiving a write parameter command, and obtaining parameter data to be confirmed according to the write parameter command;
[0010] An acquisition module, used for acquiring first parameter data stored in a non-volatile memory; the data in the first parameter data is a system parameter;
[0011] A writing module is used to write the data in the parameter data to be confirmed that is consistent with the parameter name of the first parameter data into the non-volatile memory in JSON data format.
[0012] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising: at least one processor; and
[0013] a memory communicatively connected to the at least one processor; wherein,
[0014] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the JSON-based parameter storage method described in any embodiment of the present invention.
[0015] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the JSON-based parameter storage method described in any embodiment of the present invention when executed.
[0016] The JSON-based parameter storage method, device, equipment and storage medium of the embodiment of the present invention include: receiving a write parameter command, obtaining parameter data to be confirmed according to the write parameter command; obtaining first parameter data stored in a non-volatile memory; the data in the first parameter data is a system parameter; writing the data in the parameter data to be confirmed that is consistent with the parameter name of the first parameter data into the non-volatile memory in JSON data format. When writing parameters, the method writes the parameters in JSON data format, which can improve the readability and scalability of system parameters, and solves the problems of poor scalability and difficult development when storing system parameter variables in the prior art.
[0017] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0019] Figure 1 A schematic diagram of a method for storing system parameters provided by the prior art;
[0020] Figure 2 A schematic diagram of a JSON-based parameter storage method provided in Example 1 of the present invention;
[0021] Figure 3 A flow chart of a parameter storage method based on JSON provided in Embodiment 2 of the present invention;
[0022] Figure 4 A schematic diagram of a JSON-based parameter storage method provided in Embodiment 3 of the present invention;
[0023] Figure 5 A schematic diagram of a flow chart of storage system parameters provided by an embodiment of the present invention;
[0024] Figure 6 A schematic diagram of storage of system parameters provided by an embodiment of the present invention;
[0025] Figure 7 A schematic diagram of a process for reading system parameters provided by an embodiment of the present invention;
[0026] Figure 8 A schematic diagram of the structure of a JSON-based parameter storage device provided in Embodiment 4 of the present invention;
[0027] Fig. 9 Schematic diagram of the structure of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiment of the present invention. Obviously, the described embodiment is only an embodiment of a part of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work should belong to the scope of protection of the present invention. It should be understood that the various steps recorded in the method implementation of the present invention can be performed in different orders and / or in parallel. In addition, the method implementation may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.
[0029] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0030] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, any variations of the terms "including" and "having" are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0031] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0032] The names of the messages or information exchanged between multiple devices in the embodiments of the present invention are only used for illustrative purposes, and are not used to limit the scope of these messages or information.
[0033] Embodiment 1
[0034] Figure 2 A flow chart of a JSON-based parameter storage method provided in Embodiment 1 of the present invention is provided. The method can be applied to the case where system parameters that need to be written in the memory are stored in the non-volatile memory. The method can be executed by a JSON-based parameter storage device, wherein the device can be implemented by software and / or hardware and is generally integrated on an electronic device. In this embodiment, the electronic device includes but is not limited to: computers and other devices.
[0035] like Figure 2 As shown, a parameter storage method based on JSON provided in Embodiment 1 of the present invention includes the following steps:
[0036] S110: Receive a write parameter command, and obtain parameter data to be confirmed according to the write parameter command.
[0037] The write parameter command may be a command for writing parameters, and the write parameter command may include the parameters to be written. The parameter data to be confirmed may be extracted from the write parameter command, and whether the parameters can be written needs to be confirmed.
[0038] In this embodiment, after receiving the write parameter command, the write parameter command may be analyzed to parse out parameter data in the write parameter command as the parameter data to be confirmed.
[0039] Furthermore, the method of this embodiment can be specifically applied to MCU system parameter storage without a file system. A file system is a method and data structure used by an operating system to specify files on a storage device or partition, that is, a method for organizing files on a storage device.
[0040] S120, acquiring first parameter data stored in a non-volatile memory; the data in the first parameter data is a system parameter.
[0041] Among them, the non-volatile memory may refer to a memory in which the stored data does not disappear when the current is turned off. The data in the first parameter data may include system parameters. System parameters may refer to variables related to system status, functions, and behaviors. For example, when the scenario of storing parameters is on a vehicle, the system parameters may include vehicle identity information, configuration parameters, performance parameters, electrical system parameters, and safety parameters of the vehicle.
[0042] In this embodiment, all system parameters stored in the non-volatile memory may be acquired and the system parameters may be used as the first parameter data.
[0043] S130. Writing the data in the to-be-confirmed parameter data that is consistent with the parameter name of the first parameter data into the non-volatile memory in JSON data format.
[0044] The parameter name may be a unique ID or meaning for identifying the storage parameter. JSON (JavaScript Object Notation) is a lightweight data exchange format that uses text representation to store and transmit structured data.
[0045] In this embodiment, when storing the parameters that need to be written, it is necessary to first determine whether the parameters in the parameter data to be confirmed exist in the non-volatile memory, that is, to determine whether the parameter is a system parameter; specifically, the parameter name of the parameter data to be confirmed can be compared with the parameter name of the first parameter data. If they are consistent, the parameter data to be confirmed can be written into the non-volatile memory in JSON data format; otherwise, it means that the parameter is not a system parameter and will not be stored.
[0046] A JSON-based parameter storage method provided in a first embodiment of the present invention includes: receiving a parameter write command, obtaining parameter data to be confirmed according to the parameter write command; obtaining first parameter data stored in a non-volatile memory; the data in the first parameter data is a system parameter; and writing the data in the parameter data to be confirmed that is consistent with the parameter name of the first parameter data into the non-volatile memory in the JSON data format. When writing parameters, the method writes the parameters in the JSON data format, which can improve the readability and scalability of the system parameters and solve the problems of poor scalability and difficult development when storing system parameter variables in the prior art.
[0047] Based on the above embodiment, a variant embodiment of the above embodiment is proposed. It should be noted that in order to make the description concise, only the differences from the above embodiment are described in the variant embodiment.
[0048] In one embodiment, the obtaining of the parameter data to be confirmed according to the write parameter command includes: parsing the write parameter command to obtain the parsed parameter data in the write parameter command; using the parsed parameter data as the parameter data to be confirmed; wherein the parsed parameter data includes a parameter name and a parameter value corresponding to the parameter name.
[0049] The parsed parameter data may include the parameter name of the parameter and the parameter value corresponding to the parameter name. The parameter value may be the actual physical value of the parameter data.
[0050] In this embodiment, the write parameter command can be parsed to obtain the parsed parameter data in the write parameter command, and the parsed parameter data is used as the parameter data to be confirmed. In this embodiment, the parameter data to be stored can be obtained by parsing the write parameter command.
[0051] Embodiment 2
[0052] Figure 3 This is a flow chart of a JSON-based parameter storage method provided in the second embodiment of the present invention. The second embodiment is optimized on the basis of the above embodiments. For details not yet provided in this embodiment, please refer to the first embodiment.
[0053] like Figure 3 As shown, a JSON-based parameter storage method provided in Embodiment 2 of the present invention includes the following steps:
[0054] S210: Receive a write parameter command, and obtain parameter data to be confirmed according to the write parameter command.
[0055] S220, obtaining first parameter data stored in a non-volatile memory; the data in the first parameter data is a system parameter.
[0056] S230: Use the data in the parameter data to be confirmed that is consistent with the parameter name of the system parameter in the first parameter data as the parameter data to be written.
[0057] The parameter data to be written may be system parameters that have been confirmed to exist in the NVM and need to be written into the NVM.
[0058] In this embodiment, when data with the same parameter name as the parameter data to be confirmed is found in the first parameter data, the data can be used as the parameter data to be written.
[0059] S240. Convert the data format of the parameter data to be written into the JSON data format through a JSON parser.
[0060] Among them, the JSON parser can transform the input string back into an object of a familiar type.
[0061] In this embodiment, the data format of the parameter data to be written may be converted into the JSON data format by a JSON parser.
[0062] S250: Write the converted parameter data to be written into the non-volatile memory.
[0063] In this embodiment, the parameter data to be written after the format conversion can be directly written into the non-volatile memory.
[0064] A JSON-based parameter storage method provided in the second embodiment of the present invention specifically writes the data in the parameter data to be confirmed that is consistent with the parameter name of the first parameter data into the non-volatile memory in the JSON data format, including: using the data in the parameter data to be confirmed that is consistent with the parameter name of the system parameter in the first parameter data as the parameter data to be written; converting the data format of the parameter data to be written into the JSON data format through a JSON parser; and writing the converted parameter data to be written into the non-volatile memory. By storing the system parameters in the JSON data format, this method can improve the readability and scalability of the system parameters, and solves the problems of poor scalability and difficult development when storing system parameter variables in the prior art.
[0065] In one embodiment, converting the data format of the parameter data to be written into the JSON data format through a JSON parser includes: creating an entity object through an entity creation interface; and adding parameters in the parsed parameter data to the entity object through a parameter addition interface.
[0066] The entity creation interface may be an interface for creating an entity object, and the parameter adding interface may be an interface for adding parameters to an entity object.
[0067] In this embodiment, the cJSON parser can be used. cJSON is a JSON parser implemented in C language, which only contains two files, cJson.c and cJson.h. cJSON supports the parsing and generation of JSON data and is suitable for use in resource-constrained environments. An entity object can be created first through the entity creation interface, and then the parameters in the parsed parameter data can be added to the entity object through the parameter addition interface.
[0068] For example, a certain size partition can be allocated in the non-volatile memory for storage of system parameters according to project needs. A cJSON object is created through the entity creation interface (cJSON_CreateObject), and all subsequent parameter names and parameter values are added around the cJSON object. The process of creating an object is as follows:
[0069] Definition of object variables:
[0070] cJSON*root=NULL;
[0071] cJSON*fmt=NULL;
[0072] Object creation:
[0073] root=cJSON_CreateObject();
[0074] Add parameter ITEM to the object through the parameter adding interface:
[0075] cJSON_AddItemToObject(root,"Parameter",fmt=cJSON_CreateObject());
[0076] The data formed at this time is as follows:
[0077]
[0078] In one embodiment, adding the parameters in the parsed parameter data to the entity object through the parameter adding interface includes: determining the data type of each parameter in the parsed parameter data; selecting the parameter adding interface corresponding to different parameters according to the data type of each parameter; and adding the corresponding parameters to the entity object through the parameter adding interface corresponding to each parameter.
[0079] The data types may include integer, floating point, character, and Boolean types, etc., which are not limited in this embodiment.
[0080] In this embodiment, parameters of different data types correspond to different parameter adding interfaces, and the corresponding parameter adding interface can be selected according to the data type of each parameter, and parameters of different data types can be added to the entity object through different parameter adding interfaces.
[0081] For example, the supported parameter data types can be defined in advance in the system to facilitate data conversion according to the data type of each parameter variable, as defined below:
[0082] #define APP_cJSON_Invalid(0)
[0083] #define APP_cJSON_False(1<<0) / / Boolean false
[0084] #define APP_cJSON_True(1<<1) / / Boolean true
[0085] #define APP_cJSON_Number(1<<3) / / Integer
[0086] #define APP_cJSON_String(1<<4) / / string
[0087] Add parameter names and values to the root object:
[0088] The data type of the parameter value corresponding to the current parameter name is APP_cJSON_Number, so the cJSON_AddNumberToObject interface is called to add the parameter name and parameter value to the root object.
[0089] For example: cJSON_AddNumberToObject(fmt,"width",1920.2);
[0090] The data formed at this time is as follows:
[0091]
[0092] In one embodiment, the obtaining of the first parameter data stored in the non-volatile memory includes: reading all system parameters stored in the non-volatile memory as the first parameter data through a read drive interface of the non-volatile memory; defining a memory of a specified size for the first parameter data through an address storage data structure, and storing the first parameter data to a specified address.
[0093] The read drive interface may be an interface for reading data in a non-volatile memory. The address storage data structure may be a data structure capable of defining a memory of a specified size for parameter data.
[0094] In this embodiment, the system parameter data of the current NVM is read into the memory through the read drive interface of the NVM, and the memory can be the memory of the MCU; in the MCU memory, a memory of a specified size can be defined for the first parameter data through the address storage data structure, and the first parameter data is stored in the specified address. In this embodiment, a suitable storage space can be opened up in the NVM to store system parameters. The stored system parameters may include the following data: a 32-bit cyclic redundancy check value (CyclicalRedundancy Check, CRC) of the system parameter, a parameter name (keyname), a parameter value and a parameter data type. Among them, CRC32 is the result obtained by calculating the parameter name, parameter value and parameter data type through the verification algorithm, which can be used to determine whether the stored system parameters are abnormal. The parameter name is the ID or meaning that identifies the system parameter, and which system parameter to read and write must be identified by the parameter name. The parameter value is the actual physical value of the system parameter. The parameter data type may include data types such as integer, floating point, character and Boolean.
[0095] For example, the MCU storage data structure can be declared in advance. The parameter name keyname can be defined as char* type, the MCU system parameter variable address can be defined as void* type, and the parameter data type can be defined as uint8 type. By defining the storage data structure, we prepare for defining the MCU system variable memory size. The specific definition is as follows:
[0096]
[0097] Define the memory of the specified size according to the declared MCU storage data structure. For example, the following statement can be used to define the MCU system parameter variable memory of size 3:
[0098] JsonParam g_NvmParam[3]
[0099] Furthermore, you can also define the parameter names of the system parameter variables supported by the MCU system and the corresponding parameter data types, as follows:
[0100] Declare the parameters CrCalParameter_str supported by the MCU system parameter variables: The following declarations support the MCU system parameter variables as vertical angle (V_Angle) and horizontal angle (V_Angle), and the data types are both floating point.
[0101]
[0102] According to the MCU system parameter variable structure element definition storage data structure:
[0103]
[0104] Since the MCU system has defined the supported parameter names and data types, the parameter names supported by the application can be used to find the parameter values of the corresponding parameter names in the NVM through index search and assign them to the variables in the MCU system.
[0105] Furthermore, after the above definition, the corresponding cJSON API interface (such as the entity creation interface and parameter addition interface) can be called according to the data type of the MCU system parameter variable to perform string serialization. If the parameter data to be written is V_Angle and H_Angle, and their variables are both float types, the following interface is called:
[0106] cJSON_AddItemToObject(root,"Parameter",fmt=cJSON_CreateObject());
[0107] cJSON_AddNumberToObject(fmt,g_nvm_param[0].KeyName,*(float
[0108] *)g_nvm_param[0].ParamAddr);
[0109] cJSON_AddNumberToObject(fmt,g_nvm_param[1].KeyName,*(float
[0110] *)g_nvm_param[1].ParamAddr);
[0111] cJSON_AddNumberToObject(root,g_nvm_param[2].KeyName,3584187110);
[0112] The data obtained from the non-volatile memory is as follows:
[0113]
[0114] In this embodiment, after the parameters to be written are serialized, the write driver interface of the NVM may be called to store the data in the NVM.
[0115] Embodiment 3
[0116] Figure 4 This is a flow chart of a JSON-based parameter storage method provided in Embodiment 3 of the present invention. Embodiment 3 is optimized on the basis of the above embodiments. Please refer to the above embodiments for details not yet provided in this embodiment.
[0117] like Figure 4 As shown, a JSON-based parameter storage method provided in Embodiment 3 of the present invention further includes the following steps:
[0118] S310: When a read parameter command is received, a parameter name of a parameter to be read is determined according to the read parameter command.
[0119] The read parameter command may be a command for reading parameters.
[0120] In this embodiment, when a read parameter command is received, the read parameter command may be parsed to obtain a parameter name of a parameter to be read in the read parameter command.
[0121] S320: Acquire second parameter data stored in the non-volatile memory.
[0122] The second parameter data may be system parameters read from a non-volatile memory.
[0123] In this embodiment, all system parameters can be obtained from the non-volatile memory through the read drive interface as the second parameter data.
[0124] S330: Obtain parameter data in the second parameter data whose parameter name is the same as the parameter name of the parameter to be read, and use the parameter value of the parameter data as the reading result.
[0125] In this embodiment, according to the parameter name of the parameter to be read, parameter data with the same parameter name can be found from the second parameter data, and the parameter value of the parameter data is used as the reading result.
[0126] A JSON-based parameter storage method provided in the second embodiment of the present invention further includes: when receiving a parameter read command, determining the parameter name of the parameter to be read according to the parameter read command; obtaining second parameter data stored in the non-volatile memory; obtaining parameter data in the second parameter data whose parameter name is the same as the parameter name of the parameter to be read, and using the parameter value of the parameter data as the reading result. Through this method, the data to be read can be quickly found.
[0127] In one embodiment, the obtaining of parameter data in the second parameter data having a parameter name identical to the parameter name of the parameter to be read includes: searching for parameter data having the same parameter name from the second parameter data based on the parameter name of the parameter to be read; selecting a corresponding parameter parsing interface through a data type corresponding to the parameter data; and obtaining a parameter value corresponding to the parameter data through the parameter parsing interface.
[0128] The parameter parsing interface may be an interface capable of obtaining values, and parameter data of different data types use different parameter parsing interfaces.
[0129] In this embodiment, parameter data with the same parameter name can be found from the second parameter data based on the parameter name of the parameter to be read; the corresponding parameter parsing interface is selected according to the data type corresponding to the parameter data; and the parameter value corresponding to the parameter data is obtained through the parameter parsing interface.
[0130] In one embodiment, before taking the parameter value of the parameter data as the reading result, the method further includes: calculating a check code based on the parameter name, parameter value and parameter data type of the parameter data; when the check code is different from the check code stored in the system memory of the parameter data, not taking the parameter value of the parameter data as the reading result.
[0131] The check code may be a CRC32 code.
[0132] In this embodiment, before the parameter value of the parameter data is used as the reading result, the parameter value can also be verified. Specifically, a verification code can be calculated through the parameter name, parameter value and parameter data type of the parameter data, and the verification code is compared with the verification code stored in the system memory of the parameter data. If they are inconsistent, it means that the parameter data may have changed, and the parameter value of the parameter data cannot be used as the reading result. The verification code stored in the system memory is the verification code obtained from the NVM.
[0133] Exemplarily, the parameter data of NVM is read into the memory of MCU through the read driver interface of NVM. The conversion of NVM data to MCU system parameter variables is realized by the following code:
[0134] Define a cJSON object:
[0135] cJSON*child=NULL;
[0136] cJSON*fmt=NULL;
[0137] int g_CRC32 = 0;
[0138] According to the system parameter variables supported by the MCU system, select the corresponding parameter parsing interface to find the parameter value from the NVM data, and determine whether the recalculated check code is consistent with the stored check code. The specific implementation is as follows:
[0139]
[0140] The embodiments of the present invention provide several specific implementation methods based on the technical solutions of the above embodiments.
[0141] As a specific implementation method of this embodiment, Figure 5 A schematic diagram of a flow chart of a storage system parameter provided by an embodiment of the present invention, such as Figure 5 As shown in the figure, after the system is started, a write parameter command is received, and the current NVM parameter data is read to the MCU memory through the NVM read driver interface. The parameter name and parameter value in the write parameter command are parsed, and the location of the parameter value to be written in the NVM is found by indexing using the parameter name, and the parameter value is updated to the MCU memory, and then the MCU memory parameter data is stored in the NVM through the NVM write driver interface.
[0142] Figure 6 A schematic diagram of storing system parameters provided by an embodiment of the present invention is shown in FIG. Figure 6 As shown, in the parameter storage method of this embodiment, the parameter data stored in NVM does not need to care about the storage order, so when the MCU memory resources are relatively tight, there is no need to reserve parameter space for the parameter data structure. Even if the customer's needs change, new parameters can be added at any time, reducing the subsequent maintenance costs. It can also reduce the coupling between the stored MCU system variables and the storage data structure, reducing the difficulty of development.
[0143] Figure 7 A schematic diagram of a flow chart of reading system parameters provided by an embodiment of the present invention, such as Figure 7 As shown in the figure, the system starts and reads data of a specified size from NVM. The keyname of the supported parameters and the number of supported parameters are obtained through the g_nvm_param variable, and the keyname is used to match the data read from the memory. After the match is successful, the corresponding API of cJSON is called according to the data type in g_nvm_param to parse the parameter value corresponding to the keyname, and then the value is passed to the system parameter variable.
[0144] The technical solution of this embodiment serializes the system parameter variables into strings, which has good readability, facilitates system debugging, and improves work efficiency. The system parameter variable data structure and the storage structure are not coupled, and there is no need to reserve memory for the system parameter variable data structure. New variables can be arbitrarily defined in the system parameter variable data structure according to the needs of the project, thereby improving the maintainability of the system.
[0145] Embodiment 4
[0146] Figure 8 A structural diagram of a JSON-based parameter storage device provided in Embodiment 3 of the present invention is provided, wherein the device may be applicable to situations where system parameters that need to be written in a memory are stored in a non-volatile memory, wherein the device may be implemented by software and / or hardware and is generally integrated on an electronic device.
[0147] like Figure 8 As shown, the device comprises:
[0148] The receiving module 410 is used to receive a write parameter command and obtain the parameter data to be confirmed according to the write parameter command;
[0149] The acquisition module 420 is used to acquire first parameter data stored in the non-volatile memory; the data in the first parameter data is a system parameter;
[0150] The writing module 430 is used to write the data in the to-be-confirmed parameter data that is consistent with the parameter name of the first parameter data into the non-volatile memory in JSON data format.
[0151] This embodiment provides a JSON-based parameter storage device, including: a receiving module, used to receive a write parameter command, and obtain the parameter data to be confirmed according to the write parameter command; an obtaining module, used to obtain the first parameter data stored in the non-volatile memory; the data in the first parameter data is a system parameter; a writing module, used to write the data in the parameter data to be confirmed that is consistent with the parameter name of the first parameter data into the non-volatile memory in the JSON data format. By writing the parameters in the JSON data format when writing the parameters, the readability and scalability of the system parameters can be improved, and the problems of poor scalability and difficult development when storing system parameter variables in the prior art are solved.
[0152] Furthermore, the receiving module 410 is specifically configured to:
[0153] Parsing the write parameter command to obtain parsed parameter data in the write parameter command;
[0154] Using the parsed parameter data as parameter data to be confirmed;
[0155] The parsed parameter data includes a parameter name and a parameter value corresponding to the parameter name.
[0156] Furthermore, the writing module 430 is specifically used for:
[0157] The data in the parameter data to be confirmed that is consistent with the parameter name of the system parameter in the first parameter data is used as the parameter data to be written;
[0158] Convert the data format of the parameter data to be written into JSON data format through a JSON parser;
[0159] The converted parameter data to be written is written into the non-volatile memory.
[0160] Furthermore, converting the data format of the parameter data to be written into the JSON data format by a JSON parser includes:
[0161] Create entity objects through the entity creation interface;
[0162] The parameters in the parsed parameter data are added to the entity object through a parameter adding interface.
[0163] Furthermore, adding the parameters in the parsed parameter data to the entity object through the parameter adding interface includes:
[0164] Determine the data type of each parameter in the parsed parameter data;
[0165] Select a parameter adding interface corresponding to different parameters according to the data type of each parameter;
[0166] The corresponding parameters are added to the entity object through the parameter adding interface corresponding to each parameter.
[0167] Furthermore, the acquisition module 420 is specifically used for:
[0168] Reading all system parameters stored in the non-volatile memory through a read drive interface of the non-volatile memory and using them as first parameter data;
[0169] A memory of a specified size is defined for the first parameter data through an address storage data structure, and the first parameter data is stored at the specified address.
[0170] Furthermore, the device is also used for:
[0171] When receiving a read parameter command, determining a parameter name of a parameter to be read according to the read parameter command;
[0172] Acquiring second parameter data stored in the non-volatile memory;
[0173] Parameter data in the second parameter data whose parameter name is the same as the parameter name of the parameter to be read is obtained, and the parameter value of the parameter data is used as the reading result.
[0174] Further, the obtaining of parameter data in the second parameter data having a parameter name identical to the parameter name of the parameter to be read includes:
[0175] Based on the parameter name of the parameter to be read, searching for parameter data with the same parameter name from the second parameter data;
[0176] Select a corresponding parameter parsing interface according to the data type corresponding to the parameter data;
[0177] The parameter value corresponding to the parameter data is obtained through the parameter parsing interface.
[0178] Furthermore, before taking the parameter value of the parameter data as the reading result, the device is also used for:
[0179] Calculate a check code based on the parameter name, parameter value and parameter data type of the parameter data;
[0180] When the verification code is different from the verification code of the parameter data stored in the system memory, the parameter value of the parameter data is not used as the reading result.
[0181] The above-mentioned JSON-based parameter storage device can execute the JSON-based parameter storage method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0182] Embodiment 5
[0183] Fig. 9 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0184] like Fig. 9As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0185] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0186] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a JSON-based parameter storage method.
[0187] In some embodiments, the JSON-based parameter storage method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the JSON-based parameter storage method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the JSON-based parameter storage method in any other appropriate manner (e.g., by means of firmware).
[0188] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0189] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0190] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0191] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0192] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0193] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0194] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0195] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A parameter storage method based on JSON, characterized in that: The method comprises: receiving a write parameter command, and obtaining parameter data to be confirmed according to the write parameter command; Acquire first parameter data stored in a non-volatile memory; data in the first parameter data is a system parameter; The data in the parameter data to be confirmed that is consistent with the parameter name of the first parameter data is written into the non-volatile memory in JSON data format.
2. The method according to claim 1, characterized in that The obtaining the parameter data to be confirmed according to the write parameter command includes: Parsing the write parameter command to obtain parsed parameter data in the write parameter command; Using the parsed parameter data as parameter data to be confirmed; The parsed parameter data includes a parameter name and a parameter value corresponding to the parameter name.
3. The method according to claim 1, characterized in that The step of writing the data in the parameter data to be confirmed that is consistent with the parameter name of the first parameter data into the non-volatile memory in JSON data format includes: The data in the parameter data to be confirmed that is consistent with the parameter name of the system parameter in the first parameter data is used as the parameter data to be written; Convert the data format of the parameter data to be written into JSON data format through a JSON parser; The converted parameter data to be written is written into the non-volatile memory.
4. The method according to claim 3, characterized in that The converting the data format of the parameter data to be written into the JSON data format by using a JSON parser includes: Create entity objects through the entity creation interface; The parameters in the parsed parameter data are added to the entity object through a parameter adding interface.
5. The method according to claim 4, characterized in that The adding the parameters in the parsed parameter data to the entity object through the parameter adding interface includes: Determine the data type of each parameter in the parsed parameter data; Select a parameter adding interface corresponding to different parameters according to the data type of each parameter; The corresponding parameters are added to the entity object through the parameter adding interface corresponding to each parameter.
6. The method according to claim 1, characterized in that The obtaining of first parameter data stored in the non-volatile memory comprises: Reading all system parameters stored in the non-volatile memory through a read drive interface of the non-volatile memory and using them as first parameter data; A memory of a specified size is defined for the first parameter data through an address storage data structure, and the first parameter data is stored at the specified address.
7. The method according to claim 1, characterized in that The method further comprises: When receiving a read parameter command, determining a parameter name of a parameter to be read according to the read parameter command; Acquiring second parameter data stored in the non-volatile memory; Parameter data in the second parameter data whose parameter name is the same as the parameter name of the parameter to be read is obtained, and the parameter value of the parameter data is used as the reading result.
8. The method according to claim 7, characterized in that The step of obtaining parameter data in the second parameter data whose parameter name is the same as the parameter name of the parameter to be read includes: Based on the parameter name of the parameter to be read, searching for parameter data with the same parameter name from the second parameter data; Select a corresponding parameter parsing interface according to the data type corresponding to the parameter data; The parameter value corresponding to the parameter data is obtained through the parameter parsing interface.
9. The method according to claim 7, characterized in that: Before taking the parameter value of the parameter data as the reading result, the method further comprises: Calculate a check code based on the parameter name, parameter value and parameter data type of the parameter data; When the verification code is different from the verification code of the parameter data stored in the system memory, the parameter value of the parameter data is not used as the reading result.
10. A parameter storage device based on JSON, characterized in that: The device comprises: A receiving module, used for receiving a write parameter command, and obtaining parameter data to be confirmed according to the write parameter command; An acquisition module, used for acquiring first parameter data stored in a non-volatile memory; the data in the first parameter data is a system parameter; A writing module is used to write the data in the parameter data to be confirmed that is consistent with the parameter name of the first parameter data into the non-volatile memory in JSON data format.
11. An electronic device, characterized in that: The device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the JSON-based parameter storage method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the JSON-based parameter storage method described in any one of claims 1 to 9 when executed.