Data storage method and device and single-chip microcomputer

By defining a unified data unit structure and storage rules in embedded devices and directly storing data, the problems of low efficiency and high resource consumption in traditional storage methods are solved, and a low-cost and efficient data storage solution is realized.

CN120336315APending Publication Date: 2025-07-18SHENZHEN POWEROAK NEWENER CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510262933.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-06
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

The prior art has problems in the embedded devices with low data efficiency and high resource consumption, especially when storing different types of data, the traditional storage method is complex and not flexible enough.

Method used

By obtaining the type and length of data to be stored, a unified data unit structure is defined, data storage rules are generated, and data is directly stored in the storage medium, complex format conversion and file system dependencies are avoided.

Benefits of technology

It realizes low-cost and efficient data storage, reduces the consumption of storage resources, improves the flexibility and parsing efficiency of data storage, and is suitable for embedded devices with limited resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120336315A_ABST
    Figure CN120336315A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data storage, and discloses a data storage method and device and a single-chip microcomputer. The method comprises: acquiring to-be-stored data; obtaining a data storage rule according to the to-be-stored data and a preset data unit structure; according to the data storage rule, processing the to-be-stored data to obtain target storage data and a target storage address; and storing the target storage data according to the target storage address. On the basis, a unified data unit structure is defined, so that a data storage rule is clear, the problems of complex data format and difficult analysis in a traditional storage mode are avoided, and therefore, low-cost and efficient data storage is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data storage, and particularly to a data storage method, apparatus, and single-chip microcomputer. Background Art

[0002] In the embedded field, with the continuous increase in device functions, more and more devices need to effectively store data and extract and analyze it when needed. However, many embedded devices have certain limitations in hardware resources, such as storage space and processing power, which pose quite a challenge to traditional complex data storage methods or storage methods with fixed data types. Especially when storing a large amount of different types of data, how to improve the flexibility and efficiency of storage has become an urgent problem to be solved.

[0003] Existing technical solutions usually convert data into ASCII codes and store it in storage media such as Flash or EEPROM, and need to mount file systems such as FATFS or LittleFS to manage data access. Although this method can solve certain problems, there are also certain storage efficiency and resource consumption problems, so the actual resource situation of the device still needs to be considered when designing an efficient and flexible data storage solution. Summary of the Invention

[0004] The embodiments of this application mainly solve the technical problem of how to store data at low cost and efficiently.

[0005] To solve the above technical problem, a technical solution adopted in the embodiments of this application is: to provide a data storage method, the method includes: obtaining data to be stored; obtaining a data storage rule according to the data to be stored and a preset data unit structure; processing the data to be stored according to the data storage rule to obtain target storage data and a target storage address; storing the target storage data according to the target storage address.

[0006] In some embodiments, the obtaining a data storage rule according to the data to be stored and a preset data unit structure includes: obtaining the data type of the data to be stored according to the data to be stored; determining the length of the data to be stored according to the data type; obtaining the data storage rule corresponding to the data type of the data to be stored according to the data type, the length, and the data unit structure.

[0007] In some embodiments, obtaining the data storage rule corresponding to the data type of the data to be stored according to the data type, the length, and the data unit structure includes: obtaining the data unit structure, where the data unit structure includes a serial number, a control type, first data, and second data; obtaining the control type according to the data type and the length; and obtaining the data storage rule corresponding to the data type of the data to be stored according to the control type.

[0008] In some embodiments, processing the data to be stored according to the data storage rule to obtain target stored data and a target storage address includes: obtaining the data corresponding to the data type of the data to be stored; allocating the corresponding serial number, control type, first data, second data, and target storage address for the data according to the data storage rule; reorganizing the data to be stored according to the serial number, control type, first data, and second data to obtain the reorganized data to be stored; and obtaining the target stored data according to the reorganized data to be stored and a delimiter.

[0009] In some embodiments, obtaining the target stored data according to the reorganized data to be stored and the delimiter includes: obtaining a target serial number according to the reorganized data to be stored; obtaining the delimiter according to the target serial number and the data unit structure; where the delimiter includes a serial number, the target serial number, a first check code, and a second check code; and combining the reorganized data to be stored and the delimiter to obtain the target stored data.

[0010] In some embodiments, storing the target stored data according to the target storage address includes: calculating a storage space for the target stored data according to the target storage address; and storing the target stored data according to the target storage address and the storage space.

[0011] To solve the above technical problems, another technical solution adopted in the embodiments of the present application is: providing a data storage device, where the device includes: an acquisition module, where the acquisition module is used to acquire data to be stored; a definition module, where the definition module is used to obtain a data storage rule according to the data to be stored and a preset data unit structure; a processing module, where the processing module is used to process the data to be stored according to the data storage rule to obtain target stored data and a target storage address; and a storage module, where the storage module is used to store the target stored data according to the target storage address.

