A log access method, device and storage medium

CN122507704BActive Publication Date: 2026-11-03贵州航天控制技术有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202610995765.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-07-06
Publication Date
2026-11-03
Estimated Expiration
2046-07-06

AI Technical Summary

Technical Problem

[0003]当前传统嵌入式日志存取方案普遍存在明显缺陷:多数日志系统依赖通用文件系统实现日志管理,需占用大量代码空间与运行内存,显著增加系统复杂度与资源开销;部分方案采用多级地址映射表或索引表实现日志定位,不仅需要额外存储资源维护映射关系,还需在读写时执行查表、匹配、遍历等操作,大幅降低日志存取速度,导致系统实时性变差;同时,映射表的创建、更新、校验与维护流程繁琐,提升了开发难度与运维成本

Benefits of technology

[0029](1)本发明采用时间地址直接映射计算,无需文件系统、映射表及额外数据结构维护,算法极简、资源开销小、存取速度快,可精准定位日志地址。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122507704B_ABST
    Figure CN122507704B_ABST
Patent Text Reader

Abstract

The application relates to a log access method, device and storage medium, and belongs to the technical field of embedded software log management. In view of the problems of the existing embedded log access system, such as complexity, large resource consumption, low access efficiency and poor operability, a fast access algorithm based on time address mapping is adopted, the log physical storage address is directly calculated through time information, a file system and a mapping table are not needed, and an additional data structure does not need to be maintained. The algorithm is simple, efficient and low in resource occupation, can realize fast positioning and stable access of logs, is suitable for resource limited scenes such as embedded devices, and effectively balances the reliability, timeliness and operability of log access.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of embedded software log management technology, and in particular to a log access method, apparatus and storage medium. Background Technology

[0002] With the rapid popularization and large-scale application of the Internet of Things (IoT), Industrial Internet, smart terminals, and embedded systems, embedded computing units have been widely deployed in consumer electronics, industrial control, automotive equipment, smart homes, medical instruments, and various smart terminal products. Modular, miniaturized, and low-power hardware architectures and lightweight software designs have become the mainstream trend in embedded product development. Log recording and access functions, as key supporting technologies for embedded software operation monitoring, fault location, data traceability, status backtracking, and security auditing, directly determine the maintainability, stability, and troubleshooting efficiency of the system. Especially on resource-constrained microcontroller, small SOC, and low-cost embedded hardware platforms, where storage capacity is limited, computing power is weak, and memory space is scarce, extremely high demands are placed on the simplicity, efficiency, and reliability of logging systems.

[0003] Current traditional embedded log storage solutions generally suffer from significant drawbacks: most log systems rely on general-purpose file systems for log management, requiring substantial code space and runtime memory, significantly increasing system complexity and resource overhead; some solutions employ multi-level address mapping tables or index tables for log location, necessitating additional storage resources to maintain mapping relationships and performing table lookups, matching, and traversal operations during read / write operations, drastically reducing log access speed and degrading system real-time performance; simultaneously, the creation, updating, verification, and maintenance of mapping tables are cumbersome, increasing development difficulty and operational costs. Furthermore, existing technologies generally struggle to simultaneously achieve integrity, efficiency, simplicity, and stability in log storage, easily leading to high latency, data loss, slow location, and poor compatibility in resource-constrained scenarios, failing to meet the practical needs of embedded devices for lightweight, highly reliable, and fast-response log systems.

[0004] Therefore, designing a log access method that requires no file system, has no additional mapping overhead, is simple in algorithm, has fast access speed, and is adaptable to embedded environments has become a technical problem that urgently needs to be solved in this field. Summary of the Invention

[0005] To address the aforementioned technical problems, embodiments of the present invention provide a log access method, apparatus, and storage medium based on time address mapping, enabling fast log access, accurate location, and low-resource consumption operation in embedded environments. The technical solution adopted by the present invention is as follows:

[0006] A log access method, comprising the following steps:

[0007] After the device starts up, it calculates the corresponding physical storage address based on the time information of the log generation according to the preset time address mapping algorithm, and writes the log data into the storage area corresponding to the physical storage address.

[0008] When a log read command is received, the target time information in the command is extracted, and the physical storage address corresponding to the target time is calculated using the time address mapping algorithm to determine the starting address and data length for reading the log data.

[0009] Based on the calculated physical storage address, starting address, and data length, the corresponding log data is read from the storage medium, and the reading results are output through the external communication interface.

[0010] Optionally, based on a preset time-address mapping algorithm, the corresponding physical storage address is calculated according to the time information generated by the log, specifically including:

