Text log management method, device, equipment, and medium based on embedded system

By dividing the embedded system into sub-partitions and using specific methods to manage log data, the contradiction between scarce hardware resources and the need for large-capacity storage is resolved, enabling fast and easy-to-use management of massive text logs and meeting on-site maintenance requirements.

CN119493780BActive Publication Date: 2025-10-31SHENZHEN QIHUI ELECTRIC CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311033509.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-16
Publication Date
2025-10-31
Estimated Expiration
2043-08-16

AI Technical Summary

Technical Problem

The scarce hardware resources of embedded systems pose a significant contradiction to the demand for large-capacity log data storage, and existing technologies struggle to achieve fast and easy-to-use management of massive text log data.

Method used

The embedded system's storage area is divided into a contiguous log storage area, which is further divided into multiple sub-partitions of equal size. Fast retrieval, data writing, and reading methods are adopted, including skip reading, sequential writing, cyclic overwriting, and continuous reading. The offset position is determined using preset values ​​to optimize the storage and retrieval process.

Benefits of technology

It enables efficient management of massive text log data under conditions of scarce hardware resources, with fast retrieval and sequential writing, low system resource consumption, simple and easy-to-use support for on-site maintenance, and rapid deployment capability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119493780B_ABST
    Figure CN119493780B_ABST
Patent Text Reader

Abstract

This invention discloses a text log management method, apparatus, device, and medium based on an embedded system. The text log management method for an embedded system includes a storage medium divided into storage areas, which are further divided into partitions. The management method includes a writing method, a fast retrieval method, and a data reading method. This invention can be easily applied to embedded systems with relatively scarce hardware resources, resolving the contradiction between embedded system development and the need for large-capacity log data storage. It also meets the requirements of simple and easy-to-use field maintenance, is applicable to various storage media, consumes minimal system hardware resources, enables rapid deployment, and possesses advantages such as fast retrieval, sequential writing, data reading, automatic overwriting, and minimal resource consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of embedded system development, and in particular to a text log management method, apparatus, electrical equipment, and computer-readable storage medium based on embedded systems. Background Technology

[0002] During operation, electrical equipment encounters various working conditions, leading to abnormalities or deviations in its operation. Therefore, a comprehensive operation log system is needed to record these conditions; a read-only log system, in particular, is essential for on-site maintenance personnel to quickly analyze problems and troubleshoot faults. Since electrical equipment is often an embedded system with relatively scarce hardware resources, the conflict between these resources and the need for large-capacity log data storage is significant. Therefore, it is necessary to develop a method and device for managing massive text log data suitable for embedded systems to meet practical needs. Summary of the Invention

[0003] To address the aforementioned problems, this invention provides a simple, easy-to-use, reliable, and low-cost method for managing massive amounts of text log data, as well as electrical equipment and computer-readable storage media.

[0004] A text log management method based on an embedded system is proposed. This method divides the embedded system's storage area into a log storage area, which is a contiguous space further subdivided into multiple equal-sized sub-partitions. The method for managing massive text log data includes: a fast retrieval method, a data writing method, and a data reading method.

[0005] The fast retrieval method is applied during embedded system startup and includes:

[0006] S01, read the last N bytes of each sub-partition in a skip-style manner, and if the value of all N bytes is the first preset value, stop reading and determine the sub-partition as the current operation partition;

[0007] S02, Starting from the beginning of the current operation partition, read the data of the current operation partition sequentially until the read data is equal to the first preset value. The address of the first preset value is the current write offset.

[0008] S03, read the first N bytes of the next partition of the current operation partition. If all the read data are the first preset value, then determine that the original storage offset is located in the first sub-partition; otherwise, the original storage offset is located in the next partition of the current operation partition. Wherein, N is greater than or equal to 1.

[0009] S04 stores the current write offset and the original storage offset;

[0010] Data writing methods include:

[0011] S05, When saving log data, write it sequentially from the current write offset in plain text format;

[0012] S06, if the current write offset crosses the boundary of a sub-partition, set the content of the next sub-partition to the first preset value;

[0013] S07, If the current write offset exceeds the boundary of the last sub-partition, start overwriting historical data from the first sub-partition;

[0014] Data reading methods include:

[0015] S08 starts from the original storage offset and reads data continuously according to the length and position parameters of the data to be read.