[0012] In some embodiments, the defining module is specifically configured to: obtain the data type of the data to be stored according to the data to be stored; determine the length of the data to be stored according to the data type; and obtain the data storage rule corresponding to the data type of the data to be stored according to the data type, the length, and the data unit structure.

[0013] In some embodiments, the defining module is further configured to: obtain the data unit structure, where the data unit structure includes a serial number, a control type, first data, and second data; obtain the control type according to the data type and the length; and obtain the data storage rule corresponding to the data type of the data to be stored according to the control type.

[0014] To solve the above technical problems, another technical solution adopted in the embodiments of the present application is: to provide a single-chip microcomputer, including: at least one processor; and a memory communicatively connected to the at least one processor; where the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described above.

[0015] Different from the related art, the present application provides a data storage method, apparatus, and single-chip microcomputer. By obtaining the data to be stored; obtaining the data storage rule according to the data to be stored and a preset data unit structure; processing the data to be stored according to the data storage rule to obtain the target storage data and the target storage address; and storing the target storage data according to the target storage address. Based on this, by defining a unified data unit structure, the data storage rule is made clear, avoiding the problems of complex data format and difficult parsing in the traditional storage method, thereby achieving low-cost and efficient data storage. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] One or more embodiments are exemplarily illustrated by corresponding drawings. These exemplary illustrations do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements, unless otherwise stated, and the drawings in the drawings do not constitute a proportional limitation.

[0017] Figure 1 is a flowchart of a data storage method provided by an embodiment of the present application;

[0018] Figure 2 is a flowchart of a data storage rule acquisition process provided by an embodiment of the present application;

[0019] Figure 3 is a flowchart of a data storage processing process provided by an embodiment of the present application;

[0020] Figure 4 It is a schematic diagram of the data storage result provided by an embodiment of the present application;

[0021] Figure 5 It is a schematic diagram of the data storage result provided by another embodiment of the present application;

[0022] Figure 6 It is a schematic diagram of the data storage result provided by yet another embodiment of the present application;

[0023] Figure 7 It is a structural schematic block diagram of a data storage device provided by an embodiment of the present application;

[0024] Figure 8 It is a schematic diagram of the hardware structure of a single-chip microcomputer that executes the data storage method provided by an embodiment of the present application. Detailed implementation manners

[0025] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0026] It should be noted that if there is no conflict, the various features in the embodiments of the present application can be combined with each other, and all are within the protection scope of the present application. In addition, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different module division from that in the device schematic diagram or a different order from that in the flowchart.

[0027] Unless otherwise defined, all technical and scientific terms used in this specification have the same meanings as those commonly understood by those skilled in the technical field to which the present application belongs. The terms used in the specification of the present application are only for the purpose of describing specific implementation manners and are not used to limit the present application. The term "and / or" used in this specification includes any and all combinations of one or more of the related listed items.

[0028] Please refer to Figure 1 , Figure 1 It is a flowchart of a data storage method provided by an embodiment of the present application. As Figure 1 shown, the data storage method is used for embedded devices where the operating system does not support a file system or there is no operating system. The method includes steps S101 - S104:

[0029] S101: Obtain the data to be stored.

[0030] Before data storage, it is necessary to obtain the data frame to be stored and perform preliminary preprocessing on the data to ensure that the data is complete, has a clear structure, and is suitable for the subsequent data storage process.

[0031] First, obtain the raw data from sources such as sensors, communication interfaces, and external devices. For example, sensors read environmental data (such as temperature, humidity, current, voltage). Another example is that communication interfaces (UART, I2C, SPI, CAN, etc.) receive data transmitted from external devices. Yet another example is to collect user input data (such as keys, touchscreens, command inputs).

[0032] Secondly, classify the data into different categories according to the data source and usage. For example: Numerical data: such as temperature values, pressure values, current and voltage, etc., which are usually integers or floating-point numbers. Status data: such as device operating status, alarm information, mode switching status, which are usually enumeration values or flag bits. Identification data: such as device ID, timestamp, sensor number, which are usually strings or encoded values.

[0033] Thirdly, attach time information to each frame of data for subsequent storage and analysis. For example: Obtain the current system time and convert it to a standard format (such as UNIX timestamp). If the device does not have an RTC (Real-Time Clock), an accumulated count or a fixed-period timer can be used to provide a time reference.

[0034] Fourthly, perform basic data validity checks to prevent the storage of invalid data. For example: Check whether the data is empty or out of range. Another example is to calculate and attach a simple check value, such as parity check, checksum. Yet another example is to denoise sensor data, such as filtering, taking the average value, etc.