[0011] The acquired raw time information is processed according to preset time granularity rules. Based on the system's set log storage period and time precision, key time parameters for address calculation are extracted. The time parameters are standardized and converted to remove invalid bits and redundant information, and uniformly converted into a numerical format that can be directly used in algorithm calculation, providing standardized input for address calculation.

[0012] Optionally, a preset time address mapping algorithm is invoked, and the normalized time parameters are substituted into the algorithm formula for mathematical operations. Through fixed arithmetic relationships, the time information is directly converted into physical storage addresses on the storage medium.

[0013] Optionally, the calculated physical storage address is validated to determine whether it is within the valid address range of the preset log storage area, thus preventing data writing errors caused by address out-of-bounds access. At the same time, based on the fixed length of the log data, the storage block corresponding to the current address is checked to ensure it has sufficient space. Once confirmed, the physical storage address is locked as the location for writing the log data.

[0014] Optionally, the runtime log data to be stored is encapsulated according to a preset format, supplemented with auxiliary content such as log identifier, data length, and verification information to form a complete log data package that conforms to the storage specifications; the encapsulated log data is then transferred to the data writing buffer to complete the data preparation before writing.

[0015] Based on the verified physical storage address, the storage medium is controlled to perform a write operation, accurately writing the log data in the cache to the storage area corresponding to that address. After the data is written, the write result is verified to confirm that the log data is stored completely and without error in the target location, thus completing a single log write process.

[0016] Optionally, the physical storage address corresponding to the target time is calculated using the time address mapping algorithm, specifically including:

[0017] The extracted and verified target time information will be processed according to the same time granularity and regularization rules as the log writing steps, and the numerical format, valid bits and calculation methods of the time parameters will be unified to ensure that the time parameters on the reading side and the time parameters on the writing side are consistent at the algorithm input level.

[0018] The time address mapping algorithm, which is exactly the same as the log writing step, is invoked. The standardized target time parameter is substituted into the algorithm for mathematical operations, and the physical storage address of the log is directly obtained through fixed arithmetic relationships.

[0019] Optionally, the starting address and data length for reading log data are determined, specifically including:

[0020] The physical address calculated by the algorithm is determined as the starting address for reading log data. The storage boundary of the starting address is checked to determine whether it is within the preset legal log storage range, so as to avoid reading failure or data corruption due to address out of bounds.

[0021] Based on the system's preset log storage time granularity and address allocation rules, the length of the log data stored in the corresponding address block is directly derived from the current time granularity; the determined read start address and data length are combined into complete read parameters.

[0022] Optionally, reading the corresponding log data from the storage medium specifically includes: reading log data in batches from the storage medium according to a determined address and length, and writing the read data segment by segment into a pre-locked data buffer.

[0023] A log access device for implementing the above-described log access method, the device comprising an address calculation unit, an instruction parsing unit, and a data read / write unit;

[0024] The address calculation unit is used to calculate the corresponding physical storage address based on the time information of log generation according to the preset time address mapping algorithm after the device is started, and write the log data into the storage area corresponding to the physical storage address.

[0025] The instruction parsing unit is used to extract the target time information in the instruction when a log read instruction is received, calculate the physical storage address corresponding to the target time through the time address mapping algorithm, and determine the starting address and data length of the log data read.

[0026] The data read / write unit is used to read the corresponding log data from the storage medium based on the calculated physical storage address, starting address, and data length, and output the read results through the external communication interface.

[0027] A storage medium, which is a computer-readable storage medium, has computer-readable program instructions stored thereon for performing the above-described log access method.

[0028] This invention provides a log access method, apparatus, and storage medium. The technical solutions provided by the embodiments of this invention bring at least the following beneficial effects:

[0029] (1) The present invention uses direct time address mapping calculation, which does not require file system, mapping table and additional data structure maintenance. The algorithm is extremely simple, has low resource overhead and fast access speed, and can accurately locate log address.

[0030] (2) The present invention is robust and stable in operation, adaptable to embedded resource-constrained environments, and can adaptively adjust the time granularity and storage cycle, reliably balancing the integrity, timeliness and ease of use of log access.

[0031] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0032] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0033] Figure 1 This is a flowchart illustrating the log access method.

[0034] Figure 2 A diagram showing the mapping relationship between log access time and address. Detailed Implementation

[0035] To make the objectives, technical solutions, and advantages of this invention clearer, the invention 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 merely illustrative and not intended to limit the invention.

[0036] Before describing the technical solution of the present invention in detail, the technical background and technical terms involved in the technical solution will be explained first:

