Environmental data encoding method for embedded systems
By dividing the storage space into BULK blocks and SECTOR areas, and using bitstream encoding of the change amount and actual value of the environment data, the problem of high hardware resources in embedded devices is solved, and efficient data compression effect is achieved.
Patent Information
- Application Number
- CN202211106714.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-09
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2042-09-09
AI Technical Summary
The prior art environmental data storage and compression methods in embedded devices have high hardware resource requirements and cannot be applied to low-cost IoT scenarios.
The storage space is divided into BULK blocks and SECTOR areas, and the environment data is encoded using bitstream, and the starting timestamp and data interval information are recorded, and the change amount and actual value of the environment data are encoded.
It realizes that data compression efficiency is significantly improved without increasing hardware resources, and provides an efficient data encoding solution for IoT products with tight storage resources.
Smart Images

Figure CN115664424B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data encoding, and in particular to an environmental data encoding method for an embedded system. Background Art
[0002] Existing embedded devices, such as Bluetooth temperature and humidity sensors, need to store environmental data (such as temperature, humidity, light intensity, air pressure, and odor) during operation. Existing technologies typically use direct storage (directly saving the original values of the sampled environmental data) and general compression algorithms (such as various Huffman-based compression algorithms). However, this storage method and compression algorithm have the following drawbacks:
[0003] Direct storage can perform incremental encoding as new data is added, but because it stores raw data, it contains a lot of redundant information, so the ROM space usage efficiency is not high;
[0004] General compression algorithms cannot perform incremental encoding because they perform statistics on all data and require more RAM space.
[0005] Therefore, existing encoding methods have high hardware resource requirements for IoT applications and are not suitable for low-cost usage scenarios. Summary of the Invention
[0006] This application proposes an environmental data encoding method for embedded systems, providing an efficient data compression encoding solution for IoT products with limited storage resources.
[0007] The present invention provides an environmental data encoding method for an embedded system, comprising the following steps:
[0008] S1: Divide the storage space into several independent BULK blocks, and set a header space for each BULK block, wherein the header space includes start timestamp information and data time interval information;
[0009] S2: After the header space of any BULK block, record the first piece of environmental data in the BULK block, and the first piece of environmental data is recorded using actual values;
[0010] S3: Record subsequent environmental data in the BULK block in sequence after the first environmental data at a predetermined time interval, specifically including:
[0011] a. If the current environment data has not changed compared to the previous environment data, a bit 0 is used to indicate that the current environment data has not changed;
[0012] b. If the current environment data changes compared to the previous environment data, a bit 1 is used to indicate that the current environment data has changed;
[0013] c. In step b, if the change in the current environmental data compared to the previous environmental data is less than a predetermined threshold, the current environmental data is recorded as 1 + the change amount, where 1 represents a change less than the predetermined threshold, and the change amount includes 0 or 1, where 0 represents an increase of the threshold value in the change in the current environmental data compared to the previous environmental data, and 1 represents a decrease of the threshold value in the change in the current environmental data compared to the previous environmental data;
[0014] d. In step b, if the change in the current environmental data compared to the previous environmental data is greater than a predetermined threshold, the current environmental data is recorded as 0+actual value, where 0 represents a change greater than the predetermined threshold and the actual value is the actual value of the current environmental data.
[0015] In some embodiments, any of the BULK blocks is divided into a plurality of SECTOR areas, and the header space of any of the BULK blocks is set in the first SECTOR area within the BULK block.
[0016] In some embodiments, the first piece of environmental data recorded in any of the SECTOR areas is recorded using actual values.
[0017] In some embodiments, when the space of a SECTOR area is used up or the remaining space is insufficient to write the next piece of environmental data, the recording is switched to the next SECTOR area.
[0018] In some embodiments, the start timestamp information is used to record the time when the first environmental data is recorded in the BULK block, and the data time interval information is used to record the time interval between two adjacent environmental data records in the BULK block.
[0019] In some embodiments, the storage space is divided into BULK blocks according to the erase size, and the BULK blocks include 1024 bytes and 4096 bytes.
[0020] In some embodiments, the BULK block is divided into SECTOR areas according to the erase size, and the SECTOR area includes 256 bytes.
[0021] In some embodiments, the actual value is recorded in a fixed format, which includes 2 bytes or 3 bytes.
[0022] In some embodiments, the environmental data includes numerical values and state values.
[0023] In some embodiments, the numerical quantity is data that needs to be represented by a numerical value, including temperature and humidity; the state quantity is data representing a working state, including a switch state.
[0024] Compared with the existing technology, the beneficial effect of this application is that through a simpler encoding method, for special occasions such as saving environmental data, no additional hardware resources are needed to achieve significant compression effects, providing an efficient data compression encoding solution for IoT products with limited storage resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.
[0026] Figure 1 Flowchart of the coding method for this application;
[0027] Figure 2 This is a flowchart of an embodiment of the present application;
[0028] The realization of the objectives, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0029] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments.
[0030] Unless otherwise defined, all technical and scientific terms used in this application have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application.
[0031] It should be noted that for environmental data, jumps generally do not occur in the time domain. The data at the current time and the data at the previous time have a strong correlation. When encoding, we only need to consider whether the previous and subsequent data have changed (if the absolute value of the change is less than a specified threshold, it is considered unchanged. The threshold may be the sampling accuracy or a value set to save storage space) and the magnitude of the change. Based on this characteristic of environmental data, the present application proposes the following encoding method to improve the encoding compression effect. At the same time, in order to improve the encoding efficiency, a bit stream method is adopted, and the decoder can parse the original value based on the current bits.
[0032] Specifically, refer to Figure 1 This embodiment proposes a method for encoding environmental data for an embedded system, comprising the following steps:
[0033] S1: Divide the storage space into several independent BULK blocks, and set a header space for each BULK block, wherein the header space includes start timestamp information and data time interval information;
[0034] S2: After the header space of any BULK block, record the first piece of environmental data in the BULK block, and the first piece of environmental data is recorded using actual values;
[0035] S3: Record subsequent environmental data in the BULK block in sequence after the first environmental data at a predetermined time interval, specifically including:
[0036] a. If the current environment data has not changed compared to the previous environment data, a bit 0 is used to indicate that the current environment data has not changed;
[0037] b. If the current environment data changes compared to the previous environment data, a bit 1 is used to indicate that the current environment data has changed;
[0038] c. In step b, if the change in the current environmental data compared to the previous environmental data is less than a predetermined threshold, the current environmental data is recorded as 1 + the change amount, where 1 represents a change less than the predetermined threshold, and the change amount includes 0 or 1, where 0 represents an increase of the threshold value in the change in the current environmental data compared to the previous environmental data, and 1 represents a decrease of the threshold value in the change in the current environmental data compared to the previous environmental data;
[0039] d. In step b, if the change in the current environmental data compared to the previous environmental data is greater than a predetermined threshold, the current environmental data is recorded as 0+actual value, where 0 represents a change greater than the predetermined threshold and the actual value is the actual value of the current environmental data.
[0040] It should be noted that, considering that the user may modify the interval of data storage, the present invention divides the entire storage area into several BULK blocks, and its size can be adjusted according to actual conditions. The header space of each BULK needs to contain the starting timestamp information and data time interval information. When the user changes the time interval, the new data needs to be saved to the next BULK block. In addition, the header space can also store CRC checksum, data number and other information as needed.
[0041] Furthermore, in order to avoid the gradual accumulation of errors introduced by encoding, this embodiment further divides a BULK block into several SECTOR areas. The first environmental data in each SECTOR area stores the actual value, and the subsequent environmental data uses incremental encoding.
[0042] Specifically, any of the BULK blocks is divided into a plurality of SECTOR areas, and the header space of any of the BULK blocks is set in the first SECTOR area within the BULK block.
[0043] Furthermore, the first piece of environmental data recorded in any of the SECTOR areas is recorded using actual values.
[0044] Furthermore, when the space of a SECTOR area is used up or the remaining space is insufficient to write the next piece of environmental data, the recording is switched to the next SECTOR area.
[0045] Furthermore, the start timestamp information is used to record the time when the first environmental data is recorded in the BULK block, and the data time interval information is used to record the time interval between two adjacent environmental data records in the BULK block.
[0046] Furthermore, the sizes of BULK blocks and SECTOR areas can be adjusted according to actual conditions. In this embodiment, the storage space is divided into BULK blocks according to the erase / write size, and the BULK blocks include 1024 bytes and 4096 bytes. The BULK blocks are divided into SECTOR areas according to the erase / write size, and the SECTOR areas include 256 bytes.
[0047] Furthermore, the actual value is recorded in a fixed format, which includes 2 bytes or 3 bytes.
[0048] Furthermore, the environmental data includes numerical values and state values.
[0049] Furthermore, the numerical quantity is data that needs to be expressed in numerical values, including temperature and humidity; the state quantity is data representing the working state, including the switch state.
[0050] As mentioned above, since environmental data includes numerical values, state values, etc., a piece of environmental data contains multiple variables. The following describes the recording of environmental data in detail through specific embodiments. In the following embodiments, environmental data includes three variables: switch state (state value), temperature (numerical value), and humidity (numerical value). The state value represents the switch state of the door (1 for open, 0 for closed), which requires one bit; the humidity range is 0-100%, with an accuracy unit of 1%, requiring 7 bits; the temperature range is -40°C to 62°C, with an accuracy unit of 0.1°C, requiring 10 bits (0 for -40°C, 1020 for 62°C). That is, a piece of original data requires 7+10+1=18 bits to encode.
[0051] 1. Record the first piece of environmental data. Assume that the current ambient temperature is 25°C, the humidity is 60%, and the switch state is on. The actual value of the first piece of environmental data saved is "650 60 1", which is represented by binary as "1010001010 01111001";
[0052] 2. Record the second environmental data:
[0053] 1. If the second environmental data item remains unchanged from the first, indicating a temperature of 25°C, a humidity of 60%, and an on / off state, then the second environmental data item is saved as "0." This completes the second data item recording and is represented as "0" in binary, saving 17 bits.
[0054] 2. If the second piece of environmental data changes compared to the first piece of environmental data, including changes in one or more variables, first record "1" to indicate that the second piece of environmental data has changed, and then record each variable in turn, with the current binary code being "1";
[0055] a. First, record the switch status data of the second environmental data. If the switch status is on, record "1", if the switch status is off, record "0". The current binary code is "1X", where X is the switch status, which can be 1 or 0;
[0056] b. Then record the temperature and humidity data:
[0057] b1. If the temperature and humidity of the second environmental data item remain unchanged, record "100," where 1 indicates that the data is recorded as a variable, the first 0 indicates that the temperature remains unchanged, and the second 0 indicates that the humidity remains unchanged. This completes the second data item, represented in binary as "1X100," where X represents the switch value, saving 13 bits.
[0058] b2. If the changes in both the temperature and humidity of the second piece of environmental data are less than the threshold (e.g., if the temperature of the second piece of environmental data is 25.1°C and the humidity is 59%, then "11101" is recorded. The first 1 indicates that the temperature and humidity of the second piece of environmental data are recorded as changes. The second and third 1s indicate that both the temperature and humidity have changed. The first 0 indicates that the temperature of the second piece of environmental data has increased by 0.1°C compared to the first piece of environmental data. The last 1 indicates that the humidity of the second piece of environmental data has decreased by 1% compared to the first piece of environmental data. At this point, the second piece of data is recorded. It is represented in binary as "1X11101", where X is the switching value, saving 11 bits.
[0059] b3. If one or more of the temperature and humidity in the second environmental data changes significantly and exceeds the threshold, such as the temperature is 25.2°C and the humidity is 58%;
[0060] First, "0" is recorded. The 0 here means that the temperature and humidity of the second environmental data are recorded with actual values.
[0061] Then record the actual values of temperature and humidity of the second environmental data. At this point, the second data record is completed and expressed in binary as "1X0 1010001100 0111010", using 2 more bits.
[0062] 3. The recording method of subsequent environmental data is the same as that of the second environmental data. Just compare the current environmental data with the previous environmental data, and so on. I will not go into details here.
[0063] The above are only preferred embodiments of the present application and do not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for encoding environmental data for an embedded system, characterized in that: The steps include: S1: Divide the storage space into several independent BULK blocks, and set a header space for each BULK block, wherein the header space includes start timestamp information and data time interval information; S2: After the header space of any BULK block, record the first piece of environmental data in the BULK block, and the first piece of environmental data is recorded using actual values; S3: Record subsequent environmental data in the BULK block in sequence after the first environmental data at a predetermined time interval, specifically including: a. If the current environment data has not changed compared to the previous environment data, a bit 0 is used to indicate that the current environment data has not changed; b. If the current environment data changes compared to the previous environment data, a bit 1 is used to indicate that the current environment data has changed; c. In step b, if the change in the current environmental data compared to the previous environmental data is less than a predetermined threshold, the current environmental data is recorded as 1 + the change amount, where 1 represents the current environmental data is recorded using the change amount, and the change amount includes 0 or 1, where 0 represents the change amount of the current environmental data compared to the previous environmental data by an increase of one threshold, and 1 represents the change amount of the current environmental data compared to the previous environmental data by a decrease of one threshold; d. In step b, if the change in the current environmental data compared to the previous environmental data is greater than a predetermined threshold, the current environmental data is recorded as 0+actual value, where 0 represents that the current environmental data is recorded as the actual value, and the actual value is the actual value of the current environmental data.
2. The environmental data encoding method for an embedded system according to claim 1, wherein: Any of the BULK blocks is divided into a plurality of SECTOR areas, and the header space of any of the BULK blocks is set in the first SECTOR area in the BULK block.
3. The environmental data encoding method for an embedded system according to claim 2, wherein: The first piece of environmental data recorded in any SECTOR area is recorded using actual values.
4. The environmental data encoding method for an embedded system according to claim 2, wherein: When the space of a SECTOR area is used up or the remaining space is insufficient to write the next piece of environmental data, it switches to the next SECTOR area for recording.
5. The environmental data encoding method for an embedded system according to claim 1, wherein: The start timestamp information is used to record the time when the first environmental data is recorded in the BULK block, and the data time interval information is used to record the time interval between two adjacent environmental data records in the BULK block.
6. The environmental data encoding method for an embedded system according to claim 1, wherein: The storage space is divided into BULK blocks according to the erase / write size, and the BULK blocks include 1024 bytes and 4096 bytes.
7. The environmental data encoding method for an embedded system according to claim 2, wherein: The BULK block is divided into SECTOR areas according to the erase size, and the SECTOR area includes 256 bytes.
8. The environmental data encoding method for an embedded system according to claim 1, wherein: The actual value is recorded in a fixed format, which includes 2 bytes or 3 bytes.
9. The environmental data encoding method for an embedded system according to any one of claims 1 to 8, wherein: The environmental data includes numerical values and state values.
10. The environmental data encoding method for an embedded system according to claim 9, wherein: The numerical quantity is data that needs to be expressed in numerical values, including temperature and humidity; the state quantity is data that represents the working state, including the switch state.
Citation Information
Patent Citations
Coding and decoding method and apparatus of image block
CN104104955A
Data compression coding method and device supporting line storage and time sequence database
CN114268323A