[0035] Finally, ensure that the numerical part of the data is in the same binary format (for example, hexadecimal or decimal). After confirming that the format of the numerical part is correct, assemble a complete frame of data and ensure that its structure meets the storage requirements. For example: Set the frame header and frame tail for easy parsing. Another example is to arrange the data fields in a fixed order to ensure consistency in storage and reading.

[0036] Through the above classification and timestamp marking, different types of data can be correctly identified and associated. The data integrity check improves the reliability of the stored data and avoids storing invalid or incorrect data. Also, through the unified organization of the frame structure, subsequent storage, parsing, and transmission are made more efficient. In addition, the processing logic of this step is simple and suitable for resource-constrained embedded devices, without adding additional storage and computing burdens, which helps to improve the overall operating efficiency of the system.

[0037] S102: Obtain a data storage rule according to the data to be stored and a preset data unit structure.

[0038] Please refer to Figure 2 , Figure 2 which is a flowchart of a data storage rule acquisition process provided by an embodiment of the present application. As Figure 2 shown, obtaining a data storage rule according to the data to be stored and a preset data unit structure includes steps S1021 - S1023:

[0039] S1021: Obtain the data type of the data to be stored according to the data to be stored.

[0040] First, obtain the data to be stored for each frame by frame. Identify that the data comes from different data sources such as sensors, communication interfaces, user inputs, calculation results, etc. For example, temperature data may come from sensors, voltage values may come from ADC sampling, and system status may be provided by internal flag bits.

[0041] Second, determine its data type according to the data. Among them, the data types include but are not limited to: unsigned character data (unsigned char), signed character data (signed char), unsigned short integer data (unsigned short), signed short integer data (signed short), integer data (int), and long integer data (long int). It can be understood that each frame of data to be stored contains data of various data types, and by confirming the data type corresponding to each data, it is convenient for subsequent data storage processes.

[0042] It should be noted that the data type is not limited to the above description, and it can also be single-precision floating-point data (float), double-precision floating-point data (double), and long double-precision floating-point data (long double), which can be set according to actual situations.

[0043] S1022: Determine the length of the data to be stored according to the data type.

[0044] Find the corresponding storage length according to the data type. It can be understood that the storage length of unsigned character data (unsigned char) and signed character data (signed char) is 1 byte, the storage length of unsigned short integer data (unsigned short) and signed short integer data (signed short) is 2 bytes, the storage length of integer data (int) is 4 bytes, and the storage length of long integer data (long int) is 8 bytes.

[0045] S1023: Obtain the data storage rule corresponding to the data type of the data to be stored according to the data type, length, and data unit structure.

[0046] Obtain the data storage rule corresponding to the data type of the data to be stored according to the data type, length, and data unit structure, including: obtaining the data unit structure, where the data unit structure includes a sequence number, a control type, a first data, and a second data; obtaining the control type according to the data type and length; and obtaining the data storage rule corresponding to the data type of the data to be stored according to the control type.

[0047] First, obtain the data unit structure. The data unit structure is (sequence number, control type, first data, second data). Among them, the sequence number represents the position identifying the current data unit and increases incrementally according to the storage order; the control type represents the type and storage length of the data; the first data and the second data represent partial values of the data to be stored, and the forms of the first data and the second data can be hexadecimal, decimal, octal, or binary, etc., which are not limited herein. It should be noted that the first data can be the high bit or the low bit of the data, and the second data can be the low bit or the high bit of the data, which are not limited thereto.

[0048] Second, calculate the control type. If the data is an unsigned number (unsigned), the high bit of the control type is 0. If the data is a signed number (signed), the high bit of the control type is 1. The low bit of the control type is determined according to the storage length of the data. For example, the control type corresponding to unsigned char is 0x01, the control type corresponding to signed char is 0x11, the control type corresponding to unsigned short is 0x02, the control type corresponding to signed short is 0x12, the control type corresponding to int is 0x04, and the control type corresponding to long int is 0x08.

[0049] Finally, a data storage rule is obtained. According to the data type and length, a data unit structure is allocated. It can be understood that character-type data and short-integer data are allocated 1 data unit structure, integer data is allocated 2 data unit structures, and long-integer data is allocated 4 data unit structures. For example, the data unit structure allocated for unsigned char is (0x01, 0x01, 0x00, 0x00); the data unit structure allocated for int is (0x02, 0x04, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00); the data unit structure allocated for long int is (0x05, 0x08, 0x00, 0x00, 0x06, 0x08, 0x00, 0x00, 0x07, 0x08, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00). It can be understood that step S102 mainly allocates a data unit structure corresponding to the data type for all the data in the data to be stored according to its corresponding data type, so as to be used in the subsequent data processing process. However, this step does not involve storing the numerical part of the data for the time being, that is, both the first data and the second data are defaulted to 0x00.