[0037] Time-address mapping: The time information generated by the logs is directly and uniquely converted into a physical storage address on the storage medium using a preset mathematical formula. This ensures that each set of time parameters corresponds to a fixed and unique log storage location, achieving a direct conversion relationship between "time" and "address". Time-address mapping is the core algorithm mechanism of this invention. It does not rely on mapping tables, index tables, or file systems; it only requires arithmetic operations on time (year / month / day / hour / minute / second) to obtain the physical address of the log storage. The address calculated for the same time parameter remains unchanged, ensuring consistency between the log writing and reading addresses and avoiding conflicts and errors. Fixed storage areas are used to improve addressing speed; during reading, only the target time needs to be input, and the address is immediately calculated and the data located, significantly improving response speed. Old logs are cyclically overwritten according to a set period, eliminating the need for manual storage space management and simplifying embedded system design.

[0038] On the one hand, the present invention provides a log access method, Figure 1 This is a flowchart illustrating the log access method. The method includes the following steps:

[0039] Step S101: After the device starts up, based on the preset time address mapping algorithm, the corresponding physical storage address is calculated according to the time information of the log generation, and the log data is written to the storage area corresponding to the physical storage address.

[0040] The above steps are used to implement log writing. After the device starts running, relying on the time address mapping algorithm, the real-time generated log data is automatically, quickly, and accurately written to the physical storage address uniquely determined by the time information, completing the persistent storage of log data. This step does not require file system, mapping table, or index structure support; it directly obtains the storage address through time information calculation, realizing on-demand writing of log data. The specific implementation sub-steps are as follows:

[0041] Sub-step 1-1: System power-on initialization and time source acquisition.

[0042] After the device completes power-on reset, it first initializes and configures the log storage module, clock module, and communication interface to ensure that the storage medium can be read and written normally and that the system time remains accurate. Then, it obtains the current standard time information from the device's built-in real-time clock module, including time parameters such as month, date, hour, minute, and second, and verifies the validity of the obtained time information to exclude abnormal time data and ensure the accuracy of subsequent address calculations.

[0043] Sub-steps 1-2: Time parameter normalization and format conversion.

[0044] The acquired raw time information is processed according to preset time granularity rules. Based on the system's set log storage period and time precision, key time parameters for address calculation are extracted. The time parameters are standardized and converted to remove invalid bits and redundant information, and uniformly converted into a numerical format that can be directly used in algorithm calculation, providing standardized input for address calculation.

[0045] Sub-steps 1-3: Execute the time-address mapping algorithm to calculate the physical storage address.

[0046] The algorithm calls a preset time address mapping algorithm, substitutes the normalized time parameters into the algorithm formula for mathematical operations, and directly converts the time information into a physical storage address on the storage medium through a fixed arithmetic relationship. This algorithm can ensure that each set of time parameters uniquely corresponds to a physical storage address, without querying a mapping table or relying on the file system, and directly obtains the target write address of the log data.

[0047] Sub-steps 1-4: Storage address validity and boundary verification.

[0048] The calculated physical storage address is validated to determine whether it is within the valid address range of the preset log storage area, thus preventing data writing errors caused by address out-of-bounds access. At the same time, based on the fixed length of the log data, the storage block corresponding to the current address is checked to ensure it has sufficient space. Once confirmed to be correct, the physical storage address is locked as the location for writing the log data.

[0049] Sub-steps 1-5: Log data encapsulation and writing preparation.

[0050] The runtime log data to be stored is encapsulated according to a preset format, supplemented with auxiliary content such as log identifier, data length, and verification information to form a complete log data package that conforms to the storage specifications; the encapsulated log data is then transferred to the data writing buffer to complete the data preparation before writing, ensuring stable data transmission without loss.

[0051] Sub-steps 1-6: Write log data to the target address.

[0052] Based on the verified physical storage address, the storage medium is controlled to perform a write operation, accurately writing the log data in the cache to the storage area corresponding to that address. After the data is written, the write result is verified to confirm that the log data is stored completely and without error in the target location, thus completing a single log write process. When new logs are generated subsequently, the above sub-steps are repeated to continuously perform write operations according to the time-mapped address.