[0016] A text log management device based on an embedded system includes a fast retrieval module, a data writing module, and a data reading module; wherein,

[0017] The quick search module includes:

[0018] The current operation partition determination submodule is used to read the last N bytes of each subpartition in a skipping manner. If the value of all N bytes is the first preset value, the reading is stopped and the subpartition is determined as the current operation partition.

[0019] The current write offset determination submodule is used to read the data of the current operation partition sequentially from the beginning position of the current operation partition until the read data is equal to the first preset value. The address of the first preset value is then the current write offset.

[0020] The original storage offset determination submodule is used to read the first N bytes of the next partition of the current operation partition. If all the read data are the first preset value, the original storage offset is determined to be located in the first subpartition; otherwise, the original storage offset is located in the next partition of the current operation partition. Wherein, N is greater than or equal to 1.

[0021] The cache submodule is used to store the current write offset and the original storage offset;

[0022] The data writing module includes:

[0023] The sequential write submodule is used to write log data sequentially in plain text format, starting from the current write offset.

[0024] The data reset submodule is used to set the content of the next sub-partition to the first preset value if the current write offset crosses the boundary of a sub-partition.

[0025] The loop overwrite submodule is used to overwrite historical data starting from the first subpartition if the current write offset exceeds the boundary of the last subpartition.

[0026] The data reading module includes:

[0027] The free read submodule is used to continuously read data starting from the original storage offset, based on the length and position parameters of the data to be read.

[0028] An electrical device includes an embedded system, the embedded system employing the text log management method based on the embedded system described above.

[0029] A computer-readable storage medium storing a computer program, characterized in that, when executed by a processor, the computer program implements the text log management method based on an embedded system as described above.

[0030] The aforementioned text log management method, device, equipment, and medium based on embedded systems can be easily applied to embedded systems with relatively scarce hardware resources, resolving the contradiction between embedded system development and the need for large-capacity log data storage. At the same time, it can meet the requirements of simple and easy-to-use field maintenance, is applicable to various storage media, occupies few system hardware resources, can be deployed quickly, and has advantages such as fast retrieval, sequential writing, data reading, automatic overwriting, and minimal resource consumption. Attached Figure Description

[0031] Figure 1 This is a schematic diagram of the minimum partition in an embodiment of the present invention;

[0032] Figure 2 This is a schematic diagram illustrating the determination of the current write offset in an embodiment of the present invention;

[0033] Figure 3 This is a schematic diagram illustrating the process of writing data in an embodiment of the present invention;

[0034] Figure 4 This is a schematic diagram illustrating automatic overwriting in an embodiment of the present invention. Detailed Implementation

[0035] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0036] A text log management method based on an embedded system, applied in electrical equipment, allocates a contiguous space within the embedded system's storage area as a log storage area. This log storage area is specifically used to store log data. To facilitate fast data retrieval, location, read / write operations, the allocated contiguous storage area needs to be divided according to a minimum partitioning rule, that is, the log storage area is divided into multiple sub-partitions of equal size.

[0037] The text log management method is suitable for massive amounts of text log data and includes three parts: fast retrieval method, data writing method, and data reading method.

[0038] The fast retrieval method is applied during the startup of the embedded system and includes:

[0039] S01: Read the last N bytes of each sub-partition in a skip-style manner, taking sub-partitions as the unit. If the value of all N bytes is the first preset value, stop reading and determine the sub-partition as the current operation partition.

[0040] like Figure 1 As shown, each sub-partition is also called a minimum partition, and the size of the sub-partition can be any one of 256 bytes, 512 bytes, 1024 bytes, 2048 bytes, or 4096 bytes; alternatively, it can be divided according to the available memory overhead of the embedded system, or it can be determined according to the size of the minimum partition of the storage medium (such as the Sector or Block of FLASH memory). N is a natural number greater than 1.

[0041] The first preset value, also known as reset data, is used to fill the partition. The preferred first preset value is 0xFF. Before moving from one partition to the next, the entire next partition needs to be filled with the reset data 0xFF. Therefore, if four consecutive bytes of 0xFF are found in the partition data, this partition can be identified as the current partition. Specifically, taking N=4 as an example, the last four bytes of each smallest partition are read in a skipping manner. If the last four bytes of the smallest partition are all 0xFF, the process stops, and this smallest partition is identified as the current partition.