[0050] In this embodiment, through the high and low bit encoding of the control type, different data types can be stored uniformly without additional type conversion. A unified storage rule is also designed so that tools such as the host computer or EXCEL can directly parse the data frame, improving the convenience of data reading. In addition, through the serial number marking, it is possible to support the continuous storage of multi-byte data (such as int or long int data) to ensure data integrity. That is, by reasonably designing the data unit structure, the efficiency, compatibility, and easy parsing of data storage are ensured.

[0051] S103: According to the data storage rule, process the data to be stored to obtain the target stored data and the target storage address.

[0052] Please refer to Figure 3 , Figure 3 which is a flowchart of a data storage processing flow provided by an embodiment of the present application. As Figure 3 shown, according to the data storage rule, process the data to be stored to obtain the target stored data and the target storage address, including steps S1031 - S1034:

[0053] S1031: Obtain the data corresponding to the data type of the data to be stored.

[0054] For the data within each frame of data to be stored, obtain the corresponding data type and numerical data. It can be understood that the form in which the data in the data to be stored appears may be (data type, numerical data). For example, the form of a certain data is (unsigned char, 0x02). Among them, 0x02 is the real numerical data of this data. Based on this, the data types and numerical data of all data in each frame of data to be stored can be obtained.

[0055] S1032: According to the data storage rules, assign corresponding serial numbers, control types, first data, second data, and target storage addresses to the data.

[0056] First, assign a data storage serial number. Set the storage order of the data unit structure to ensure that the data is arranged in an orderly manner in the memory. For example, the serial number increments from 0x01. It should be noted that if storing multi-byte data, multiple data unit structures need to be split, and the serial numbers are consecutive.

[0057] Second, assign a control type. It is directly filled with the control type calculated in step S102. For example, the corresponding control type for unsigned char is 0x01.

[0058] Third, assign the first data and the second data. Fill the numerical data of the data to be stored into the first data and second data fields of the data unit structure. It can be understood that for 1-byte data, the first data stores 0x00, and the second data fills the numerical data. For 2-byte data, the first data stores the high byte, and the second data stores the low byte. For 4-byte data, it is split into two data unit structures, each storing 2 bytes, and the serial number increments. For example, for (unsigned char, 0x32), the first data is 0x00, and the second data is 0x32. Another example is for (signed short, 0x1234), the first data is 0x12, and the second data is 0x34.

[0059] Finally, calculate the target storage address. It can be understood that a starting storage address (Base_Addr) is usually set by default, which is usually determined by the free storage area of the Flash or EEPROM. For example, Base_Addr is 0x1000. Since each data unit structure is (serial number, control type, first data, second data). Among them, each element occupies 1 byte. Therefore, each data unit structure occupies 4 bytes. Therefore, the address is allocated according to the data unit structure, and its calculation formula is as follows:

[0060] Addr(n) = Base_Addr + (serial number - 1) × 4;

[0061] It should be noted that when allocating addresses for multi-byte data, multiple data units need to be occupied. Then: Addr(Second data unit structure) = Addr(First data unit structure) + 4, and so on. For example, after the stored (unsigned char, 0x32) is converted into a data unit structure according to the above description, it becomes (0x01, 0x01, 0x00, 0x32). From this, it can be known that the serial number 0x01 represents the data to be stored with serial number 1. According to the above formula, the corresponding storage address is calculated as Addr(0x01) = 0x1000 + (1 - 1) × 4 = 0x1000. Another example, after (signed short, 0x1234) is converted into a data unit structure, it becomes (0x02, 0x12, 0x12, 0x34). From this, it can be known that the serial number 0x02 represents the data to be stored with serial number 2. According to the above formula, the corresponding storage address is calculated as Addr(0x02) = 0x1000 + (2 - 1) × 4 = 0x1004.

[0062] S1033: Recombine the data to be stored according to the serial number, control type, first data, and second data to obtain the recombined data to be stored.

[0063] Recombine the data to be stored in the form of (serial number, control type, first data, second data). For example, (unsigned char, 0x32) is recombined into (0x01, 0x01, 0x00, 0x32). Another example, (signed short, 0x1234) is recombined into (0x02, 0x12, 0x12, 0x34).

[0064] S1034: Obtain the target stored data according to the recombined data to be stored and the delimiter.

[0065] Obtaining the target stored data according to the recombined data to be stored and the delimiter includes: obtaining the target serial number according to the recombined data to be stored; obtaining the delimiter according to the target serial number and the data unit structure; where the delimiter includes the serial number, target serial number, first check code, and second check code; combining the recombined data to be stored and the delimiter to obtain the target stored data.

[0066] First, calculate the target serial number. It can be understood that the target serial number is the largest serial number in the current frame of data and is used to verify whether the data is complete. For example, the target serial number is 0x04 (because the serial number of the last data unit structure is 0x04).