[0053] The above steps ensure reliable storage of log data, solidifying device operating status, events, and fault information into the storage medium to prevent data loss due to power outages or restarts. A unique correspondence between time and storage address is established, ensuring each log entry has a fixed location in the storage medium that can be directly located by time. Automatic allocation and management of storage addresses are implemented, cyclically overwriting old data according to a preset period without requiring manual maintenance of storage space. Resource consumption in embedded systems is reduced by using a simplified algorithm for writing, minimizing code size, memory usage, and computational overhead. These steps provide a queryable and location-based log data source for device operation monitoring, fault tracing, and status auditing; achieve lightweight, efficient, and stable log recording in embedded environments, solving the problems of complexity, inefficiency, and high overhead in traditional solutions; and lay the foundation for address rules for subsequent fast log reading and accurate querying, ensuring that writing and reading use completely consistent address mapping logic.

[0054] Based on the unique correspondence between time and physical storage address established in the above log writing steps, as well as the unified time address mapping algorithm rules throughout the process, a reliable addressing foundation has been laid for the rapid retrieval and accurate reading of log data. This ensures that log writing and reading use completely consistent address calculation logic, achieving seamless matching between storage rules and reading rules. Under this premise, the log reading step can be directly entered to efficiently obtain the specified log data.

[0055] Step S102: When a log read instruction is received, the target time information in the instruction is extracted, and the physical storage address corresponding to the target time is calculated using the time address mapping algorithm to determine the starting address and data length of the log data read.

[0056] The above steps are used to calculate the log read address. The core function of this step is to parse the log read command upon receipt, extract the target time information, and use the same time-address mapping algorithm as log writing to convert the time information to the physical storage address. This ultimately determines the starting address and corresponding data length for log reading, providing accurate, valid, and complete addressing parameters for subsequent log read operations. This step completes the parsing of the read command and extraction of time information, establishing an effective conversion from command information to addressing parameters; ensuring that log reading uses the exact same address mapping rules as writing, guaranteeing address reproducibility and matchability; validating the target time and calculated address to avoid address out-of-bounds errors and abnormal data reading; and simultaneously determining the starting address and data length for reading, providing a complete and reliable execution basis for subsequent data reading. The specific implementation sub-steps are as follows:

[0057] Sub-step 2-1: Instruction reception and validity verification.

[0058] The system listens for and receives log reading commands from external devices in real time through an external communication interface. It verifies the completeness, format, and type of the commands, filters out invalid, erroneous, or abnormally formatted commands, and proceeds to the next processing step after confirming that the command is a valid log reading command.

[0059] Sub-step 2-2: Extraction and parsing of target time information.

[0060] From the valid log read commands, locate and extract the target time parameters carried by the commands, including time information such as month, date, hour, minute, and second that are consistent with the log write phase; perform format parsing and validity verification on the extracted time information, exclude erroneous data such as time out of bounds and abnormal values, and ensure that the time parameters used in address calculation are accurate and usable.

[0061] Sub-step 2-3: Time parameter standardization and alignment.

[0062] The extracted and verified target time information will be processed according to the same time granularity and regularization rules as the log writing steps. The numerical format, valid bits, and calculation caliber of the time parameters will be unified to ensure that the time parameters on the reading side and the writing side are consistent at the algorithm input level, providing a prerequisite for accurate address calculation.

[0063] Sub-step 2-4: Execute the time-address mapping algorithm to calculate the target physical address.

[0064] The time address mapping algorithm, which is exactly the same as the log writing step, is invoked. The standardized target time parameter is substituted into the algorithm for mathematical operations, and the physical storage address of the log is directly obtained through fixed arithmetic relations. This calculation process does not require querying the mapping table or traversing the index, and directly outputs the unique target read address.

[0065] Sub-step 2-5: Read the starting address for confirmation and verify the storage boundary.

[0066] The physical address calculated by the algorithm is determined as the starting address for reading log data. The storage boundary of this starting address is checked to determine whether it is within the preset legal log storage range. This avoids reading failure or data corruption due to address out-of-bounds errors and ensures the security and stability of subsequent data reading.

[0067] Sub-step 2-6: Determine the log data length based on the time granularity.

[0068] Based on the system's preset log storage time granularity and address allocation rules, the length of the log data stored in the corresponding address block is directly derived from the current time granularity; the determined read start address and data length are combined into complete read parameters, providing a basis for accurately reading log data from the storage medium in the future.

[0069] The above steps enable precise addressing of logs without table lookups or traversals, quickly locating the storage location of the target log; ensuring the standardization, security, and stability of the log reading process, and improving the reliability of log reading in embedded systems; providing necessary parameter support for the final log data reading and output, so that subsequent execution steps can run directly based on the calculation results.

[0070] Through the above log reading address calculation steps, the starting address and corresponding data length of the log data have been accurately determined, forming complete and valid reading execution parameters, which provide a direct and reliable execution basis for the subsequent acquisition and output of log data. With the above addressing and parameter preparation work completed, the system can directly enter the execution stage of log data reading and result output to complete the entire log reading process.

