Data storage method and device, electronic equipment and readable storage medium
By obtaining the number of weeks of the current date when the microcontroller is powered on, determining the consistency with the power-on date recorded in the storage device, and determining the data storage method, the problem of massive data storage and reading of the microcontroller is solved, and the number of weeks is realized Circular storage improves data search efficiency.
Patent Information
- Application Number
- CN202411227193.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2025-01-03
AI Technical Summary
When microcontrollers run for a long time, the existing technology is difficult to meet the storage and reading needs of massive data, the storage capacity is limited, and the file system is difficult to effectively manage and search data.
By obtaining the number of weeks of the current date when powering on the microcontroller, we will determine whether it is consistent with the power-on date recorded in the storage device. If it is consistent, add storage data to the corresponding folder. If it is inconsistent, overwrite the storage data and use the folder name to The corresponding method of the number of weeks realizes circular storage in units of weeks, improving data search efficiency.
It realizes effective storage and management of massive data, ensures that the data is relatively the earliest data in the storage device, and ensures the effectiveness and search efficiency of data in the storage device.
Smart Images

Figure CN119248186A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of single-chip microcomputers, and in particular to a data storage method, device, electronic device and readable storage medium. Background Art
[0002] With the development of information technology, especially the improvement of processing speed of various digital processing devices, in the single-chip microcomputer application system, there are some special application occasions that require large-capacity data storage, while the storage capacity of general single-chip microcomputers is generally tens of K to hundreds of K bytes, which cannot meet the needs of single-chip microcomputers to store massive data.
[0003] In the related art, FATFS is used as a file system and an SD card is used as a memory to implement data storage.
[0004] The above method only stores data directly in the SD card. However, when the single-chip microcomputer runs for a long time and stores a large amount of data, the existing technology is difficult to meet the storage and reading of data in the single-chip microcomputer. Summary of the invention
[0005] In view of the above problems, embodiments of the present invention are proposed to provide a data storage method, device, electronic device and readable storage medium that overcome the above problems or at least partially solve the above problems.
[0006] In a first aspect, an embodiment of the present application discloses a data storage method, which is applied to a single chip microcomputer, and the method includes:
[0007] When the single chip microcomputer is powered on, obtaining the first week number corresponding to the current date;
[0008] Determine whether the current date is consistent with the power-on date recorded in the storage device;
[0009] If they are consistent, and there is a first target folder in the storage device whose folder name corresponds to the first week number, then the data to be stored on the current date is stored in the last file in the first target folder in the writing order;
[0010] If they are inconsistent, and there exists a first target folder in the storage device whose folder name corresponds to the first week number, the data to be stored is stored in the order in which the files in the first target folder are written, by overwriting the contents of the files in the first target folder with the data to be stored.
[0011] Optionally, the method further comprises:
[0012] If the first target folder whose folder name corresponds to the first week number does not exist in the storage device, creating a second target folder whose folder name corresponds to the first week number;
[0013] A sub-file is created in the directory of the second target folder, and the data to be stored on the current date is stored in the sub-file.
[0014] Optionally, determining whether the current date is consistent with a power-on date recorded in the storage device includes:
[0015] If not, recording the current date in the storage device;
[0016] If they are consistent, the power-on date recorded in the storage device remains unchanged.
[0017] Optionally, storing the data to be stored in a manner of overwriting the contents of the files in the first target folder by the data to be stored according to the writing order of the files in the first target folder includes:
[0018] Obtain the file names of the files in the first target folder; the file names are named according to the order in which the files are written;
[0019] Determine a first target file to be written by using the file name, and write the data to be stored into the first target file to be written by overwriting the original data in the target file;
[0020] If the storage space of the first target file to be written is full, the unwritten data to be stored is written into the second target file until all the data to be stored is written into the first target folder.
[0021] Optionally, storing the data to be stored on the current date in a file in the first target folder that is the last in the writing order includes:
[0022] Obtain the file names of the files in the first target folder; the file names are named according to the order in which the files are written;
[0023] According to the file name, determining the target file that is last in the writing order in the first target folder, and writing the data to be stored into the target file;
[0024] If the storage space of the target file is full, a new target file is created in a naming manner according to the writing order, and the unwritten data to be stored is written into the new target file.
[0025] Optionally, the method further comprises:
[0026] During the operation of the single chip microcomputer, the current date is obtained in real time;
[0027] If the current date has changed relative to the date when the single-chip microcomputer was just powered on, re-determine the second week number according to the changed date;
[0028] The data to be stored is stored in a third target folder in the storage device whose folder name corresponds to the second week number.
[0029] Optionally, if the data to be stored have different data types, the method further includes:
[0030] Obtain the file name of the file in the first target folder; the file name is named according to the data type and writing order;
[0031] According to the data type of the data to be stored and the file name, the candidate file with the first write order among the candidate files matching the data type is determined as the first write target file.
[0032] Optionally, determining the first target file to be written by using the file name includes:
[0033] Extract the file names of all files in the first target folder;
[0034] The first target file to be written is determined according to the field representing the writing order in the file name.
[0035] Optionally, before storing the data to be stored on the current date in a file in the first target folder that is the last in the writing order, the method further includes:
[0036] Determine whether there is a file in the first target folder;
[0037] If it does not exist, create the file to be written; the file name of the file to be written corresponds to the writing order.
[0038] In a second aspect, an embodiment of the present application discloses a data storage device, which is applied to a single-chip microcomputer, and the device includes:
[0039] An acquisition module, used for acquiring the first week number corresponding to the current date when the single chip microcomputer is powered on;
[0040] A judgment module, used to judge whether the current date is consistent with the power-on date recorded in the storage device;
[0041] A first writing module is used for storing the data to be stored on the current date into a file that is last in the writing order in the first target folder if the two files are consistent and there is a first target folder with a folder name corresponding to the first week number in the storage device;
[0042] A second writing module is used to store the data to be stored in a manner that overwrites the contents of the files in the first target folder with the data to be stored, according to the writing order of the files in the first target folder, if there is no inconsistency and there is a first target folder with a folder name corresponding to the first week number in the storage device.
[0043] In a third aspect, an embodiment of the present application further discloses an electronic device, comprising a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the program or instructions are executed by the processor, the steps of the data storage method described in the first aspect are implemented.
[0044] In a fourth aspect, an embodiment of the present application further discloses a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the data storage method described in the first aspect are implemented.
[0045] In an embodiment of the present application, when the single-chip microcomputer is powered on, the first week number corresponding to the current date is obtained; it is determined whether the current date is consistent with the power-on date recorded in the storage device; if they are consistent, and there exists a first target folder in the storage device whose folder name corresponds to the first week number, the data to be stored of the current date is stored in a file whose writing order is the last in the first target folder; if they are inconsistent, and there exists a first target folder in the storage device whose folder name corresponds to the first week number, the data to be stored is stored in a manner that the data to be stored overwrites the contents of the files in the first target folder in accordance with the writing order of the files in the first target folder. After the single-chip microcomputer is powered on, the method of the present application first determines whether the current power-on date and the power-on date recorded in the storage device are the same day. If they are the same day, it is further determined whether there is a folder corresponding to the week number corresponding to the current date in the storage device. If so, it is stored in the folder corresponding to the week number. If they are not the same day, the folder corresponding to the current week number is determined, and the original data is overwritten for storage. That is, in the present application, the name of the folder is corresponded to the week number, so that the current week number is stored in the folder of the week number, and the data of the same week number last week is overwritten by the data of the current week number, thereby realizing cyclic storage of data in units of weeks, that is, the storage of massive data is realized in units of weeks through polling storage. At the same time, the storage date of the data can be determined by the name of the folder, thereby improving the efficiency of data search. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 This is a flow chart of steps of a data storage method provided by an embodiment of the present invention;
[0047] Figure 2This is a flowchart of another data storage method provided by an embodiment of the present invention;
[0048] Figure 3 is a block diagram of a data storage device provided by an embodiment of the present invention;
[0049] Figure 4 is a block diagram of an electronic device provided by an embodiment of the present invention;
[0050] Figure 5 is a block diagram of another electronic device according to another embodiment of the present invention. DETAILED DESCRIPTION
[0051] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present invention and to enable the scope of the present invention to be fully communicated to those skilled in the art.
[0052] refer to Figure 1 , which shows a data storage method provided by an embodiment of the present application, a flowchart of steps applied to a single-chip microcomputer, the method comprising:
[0053] Step 101, when the single chip microcomputer is powered on, obtain the first week number corresponding to the current date.
[0054] In an embodiment of the present invention, the single-chip microcomputer can be a device that implements storage based on an SD card and a FATFS file system. After the single-chip microcomputer is powered on, it can read the RTC (Real-Time Clock) clock to calculate the current time. According to the current time, the first week number corresponding to the current date can be determined. The first week number is used to represent the day of the week corresponding to the current date. For example, based on the RTC clock information, it is determined that the first week number corresponding to the current date is Monday, or Tuesday, etc.
[0055] By determining the first week number, it can be determined in which folder the to-be-stored data corresponding to the current date should be stored.
[0056] Step 102, determining whether the current date is consistent with the power-on date recorded in the storage device.
[0057] In the embodiment of the present invention, after obtaining the current date, it can be determined whether the current date is consistent with the power-on date recorded in the storage device. The power-on date recorded in the storage device can be the date of the last power-on before the current power-on. By comparing the current date with the power-on date recorded in the storage device, it can be determined whether the current power-on date and the previous power-on date are the same day. If they are the same day, the data to be stored should be written in the folder corresponding to the first week number of the current date. If they are not the same day, the data to be stored should be written over the folder corresponding to the first week number.
[0058] For example, if the first week number is Monday, if the current power-on date is the same as the previous power-on date, the data to be stored generated after the current power-on should be added to the folder named Monday. If the current power-on date is not the same as the previous power-on date, the data to be stored generated after the current power-on should overwrite the original data in the folder named Monday for storage. That is, by judging whether the dates are consistent, the storage processing method for the data to be stored can be determined.
[0059] Optionally, step 102 includes:
[0060] Sub-step 1021, if not consistent, recording the current date in the storage device;
[0061] Sub-step 1022: If they are consistent, the power-on date recorded in the storage device remains unchanged.
[0062] In the embodiment of the present invention, for sub-steps 1021 and 1022, if the current date after the single-chip microcomputer is powered on is inconsistent with the power-on date originally recorded in the storage device, the date recorded in the storage device is updated to the current date. If they are consistent, the power-on date recorded in the storage device does not need to be changed. By continuously updating the power-on date recorded in the storage device, it is determined whether the two startups of the single-chip microcomputer are within the same day, and then the location of the data to be stored in the folder is determined.
[0063] Step 103: If they are consistent, and there is a first target folder in the storage device whose folder name corresponds to the first week number, the data to be stored on the current date is stored in a file in the first target folder that is the last in the writing order.
[0064] In an embodiment of the present invention, the current date after the single-chip microcomputer is powered on is consistent with the power-on date originally recorded in the storage device, and there is a first target folder in the storage device whose folder name corresponds to the first week number, then the data to be stored on the current date should be stored in the first target folder in a file with the last writing order.
[0065] For example, if Monday's data is stored in folder 1, the name of folder 1 can be "Monday", Tuesday's data is stored in folder 2, the name of folder 2 can be "Tuesday", and so on, Sunday's data is stored in folder 7 with the folder name "Sunday", thus forming a storage of 7 days of data. The actual data is stored in the above 7 folders and saved in the naming method of file name 1, file name 2, file name 3, etc. When storing, it can be stored in the file of file name 1 first, and after the file of file name 1 is full, it can continue to be stored in the file of file name 2. Therefore, if the first week number is Monday, the current date after the single-chip microcomputer is powered on is consistent with the power-on date originally recorded in the storage device, and there exists a first target folder in the storage device with a folder name corresponding to the first week number, that is, there exists a folder with the file name "Monday", then when storing, there is no need to create a new folder. Furthermore, after determining the first target folder with the folder name "Monday", determine whether there are already files in the first target folder. If so, continue to write the data to be stored after this power-on into the file that is the last in the writing order, that is, if the first target folder contains: file 1, file 2, file 3 and file 4, then the data of this power-on can continue to be written into file 4 to avoid the current day's data stored in files 1, 2 and 3 being overwritten, resulting in the loss of current day's data.
[0066] Optionally, step 103 includes:
[0067] Sub-step 1031, obtaining the file names of the files in the first target folder; the file names are named according to the order in which the files are written;
[0068] Sub-step 1032, determining the target file that is the last in the writing order in the first target folder according to the file name, and writing the data to be stored into the target file;
[0069] Sub-step 1033: if the storage space of the target file is full, a new target file is created in the order of writing and the unwritten data to be stored is written into the new target file.
[0070] In an embodiment of the present invention, for sub-steps 1031 to 1033, the file names of the files in the first target folder can be named in the order of writing. For example, the files include: file 1, file 2, file 3, then file 1 is the first file written, file 2 is the second file written, and file 3 is the third file written. If the current date is consistent with the power-on date recorded in the storage device, it means that files 1, file 2, and file 3 in the first target folder store today's data. Then, when writing the data to be stored, additional writing should be continued on the basis of file 3. If the storage space of file 3 is full, a new target file named file 4 can be created, and the unwritten data to be stored can continue to be written in file 4.
[0071] Step 104: If there is inconsistency, and there exists a first target folder in the storage device whose folder name corresponds to the first week number, the data to be stored is stored in the order in which the files in the first target folder are written, by overwriting the contents of the files in the first target folder with the data to be stored.
[0072] In an embodiment of the present invention, the current date after the single-chip microcomputer is powered on is inconsistent with the power-on date originally recorded in the storage device, and there is a first target folder in the storage device whose folder name corresponds to the first week number, then the data to be stored on the current date should overwrite the data in the first target folder for storage.
[0073] For example, if the first week number is Monday, the current date after the single-chip microcomputer is powered on is inconsistent with the power-on date originally recorded in the storage device, and there is a first target folder in the storage device with a folder name corresponding to the first week number, that is, there is a folder with a file name of "Monday", then when storing, there is no need to create a new folder. Further, after determining the first target folder with a folder name of "Monday", it is determined whether there are already files in the first target folder. If so, and the first target folder contains: file 1, file 2, file 3 and file 4, then the data of this power-on can be first downloaded into file 1. If file 1 is full, then file 2 is written, so that the original file data in the first target folder is sequentially overwritten for storage. That is, if it is determined that the data stored in the first target folder is the data of the previous cycle, then when storing, the data with the earliest storage time can be automatically overwritten according to the storage time of the data in the first target folder to meet the current storage needs of the single-chip microcomputer.
[0074] Optionally, step 104 includes:
[0075] Sub-step 1041, obtaining the file names of the files in the first target folder; the file names are named according to the order in which the files are written;
[0076] Sub-step 1042, determining a first target file to be written according to the file name, and writing the data to be stored into the first target file to be written by overwriting the original data in the target file;
[0077] Optionally, sub-step 1042 includes:
[0078] Sub-step 10421, extracting the file names of all files in the first target folder;
[0079] Sub-step 10422, determining the first target file to be written according to the field representing the writing order in the file name.
[0080] Sub-step 1043, if the storage space of the first target file to be written is full, write the unwritten data to be stored into the second target file until all the data to be stored are written into the first target folder.
[0081] In an embodiment of the present invention, for sub-step 1041 and sub-step 1043, the file names of the files in the first target folder can be named according to the writing order. For example, the files include: file 1, file 2, file 3, then file 1 is the first file written, file 2 is the second file written, and file 3 is the third file written. If the current date is inconsistent with the power-on date recorded in the storage device, it means that files 1, file 2, and file 3 in the first target folder store data from the previous cycle or earlier. Then, when writing the data to be stored, it can be written in the order of file 1, file 2, and file 3, that is, the data in file 1, file 2, and file 3 are deleted, and the data to be stored is first written into the first target file, file 1. If file 1 is full, continue to write into the second target file, file 2, and so on, until all the data to be stored is written into the first target folder.
[0082] Furthermore, after the first target folder is determined according to the folder name, the writing order of the files may be determined according to the names of the files in the first target folder.
[0083] For example, after determining that the first week number is Monday, you can first extract the folder name of the folder in the storage device to determine whether there is a first target folder named "Monday" in the folder name. If so, continue to determine whether there are any files in the first target folder. If there are files, extract the file name, and determine the writing order of the files based on the file name. For example, the numbers in the file name can represent the writing order of the files, and the numbers are the fields that represent the writing order. According to the numbers in the extracted file name, determine the first target file to be written. For example, determine that file 1 is the first target file to be written, then start overwriting the original data from file 1, write new data to be stored, and write the remaining data to be stored in turn.
[0084] The method of the present application can quickly determine the file with the earliest writing time through the file name, and then when storing new data to be stored, it can directly overwrite the data in the file with the earliest writing time for storage, thereby improving the efficiency of locating written files, so that the old data with the earliest storage time is deleted first, and the data stored in the storage device is the earliest data relative to the current time, thereby ensuring the validity of the data in the storage device.
[0085] Optionally, if the data to be stored have different data types, the method further includes:
[0086] Sub-step 1044, obtaining the file name of the file in the first target folder; the file name is named according to the data type and the writing order;
[0087] Sub-step 1045, according to the data type of the data to be stored and the file name, determine the candidate file that is the first in the writing order among the candidate files matching the data type as the first target file to be written.
[0088] In an embodiment of the present application, for sub-step 1044 and sub-step 1045, in a scenario, there are different data types for the data to be stored. For example, the data types may include: text data, audio data, image data, and video data. In order to facilitate data query after data storage, when creating files in a folder, different file names can be distinguished according to the data type for creation, so that when storing the data to be stored, it can be stored in the corresponding file according to the data type of the data to be stored.
[0089] For example, ordinary text data is named with the file name t_1, audio data is named with m_1, image data is named with p_1, audio data is named with v_1, etc. If the data to be stored is text data, then when storing, the file with the file name t_1 can be determined to be stored. If the data to be stored is audio data, then when storing, the file with the file name v_1 can be determined to be stored. For files storing different data types, the file names are also named in the order of writing. For example, if the data to be stored is stored in a way of overwriting the data in the first target folder, and the data to be stored is text type data, then when storing, you can first find out whether there is a file storing text type data. If so, the input to be stored is written into t_1. If t_1 is full, continue to write into t_2. If t_2 does not exist, first create t_2 and then write into t_2. The file names of files storing different data types can also be named in a way of digital accumulation, which is convenient for quickly determining the storage location when storing and searching. The writing method of data to be stored of other data types is similar, and this application will not repeat it here.
[0090] When the device has text data, audio data, image data, and video data to store, the method of the present application can distinguish them by file name based on the data format type, thereby improving storage efficiency. When reading file data, the data format type of the data can be directly known by searching for different file names, thereby improving query efficiency.
[0091] Optionally, the method further comprises:
[0092] Step 105, if the first target folder whose folder name corresponds to the first week number does not exist in the storage device, then create a second target folder whose folder name is the first week number;
[0093] Step 106: create a sub-file in the directory of the second target folder, and store the data to be stored on the current date in the sub-file.
[0094] In an embodiment of the present invention, with respect to step 105 and step 106, if after the first week number is determined, it is found that a first target folder corresponding to the first week number does not exist in the storage device, a second target folder can be directly created, the folder name of the second target folder corresponds to the first week number, a sub-file is created under the directory of the second target folder, and the data to be stored is written into it.
[0095] For example, the first week number is Monday, and there is no first target folder named "Monday" in the storage device. Then you can create a second target folder named "Monday" in the storage device, create a sub-file such as file 1 under the second target file, and write the data to be stored in sub-file 1. If file 1 is full, such as file 1 has stored 10k of data, continue to create file 2 for writing, and so on, until all the data to be stored are written into the second target folder.
[0096] It should be noted that the folder names in this application are: Monday, Tuesday, etc. are only used as examples. In actual operation, they can be named: 1, 2, 3, etc., any names that can distinguish different days of the week. The embodiments of this application are not limited here.
[0097] Optionally, the method further comprises:
[0098] Step 107, obtaining the current date in real time during the operation of the single chip microcomputer;
[0099] Step 108, if the current date has changed relative to the date when the microcontroller was just powered on, then re-determine the second week number according to the changed date;
[0100] Step 109: store the data to be stored in a third target folder in the storage device whose folder name corresponds to the second week number.
[0101] In the embodiment of the present invention, for steps 107 to 109, after the single-chip microcomputer is powered on once, it may run for a long time, for example, more than 24 hours. At this time, it involves the situation that the target folder where the data to be stored should be stored has changed. Therefore, during the power-on process, the RTC clock of the single-chip microcomputer can be monitored in real time to determine whether the current date obtained has changed relative to when the power was just turned on. If changed, the second week number corresponding to the current date is re-determined, so that the current data to be stored is stored in the folder corresponding to the second week number.
[0102] For example, if the date when the microcontroller is powered on corresponds to Tuesday, the data to be stored is stored in a folder named "Tuesday". After running for a period of time, the date obtained corresponds to Wednesday, then the data should be changed to be stored in a folder named "Wednesday" to avoid file storage confusion and affect the subsequent deletion or search of files.
[0103] Optionally, before step 103, the method further includes:
[0104] Step 110, determining whether there is a file in the first target folder;
[0105] Step 111: If the file does not exist, create a file to be written; the file name of the file to be written corresponds to the writing order.
[0106] In an embodiment of the present invention, with respect to step 110 and step 111, after determining the first target folder according to the first week number, it is possible to first determine whether there is a file in the first target folder. If so, the data is written into the newly created file. If not, the file is created first, and then the data to be stored is written into the newly created file. When creating the file, the file name is named in the order in which the file is written to ensure that the storage location of the data to be stored can be quickly determined later and that the order of the data writing time can be determined when searching for data.
[0107] refer to Figure 2 , Figure 2 Another data storage method provided by an embodiment of the present application is shown, including:
[0108] Step S1, get the time, calculate the day of the week, and create a folder (e.g., if it is Monday, create folder 1);
[0109] Step S2, comparing the current date with the date recorded in the flash (storage device);
[0110] Step S3, if the current date is the same as the date recorded in the flash (storage device), the current date does not need to be recorded again, and the process proceeds to step S4; if they are different, the current date is recorded in the flash (storage device), and the process proceeds to step S9;
[0111] Step S4, determine whether there are files in the folder, if yes, go to step S5, if not, go to step S9.
[0112] Step S5, counting the number of files in the folder of the day of the week.
[0113] Step S6, obtain the day of the week and determine whether it is the next day. If so, proceed to step S4; if not, proceed to step S7.
[0114] Step S7, writing data to the file with the largest file name.
[0115] In the embodiment of the present application, for steps S1 to S7, when the SD card-based single-chip microcomputer device is powered on, it first reads the RTC clock, calculates the current time, and which day of the week it belongs to. If it is Monday, a folder is created, and the name of the folder is named after the current week. For example, if it is Monday, the folder name is 1. If the folder exists, it does not need to be created, and the power-on date of the single-chip microcomputer at this moment is recorded in the flash. When the single-chip microcomputer device is powered on next time, the power-on date is read and compared with the power-on date recorded by the device. If the current power-on date is the same as the power-on date recorded in the storage device, the number of files contained in the folder named with the current week number is counted. If there is no file under the folder, a new file with the file name of 1 is created in the folder, and the data is recorded in this file. When the file stores more than 10K data, the data is recorded in the next file, and the file name is increased by 1. If there are files under the folder, the number of files under the folder is counted, the number with the largest file name is counted, and then the data is appended to the file with the largest file name.
[0116] When the device is powered on, the current date is read and compared with the date recorded in the storage device. If the date read by the device at the time of startup is different from the date recorded in the storage device, the device will record the data in a file named 1 under the folder named after the current week obtained at the time of startup. When the file storage data is greater than 10K, the data will be recorded in the next file, and the file name will increase by 1.
[0117] Furthermore, during the operation of the device, the time is read in real time and the week is calculated. If the device runs from Monday to Tuesday, that is, the device runs for more than one day, a new folder is created and the folder name is named after the current week number. If the folder with the current week number exists, it does not need to be created. The number of files contained in the folder named after the current week number is counted. If there is no file under the folder, a new file named 1 is created in the folder and the data is recorded in this file. When the file storage data is greater than 10K, the data is recorded in the next file and the file name is increased by 1. If there is a file under the folder, data writing starts from file 1.
[0118] Step S8, write data and determine whether the file is full. If not, continue writing. If full, proceed to step S10.
[0119] In an embodiment of the present application, during the process of writing data into a file, it is determined whether the file is full. If not, writing continues; if full, writing is performed on the next file or a new file is created for writing.
[0120] Step S9, writing data to the file named 1.
[0121] In the embodiment of the present application, if the current date is different from the date recorded in the flash, data is written to a file named 1 in a folder corresponding to the day of the week of the current date to overwrite the old data.
[0122] Step S10, the file name is incremented by 1, and data writing continues.
[0123] In the embodiment of the present application, during the process of writing data into a file, if the file is full, the data is written into the next file, that is, the file with the file name plus 1, or a new file is created for writing.
[0124] The method of the present application sets 7-day data loop storage. It is designed to address the problem that some devices need to store some data or logs for a long time, but cannot store them all the time. If they store them all the time, it will cause memory overflow. The previous data is deleted over a period of time to achieve long-term storage of massive data. When the device runs for more than 7 days, the data runs again until Monday, and the data is stored in a folder named 1, overwriting the data of file name 1 under folder 1. And so on, 7-day data loop storage is achieved. When the storage space is insufficient, the device automatically overwrites the data with the earliest date, calculates the file with the earliest date based on the file name, clears the data inside, and rewrites the new data. By calculating and processing the storage logic based on the file name, the microcontroller algorithm can be reduced to access any data, such as text, audio, pictures, videos, etc., to ensure the operation rate of the microcontroller.
[0125] In summary, in the embodiment of the present application, when the single-chip microcomputer is powered on, the first week number corresponding to the current date is obtained; it is determined whether the current date is consistent with the power-on date recorded in the storage device; if they are consistent, and there is a first target folder in the storage device whose folder name corresponds to the first week number, the data to be stored of the current date is stored in a file whose writing order is the last in the first target folder; if they are inconsistent, and there is a first target folder in the storage device whose folder name corresponds to the first week number, the data to be stored is stored in a manner that the data to be stored overwrites the contents of the files in the first target folder in the writing order of the files in the first target folder. After the single-chip microcomputer is powered on, the method of the present application first determines whether the current power-on date and the power-on date recorded in the storage device are the same day. If they are the same day, it is further determined whether there is a folder corresponding to the week number corresponding to the current date in the storage device. If so, it is stored in the folder corresponding to the week number. If they are not the same day, the folder corresponding to the current week number is determined, and the original data is overwritten for storage. That is, in the present application, the name of the folder is corresponded to the week number, so that the current week number is stored in the folder of the week number, and the data of the same week number last week is overwritten by the data of the current week number, thereby realizing cyclic storage of data in units of weeks, that is, the storage of massive data is realized in units of weeks through polling storage. At the same time, the storage date of the data can be determined by the name of the folder, thereby improving the efficiency of data search.
[0126] refer to Figure 3 , which shows a data storage device 20 provided in an embodiment of the present application, applied to a single chip microcomputer, including:
[0127] An acquisition module 201 is used to acquire the first week number corresponding to the current date when the single chip microcomputer is powered on;
[0128] A determination module 202 is used to determine whether the current date is consistent with the power-on date recorded in the storage device;
[0129] A first writing module 203 is used for storing the to-be-stored data of the current date into a file in the first target folder that is the last in the writing order if the two files are consistent and there is a first target folder in the storage device whose folder name corresponds to the first week number;
[0130] The second writing module 204 is used to store the data to be stored in a manner of overwriting the contents of the files in the first target folder with the data to be stored in accordance with the writing order of the files in the first target folder if there is no inconsistency and there exists a first target folder with a folder name corresponding to the first week number in the storage device.
[0131] Optionally, the device further comprises:
[0132] a creation module, configured to create a second target folder with a folder name corresponding to the first week number if a first target folder with a folder name corresponding to the first week number does not exist in the storage device;
[0133] The third writing module is used to create a sub-file in the directory of the second target folder, and store the data to be stored on the current date in the sub-file.
[0134] Optionally, the judging module includes:
[0135] A first judgment submodule, configured to record the current date in the storage device if there is inconsistency;
[0136] The second judgment submodule is used to keep the power-on date recorded in the storage device unchanged if they are consistent.
[0137] Optionally, the second writing module includes:
[0138] The first submodule is used to obtain the file names of the files in the first target folder; the file names are named according to the order in which the files are written;
[0139] The second submodule is used to determine the first written target file by the file name, and write the data to be stored into the first written target file by overwriting the original data in the target file;
[0140] The third submodule is used to write the unwritten data to be stored into the second target file if the storage space of the first target file to be written is full, until all the data to be stored are written into the first target folder.
[0141] Optionally, the first writing module includes:
[0142] The fourth submodule is used to obtain the file names of the files in the first target folder; the file names are named according to the order in which the files are written;
[0143] A fifth submodule, configured to determine, according to the file name, a target file that is last in the writing order in the first target folder, and write the data to be stored into the target file;
[0144] The sixth submodule is used to create a new target file in a naming manner according to the writing order if the storage space of the target file is full, and write the unwritten data to be stored into the new target file.
[0145] Optionally, the device further comprises:
[0146] A real-time determination module, used to obtain the current date in real time during the operation of the single-chip microcomputer;
[0147] A week number redetermining module, for redetermining the second week number according to the changed date if the current date has changed relative to the date when the single chip microcomputer is just powered on;
[0148] The storage module is used to store the data to be stored in a third target folder in the storage device whose folder name corresponds to the second week number.
[0149] Optionally, if the data to be stored have different data types, the device further includes:
[0150] A name acquisition module, used to acquire the file name of the file in the first target folder; the file name is named according to the data type and writing order;
[0151] The file matching module is used to determine, according to the data type of the data to be stored and the file name, the candidate file with the first writing order among the candidate files matching the data type as the first written target file.
[0152] Optionally, the second submodule includes:
[0153] An extraction unit, used for extracting the file names of all files in the first target folder;
[0154] The determination unit is used to determine the first target file to be written according to the field representing the writing order in the file name.
[0155] Optionally, before storing the data to be stored on the current date in the first target folder in a file that is last in the writing order, the device further comprises:
[0156] A folder content determination module, used to determine whether there is a file in the first target folder;
[0157] The file creation module is used to create a file to be written if it does not exist; the file name of the file to be written corresponds to the writing order.
[0158] In summary, in the embodiment of the present application, when the single-chip microcomputer is powered on, the first week number corresponding to the current date is obtained; it is determined whether the current date is consistent with the power-on date recorded in the storage device; if they are consistent, and there is a first target folder in the storage device whose folder name corresponds to the first week number, the data to be stored of the current date is stored in a file whose writing order is the last in the first target folder; if they are inconsistent, and there is a first target folder in the storage device whose folder name corresponds to the first week number, the data to be stored is stored in a manner that the data to be stored overwrites the contents of the files in the first target folder in the writing order of the files in the first target folder. After the single-chip microcomputer is powered on, the method of the present application first determines whether the current power-on date and the power-on date recorded in the storage device are the same day. If they are the same day, it is further determined whether there is a folder corresponding to the week number corresponding to the current date in the storage device. If so, it is stored in the folder corresponding to the week number. If they are not the same day, the folder corresponding to the current week number is determined, and the original data is overwritten for storage. That is, in the present application, the name of the folder is corresponded to the week number, so that the current week number is stored in the folder of the week number, and the data of the same week number last week is overwritten by the data of the current week number, thereby realizing cyclic storage of data in units of weeks, that is, the storage of massive data is realized in units of weeks through polling storage. At the same time, the storage date of the data can be determined by the name of the folder, thereby improving the efficiency of data search.
[0159] Figure 4 A block diagram of an electronic device 600 is shown according to an exemplary embodiment. For example, the electronic device 600 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0160] Reference Figure 4 , the sub-device 600 may include one or more of the following components: a processing component 602 , a memory 604 , a power component 606 , a multimedia component 608 , an audio component 610 , an input / output (I / O) interface 612 , a sensor component 614 , and a communication component 616 .
[0161] The processing component 602 generally controls the overall operation of the electronic device 600, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 602 may include one or more processors 620 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 602 may include one or more modules to facilitate the interaction between the processing component 602 and other components. For example, the processing component 602 may include a multimedia module to facilitate the interaction between the multimedia component 608 and the processing component 602.
[0162] The memory 604 is used to store various types of data to support the operation of the electronic device 600. Examples of such data include instructions for any application or method operating on the electronic device 600, contact data, phone book data, messages, pictures, multimedia, etc. The memory 604 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0163] The power supply component 606 provides power to the various components of the electronic device 600. The power supply component 606 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 600.
[0164] The multimedia component 608 includes a screen that provides an output interface between the electronic device 600 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 608 includes a front camera and / or a rear camera. When the electronic device 600 is in an operating mode, such as a shooting mode or a multimedia mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and the rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0165] The audio component 610 is used to output and / or input audio signals. For example, the audio component 610 includes a microphone (MIC), and when the electronic device 600 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is used to receive an external audio signal. The received audio signal can be further stored in the memory 604 or sent via the communication component 616. In some embodiments, the audio component 610 also includes a speaker for outputting audio signals.
[0166] I / O interface 612 provides an interface between processing component 602 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0167] The sensor assembly 614 includes one or more sensors for providing various aspects of status assessment for the electronic device 600. For example, the sensor assembly 614 can detect the open / closed state of the electronic device 600, the relative positioning of the components, such as the display and keypad of the electronic device 600, and the sensor assembly 614 can also detect the position change of the electronic device 600 or a component of the electronic device 600, the presence or absence of contact between the user and the electronic device 600, the orientation or acceleration / deceleration of the electronic device 600, and the temperature change of the electronic device 600. The sensor assembly 614 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 614 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 614 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0168] The communication component 616 is used to facilitate wired or wireless communication between the electronic device 600 and other devices. The electronic device 600 can access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 616 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 616 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0169] In an exemplary embodiment, the electronic device 600 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to implement the data storage method provided in the embodiments of the present application.
[0170] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 604 including instructions, and the instructions can be executed by a processor 620 of an electronic device 600 to perform the above method. For example, the non-transitory storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0171] Figure 5A block diagram of an electronic device 700 is shown according to an exemplary embodiment. For example, the electronic device 700 can be provided as a server. Figure 5 The electronic device 700 includes a processing component 722, which further includes one or more processors, and a memory resource represented by a memory 732 for storing instructions that can be executed by the processing component 722, such as an application. The application stored in the memory 732 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 722 is configured to execute instructions to perform a data storage method provided in an embodiment of the present application.
[0172] The electronic device 700 may also include a power supply component 726 configured to perform power management of the electronic device 700, a wired or wireless network interface 750 configured to connect the electronic device 700 to a network, and an input / output (I / O) interface 758. The electronic device 700 may operate based on an operating system stored in the memory 732, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™ or the like.
[0173] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the application disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0174] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A data storage method, applied to a single-chip microcomputer, characterized in that: The method comprises: When the single chip microcomputer is powered on, obtaining the first week number corresponding to the current date; Determine whether the current date is consistent with the power-on date recorded in the storage device; If they are consistent, and there is a first target folder in the storage device whose folder name corresponds to the first week number, then the data to be stored on the current date is stored in the last file in the first target folder in the writing order; If they are inconsistent, and there exists a first target folder in the storage device whose folder name corresponds to the first week number, the data to be stored is stored in the order in which the files in the first target folder are written, by overwriting the contents of the files in the first target folder with the data to be stored.
2. The method according to claim 1, characterized in that The method further comprises: If the first target folder whose folder name corresponds to the first week number does not exist in the storage device, creating a second target folder whose folder name corresponds to the first week number; A sub-file is created in the directory of the second target folder, and the data to be stored on the current date is stored in the sub-file.
3. The method according to claim 1, characterized in that The determining whether the current date is consistent with the power-on date recorded in the storage device includes: If not, recording the current date in the storage device; If they are consistent, the power-on date recorded in the storage device remains unchanged.
4. The method according to claim 1, characterized in that: The storing the data to be stored in a manner of overwriting the contents of the files in the first target folder by the data to be stored according to the writing order of the files in the first target folder includes: Obtain the file names of the files in the first target folder; the file names are named according to the order in which the files are written; Determine a first target file to be written by using the file name, and write the data to be stored into the first target file to be written by overwriting the original data in the target file; If the storage space of the first target file to be written is full, the unwritten data to be stored is written into the second target file until all the data to be stored is written into the first target folder.
5. The method according to claim 1, characterized in that The step of storing the data to be stored on the current date in a file in the first target folder that is the last in the writing order comprises: Obtain the file names of the files in the first target folder; the file names are named according to the order in which the files are written; According to the file name, determining the target file that is last in the writing order in the first target folder, and writing the data to be stored into the target file; If the storage space of the target file is full, a new target file is created in a naming manner according to the writing order, and the unwritten data to be stored is written into the new target file.
6. The method according to claim 1, characterized in that The method further comprises: During the operation of the single chip microcomputer, the current date is obtained in real time; If the current date has changed relative to the date when the single-chip microcomputer was just powered on, re-determine the second week number according to the changed date; The data to be stored is stored in a third target folder in the storage device whose folder name corresponds to the second week number.
7. The method according to claim 4, characterized in that If the data to be stored have different data types, the method further includes: Obtain the file name of the file in the first target folder; the file name is named according to the data type and writing order; According to the data type of the data to be stored and the file name, the candidate file with the first write order among the candidate files matching the data type is determined as the first write target file.
8. The method according to claim 4, characterized in that Determining the first target file to be written by the file name includes: Extract the file names of all files in the first target folder; The first target file to be written is determined according to the field representing the writing order in the file name.
9. The method according to claim 1, characterized in that: Before storing the data to be stored on the current date in the first target folder in a file that is last in the writing order, the method further includes: Determine whether there is a file in the first target folder; If it does not exist, create the file to be written; the file name of the file to be written corresponds to the writing order.
10. A data storage device, applied to a single-chip microcomputer, characterized in that: The device comprises: An acquisition module, used for acquiring the first week number corresponding to the current date when the single chip microcomputer is powered on; A judgment module, used to judge whether the current date is consistent with the power-on date recorded in the storage device; A first writing module is used for storing the data to be stored on the current date into a file that is last in the writing order in the first target folder if the two files are consistent and there is a first target folder with a folder name corresponding to the first week number in the storage device; A second writing module is used to store the data to be stored in a manner that overwrites the contents of the files in the first target folder with the data to be stored, according to the writing order of the files in the first target folder, if there is no inconsistency and there is a first target folder with a folder name corresponding to the first week number in the storage device.
11. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the data storage method according to any one of claims 1 to 9 are implemented.
12. A readable storage medium, characterized in that: The readable storage medium stores a program or an instruction, and when the program or the instruction is executed by a processor, the steps of the data storage method according to any one of claims 1 to 9 are implemented.