[0067] Secondly, obtain the delimiter. The form of (sequence number, target sequence number, first check code, second check code) is used as the delimiter. It can be understood that the delimiter also adopts the form of a data unit structure, but its constituent elements are different. Among them, the first check code and the second check code are the high and low bits of the CRC check code. That is, a delimiter will be added to the end of each frame of data to consider it as recording one frame of data.

[0068] Finally, obtain the target stored data. That is, the target stored data is the combination of the recombined data to be stored and the delimiter. For example: the target stored data of one frame is (0x01 0x01 0x00 0x32 0x02 0x12 0x12 0x34 0x03 0x04 0XF5 0XC3 0x04 0x04 0x40 0x48 0x00 0x04 0xXX 0xYY).

[0069] This embodiment not only makes the data storage format unified and easy to parse through the data unit structure composed of sequence number, control type, first data, and second data, but also can verify the integrity during data reading through the delimiter to avoid data loss or damage. In addition, the host computer or other devices can directly parse the stored data according to the sequence number and control type without complex format conversion, ensuring that the data is efficiently and reliably stored and read in an embedded device without a file system.

[0070] S104: Store the target stored data according to the target storage address.

[0071] Storing the target stored data according to the target storage address includes: calculating the storage space for the target stored data according to the target storage address; storing the target stored data according to the target storage address and the storage space.

[0072] Before storing data, it is necessary to ensure that the storage area has enough space to store the target data. The process of calculating the storage space includes the following aspects: Confirm the length of the target stored data: In the previous step (such as step S103), the total length of the target stored data has been obtained. This length usually includes the data content itself and additional structural information (such as sequence number, control type, checksum, etc.). Calculate the starting address of the storage area: Based on the target storage address calculated in step S103 (for example, Addr(target stored data)), determine the starting position of data storage. If the target storage address is already occupied by other data, it is necessary to ensure that there is enough storage space to store the target data. If necessary, the storage area can be adjusted or moved to the next free address. Verify the storage space: Before storing data, confirm that the area between the target storage address and the expected storage end position is free. If the target storage area is insufficient, it may be necessary to roll back and allocate a new storage space, or perform data overwrite (if the data tolerates such an operation).

[0073] After confirming that there is enough storage space, the target stored data can be written to the storage medium. First, allocate the corresponding storage space according to the calculated target storage address and the length of the data (including the size of the data unit, etc.). For example, if storing data requires 8 bytes and the target storage address is 0x1000, the data should be stored starting from address 0x1000 and continuing to 0x1007. Second, write the target stored data sequentially to the predetermined position of the storage medium. The write operation is usually completed by direct memory access (DMA) or other low-level interfaces. Each time a data unit is stored, it is necessary to ensure that each field of the data (such as sequence number, control type, data field, etc.) is stored correctly according to the corresponding format. Finally, after writing the data, verification (such as CRC verification) can be performed to ensure the integrity of data storage.

[0074] This embodiment realizes storage without a file system, which can greatly reduce the dependence of the embedded device on the file system during storage and save system resources (such as storage space, computing power, etc.) significantly. In addition, by accurately calculating the storage address and storage space, it is ensured that each piece of data can be stored correctly and effectively, avoiding storage conflicts or data overwrite problems. At the same time, by introducing the checksum, the integrity and consistency of data storage are ensured, greatly improving the reliability of the data and providing a solid foundation for subsequent reading, analysis, and processing.

[0075] The following lists two embodiments to explain the implementation process of the data storage method proposed in this application:

[0076] For Embodiment 1, taking the data to be stored in one frame as an example, the data to be stored includes (unsigned char, 0x02), (int, 0x34331111), …, (signed short, 0x3202), (long, 0x3433111134331111), (signed short, 0x3202), (signed char, 0x02), and (unsigned short, 0x3202).

[0077] First, according to the data to be stored and the data unit structure, the data storage rule is obtained. It can be understood that from the above description: the data storage rule for each data corresponding to the data type in the data to be stored is: (0x01, 0x01, 0x00, 0x00), (0x02, 0x04, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00), …, (0x08, 0x12, 0x00, 0x00), (0x09, 0x08, 0x00, 0x00, 0x0A, 0x08, 0x00, 0x00, 0x0B, 0x08, 0x00, 0x00, 0x0C, 0x08, 0x00, 0x00), (0x0D, 0x12, 0x00, 0x00), (0x0E, 0x11, 0x00, 0x00), (0x0F, 0x02, 0x00, 0x00).