[0071] Step S103: Based on the calculated physical storage address, starting address and data length, read the corresponding log data from the storage medium and output the reading result through the external communication interface.

[0072] The above steps are used to implement log data reading and output. The core function of this step is to accurately read the target log data from the storage medium based on the physical storage address, starting address, and data length determined in the previous steps, and to output the log data completely and stably to the external device through the external communication interface according to the communication specifications, completing the closed-loop execution of the entire process from instruction parsing and address calculation to log return. This step achieves accurate reading of log data, directly reading data according to the calculated address and length without addressing, table lookup, or traversal, ensuring reading efficiency and data accuracy; it completes the external output of log data, converting offline logs stored on the local medium into online data that can be obtained externally, meeting the needs of log viewing, fault analysis, and status tracing; it ensures the standardization and reliability of data transmission, organizing, encapsulating, and verifying the read data to avoid packet loss, errors, or anomalies during transmission; as the final step in the entire log access process, it receives the address calculation results, performs the final read / write action, and provides feedback on the results, giving the log system complete query and export capabilities. The specific implementation sub-steps are as follows:

[0073] Sub-step 3-1: Read parameter reception and cache locking.

[0074] The system receives the starting address, data length, and physical storage address parameters output in the previous step, performs integrity and consistency checks on the parameters, and after confirming that the parameters are legal and valid, locks the read channel and data buffer of the log storage medium to avoid data reading abnormalities caused by multi-task conflicts, and provides a stable execution environment for data reading.

[0075] Sub-step 3-2: Storage medium addressing and reading preparation.

[0076] Based on the verified starting address, and combined with the preset data length, the target data block in the storage medium is located. The storage medium is controlled to complete the addressing action, and the read / write pointer is positioned at the starting position of the data to be read. At the same time, the read enable configuration of the storage medium is completed, and the system enters the read-read state.

[0077] Sub-step 3-3: Perform data reading according to the specified length.

[0078] Log data is read in batches from the storage medium according to the determined address and length. The read data is written to a pre-locked data buffer segment by segment. During the reading process, the integrity and correctness of the data are verified in real time to ensure that the read data is consistent with the log data at the time of writing, without loss or error.

[0079] Sub-steps 3-4: Reading, organizing, and formatting the data.

[0080] The raw log data in the buffer is organized, redundant padding information is removed, and the log data is encapsulated according to the communication protocol requirements. Auxiliary information such as data identifier, length description, and check code are added to form a complete data frame that conforms to the external device's reception specifications.

[0081] Sub-step 3-5: Prepare for external communication interface output.

[0082] The encapsulated log data is transmitted to the sending buffer of the external communication interface, the interface communication parameters are configured, a data transmission link with the external device is established, and after confirming that the sending channel is idle and the link is normal, the data transmission ready state is entered.

[0083] Sub-steps 3-6: Log data sending and result feedback.

[0084] The encapsulated log data is sent out through an external communication interface. After the sending is completed, the sending status is confirmed and the reading and output execution results are fed back. If the reading or sending is abnormal, the abnormal status is automatically marked. If it is normal, the entire process of reading and outputting logs is completed.

[0085] The above steps provide users or external devices with directly usable log data, enabling the monitoring, traceability, and analysis of the embedded device's operating status; ensuring that the log reading process is efficient, simple, and stable, achieving lightweight and highly reliable data output in resource-constrained embedded environments; and completing the entire closed-loop process of log access methods, making the log writing, addressing, reading, and output form a unified, coherent, and implementable execution system.

[0086] Figure 2This diagram illustrates the log access time-address mapping relationship, showcasing the direct time-physical address mapping mechanism based on pure arithmetic operations employed in this invention. It clearly demonstrates the simplified addressing logic that eliminates the need for a file system and mapping tables. The core calculation expression for the time-address mapping algorithm of this invention is explicitly shown at the top of the diagram.

[0087] ;

[0088] This formula follows a fixed set of linear arithmetic operations, with no conditional branches or table lookups. It directly converts the log generation time information into a linear physical address offset on the storage medium through modulo, multiplication, and addition operations on the time parameter, providing a unified addressing basis for log writing and reading. The operational logic of each part of the formula is explained below:

[0089] The modulo operation of month%2 is performed on the month, and the address space is partitioned by the parity of the month (odd month takes 1, even month takes 0), and the basic layer of address offset is built with "month" as the unit.

