Data processing method, electronic device, and storage medium
Patent Information
- Application Number
- CN202310350359.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2026-10-23
- Estimated Expiration
- 2043-03-28
AI Technical Summary
[0004]本申请实施例提供了一种数据处理方法、电子设备及存储介质,以解决按照固定的读取长度读取数据导致数据丢失或错乱的问题
[0006]本申请实施例提供的数据处理方法中,在预设的存储区域中写入了新的数据帧之后,计算新的数据帧的结束位置至前一分段位置的数据长度,若新的数据帧的结束位置至前一分段位置的数据长度大于预设长度,将前一个数据帧的结束位置确定为新的分段位置,使得相邻两个分段位置之间的数据小于预设长度,本申请通过更新分段位置,使得相邻两个分段位置之间的数据始终小于预设长度,从而在依次读取相邻两个分段位置之间的数据时,能够确保读取的数据是完整的,避免了相关技术中按照固定长度去读取数据,导致的数据丢失或错乱的问题。
Smart Images

Figure CN116360727B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of computer technology, and in particular relates to a data processing method, electronic device and storage medium. Background Technology
[0002] When an electronic device uses a First-In, First-Out (FIFO) memory, the electronic device can write data frames into the FIFO memory in sequence and read data frames in sequence according to the FIFO order.
[0003] In relevant data reading schemes, electronic devices read data according to a fixed read length (e.g., 4KB). Since the lengths of the individual data frames written by the electronic device vary, if the device reads data according to a fixed length, incomplete data frames may be present, leading to data loss or corruption and affecting the normal operation of the electronic device. Summary of the Invention
[0004] This application provides a data processing method, an electronic device, and a storage medium to solve the problem of data loss or corruption caused by reading data according to a fixed reading length.
[0005] The first aspect of this application provides a data processing method, including: after writing a new data frame in a preset storage area, calculating the data length from the end position of the new data frame to the previous segment position; if the data length is greater than a preset length, determining the end position of the previous data frame as a new segment position; and in response to a data read instruction, sequentially reading data between two adjacent segment positions and sending the data to the receiver specified by the data read instruction.
[0006] In the data processing method provided in this application embodiment, after a new data frame is written into a preset storage area, the data length from the end position of the new data frame to the previous segment position is calculated. If the data length from the end position of the new data frame to the previous segment position is greater than the preset length, the end position of the previous data frame is determined as the new segment position, so that the data between two adjacent segment positions is less than the preset length. This application updates the segment positions so that the data between two adjacent segment positions is always less than the preset length. Therefore, when reading the data between two adjacent segment positions in sequence, it can ensure that the read data is complete, avoiding the problem of data loss or disorder caused by reading data according to a fixed length in related technologies.
[0007] A second aspect of this application also provides an electronic device, the electronic device including a processor, the processor being configured to implement the above-described data processing method when executing a computer program stored in a memory.
[0008] A third aspect of this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the above-described data processing method. Attached Figure Description
[0009] Figure 1 This is an application scenario diagram of a data processing method provided in an embodiment of this application.
[0010] Figure 2 This is a flowchart of a data processing method provided in an embodiment of this application.
[0011] Figure 3 This is a schematic diagram showing the segmentation positions provided in an embodiment of this application.
[0012] Figure 4 This is the process for determining the segment position provided in the embodiments of this application.
[0013] Figure 5 This is the process for determining the initialization value of N provided in the embodiments of this application.
[0014] Figure 6 This is a flowchart illustrating the writing process of a data frame provided in an embodiment of this application.
[0015] Figure 7 This is a flowchart of the response to the read command provided in the embodiments of this application.
[0016] Figure 8 This is a schematic diagram of the structure of the data processing device provided in the embodiments of this application.
[0017] Figure 9 This is a structural diagram of the electronic device provided in the embodiments of this application. Detailed Implementation
[0018] It should be noted that the terms "first" and "second" in the specification, claims and drawings of this application are used to distinguish similar objects, rather than to describe a specific order or sequence.
[0019] It should also be noted that the methods disclosed in the embodiments of this application or the methods shown in the flowcharts include one or more steps for implementing the method. Without departing from the scope of the claims, the execution order of multiple steps can be interchanged, and some steps can also be deleted.
[0020] Some embodiments will now be described with reference to the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0021] The electronic device can be a self-moving device or other device capable of communication monitoring. For example, a self-moving device can be a device incorporating self-movement assistance functionality. This self-movement assistance functionality can be provided by an onboard terminal, and the corresponding self-moving device can be a vehicle equipped with that onboard terminal. The self-moving device can also be a semi-self-moving device or a fully autonomous device. Examples include lawnmowers, sweepers, and robots with navigation capabilities. The electronic device can also be an energy storage device with communication capabilities; this application does not limit the scope of the electronic device.
[0022] When an electronic device uses a First-In, First-Out (FIFO) memory, it can sequentially write and read data frames into the FIFO memory according to the FIFO order. Writing and reading data frames occur simultaneously, with the writing process occupying a portion of the FIFO memory's storage area. If the writing rate is faster than the reading rate, the data frame will be stored in the FIFO memory first, awaiting retrieval. If the amount of data in a written frame exceeds the FIFO memory's storage capacity, the writing process stops.
[0023] Combination Figure 1 This application describes the application scenarios of the data processing method provided in the embodiments of this application. For example... Figure 1 As shown, 12 squares are used to identify storage areas in the FIFO memory, and each square indicates that it can store 1K of data. Figure 1 0K and 12K are used to identify the scale values of the storage area. It can be understood that the storage space of the FIFO memory can be set according to the actual memory specifications; for example, the storage space of the FIFO memory is 64K. Figure 1 This example only uses a 12K storage area in a FIFO memory; in practical applications, it is not limited to this.
[0024] Data frames in the FIFO memory are written and read in sequence. When the FIFO memory receives the first data frame, it stores the first data frame. Figure 1 The leftmost storage area ( Figure 1 Within the location corresponding to the total 0K, the remaining data frames are written sequentially within the storage area; when reading data frames from the FIFO memory, from... Figure 1The first data frame is read from the leftmost storage area, and then the remaining data frames are read sequentially from the storage area. For example, data frames V1, V2, V3, V4, V5, and V6 are written to the FIFO memory in chronological order. The lengths of V1, V2, V3, V4, V5, and V6 are 0.8K, 1K, 0.7K, 0.4K, 0.8K, and 1K respectively, with varying lengths for each data frame. The total length of V1, V2, V3, V4, V5, and V6 is 4.7K. If the electronic device reads data according to a fixed read length (e.g., 4K), it reads a portion of the data from V1, V2, V3, V4, V5, and V6 sequentially. In this case, the length of the read data frame in V6 is 0.7K, leaving 0.3K of data frames unread. Therefore, V6 is an incomplete data frame, with data loss or corruption. Therefore, reading data based on a fixed length will lead to data loss or corruption, affecting the normal use of electronic devices.
[0025] To address the aforementioned issues, this application provides a data processing method that avoids data loss or corruption caused by reading incomplete data frames.
[0026] Figure 2 This is a flowchart illustrating a data processing method provided in an embodiment of this application, which is applied to an electronic device. Figure 2 As shown, the data processing method may include the following steps. Depending on different needs, the order of the steps in this flowchart may be changed, and some may be omitted.
[0027] S11: After writing a new data frame in the preset storage area, calculate the data length from the end position of the new data frame to the previous segment position.
[0028] In at least one embodiment of this application, the preset storage area can be a storage area within a FIFO memory. The end position of a data frame refers to its position within the storage area after it has been stored. A segment position refers to the data segment read position, and a data segment can be a combination of multiple data frames. The storage area contains multiple segment positions, with the 0th segment position being the start write position of the storage area. The data length between the i-th segment position and the (i+1)-th segment position is the sum of the data frame lengths corresponding to several data frames. This sum of data frame lengths is any value less than a preset length, where the initial value of i is 0. The preset length refers to the maximum data length that the FIFO memory can read in a single operation. The preset length can be set according to actual needs; for example, the preset length is 4K.
[0029] by Figure 1 Taking the application scenario in the example, the starting write position of the storage area (the leftmost area, i.e.) Figure 1 The 0K mark is used as the 0th segment position. When the preset length of the FIFO memory is set to 4K, meaning the maximum data length read in a single FIFO read is 4K, if the electronic device reads data frames V1, V2, V3, V4, V5, and V6 sequentially, when reading data frame V5, the sum of the data frame lengths corresponding to data frames V1-V5 is 3.7K; when reading data frame V6, the sum of the data frame lengths corresponding to data frames V1-V6 is 4.7K. Since the sum of the data frame lengths of V1-V6 (e.g., 4.7K) exceeds the preset length (e.g., 4K), reading according to the preset length would result in V6 not being read completely. Therefore, to ensure the integrity of the read data, the end position of data frame V5 can be used as the 1st segment position, thus ensuring that the data of data frame V6 can be read completely. Following this logic, multiple segment positions can be obtained, which will not be elaborated here.
[0030] In one embodiment, calculating the data length from the end position of the new data frame to the previous segment position means calculating the sum of the lengths and values of multiple data frames between the previous segment position and the end position of the new data frame. Figure 1Taking the application scenario as an example, the scale position corresponding to 0K is the 0th segment position, and the end position of the V5 data frame is the 1st segment position. If the electronic device writes a new data frame V1 to the storage area of the FIFO memory for the first time, the data length from the end position of the new data frame to the previous segment position is the data length from the end position of data frame V1 to the scale position corresponding to 0K, which is 0.8K; if the electronic device writes a new data frame V2 to the storage area of the FIFO memory, the data length from the end position of the new data frame to the previous segment position is the data length from the end position of data frame V2 to the scale position corresponding to 0K, which is 1.8K; if the electronic device writes a new data frame V3 to the storage area of the FIFO memory, the data length from the end position of the new data frame to the previous segment position is the data length from the end position of data frame V3 to the scale position corresponding to 0K, which is 2.5 ... previous segment position, the data length from the end position of the new data frame to the previous segment position is the data length from the end position of data frame V3 to the scale position corresponding to 0K, which is 2.5K; if the electronic device writes a new data frame V3 to the previous segment position, the data length from the end position of the new data frame to the previous segment position is the data length from the end position of data frame V3 to the scale position corresponding to 0K, which is 2.5K; if the electronic device writes a new data frame V1 to the previous segment position, the data length from the end position of the new data frame to the previous segment position is the data length from the end position of data frame V3 to If a new data frame V4 is written to the storage area of the IFO memory, the data length from the end position of the new data frame to the previous segment position is the same as the data length from the end position of data frame V4 to the corresponding 0K scale position, which is 2.9K. If the electronic device writes a new data frame V5 to the storage area of the FIFO memory, the data length from the end position of the new data frame to the previous segment position is the same as the data length from the end position of data frame V5 to the corresponding 0K scale position, which is 3.7K. If the electronic device writes a new data frame V6 to the storage area of the FIFO memory, the data length from the end position of the new data frame to the previous segment position (the first segment position, i.e., the end position of data frame V5) is the same as the data length from the end position of data frame V6 to the first segment position, which is 1K.
[0031] S12, if the data length is greater than the preset length, then the end position of the previous data frame is determined as the new segment position.
[0032] As illustrated in the above embodiments, the preset length refers to the maximum data length that can be read from the FIFO memory in a single operation; for example, the preset length is 4K. If the data length is greater than the preset length, it indicates that reading new data frames contained in the current data segment will begin from the data frame after the previous segment position, resulting in the new data frames not being read completely. Therefore, the end position of the previous data frame is used as the new segment position, which ensures that new data frames in the current data segment can be read completely.
[0033] S13, in response to the data read command, sequentially reads the data between two adjacent segment positions and sends the data to the receiver specified by the data read command.
[0034] In at least one embodiment of this application, a data read instruction refers to an instruction for reading data within a storage area. Upon receiving a data read instruction, multiple segment locations corresponding to the storage area are determined. Figure 3 This is a schematic diagram illustrating the segmentation positions provided in an embodiment of this application. Wherein, Figure 3 This is merely one example of implementing S13; the same method can be used when writing multiple data frames. Please refer to [link / reference]. Figure 3 The 12 squares are used to identify storage areas in the FIFO memory, and each square can store 1KB of data. Figure 1 0K and 12K are used to identify the scale values of the storage area. Data frames V1-V10 are written sequentially within the storage area, where V1 is 0.8K in length, V2 is 1K, V3 is 0.7K, V4 is 0.4K, V5 is 0.8K, V6 is 1K, V7 is 0.9K, V8 is 0.8K, V9 is 0.7K, and V10 is 0.8K. Following the above method for determining segment positions, it can be determined that there are 3 segment positions within this storage area (…). Figure 3 The middle arrow indicates the segment position, which is the 0th segment position ( Figure 3 The 0K scale value position), the first segment position ( Figure 3 The end position of the V5 data frame and the position of the second segment ( Figure 3 The end position of the V9 data frame). Read the data A between the 0th segment position and the 1st segment position sequentially (e.g., Figure 1 The data between data frames V1 and V5 is data A, and the data between the first segment position and the second segment position is data B (for example, Figure 1 The data between data frames V6 and V9 is data B. Data A and data B are transmitted to the receiver specified by the read command.
[0035] In the data processing method provided in this application embodiment, after a new data frame is written into a preset storage area, the data length from the end position of the new data frame to the previous segment position is calculated. If the data length from the end position of the new data frame to the previous segment position is greater than the preset length, the end position of the previous data frame is determined as the new segment position, so that the data between two adjacent segment positions is less than the preset length. This application updates the segment positions so that the data between two adjacent segment positions is always less than the preset length, thereby ensuring that the read data is complete when reading data between two adjacent segment positions sequentially, avoiding the data loss or corruption problems caused by reading data according to a fixed length in related technologies. For example, refer to Figure 3 The solution proposed in this application can prevent the loss of data frame V6. Therefore, the solution proposed in this application can ensure that the read data is complete.
[0036] In at least one embodiment of this application, if the data length is less than or equal to a preset length, it indicates that a new data frame contained in the current data segment is read starting from the data frame after the previous segment position, and the new data frame can be read completely. Therefore, the end position of the new data frame is assigned to the write position parameter, wherein the write position parameter is used to identify the write position of the data frame in the storage area, and the initial value of the write position parameter can be set to the start write position of the storage area (refer to...). Figure 1 (The leftmost region in the text). For example, with Figure 1 For example, when data frame V2 is written, since the data length from the end position of data frame V2 to the previous segment position (the 0th segment position) is 1.8K, which is less than the preset length, the scale corresponding to 1.8K is assigned to the write position parameter.
[0037] Figure 4 This is the process for determining the segment position provided in the embodiments of this application, such as... Figure 4 As shown, if the data length is greater than the preset length, the end position of the previous data frame is determined as the new segment position, including the following steps:
[0038] S121, increment the value of N by 1, the initial value of N is 0.
[0039] In one embodiment, N can be used to identify the number of segment positions within the same cycle of the storage region. The initial value of N is 0, corresponding to the starting write position of the storage region (e.g., ...). Figure 1 (Leftmost). The value of N is related to the maximum amount of data that can be read from the FIFO storage area in a single operation and the total amount of data in the storage area.
[0040] For example, with Figure 1 Taking the application scenario as an example, the scale position corresponding to 0K is the 0th segment position, and the value of N corresponding to the 0th segment position is 0; data frames V1-V6 are written sequentially from the 0th segment position. Since the length and value of the data frames corresponding to V1-V6 are 4.7K, which exceeds the preset length (4K), the value of N is increased by 1, that is, N is 1.
[0041] S122, if the data length is greater than the preset length, the value of the write position parameter is assigned to the Nth segment position; the value of the 0th segment position is the starting write position of the storage area.
[0042] In one embodiment, if the data length is greater than a preset length, the current write position parameter value is the end position of the previous data frame, and the end position of the previous data frame is used as the value of the write position parameter and assigned to the Nth segment position.
[0043] For example, with Figure 1Taking the application scenario in the example, the value of the 0th segment position is the starting write position of the storage area, starting from the 0th segment position ( Figure 1 Write data frames V1-V6 sequentially (corresponding to the 0K scale position). At this time, the value of N is 1. Determine the value of the current write position parameter, which is the end position of data frame V5, and assign the end position of data frame V5 to the first segment position.
[0044] S123, assign the end position of the new data frame to the write position parameter.
[0045] In one embodiment, if the data length is greater than a preset length, after assigning the value of the write position parameter to the Nth segment position, the write position parameter is updated to the end position of the new data frame.
[0046] For example, with Figure 1 Taking the application scenario as an example, after assigning the end position of the V5 data frame to the first segment position, the end position of the new data frame V6 is then assigned to the write position parameter.
[0047] Figure 5 This is the process for determining the initialization value of N provided in the embodiments of this application, such as... Figure 5 As shown, the method also includes:
[0048] S124, calculate the number of segment locations within the storage area.
[0049] In one embodiment, this number can be the number of segment positions after the write position parameter value is assigned. The number of segment positions is related to the maximum amount of data read from the FIFO storage area in a single operation and the total amount of data in the storage area. For example, the maximum amount of data read by the electronic device from the FIFO storage area in a single operation is 4K, and the total amount of data in the storage area is 64K. Considering that the length of each data frame is less than 1K, the data written to the storage area in a single operation is at least 3K. Therefore, N = 64 / 3 + 1, and the maximum value of N is 23, meaning that the 64K storage area can contain 23 segment positions.
[0050] S125, if the quantity is greater than or equal to the preset quantity, then initialize the value of N.
[0051] In the above embodiments, the preset quantity is the maximum value of N (for example, the value of N is 23). If the quantity is greater than or equal to the preset quantity, it indicates that a new data frame cannot be written to the storage area of the current cycle, and the value of N needs to be initialized. By initializing the value of N to 0, a new data frame can be written to the storage area of the next cycle, realizing the recycling of the FIFO memory.
[0052] In at least one embodiment of this application, writing and reading data frames are performed simultaneously. Multiple data frames are sequentially written into the FIFO memory, and the process of writing data frames occupies a portion of the storage area in the FIFO memory. Data frames are sequentially read from the FIFO memory, and data frames within a storage area can be cleared from the storage area after being read. Figure 1 Taking application scenarios as an example, Figure 1 0K and 12K are used to identify the scale values of the storage area. The end position of the current data frame corresponds to the scale value of 9K in the storage area, and the position of the current data frame being read corresponds to the scale value of 5K in the storage area. Subsequently, when writing a new data frame, the writing continues from the scale value of 9K; when reading a data frame, the reading continues from the scale value of 5K.
[0053] In one embodiment, if the scale value corresponding to the newly written data frame exceeds the storage space of the FIFO memory (e.g., 12K), the newly written data frame is re-stored to the starting write position of the corresponding storage area of the FIFO memory (e.g., ...). Figure 1 The leftmost position in the middle is used to achieve the recycling of the FIFO memory. Figure 6 This is a flowchart illustrating the writing process of a data frame provided in an embodiment of this application, such as... Figure 6 As shown, the method also includes the following steps:
[0054] S111, when writing a new data frame in the storage area, if the length from the end position of the previous data frame to the end write position of the storage area is greater than or equal to the length of the new data frame, then the new data frame is written starting from the end position of the previous data frame.
[0055] In one embodiment, the end-of-write position of the storage area refers to the position where the storage area can store the maximum amount of data. Figure 1 Taking an application scenario as an example, the end-write position of the storage area is the 12K scale value position (the rightmost area). By comparing the length from the end position of the previous data frame to the end-write position of the storage area with the length of the new data frame, it is used to determine whether the new data frame can be written into the storage area of the current loop.
[0056] In one embodiment, if the length from the end position of the previous data frame to the end write position of the storage area is greater than or equal to the length of the new data frame, it is determined that the new data frame can be written to the storage area of the current cycle. Then, the new data frame can be written starting from the end position of the previous data frame. For example, the scale value of the starting write position of the storage area is 0K, and the scale value of the ending write position is 12K, meaning the storage area can write 12K of data. Multiple data frames are written sequentially from the starting write position of the storage area. When the sum of the lengths of the multiple data frames is 11.2K, the remaining data amount in the storage area is 0.8K, meaning the storage area can write another 3K of data frames. If the length of the newly written data frame is 0.7K, and the new data frame can be written to the storage area of the current cycle, then the new data frame is written to the storage area sequentially.
[0057] S112, if the length from the end position of the previous data frame to the end write position of the storage area is less than the length of the new data frame, then start writing the new data frame from the start write position of the storage area.
[0058] In one embodiment, if the length from the end position of the previous data frame to the end write position of the storage area is less than the length of the new data frame, it is determined that the new data frame cannot be written into the storage area of the current cycle. In this case, the new data frame needs to be written from the beginning write position of the storage area, that is, the new data frame is written into the storage area of the next cycle.
[0059] For example, the storage area can write 12K of data. When the sum of the lengths of multiple data frames is 11.2K, the storage area can write another 0.8K of data frames. If the length of the newly written data frame is 0.9K, the new data frame cannot be written into the storage area of the current loop. In this case, it is determined that the new data frame cannot be written into the storage area of the current loop, and the new data frame needs to be written starting from the beginning of the write position of the storage area, that is, starting from 0K to write the new data frame (the data at that position has already been read).
[0060] The solution proposed in this application can prevent the data in a data frame from being continuous and split into the beginning and end of the FIFO, thus further preventing data corruption.
[0061] In at least one embodiment of this application, a process for determining the data length is also provided, which is described in the corresponding section. Figure 6 The following section is described below. After the electronic device writes a new data frame to a preset storage area, it calculates the data length from the end position of the new data frame to the previous segment position, including the following steps:
[0062] S113: After a new data frame is written to the storage area, if the end position of the new data frame is greater than the end position of the previous data frame, then calculate the data length from the end position of the new data frame to the previous segment position.
[0063] In one embodiment, Figure 1 0K and 12K are used to identify the scale values of the storage area. Within the same cycle, the end position of the previous data frame in the storage area is less than the end position of the new data frame. Figure 1 Taking the application scenario as an example, V2 is a new data frame. The end position of the previous data frame V1 is 0.8K, and the end position of data frame V2 is 1.8K. The end position of V1 is less than the end position of V2.
[0064] It can be understood that if the end position of the new data frame is greater than the end position of the previous data frame, it indicates that the new data frame and the previous data frame are in the same storage area of the same loop, meaning that the new data frame can be written into the storage area of the current loop. In this case, the data length from the end position of the new data frame to the position of the previous segment can be directly calculated.
[0065] For example, continue with Figure 1 For example, when the end position of data frame V2 is 1.8K, and the end position of V1 is less than the end position of V2, we can directly calculate the data length from the end position of the new large data frame to the previous segment position (the scale corresponding to 0K), and calculate that the current data length is 1.8K.
[0066] In one embodiment of this application, if the end position of the new data frame is less than the end position of the previous data frame, then the end position of the previous data frame is determined as the new segment position.
[0067] In one embodiment, if the end position of the new data frame is less than the end position of the previous data frame, it indicates that the new data frame and the previous data frame are not in the same storage area of the cycle, meaning the new data frame cannot be written into the storage area of the current cycle. In this case, the end position of the previous data frame is determined as the new segment position.
[0068] For example, the storage area can write 12K of data. When the sum of the lengths of multiple data frames is 11.2K, the storage area can write another 0.8K of data frames. If the length of the newly written data frame is 0.9K, the new data frame cannot be written into the storage area of the current loop. In this case, it is determined that the new data frame cannot be written into the storage area of the current loop, and the new data frame needs to be written starting from the beginning of the write position of the storage area, that is, starting from 0K (the data at that position has already been read). At this time, the end position of the previous data frame is determined as the new segment position, that is, the 11.2K scale is used as the new segment position.
[0069] In one embodiment of this application, when step S112 occurs, when reading the data between two adjacent segment positions to the designated receiver for data reading, the length of the part that has not been written can be removed to avoid writing invalid data.
[0070] For example, continue with Figure 1 For example, when the previous segment position was 11.2K, five new data frames were written: 0.9K, 1K, 0.8K, 0.9K, and 1K, with a total data length of 4.6K. Since the length of this newly written data frame (0.9K) is greater than the remaining 0.8K in the FIFO, it is written starting from the beginning of the write position in the storage area, i.e., from 0K. Correspondingly, when calculating the next segment position, because the data length of the fifth data frame (1K) exceeds the preset length, the end position of the fourth data frame is used as the new segment position, i.e., the new segment position is at 3.6K. Therefore, when reading data next time, although the two adjacent segment positions are 11.2K and 3.6K respectively, since there is no data in the FIFO's 11.2K-12K range, data reading will still read data between 11.2K and 3.6K, and no data loss will occur.
[0071] In one embodiment of this application, if the length from the end position of the previous data frame to the end write position of the storage area is less than the length of the new data frame, then writing continues from the end position of the previous data frame; if there is not enough space, writing starts from the beginning write position of the storage area. The solution of this application avoids wasting data capacity in the FIFO, ensuring that each capacity stores data.
[0072] For example, the storage area can write 12K of data. When the sum of the lengths of multiple data frames is 11.2K, the storage area can write another 0.8K data frame. If the length of the newly written data frame is 0.9K, the new data frame cannot be written into the storage area of the current loop, then it is determined that the new data frame cannot be written into the storage area of the current loop. In this solution, when writing fails, writing can continue from the end position of the previous data frame, and if it cannot be written, it can start writing from the beginning position of the storage area.
[0073] In one embodiment of this application, when the above situation occurs, when reading the data between two adjacent segment positions to the designated receiver for data reading, the data between two adjacent segment positions can be read to the designated receiver for data reading as usual.
[0074] For example, continue with Figure 1 For example, when the previous segment position was at 11.2K, five new data frames were written: 0.9K, 1K, 0.8K, 0.9K, and 1K, with a total data length of 4.6K. Since the length of this newly written data frame (0.9K) is greater than the remaining 0.8K in the FIFO, writing continues. That is, 0.8K of the first of the five new data frames is written after the previous segment position of 11.2K, while the remaining 0.1K is written from the beginning of the storage area, starting from 0K. Correspondingly, when calculating the next segment position, since the data length is greater than the preset length when the fifth data frame (1K) is written, the end position of the fourth data frame is taken as the new segment position, i.e., the new segment position is at 2.7K. Therefore, when reading data next time, the data between the previous segment position (11.2K) and the next segment position (2.7K) is read directly. The corresponding data is the first four frames of data in the new five data frames.
[0075] Figure 7 This is a flowchart of the response to the read instruction provided in an embodiment of this application, such as... Figure 7 As shown, the electronic device sequentially reads data between two adjacent segment positions and sends it to the receiver specified by the data reading command, including the following steps:
[0076] S131, calculate the target data length between the i-th segment position and the (i+1)-th segment position; the initial value of i is 0.
[0077] In one embodiment, multiple data frames are contained between the i-th segment position and the (i+1)-th segment position. Each data frame corresponds to a data frame length, and the sum of the data frame lengths corresponding to each data frame is calculated as the target data length. Here, the initial value of i is 0, meaning that during the first read, data within the storage area is read sequentially starting from the beginning of the write position. During subsequent reads, the previous read address and the segment position corresponding to that read address are determined, and the data length between that segment position and the next segment position is calculated as the target data length.
[0078] S132, starting from the address corresponding to the read position parameter, read data of the target data length to the receiver.
[0079] In one embodiment, the read location parameter is used to identify the address of the last read within the storage area, and the target data length can be complete data that is less than a preset length.
[0080] S133, assign the (i+1)th segment position to the read position parameter, increment the value of i by 1, and then return to step S131 to continue calculating the target data length between the i-th segment position and the (i+1)th segment position.
[0081] In one embodiment, after reading the data between the i-th segment position and the (i+1)-th segment position, the read position parameter is updated, that is, the (i+1)-th segment position is the nearest read address. The value of i is incremented by 1, and then the process returns to step S131 to perform the step of calculating the target data length between the i-th segment position and the (i+1)-th segment position, until the data in the storage area is completely read.
[0082] by Figure 3 Taking an application scenario as an example, when reading for the first time, the initial value of i is 0, and the data between the 0th segment position and the 1st segment position (data frames V1 to V5) is read to the receiver; then, the value of i is incremented by 1, and the data between the 1st segment position and the 2nd segment position (data frames V6 to V9) is read to the receiver; and so on, until all the data in the storage area has been read. Therefore, using the scheme of this application for reading can avoid data loss.
[0083] Please see Figure 8 , Figure 8 This is a schematic diagram of the structure of a data processing apparatus provided in an embodiment of this application. In some embodiments, the data processing apparatus 20 may include multiple functional modules composed of computer program segments. The computer programs of each program segment in the data processing apparatus 20 may be stored in the memory of the computer device 30 and executed by at least one processor to perform (see details). Figure 2 (Description) Data processing functions.
[0084] In this embodiment, the data processing device 20 can be divided into multiple functional modules according to the functions it performs. When the data processing device 20 is applied to an electronic device, the functional modules may include: a data length calculation module 201, a segment position determination module 202, and a read instruction response module 203. The term "module" in this application refers to a series of computer program segments that can be executed by at least one processor and perform a fixed function, and which are stored in memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.
[0085] The data length calculation module 201 can calculate the data length from the end position of the new data frame to the previous segment position after a new data frame is written into the preset storage area.
[0086] The segment position determination module 202 can determine the end position of the previous data frame as the new segment position if the data length is greater than the preset length.
[0087] The read instruction response module 203 can respond to a data read instruction by sequentially reading the data between two adjacent segment positions and sending the data to the receiver specified by the data read instruction.
[0088] It is understood that the data processing device 20 and the data processing method of the above embodiments belong to the same inventive concept. The specific implementation of each module of the data processing device 20 corresponds to each step of the data processing method in the above embodiments, and will not be repeated here.
[0089] The module division described above is a logical functional division, and other division methods may be used in actual implementation. Furthermore, the functional modules in the various embodiments of this application can be integrated into the same processing unit, or each module can exist physically separately, or two or more modules can be integrated into the same unit. The integrated modules described above can be implemented in hardware or in a combination of hardware and software functional modules.
[0090] Figure 9 This is a schematic diagram of an electronic device provided in an embodiment of this application. The embodiments of this application are combined with... Figure 9 Describe the structure of the electronic device. For example... Figure 9 As shown, the electronic device 30 includes a memory 31, at least one controller 32, and at least one communication bus 33.
[0091] Those skilled in the art should understand that Figure 9 The illustrated structure of the electronic device does not constitute a limitation of the embodiments of this application. The electronic device 30 may also include more or fewer other hardware or software, or different component arrangements than those shown. For example, the electronic device 30 may also include multiple interfaces, with a first interface for connecting a load to power the load, and a second interface for connecting a separate battery pack to increase the capacity of the electronic device.
[0092] Electronic device 30 may also include client equipment, including but not limited to any electronic product that can interact with a client via a keyboard, mouse, remote control, touchpad or voice control device, such as personal computer, tablet computer, smartphone, digital camera, etc.
[0093] It should be noted that electronic device 30 is only an example. Other existing or future electronic products that are suitable for this application should also be included within the scope of protection of this application and are incorporated herein by reference.
[0094] In some embodiments, the memory 31 stores a computer program that, when executed by at least one controller 32, implements all or part of the steps in a data processing method. The memory 31 includes read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium capable of carrying or storing data.
[0095] Furthermore, the computer-readable storage medium may primarily include a program storage area and a data storage area, wherein the program storage area may store the operating system, an application program required for at least one function, etc.; and the data storage area may store data created based on the use of the electronic device 30, etc.
[0096] In some embodiments, at least one controller 32 is the control unit of the electronic device 30, connecting various components of the electronic device 30 via various interfaces and lines. It executes programs or modules stored in the memory 31 and calls data stored in the memory 31 to perform various functions and process data. For example, when at least one controller 32 executes a computer program stored in the memory, it implements all or part of the steps of the data processing method in the embodiments of this application; or it implements all or part of the functions of the data processing device. At least one controller 32 may be composed of integrated circuits, such as a single-packaged integrated circuit or multiple integrated circuits with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips.
[0097] In some embodiments, at least one communication bus 33 is configured to enable communication between the memory 31 and at least one controller 32, etc.
[0098] Although not shown, electronic device 30 may also include a battery pack powering various components. Preferably, the battery pack can be logically connected to at least one controller 32 via a power management device, thereby enabling functions such as charging, discharging, and power consumption management through the power management device. Electronic device 30 may also include one or more DC or AC power supplies, recharging devices, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components. Electronic device 30 may also include various sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be described in detail here.
[0099] The integrated unit implemented as a software functional module described above can be stored in a computer-readable storage medium. This software functional module, stored in a storage medium, includes several instructions to cause an electronic device (which may be a personal computer, electronic device, or network device, etc.) or a controller (processor) to execute portions of the methods of the various embodiments of this application.
[0100] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.
[0101] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0102] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional modules.
[0103] It will be apparent to those skilled in the art that this application is not limited to the details of the exemplary embodiments described above, and that it can be implemented in other specific forms without departing from the spirit or essential characteristics of this application. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of this application is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within this application. No reference numerals in the claims should be construed as limiting the scope of the claims. Furthermore, it is clear that the word "comprising" does not exclude other elements or, and the singular does not exclude the plural. Multiple elements or devices recited in the specification may also be implemented by a single element or device through software or hardware. The terms "first," "second," etc., are used to indicate names and do not indicate any particular order.
[0104] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application 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 this application without departing from the spirit and scope of the technical solutions of this application.
Claims
1. A data processing method, characterized in that, include: After a new data frame is written into the preset storage area, the data length from the end position of the new data frame to the previous segment position is calculated. If the data length is greater than a preset length, the end position of the previous data frame is determined as the new segment position, including: incrementing the value of N by 1, where the initial value of N is 0; if the data length is greater than the preset length, assigning the value of the write position parameter to the Nth segment position; the value of the 0th segment position is the start write position of the storage area; assigning the end position of the new data frame to the write position parameter; calculating the number of segment positions in the storage area; if the number is greater than or equal to a preset number, initializing the value of N; In response to a data read command, data between two adjacent segment positions is read sequentially, and the data is sent to the receiver specified by the data read command.
2. The data processing method as described in claim 1, characterized in that, After calculating the data length from the end position of the new data frame to the previous segment position, the method further includes: If the data length is less than or equal to the preset length, the end position of the new data frame is assigned to the write position parameter; the initial value of the write position parameter is the start write position of the storage area.
3. The data processing method according to any one of claims 1 to 2, characterized in that, The method further includes: When writing the new data frame to the storage area, if the length from the end position of the previous data frame to the end writing position of the storage area is greater than or equal to the length of the new data frame, then the new data frame is written starting from the end position of the previous data frame. If the length from the end position of the previous data frame to the end write position of the storage area is less than the length of the new data frame, then the new data frame is written starting from the start write position of the storage area.
4. The data processing method as described in claim 3, characterized in that, After a new data frame is written into the preset storage area, the data length from the end position of the new data frame to the previous segment position is calculated, including: After a new data frame is written to the storage area, if the end position of the new data frame is greater than the end position of the previous data frame, the data length from the end position of the new data frame to the previous segment position is calculated.
5. The data processing method as described in claim 4, characterized in that, The method further includes: if the end position of the new data frame is less than the end position of the previous data frame, then the end position of the previous data frame is determined as the new segment position.
6. The data processing method as described in claim 1, characterized in that, The step of sequentially reading data between two adjacent segment positions and sending the data to the receiver specified by the data reading instruction includes: Calculate the target data length between the i-th segment position and the (i+1)-th segment position; the initial value of i is 0; Starting from the address corresponding to the read position parameter, read data of the target data length to the receiver; Assign the (i+1)th segment position to the read position parameter, increment the value of i by 1, and return to the step of calculating the target data length between the i-th segment position and the (i+1)-th segment position.
7. An electronic device, characterized in that, The electronic device includes a processor that executes a computer program stored in a memory to implement the data processing method as described in any one of claims 1 to 6.
8. A computer-readable storage medium storing a computer program thereon, characterized in that, When the computer program is executed by a processor, it implements the data processing method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Reliable serial port transmission method and device based on hardware system
CN102724122A
Database system, data processing method and electronic equipment
CN115168319A