[0078] Secondly, please combine with Figure 4 , Figure 4 which is a schematic diagram of the data storage result provided by the embodiment of the present application. As Figure 4As shown, according to the data storage rule, the data to be stored is processed to obtain the target stored data. The results are: (0x01, 0x01, 0x00, 0x02), (0x02, 0x04, 0x34, 0x33, 0x03, 0x04, 0x11, 0x11), …, (0x08, 0x12, 0x32, 0x02), (0x09, 0x08, 0x34, 0x33, 0x0A, 0x08, 0x11, 0x11, 0x0B, 0x08, 0x34, 0x33, 0x0C, 0x08, 0x11, 0x11), (0x0D, 0x12, 0x32, 0x02), (0x0E, 0x11, 0x00, 0x02), (0x0F, 0x02, 0x32, 0x02) and the separator (0x00, 0x0F, CRCH, CRCL). Among them, (0x00, 0x0F, CRCH, CRCL) means that after recording all data types once, it is regarded as recording one frame. After each frame is recorded, a group of separators needs to be recorded. The target serial number (corresponding to 0x0F) is the serial number of the last data unit sent, and CRCH and CRCL are the high and low bits of the CRC check code of the data recorded in this round. It should be noted that in this way, at most 255 single-byte data type data can be recorded each time. When it is necessary to read and analyze the data, other tools (such as the host computer) can be used to parse it in this way.

[0079] For Embodiment 2, combining Table 1 and Table 2, the differences between the data storage method proposed in the embodiment of the present application and the existing recording method are compared as follows:

[0080] Table 1 - Existing Recording Method

[0081]

[0082] Table 2 - Data Storage Method

[0083] 01021232 02010033 030204CE 04020154 05020226 01021232 02010034 030204CE 04020168 050201D6 01021232 02010035 030204E2 04020140 05020370

[0084] Taking the three frames of data to be stored provided in Table 1 as an example, if the data storage method provided in the embodiments of the present application is used, the recorded data is shown in Table 2. It should be noted that when storing time-type data, two serial numbers are occupied. It can be understood that taking the first frame of data to be stored as an example, for the time-type data (18:50:51), when stored by the data storage method (default to store data in hexadecimal), that is, (18:50:51) corresponds to (01021232, 02010033). Among them, 01 in 01021232 represents the serial number, 02 represents the control type, and 1232 represents 18 and 50. Also, because two serial numbers are occupied when storing time-type data, so 02 in 02010033 represents the serial number, 01 represents the control type, and 0033 represents 51. For 1230 of data type 1, it corresponds to (030204CE). Among them, 03 represents the serial number, 02 represents the control type, and 04CE represents 1230, and so on.

[0085] Please refer to Figure 5 and Figure 6 , Figure 5 which is a schematic diagram of the data storage result provided by another embodiment of the present application. Among them, Figure 5 (a) is the actual storage result corresponding to Table 1 using the existing recording method, Figure 5 (b) is the parsing result corresponding to the actual storage result of the existing recording method, Figure 6 which is a schematic diagram of the data storage result provided by another embodiment of the present application. Among them, Figure 6 (a) is the actual storage result corresponding to Table 2 using the data storage method, Figure 6 (b) is the parsing result corresponding to the actual storage result of the data storage method.

[0086] It can be seen from Figure 5 that Figure 5 in (a), all data are first converted to ASCII code values and then stored. Among them, the stored data includes tag data and numerical data (corresponding ASCII code values). Address (00000000 - 00000031) is the data tag address, and Address (00000032 - 00000074) is the numerical data address. When reading the subsequent data, according to the ASCII code table (hexadecimal), it can be found by looking up the table that: 30 represents 0, 31 represents 1, and so on. 39 represents 9, 3a represents the symbol ":", and 20 represents a space. By parsing the ASCII code, the following can be obtained Figure 5The result of (b). It can be understood that, for example, (31, 38, 3a, 35, 30, 3a, 35, 33) actually represents (18:50:53), and its corresponding data type is the time type. (20, 31, 32, 35, 30, 20, 33, 32, 30, 20, 38, 38, 30) actually represents (space, 1250, space, 320, space, 880), and its corresponding data types are (data type 1, data type 2, data type 3) respectively.