[0090] (month%2)*31+day-1 combines the month parity offset with the date sequence number to calculate the address offset in "day" granularity. The coefficient of multiplying by 31 ensures that the date address ranges of different months do not overlap. Even if the number of days in a month is different, a linear and continuous address space can be obtained through this operation.

[0091] *24+hour extends the "day" level address offset, refining the address granularity to the "hour". By multiplying by 24 (the number of hours in a day) and adding the current hour value, a unique address value ADDR with hour precision is finally obtained, realizing the complete conversion from three-level time parameters of month, day, and hour to linear address.

[0092] A downward-pointing arrow in the diagram points from the aforementioned algorithm formula to a continuous array of rectangular storage cells below, clearly illustrating the core logic that "time parameters are directly mapped to physical storage locations through algorithmic calculations." The multiple rectangles below represent dedicated, contiguous storage areas allocated for log data within the storage medium. Each rectangle corresponds to a unique physical address offset calculated by the algorithm, representing a fixed point in time. The arrow's direction visually demonstrates the unidirectional and direct nature of the mapping relationship: each unique set of month, day, and hour parameters yields only one unique physical address through this algorithm; conversely, when reading, inputting the same set of time parameters allows for the recalculation of a completely identical physical address offset using the same algorithm, achieving unified and mutually recognized address rules for writing and reading.

[0093] This schematic diagram fully reveals the core technical features of the present invention: by establishing a one-to-one correspondence between time information and storage address through a preset pure arithmetic operation formula, the addressing process that originally required the file system or multi-level index table is simplified into a one-step direct calculation, thereby eliminating the overhead of mapping table maintenance, improving access efficiency, and providing a lightweight and highly reliable log access solution for resource-constrained embedded environments.

[0094] The technical solution of the present invention will be described below through a specific application example.

[0095] 1. Application scenario background.

[0096] An industrial control embedded device uses a low-power microcontroller and an external Flash memory chip as the log storage medium. It needs to record the device's operation logs, stored in hourly increments. The "time-address mapping" scheme of this invention is adopted, and the core algorithm is as follows:

[0097] ;

[0098] Each log entry is written in "hours", and each hour's log entry occupies a fixed-size storage block in Flash. Reading and writing are done by directly calculating the address based on time, without the need for a file system or index table.

[0099] 2. Log writing process.

[0100] Assuming the device's current system time is 14:30 on March 15, 202X, and the device is running, generating an operation log, the writing process is as follows:

[0101] (1) Obtain and normalize the time parameters.

[0102] The device reads the current time from the built-in RTC clock module: month=3, day=15, hour=14. Since this invention uses "hours" as the log storage granularity, it directly extracts the month, day, and hour as time parameters for address calculation.

[0103] (2) Execute the time address mapping algorithm to calculate the storage address.

[0104] Substitute the time parameter into the algorithm formula:

[0105] ADDR=((3%2)*31+15-1)*24+14;

[0106] The calculation steps are as follows:

[0107] Month modulo: 3%2=1 (March is an odd-numbered month, so the offset coefficient is 1);

[0108] Date offset: 1*31+15-1=45 (offset in days).

[0109] Hour extension: 45*24+14=1094 (finally resulting in a linear address offset of 1094 in hourly granularity).

[0110] Multiplying this offset by the byte length of a single hourly log block yields the corresponding physical storage starting address in the Flash memory.

[0111] (3) Log data encapsulation and writing.

[0112] The device encapsulates the current operating data (such as temperature, status, fault codes, etc.) from 14:00 to 15:00 into a standard log data block, and writes it into the storage area corresponding to address 1094 in Flash via the SPI interface, thus completing the writing of the hourly log.

[0113] Subsequently, every hour on the hour, the device will reacquire the current time, calculate a new address using the same algorithm, and write the log to the corresponding storage block, thus achieving automatic writing and cyclic overwriting on an hourly basis.

[0114] 3. Log reading process.

[0115] The equipment malfunctioned at 15:00 on March 15, 202X. Maintenance personnel sent a log read command through the host computer to query the log data for "14:00 on March 15, 202X". The read process is as follows:

[0116] (1) Receive and parse the read command;

[0117] The device receives log reading commands sent by the host computer via serial port, extracts the target time parameters: month=3, day=15, hour=14, and performs legality checks on the command format and time parameters.

[0118] (2) Use the same algorithm to calculate the target read address;

[0119] Substitute the target time parameter into the same algorithm formula as the write phase:

[0120] ADDR=((3%2)*31+15-1)*24+14=1094;