[0042] S02, starting from the beginning of the current operation partition, read the data of the current operation partition sequentially until the read data is equal to the first preset value, then the address of the first preset value is the current write offset.

[0043] The current write offset points to the location where log data is written. For example... Figure 2 As shown, taking a first preset value of 0xFF as an example, starting from the beginning of the current operation partition, the data of the current operation partition is read sequentially until the place where the reset data 0xFF is found is found. Figure 2(At point A). At this time, the value of A is 0xFF, and the address of A is the current write offset. Understandably, after the log content is sequentially written to the currently operating partition, the offset for filling and resetting the data by 0xFF will be shifted forward within the partition.

[0044] S03, read the first N bytes of the next partition of the current operation partition. If all the read data are the first preset value, then determine that the original storage offset is located in the first sub-partition; otherwise, the original storage offset is located in the next partition of the current operation partition. Wherein, N is greater than or equal to 1.

[0045] Because log data is stored and overwritten cyclically within the storage space, the original storage offset of the log data is not necessarily the starting position of the first subpartition; it could be on another subpartition. The original storage offset is used to point to the starting position of the log data. For example, when reading the first 4 bytes of data of the next partition after the currently operated partition, if the read data is the reset data 0xFF, then the original storage offset is determined to be the first smallest partition; otherwise, it is the next partition after the previous partition.

[0046] S04 stores the current write offset and the original storage offset.

[0047] The current write offset and the original storage offset obtained from the above traversal are cached. Both offsets are used for subsequent log data writing and reading operations.

[0048] For data writing methods, please refer to [reference]. Figure 3 , Figure 4 ,include:

[0049] S05, When saving log data, write it sequentially in plain text format starting from the current write offset. That is, based on the current write offset, write the log data to be saved in the order of the current write offset, and the log data should be in plain text format.

[0050] S06, if the current write offset crosses the boundary of a sub-partition, set the content of the next sub-partition to the first preset value. That is, during the data saving process, if the write offset crosses the minimum partition boundary, the next minimum partition should be reset so that all the content of the next minimum partition becomes 0xFF.

[0051] S07, if the current write offset exceeds the boundary of the last sub-partition, historical data is overwritten starting from the first sub-partition. That is, when the write offset exceeds the boundary of the defined storage medium range, the next smallest partition to be written to will return to the first smallest partition. At this time, the write offset is reset to zero, the starting save offset is reset, historical data is sequentially overwritten, and the write overwrite flag is reset for log reading retrieval.

[0052] Furthermore, during the data writing process, when the length of the saved data is not aligned, for example, if it is not aligned to 4 bytes, a space character is added at the end of the write operation to ensure that the overall length of the data is aligned to 4 bytes, thereby saving fragmented space and improving the utilization of storage space.

[0053] Data reading methods include:

[0054] S08 starts from the original storage offset and reads data continuously according to the length and position parameters of the data to be read.

[0055] Specifically, let the known parameters be: total storage capacity Sz, original storage offset Ma of the log data, relative offset RO of the data to be read, and length RL of the data to be read. If the text to be read is a continuous region in the storage space, then the starting position offset of this region = Ma + RO, and the specified length RL of data can be read continuously starting from this offset.

[0056] Because the storage log is constantly being added and overwritten, the original offset Ma is constantly changing. Ma could be the starting position of any partition within the storage space, so Ma+RO may exceed the storage space range. When Ma+RO exceeds the storage space size (Sz), a rollback operation should be performed. The rollback operation includes, but is not limited to, taking the remainder of the calculation result by the storage space size (Sz), and so on. That is, if this problem occurs when the address is continuously read and incremented, it should also be handled in this way.

[0057] A text log management device based on an embedded system is provided, including a fast retrieval module, a data writing module, and a data reading module. The fast retrieval module includes: a current operation partition determination submodule, a current write offset determination submodule, a raw storage offset determination submodule, and a cache submodule. The data writing module includes a sequential write submodule, a data reset submodule, and a loop overwrite submodule. The data reading module includes a free read submodule. The functions of each of these submodules correspond to the aforementioned text log management method and will not be repeated here.