[0087] From Figure 6 it can be known that ( Figure 6 (the delimiter is omitted in (a)), Figure 6 all the data in (a) are stored using the data storage method proposed in the embodiments of the present application. Among them, all the data do not need to be converted to ASCII code values before storage. Address (00000000 - 0000003b) is the actual storage result corresponding to the data in Table 2. The data storage method described by the above embodiments can obtain Figure 6 the result of (b). It can be understood that, for example, (01, 02, 12, 32, 02, 01, 00, 33, 03, 02, 04, ce, 04, 02, 01, 54, 05, 02, 02, 26) actually represents this set of data (18:50:51, 1230, 340, 550).

[0088] In addition, by comparing Figure 5 and Figure 6 , it can also be seen that: the memory resources consumed by the data storage method are significantly less than those of the existing recording method. In addition, when the data type of the recorded data is 64 - bit or 32 - bit data, the existing recording method needs to record at least 10 - 20 bytes, while the 32 - bit data of the data storage method requires 8 bytes and occupies 2 serial numbers; if it is 64 - bit data, it occupies 16 bytes and a total of 4 serial numbers, that is, the actual content recorded by the data storage method is less and more space - saving.

[0089] The embodiments of the present application have the following three characteristics through comparison with the existing recording method:

[0090] In the first aspect, the original data is directly recorded, improving the storage efficiency and reducing the CPU burden. The data storage method of this application can directly write data into the storage device without additional conversion to ASCII code. This improvement eliminates the additional overhead of converting data to ASCII code in the traditional method, making the data recording process more efficient. Since there is no need to perform character conversion and additional processing steps, the recording speed is significantly increased, especially suitable for a CPU with heavy tasks. The CPU does not have to consume a large amount of computing resources on data conversion and storage operations, but can focus on executing the core business logic, improving the overall response speed and performance of the system. This method is particularly important for embedded devices, which can effectively reduce the CPU load and optimize the system operation efficiency.

[0091] In the second aspect, there is no need to mount a file system, which is suitable for resource-constrained embedded devices. Traditional data storage methods usually rely on file systems (such as FATFS, LittleFS) to manage and store data. However, the mounting and management of file systems require additional storage space and computing resources, which is not friendly to resource-constrained microcontrollers or embedded devices without an operating system. The data storage method of this application adopts a direct storage mechanism and does not rely on a file system, avoiding the additional storage management overhead brought by the file system, thus saving system resources. In addition, the absence of a file system means that the data storage and reading processes are simpler and can run under smaller storage space and lower computing power conditions, making this method more suitable for low-power, small embedded systems.

[0092] In the third aspect, the data storage format is optimized to increase the effective data payload rate. Traditional data storage methods usually require additional delimiters (such as spaces or commas) to distinguish adjacent data points, but these delimiters themselves do not carry any useful information, resulting in a waste of storage space. For example, when recording ten single-byte data (assuming that a single-byte data converted to decimal occupies 3 bytes), the effective data payload rate of the traditional method is about 75%. It can be understood that the effective data occupies 30 bytes and the total storage occupancy is 40 bytes, of which 10 bytes are delimiters. The effective data payload rate of the data storage method of this application is increased to 90%. It can be understood that since a data structure unit occupies 4 bytes and a delimiter occupies 4 bytes, but taking ten single-byte data as a frame of data, only one delimiter is needed. Therefore, the effective data occupies 40 bytes and the total storage occupancy is 44 bytes.

[0093] Based on this, by reasonably designing the data storage rules and only using necessary delimiters to isolate data at different time points, the storage of redundant characters is avoided, and the utilization rate of storage space is increased. For embedded devices with limited storage capacity, this method can store more data, improve the storage efficiency, and make the effective information carrying capacity of the unit storage space stronger.

[0094] Based on the data storage method provided in the above embodiments, the embodiments of the present application further provide a data storage device. Please refer to Figure 7 , Figure 7 which is a structural schematic diagram of the data storage device. As Figure 7 shown, the data storage device 200 includes: an acquisition module 210, a definition module 220, a processing module 230, and a storage module 240.

[0095] Among them, the acquisition module 210 is used to acquire the data to be stored. The definition module 220 is used to obtain a data storage rule according to the data to be stored and a preset data unit structure. The processing module 230 is used to process the data to be stored according to the data storage rule to obtain target storage data and a target storage address. The storage module 240 is used to store the target storage data according to the target storage address.

[0096] In some embodiments, the definition module 220 is specifically used for: obtaining the data type of the data to be stored according to the data to be stored; determining the length of the data to be stored according to the data type; and obtaining the data storage rule of the data type corresponding to the data to be stored according to the data type, the length, and the data unit structure.

[0097] In some embodiments, the definition module 220 is further used for: obtaining the data unit structure, where the data unit structure includes a serial number, a control type, first data, and second data; obtaining the control type according to the data type and the length; and obtaining the data storage rule of the data type corresponding to the data to be stored according to the control type.

[0098] It should be noted that the above data storage device can execute the data storage method provided by the embodiments of the present application, and has corresponding functional modules and beneficial effects for executing the method. For technical details not described in detail in the embodiments of the data storage device, reference can be made to the data storage method provided by the embodiments of the present application.

[0099] The embodiments of the present application further provide a single-chip microcomputer. Please refer to Figure 8 , which shows the hardware structure of a single-chip microcomputer capable of executing the method described in the above embodiments. The single-chip microcomputer 300 includes: at least one processor 310; and a memory 320 communicatively connected to the at least one processor 310. Figure 8 Taking one processor 310 as an example. The memory 320 stores instructions executable by the at least one processor 310, and the instructions are executed by the at least one processor 310 so that the at least one processor 310 can execute the data storage method described in the above embodiments. The processor 310 and the memory 320 can be connected by a bus or other means. Figure 8Take the bus connection as an example.

[0100] As a non-volatile computer-readable storage medium, the memory 320 can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as the program instructions / modules corresponding to the data storage method in the embodiments of the present application. By running the non-volatile software programs, instructions, and modules stored in the memory 320, the processor 310 executes various functional applications and data processing of the server, that is, implements the data storage method described in the above embodiments.

[0101] The memory 320 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created according to the use of the computing device. In addition, the memory 320 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some of these embodiments, the memory 320 may optionally include a memory remotely provided relative to the processor 310, and these remote memories can be connected to the computing device through a network. Examples of the above networks include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.

[0102] The one or more modules are stored in the memory 320 and, when executed by the one or more processors 310, execute the data storage method described in the above embodiments.

[0103] The above product can execute the method provided in the embodiments of the present application and has corresponding functional modules and beneficial effects for executing the method. For technical details not described in detail in this embodiment, reference can be made to the data storage method described in any embodiment of the present application.

[0104] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0105] Through the description of the above embodiments, those of ordinary skill in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course also by hardware. Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM), etc.