[0121] The calculated address offset of 1094 is exactly the same as that at the time of writing, corresponding to the same memory block in Flash.

[0122] (3) Read the log data and return it;

[0123] The device reads log data blocks of the corresponding length starting from address 1094, verifies the data, and sends it to the host computer via serial port. Maintenance personnel can then obtain the device operation log at 14:00 and complete the fault analysis.

[0124] In the above application example, the entire log access process does not rely on the file system at all, nor does it maintain any index table: when writing, the device only needs to obtain the current time, calculate the storage address through a simple arithmetic operation, and write it to the log; when reading, the host computer only needs to send the target time, and the device can quickly locate the address and return the data through the same algorithm; the uniqueness and reproducibility of the address ensure that "the log written at any time can definitely be read through the same time parameter", and there will be no addressing errors.

[0125] Secondly, the present invention provides a log storage and retrieval device, corresponding one-to-one with the steps of the above method, including an address calculation unit, an instruction parsing unit, and a data read / write unit. These modules are connected sequentially to achieve data interaction, and their specific structure and functions are as follows:

[0126] The address calculation unit is used to calculate the corresponding physical storage address based on the time information of log generation according to the preset time address mapping algorithm after the device is started, and write the log data into the storage area corresponding to the physical storage address.

[0127] The instruction parsing unit is used to extract the target time information in the instruction when a log read instruction is received, calculate the physical storage address corresponding to the target time through the time address mapping algorithm, and determine the starting address and data length of the log data read.

[0128] The data read / write unit is used to read the corresponding log data from the storage medium based on the calculated physical storage address, starting address, and data length, and output the read results through the external communication interface.

[0129] In the aforementioned log storage and retrieval device, the address calculation unit is connected to both the device clock module and the data read / write unit. It acquires the device's real-time time information, executes a preset time-address mapping algorithm, uniquely calculates the physical storage address corresponding to the log data based on the time information, and transmits the calculated physical storage address to the data read / write unit. Simultaneously, it receives target time information transmitted by the instruction parsing unit, completes target address calculation based on the same time-address mapping algorithm, and feeds back the target address and corresponding data length to the instruction parsing unit. This unit does not require maintaining a mapping table or file system; it achieves a one-to-one mapping between time and storage address through pure algorithmic calculation, ensuring the uniqueness and efficiency of address calculation.

[0130] The instruction parsing unit is connected to the external communication interface, the address calculation unit, and the data read / write unit. It receives log read instructions from external devices via the external communication interface, extracts the target time information from the instructions, and transmits it to the address calculation unit. It also receives the target physical storage address and data length from the address calculation unit and synchronously sends the read control instruction, target address, and data length to the data read / write unit, thus parsing the read instruction and issuing read / write parameters. This unit completes instruction reception, information extraction, and parameter forwarding, ensuring smooth instruction interaction during the read / write process.

[0131] The data read / write unit is connected to the address calculation unit, the instruction parsing unit, and the log storage medium, respectively. After power-on initialization, the unit receives the real-time physical storage address transmitted by the address calculation unit and writes the log data to the corresponding area of ​​the storage medium according to the address. It also receives read control commands, target addresses, and data lengths from the instruction parsing unit, accurately reads the corresponding log data from the log storage medium according to the specified parameters, and sends the read log data back to the instruction parsing unit. Finally, it outputs the log data through an external communication interface. This unit directly performs read / write operations based on the calculated address, eliminating the need for address lookups and mapping table traversal, thus improving data access speed and stability.

[0132] The device, through the coordinated operation of its address calculation unit, instruction parsing unit, and data read / write unit, employs a space-for-time tradeoff design to achieve fast and efficient log access with no additional overhead, making it suitable for resource-constrained devices such as embedded microcontrollers. The specific implementation methods of each module have been detailed in the log access method section and will not be repeated here.

[0133] Thirdly, the present invention provides an electronic device comprising: 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, the instructions being executed by the at least one processor to enable the at least one processor to perform the above-described log access method.

[0134] Fourthly, the present invention provides a storage medium, which may be a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the above-described log access method.