[0058] An electrical device is provided, which includes an embedded system that employs the text log management method based on the embedded system described above.

[0059] A computer-readable storage medium is provided, the computer-readable storage medium storing a computer program, which, when executed by a processor, implements the text log management method based on an embedded system as described above.

[0060] The above is a description of the present invention to help understand it. However, the implementation of the present invention is not limited to the above embodiments. Any changes, modifications, substitutions, combinations, or simplifications made without departing from the principle of the present invention should be considered equivalent substitutions and are included within the protection scope of the present invention.

Claims

1. A text log management method based on an embedded system, characterized in that, A log storage area is defined in the storage area of ​​the embedded system. The log storage area is a contiguous space and is divided into multiple sub-partitions of equal size. The text log management method includes: a fast retrieval method, a data writing method, and a data reading method, wherein, The fast retrieval method is applied during the startup of the embedded system and includes: S01, taking the sub-partition as a unit, read the last N bytes of each sub-partition in a skipping manner. If the value of the N bytes is the first preset value, stop reading and determine the sub-partition as the current operation partition. S02, Starting from the beginning of the current operation partition, read the data of the current operation partition sequentially until the read data is equal to the first preset value, then the address of the first preset value is the current write offset; S03, read the first N bytes of the next partition of the current operation partition. If all the read data are the first preset value, then determine that the original storage offset is located in the first sub-partition; otherwise, the original storage offset is located in the next partition of the current operation partition; wherein, N is greater than or equal to 1. S04, store the current write offset and the original storage offset; The data writing method includes: S05, when saving log data, write it sequentially from the current write offset in plain text format; S06, if the current write offset crosses the boundary of a sub-partition, the content of the next sub-partition is set to the first preset value; S07, if the current write offset exceeds the boundary of the last sub-partition, the historical data is overwritten starting from the first sub-partition; The data reading method includes: S08, starting from the original storage offset, continuously read data according to the length and position parameters of the read data.

2. The text log management method based on an embedded system as described in claim 1, characterized in that, In the data writing method, when the length of the saved data is not aligned to 4 bytes, a space character is added at the end of the write operation.

3. The text log management method based on an embedded system as described in claim 1 or 2, characterized in that, The first preset value is 0xFF.

4. The text log management method based on an embedded system as described in claim 1 or 2, characterized in that, The value of N is 4.

5. The text log management method based on an embedded system as described in claim 1 or 2, characterized in that, The size of the sub-partition is any one of 256 bytes, 512 bytes, 1024 bytes, 2048 bytes, or 4096 bytes.

6. A text log management device based on an embedded system, characterized in that, The embedded system-based text log management device is used to implement the embedded system-based text log management method as described in any one of claims 1 to 5, and includes a fast retrieval module, a data writing module, and a data reading module; wherein, The fast retrieval module includes: The current operation partition determination submodule is used to read the last N bytes of each subpartition in a skipping manner, and if the value of the N bytes is the first preset value, then the reading is stopped and the subpartition is determined as the current operation partition. The current write offset determination submodule is used to read the data of the current operation partition sequentially from the beginning position of the current operation partition until the read data is equal to the first preset value. The address of the first preset value is then the current write offset. The original storage offset determination submodule is used to read the first N bytes of the next partition of the current operation partition. If all the read data are the first preset value, the original storage offset is determined to be located in the first subpartition; otherwise, the original storage offset is located in the next partition of the current operation partition. Wherein, N is greater than or equal to 1. The cache submodule is used to store the current write offset and the original storage offset; The data writing module includes: The sequential write submodule is used to write log data sequentially in plain text format starting from the current write offset when saving log data; The data reset submodule is used to set the content of the next sub-partition to the first preset value if the current write offset crosses the boundary of the sub-partition. The loop overwrite submodule is used to overwrite historical data starting from the first subpartition if the current write offset exceeds the boundary of the last subpartition. The data reading module includes: The free read submodule is used to continuously read data starting from the original storage offset, based on the length and position parameters of the data to be read.

7. An electrical device, characterized in that, The electrical equipment includes an embedded system, which employs the text log management method based on the embedded system as described in any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the text log management method based on an embedded system as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Vehicle-mounted MCU configurable log storage and analysis method and system

    CN112732522A

  • Cross-region access method for embedded file system

    US20120102012A1