[0106] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; under the idea of the present application, the technical features in the above embodiments or different embodiments can also be combined, and the steps can be implemented in any order, and there are many other changes in different aspects of the present application as above. For the sake of brevity, they are not provided in detail; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A data storage method, characterized in that The method includes: Obtaining data to be stored; Obtaining a data storage rule according to the data to be stored and a preset data unit structure; Processing the data to be stored according to the data storage rule to obtain target storage data and a target storage address; Storing the target storage data according to the target storage address.

2. The data storage method according to claim 1, wherein The obtaining a data storage rule according to the data to be stored and a preset data unit structure includes: Obtaining the data type of the data to be stored according to the data to be stored; Determining the length of the data to be stored according to the data type; Obtaining a data storage rule corresponding to the data type of the data to be stored according to the data type, the length, and the data unit structure.

3. The data storage method according to claim 2, wherein The obtaining a data storage rule corresponding to the data type of the data to be stored according to the data type, the length, and the data unit structure includes: Obtaining the data unit structure, where the data unit structure includes a serial number, a control type, first data, and second data; Obtaining the control type according to the data type and the length; Obtaining the data storage rule corresponding to the data type of the data to be stored according to the control type.

4. The data storage method according to claim 3, wherein The processing the data to be stored according to the data storage rule to obtain target storage data and a target storage address includes: Obtaining data corresponding to the data type of the data to be stored; Allocating corresponding serial number, control type, first data, second data, and target storage address to the data according to the data storage rule; Recombining the data to be stored according to the serial number, the control type, the first data, and the second data to obtain recombined data to be stored; Obtaining the target storage data according to the recombined data to be stored and a separator.

5. The data storage method according to claim 4, characterized in that, The obtaining the target storage data according to the recombined data to be stored and a separator includes: Obtaining a target serial number according to the recombined data to be stored; Obtaining the separator according to the target serial number and the data unit structure; where the separator includes a serial number, the target serial number, a first check code, and a second check code; Combining the recombined data to be stored and the separator to obtain the target storage data.

6. The data storage method according to claim 1, wherein The storing the target storage data according to the target storage address includes: Calculating a storage space for the target storage data according to the target storage address; Storing the target storage data according to the target storage address and the storage space.

7. A data storage device, characterized in that, The device includes: An obtaining module, which is used to obtain data to be stored; A defining module, which is used to obtain a data storage rule according to the data to be stored and a preset data unit structure; A processing module, which is used to process the data to be stored according to the data storage rule to obtain target storage data and a target storage address; A storing module, which is used to store the target storage data according to the target storage address.

8. The data storage device according to claim 7, wherein The defined module is specifically configured to: Obtain the data type of the data to be stored according to the data to be stored; Determine the length of the data to be stored according to the data type; Obtain the data storage rule corresponding to the data type of the data to be stored according to the data type, the length, and the data unit structure.

9. The data storage device according to claim 8, wherein The defined module is further configured to: Obtain the data unit structure, where the data unit structure includes a serial number, a control type, first data, and second data; Obtain the control type according to the data type and the length; Obtain the data storage rule corresponding to the data type of the data to be stored according to the control type.

10. A single-chip microcomputer, characterized in that, It includes: At least one processor; And, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method according to any one of claims 1-6.

Citation Information

Cited By

  • Data storage method and device, storage medium and program product

    CN120596035A