[0135] The computer-readable storage medium provided by this invention may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0136] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. A log access method, characterized in that, The method includes the following steps: After the device starts up, it calculates the corresponding physical storage address based on the time information of the log generation according to the preset time address mapping algorithm, and writes the log data into the storage area corresponding to the physical storage address. When a log read command is received, the target time information in the command is extracted, and the physical storage address corresponding to the target time is calculated using the time address mapping algorithm to determine the starting address and data length for reading the log data. Based on the calculated physical storage address, starting address, and data length, the corresponding log data is read from the storage medium, and the reading result is output through the external communication interface. Based on a preset time-address mapping algorithm, the corresponding physical storage address is calculated according to the time information generated by the log, specifically including: The acquired raw time information is processed according to the preset time granularity rules. Based on the system's set log storage period and time precision, key time parameters for address calculation are extracted. The time parameters are standardized and converted to remove invalid bits and redundant information, and uniformly converted into a numerical format that can be directly used in the algorithm calculation, providing standardized input for address calculation. The preset time address mapping algorithm is invoked, and the normalized time parameters are substituted into the algorithm formula for mathematical operations. Through fixed arithmetic relationships, the time information is directly converted into the physical storage address on the storage medium. The calculation expression for the time-address mapping algorithm is as follows: ; The month%2 operation performs a modulo operation on the month, and partitions the address space based on the parity of the month, building the basic layer of address offsets in units of "month"; (month%2)*31+day-1 combines the month parity offset with the date sequence number to calculate the address offset in "day" granularity. The coefficient of multiplying by 31 ensures that the date address ranges of different months do not overlap, so that even months with different numbers of days can obtain a linear and continuous address space. *24+hour extends the "day" level address offset, refining the address granularity to the "hour". By multiplying by 24 and adding the current hour value, a unique address value ADDR with hour precision is finally obtained, realizing the complete conversion from three-level time parameters of month, day and hour to linear address.

2. The log access method according to claim 1, characterized in that, The calculated physical storage address is validated to determine whether it is within the valid address range of the preset log storage area, thus preventing data writing errors caused by address out-of-bounds access. At the same time, based on the fixed length of the log data, it verifies whether the storage block corresponding to the current address has enough space. Once confirmed, it locks the physical storage address as the write location for the log data.

3. The log access method according to claim 1 or 2, characterized in that, The runtime log data to be stored is encapsulated according to a preset format, and auxiliary content such as log identifier, data length, and verification information is added to form a complete log data package that conforms to the storage specifications; the encapsulated log data is then transferred to the data writing buffer to complete the data preparation before writing. Based on the verified physical storage address, control the storage medium to perform a write operation, and accurately write the log data in the cache to the storage area corresponding to that address. After the data is written, the writing result is verified to confirm that the log data is stored completely and accurately in the target location, thus completing a single log writing process.

4. The log access method according to claim 1, characterized in that, The physical storage address corresponding to the target time is calculated using the time-address mapping algorithm, specifically including: The extracted and verified target time information will be processed according to the same time granularity and regularization rules as the log writing steps, and the numerical format, valid bits and calculation methods of the time parameters will be unified to ensure that the time parameters on the reading side and the time parameters on the writing side are consistent at the algorithm input level. The time address mapping algorithm, which is exactly the same as the log writing step, is invoked. The standardized target time parameter is substituted into the algorithm for mathematical operations, and the physical storage address of the log is directly obtained through fixed arithmetic relationships.

5. The log access method according to claim 1, characterized in that, Determine the starting address and data length for reading log data, specifically including: The physical address calculated by the algorithm is determined as the starting address for reading log data. The storage boundary of the starting address is checked to determine whether it is within the preset legal log storage range, so as to avoid reading failure or data corruption due to address out of bounds. Based on the system's preset log storage time granularity and address allocation rules, the length of the log data stored in the corresponding address block is directly derived from the current time granularity; the determined read start address and data length are combined into complete read parameters.

6. The log access method according to claim 1, characterized in that, Reading the corresponding log data from the storage medium specifically includes: reading log data in batches from the storage medium according to a determined address and length, and writing the read data segment by segment into a pre-locked data buffer.

7. A log access apparatus for implementing the log access method according to any one of claims 1 to 6, characterized in that, The device includes an address calculation unit, an instruction parsing unit, and a data read / write unit; The address calculation unit is used to calculate the corresponding physical storage address based on the time information of log generation according to the preset time address mapping algorithm after the device is started, and write the log data into the storage area corresponding to the physical storage address. The instruction parsing unit is used to extract the target time information in the instruction when a log read instruction is received, calculate the physical storage address corresponding to the target time through the time address mapping algorithm, and determine the starting address and data length of the log data read. The data read / write unit is used to read the corresponding log data from the storage medium based on the calculated physical storage address, starting address, and data length, and output the read results through the external communication interface.

8. A storage medium, characterized in that, The storage medium is a computer-readable storage medium having computer-readable program instructions stored thereon, the computer-readable program instructions being used to perform the log access method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Data management method and device, equipment and storage medium

    CN122331830A