A method for storing and retrieving sensor data
Patent Information
- Application Number
- CN202311135190.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-04
- Publication Date
- 2026-09-01
- Estimated Expiration
- 2043-09-04
AI Technical Summary
[0005]有鉴于此,本发明的目的在于提供一种传感器数据的存储和查询方法,解决存储和查询效率与配置需求的冲突,以及因数据量增加造成的算法效率降低和存储资源损耗增大的的技术问题
[0032] First, this invention can greatly reduce the need for high-performance hardware configurations to improve storage and query efficiency, and its implementation efficiency is not affected by the size of the data.
Smart Images

Figure CN117149079B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of sensor data processing technology and relates to a method for storing and querying sensor data. Background Technology
[0002] With the development of intelligent sensors, their functions are becoming increasingly diverse. There is a growing need to query periodically accumulated data from sensors measuring flow, quality, mileage, and transmission counts, such as historical daily flow, daily shipment volume, and single trip distance. A necessary condition for realizing these functions is the rapid storage and retrieval of large amounts of data. However, sensor devices often have limited processor and memory configurations due to constraints such as power consumption, space, and cost, making it difficult to achieve rapid data storage and retrieval. Currently, optimizing algorithms and data tagging methods to achieve rapid data storage and retrieval is the dominant direction.
[0003] The most important aspect of achieving fast data storage and retrieval is rapid matching and location of the target position. Currently, the approach often involves trading space for time, which means creating an index area for data during storage and optimizing matching and location efficiency during retrieval.
[0004] The essence of data tagging and indexing is to extract features from the data and classify and group them. When matching and locating, the features of the index area are traversed first, and then the search scope is narrowed down to the group. As the amount of data increases, more groups and greater index depth are required to build multi-level indexes. Such matching and locating algorithms greatly reduce query efficiency and significantly increase the storage resources occupied. Summary of the Invention
[0005] In view of this, the purpose of the present invention is to provide a method for storing and querying sensor data, which solves the conflict between storage and query efficiency and configuration requirements, as well as the technical problems of reduced algorithm efficiency and increased storage resource consumption caused by the increase in data volume.
[0006] To achieve the above objectives, the present invention provides the following technical solution:
[0007] A method for storing and retrieving sensor data, the method comprising the following steps:
[0008] S1: Initialize the storage area, including clearing all data in the storage area, dividing the storage area with cleared data into several data blocks according to the length of the target data content, using the first data block to store the start time of the target data storage, and the other data blocks to store application data;
[0009] S2: Store data, obtain the target storage time, start time and data block length to calculate the storage offset address of the target data block, calculate the storage offset address with the first storage address to accurately obtain the address of the target storage segment in the storage area, and quickly write the target data at the calculated address. The stored target data is an absolute cumulative value.
[0010] S3: Data Query. Obtain the start and end times, start time, and data block length of the query time period. Accurately calculate the start and end offset addresses of the query data time period. Calculate the absolute start and end addresses of the query time period by combining the start and end offset addresses with the first storage address, which is the address of the target data block in the storage area. Quickly read the target data from the absolute start and end addresses of the target data block. Based on the target data read from the absolute start and end addresses of the target data block, calculate the cumulative increment of the stored data for the query time period to obtain the query result.
[0011] Furthermore, in S1, initializing the storage area specifically involves clearing all byte data in the unit to 0xFF;
[0012] The storage area is divided into several data blocks with block addresses ADDR0 to ADDRm according to the length of the target data LENGTH_DATA. The start time of the target data storage is obtained and written to the first storage address ADDR0, which is recorded as the base point TIME_BASE. ADDR1 to ADDRm store the application data.
[0013] Furthermore, in S1, the length of the partitioned region is an integer multiple of the data block length.
[0014] Furthermore, in S2, storing data specifically involves: reading the storage content of the first storage address ADDR0 to obtain the storage time base point TIME_BASE;
[0015] The storage offset address of the target data block is calculated by combining the obtained time base point TIME_BASE, the target storage time, and the data block length. The calculation formula is as follows:
[0016] ADDR_OFFSET=(TIME_STORE-TIME_BASE)*LENGTH_DATA (1)
[0017] The absolute address of the target data block is calculated by combining the storage offset address of the target data block with the first storage address ADDR0. The calculation formula is as follows:
[0018] ADDR_STORE=ADDR0+ADDR_OFFSET (2)
[0019] The target data is stored in the calculated absolute address, and the stored target data is the absolute cumulative value.
[0020] Furthermore, in S3, the data query specifically involves: reading the storage content at the first storage address ADDR0, obtaining the storage time base point TIME_BASE, and calculating the offset addresses of the start and end of the query time period by combining the obtained start time with the data block length. The calculation formula is as follows:
[0021] ADDR_OFFSET_START=(TIME_QUERY_START-TIME_BASE)*LENGTH_DATA(3)
[0022] ADDR_OFFSRT_END=(TIME_QUERY_END-TIME_BASE)*LENGTH_DATA (4)
[0023] Where TIME_QUERY_START is the start time of the query period, TIME_QUERY_END is the end time of the query period, ADDR_OFFSET_START is the offset address at the start of the query period, and ADDR_OFFSET_END is the offset address at the end of the query period.
[0024] The absolute start and end addresses of the query time period are calculated by combining the start and end offset addresses with the first memory address ADDR0, respectively. The calculation formula is as follows:
[0025] ADDR_START=ADDR0+ADDR_OFFSET_START (5)
[0026] ADDR_END=ADDR0+ADDR_OFFSRT_END (6)
[0027] Where ADDR_START and ADDR_END are the absolute start and end addresses of the query time period, respectively, which are the addresses of the target data blocks in the storage area;
[0028] Quickly read the target data from the absolute start and end addresses of the target data block to obtain: DATA_DST_START and DATA_DST_END;
[0029] Based on the target data in the absolute start and end addresses of the target data block, the cumulative increment of the stored data for the queried time period is calculated, which is the query result. The calculation formula is as follows:
[0030] DATA_DST=DATA_DST_END-DATA_DST_START (7).
[0031] The beneficial effects of this invention are as follows:
[0032] First, this invention can greatly reduce the need for high-performance hardware configurations to improve storage and query efficiency, and its implementation efficiency is not affected by the size of the data.
[0033] Second, this invention enables rapid storage and retrieval of sensor data by establishing a hidden index area using structured data.
[0034] Other advantages, objectives, and features of the invention will be set forth in part in the description which follows, and in part will be apparent to those skilled in the art from the following examination, or may be learned from practice of the invention. The objectives and other advantages of the invention can be realized and obtained through the following description. Attached Figure Description
[0035] To make the objectives, technical solutions, and advantages of the present invention clearer, the preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings, wherein:
[0036] Figure 1 A diagram illustrating a method for fast storage and retrieval;
[0037] Figure 2 This is a schematic diagram of data structuring;
[0038] Figure 3 Flowchart for initializing the storage area;
[0039] Figure 4 Data storage flowchart;
[0040] Figure 5 This is a flowchart of the data query process. Detailed Implementation
[0041] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0042] The accompanying drawings are for illustrative purposes only and are schematic diagrams, not actual pictures. They should not be construed as limiting the invention. To better illustrate the embodiments of the invention, some parts in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions. It is understandable to those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.
[0043] In the accompanying drawings of the embodiments of the present invention, the same or similar reference numerals correspond to the same or similar components. In the description of the present invention, it should be understood that if terms such as "upper," "lower," "left," "right," "front," and "rear" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, they are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, the terms used to describe positional relationships in the drawings are only for illustrative purposes and should not be construed as limiting the present invention. For those skilled in the art, the specific meaning of the above terms can be understood according to the specific circumstances.
[0044] Please see Figures 1-5 This is a method for storing and retrieving sensor data.
[0045] In gas drainage systems, it is necessary to have access to mixed cumulative flow data for years, months, and days, as well as pure cumulative flow data. In some cases, it is even necessary to have access to hourly cumulative flow data within 30 days. Here is an example of storing and querying daily cumulative flow data.
[0046] The flow meter's memory is structured with a total size of 32*1024 bytes. Based on the mixed cumulative flow and pure cumulative flow, the target data length is LENGTH_DATA = 16 bytes. Therefore, the memory address is divided into ADDR0 = 0x00000000, ADDR1 = 0x00000010, ..., ADDR2047 = 0x007FF0, totaling 2048 data blocks, which can record the cumulative flow data of one start time and 2047 consecutive days.
[0047] Initialization involves first clearing the entire storage area by writing 0xFF, and then writing the start time (year, month, and day) into ADDR0, i.e., TIME_BASE = June 1, 2023.
[0048] During data storage and flow meter measurement, at the end of June 2, 2023, the flow meter reads the start time (TIME_BASE = June 1, 2023) from ADDR0, obtains the current storage time (TIME_STORE = June 2, 2023), calculates the storage offset address (ADDR_OFFSET = 0x00000010), and further calculates the storage address (ADDR_STORE = 0x00000010). The mixed cumulative flow and pure cumulative flow are then written to ADDR_STORE = 0x00000010, completing one storage cycle. This process is repeated daily thereafter to store data.
[0049] During data query and flow meter measurement, when a command is received to query the cumulative flow from June 2, 2023 to August 1, 2023, the flow meter reads the start time (ADDR0 = 0x00000000) and its corresponding year, month, and day (TIME_BASE = June 1, 2023). This data is then compared with the query start time (TIME_QUERY_START = June 2, 2023), the end time (TIME_QUERY_END = August 1, 2023), and the data block length (LENGTH_DATA = 16) to calculate the data storage offset address (ADDR_OFFSET_START = 0x00000010) for the start time of the query period and the data storage offset address (ADDR_OFFSET_START = 0x00000010) for the end time. Offset address ADDR_OFFSET_END = 0x000003D0, further calculated with the starting address ADDR0, yields the absolute start and end addresses of the data storage for the query period: ADDR_START = 0x00000010, ADDR_END = 0x000003D0. The mixed cumulative traffic start and end data DATA_DST_START1, DATA_DST_END1 and the pure cumulative traffic start and end data DATA_DST_START2, DATA_DST_END2 are quickly read out. The mixed cumulative traffic DATA_DST1 and pure cumulative traffic DATA_DST2 for the period from June 2, 2023 to August 1, 2023 are then calculated.
[0050] DATA_DST1=DATA_DST_END1-DATA_DST_START1 (1)
[0051] DATA_DST2=DATA_DST_END2-DATA_DST_START2 (2)
[0052] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A method for storing and retrieving sensor data, characterized in that: The method includes the following steps: S1: Initialize the storage area, including clearing all data in the storage area, dividing the storage area with cleared data into several data blocks according to the length of the target data content, using the first data block to store the start time of the target data storage, and the other data blocks to store application data; In step S1, initializing the storage area specifically involves clearing all bytes of data in the unit to 0xFF. The storage area is divided into several data blocks with block addresses ADDR0 to ADDRm according to the length of the target data LENGTH_DATA. The start time of the target data storage is obtained and written into the first storage address ADDR0, which is recorded as the base point TIME_BASE. ADDR1 to ADDRm store the application data. S2: Store data, obtain the target storage time, start time and data block length to calculate the storage offset address of the target data block, calculate the storage offset address with the first storage address to accurately obtain the address of the target storage segment in the storage area, and quickly write the target data at the calculated address. The stored target data is an absolute cumulative value. In step S2, storing data specifically involves reading the storage content at the first storage address ADDR0 to obtain the storage time base point TIME_BASE. The storage offset address of the target data block is calculated by combining the obtained time base point TIME_BASE, the target storage time, and the data block length. The calculation formula is as follows: ADDR_OFFSET=(TIME_STORE-TIME_BASE)*LENGTH_DATA(1) The absolute address of the target data block is calculated by combining the storage offset address of the target data block with the first storage address ADDR0. The calculation formula is as follows: ADDR_STORE=ADDR0+ADDR_OFFSET (2) The target data is stored in the calculated absolute address, and the stored target data is the absolute cumulative value. S3: Data Query. Obtain the start and end times, start time, and data block length of the query time period. Accurately calculate the start and end offset addresses of the query data time period. Calculate the absolute start and end addresses of the query time period by combining the start and end offset addresses with the first storage address, which is the address of the target data block in the storage area. Quickly read the target data from the absolute start and end addresses of the target data block. Based on the target data read from the absolute start and end addresses of the target data block, calculate the cumulative increment of the stored data for the query time period to obtain the query result.
2. The method for storing and querying sensor data according to claim 1, characterized in that: In S1, the length of the partitioned region is an integer multiple of the data block length.
3. The method for storing and querying sensor data according to claim 2, characterized in that: In step S3, the data query specifically involves: reading the storage content at the first storage address ADDR0, obtaining the storage time base point TIME_BASE, and calculating the offset addresses of the start and end of the query time period by comparing the obtained start time with the data block length. The calculation formula is as follows: ADDR_OFFSET_START=(TIME_QUERY_START-TIME_BASE)*LENGTH_DATA(3) ADDR_OFFSRT_END=(TIME_QUERY_END-TIME_BASE)*LENGTH_DATA (4) Where TIME_QUERY_START is the start time of the query period, TIME_QUERY_END is the end time of the query period, ADDR_OFFSET_START is the offset address at the start of the query period, and ADDR_OFFSET_END is the offset address at the end of the query period. The absolute start and end addresses of the query time period are calculated by combining the start and end offset addresses with the first memory address ADDR0, respectively. The calculation formula is as follows: ADDR_START=ADDR0+ADDR_OFFSET_START (5) ADDR_END=ADDR0+ADDR_OFFSRT_END (6) Where ADDR_START and ADDR_END are the absolute start and end addresses of the query time period, respectively, which are the addresses of the target data blocks in the storage area; Quickly read the target data from the absolute start and end addresses of the target data block to obtain: DATA_DST_START and DATA_DST_END; Based on the target data in the absolute start and end addresses of the target data block, the cumulative increment of the stored data for the queried time period is calculated, which is the query result. The calculation formula is as follows: DATA_DST=DATA_DST_END-DATA_DST_START (7).
Citation Information
Patent Citations
Establishing method for process control historical data file structure and data read-write method
CN102043795A