A kind of method that real time data is stored
Technical field
The present invention relates to infotech and automatic field technical field of information processing, the storage means that relates to a kind of real time data of on embedded collector, using, be a kind of software flow of on embedded OS, carrying out, be applicable to the embedded collector real-time data memory in the abominable applied environment.
Background technology
In industrial processes, the change procedure of various parameters has often reflected the operation conditions of production equipment in a stage and the linking situation of production process, and various parametric procedures are for the reasonable formulation production schedule, safeguard, guarantee safe production equipment and require etc. all to have very important significance in good time.Be embedded in the formula collector at industrial circle and be widely used, many technological parameters (as temperature, pressure, flow etc.) are measured and record, generate continuous historical data, the first-hand data of analysis and research is provided for technician and managerial personnel.But because in many commercial production, working environment is abominable (as high temperature, high humidity, deep-etching etc.) relatively, the service condition of embedded collector is not very stable (as frequent outage, external disturbance serious etc.), though collector has certain adaptive capacity to environment, but still collector outage inevitably can frequently occur causing, restart even fortuitous events such as deadlock, damage occur.If so just program is by accidental interruption in storing process, the data that then store in the storer are just imperfect, may make an explanation to the data content when reading once more.In order to guarantee that under the condition that the collector memory hardware does not damage the storage data in it does not lose, just need to adopt the date storage method of high reliability, improve the utilization factor of storer, and improve the fault-tolerance of software systems, ensure the continuity of historical data.The file management system of the data storage operating specification on the present computing machine, as FAT, NTFS etc., they all adopt the way to manage of catalogue formula, in actual physical address, point to the memory address at file content place step by step by the mode of pointer, unified data to a plurality of files manage, in case certain directory pointer in the physical address is made mistakes like this, just can't the content in the file be read and explain, in embedded collector, use to have certain risk.Adopt storage mode in the present many embedded collector based on record, every record comprises all information of data content, storage continuously in physical address, guarantee to cause the unreadable drawback of all data with this because of some corrupted data, but this mode needs every record to adopt fixing storage format to comprise all canned datas, cause every record all to take a lot of bytes, be not easy to store up more record count at the store memory of finite capacity.Therefore, the date storage method of high-level efficiency, high reliability is a kind of effective means that solves embedded collector data storage requirement in the industrial processes.
Summary of the invention
In order to solve prior art problems, the purpose of this invention is to provide a kind of method of real time data being stored at embedded collector, in Industrial Process Monitoring, the parameter change procedure is carried out reliable memory expeditiously, avoid causing the unreadable situation of all historical datas of being stored because of external cause, improve the security that embedded collector uses, ensure the parameter monitoring process in the commercial production.
For achieving the above object, technical solution of the present invention provides a kind of method of real time data being stored based on the embedded collector of two index, and its technical scheme is:
Steps A: gather the numerical value of each sensor in real time by collector earlier, and needing to obtain the data content of storage after treatment;
Step B: read main part of index summary info;
Step C: main part of index summary info carried out verification relatively; If verification master part index summary info is correct, then execution in step D; If verification master part index summary info mistake, then execution in step N;
Step D: the up-to-date pointer that extracts main part index content;
Step e: read the main part of up-to-date storage pointer of index content, utilize up-to-date storage pointer in index content, to read a up-to-date index information;
Step F: a up-to-date index information is carried out verification relatively, if check errors, execution in step N then, if verification is correct, execution in step G then;
Step G: the up-to-date storage pointer of data content of extraction step Q from a up-to-date index information, and in the address at storage pointer place, store the time, minute, second, passage, numerical value data content and check code;
Step H: calculate new index content and check code, and whether arrive physics maximum storage address and determine whether that needs carry out annular overlapping operation according to the storage pointer, if the content that needs to cover then index year, month, day, memory contents start address, memory contents length adjusts accordingly;
Step I: main part index content of storage and check code;
Step J: upgrade main part of index summary;
Step K: main part of index summary of storage;
Step L: storage backup index content and check code;
Step M: storage backup index summary, finish this storage operation, and begin to re-execute by steps A;
Step N: read the archive index summary, utilize archive index to carry out associative operation;
Step O: during to the archive index outline operation, carry out verification relatively,, utilize software can not continue to safeguard, then execution in step R if the content check errors in the archive index summary illustrates that the data of this storer are damaged fully; If also verification is correct for the content in the archive index, then execution in step P;
Step P: obtain the up-to-date pointer of archive index;
Step Q: the up-to-date storage pointer of reading of data content, and execution in step G;
Step R: rebulid canned data, begin to re-execute from steps A.
According to embodiments of the invention, described real-time image data also comprises:
Steps A 1: with comprising of described real-time collection: channel number, year, month, day, hour, min, second, data value information, check code data per diem are that the unit generates index and data content;
Steps A 2: will include year, month, day, start address, end address, check code, index information is compared with storing index, the memory address of specified data content;
Steps A 3: the memory address according to data content judges whether that needs cover storing data, covers if desired, then will need to cover the content deletion of memory block, at this area stores data content, and the change index information; If do not need then directly data content be stored in the memory address that is obtained by steps A 2;
Steps A 4: determine whether that according to the storage condition of data content needs upgrade index information, the index that then will store changes to new index information if desired, if do not need then to keep former index constant.
According to embodiments of the invention, described storage data content covers and adopts the circulation of annular sequential storage to cover storage mode, and step is as follows:
Steps A 31: in the SD storage card, store successively by the physical address order;
Steps A 32: when storing the maximum physical address of SD storage card into, with in the SD storage card the earliest one day data deletion fall;
Steps A 33: continue the storage data at the physical address place of one day the earliest memory contents then, the looping storage mode, and index content carried out corresponding change.
According to embodiments of the invention, described index also comprises:
Described index comprises the physical storage address of the data content that points to this day, the storage index adopts main part and the storage mode of backup of two index, the main part index that content is identical is stored in the physical addresss different in the ferroelectric memory with archive index, contains check information separately;
The storage index is made up of index summary and index content, the content of index summary comprise index content initial with finish physical address, stored record sum, physical storage remaining space, index content is to be the index information of the sensing storage data that generate of unit with the sky.
According to embodiments of the invention, in the described embedded collector method for storing real-time data, its described check code R (X) polynomial expression is the CRC16 cyclic check code, and its computing formula is
Wherein B (X) is for wanting the n position binary sequence number of verification, G (X)=X
16+ X
15+ X
2+ 1 is fixed polynomial, and Q (X) is whole polynomial expression, and R (X) residue is a cyclic check code, and X is the polynomial expression free variable.
According to embodiments of the invention, in the described embedded collector method for storing real-time data, its described real time data value is a single precision floating datum, and by 4 byte representations, start address and end address are the integer number, by 4 byte representations.
According to embodiments of the invention, in the described embedded collector method for storing real-time data, the memory capacity of its described SD storage card is 256MB~4GB, and the memory capacity of described ferroelectric memory is 16KB~128KB.
According to embodiments of the invention, in the described embedded collector method for storing real-time data, its described embedded collector is not transplanted file system for the device of the transplanting embedded OS that is made of arm processor in this device software.
The application of method on the embedded-type ARM collector that the present invention stores real time data.
The embedded collector that the present invention proposes is that the reliability method for storing real-time data major advantage of using in the acquisition system of hardware is as follows: adopt indexed mode that the data content is managed, can reduce by every byte number that data content is shared, improve the stored number of data recording under the certain storage capacity; Every data recording all adopts the CRC16 verification, has guaranteed the correctness of every data of being stored; Adopt the storage mode of main part and the two index of backup, avoided because of main part or back up an index corruption and cause the unaccountable situation of whole data content to occur; Main part and archive index all are made of index summary and index content, and each have the CRC16 check code, have guaranteed the maintainability that memory contents reads and explains; Data storage procedure is according to first content index again, and the order that former head's part is backed up has again guaranteed can not occur because of accidental interruption cause the situation of canned data entanglement in the storing process.The mode that adopts circulation to cover realizes that the data content under the fixed storage capacity stores continuously, cover historical data the earliest with up-to-date image data, guarantee the continuity of storage data in the collector, can improve the reliability and the integrality of important parameter record in the industrial processes.This storage means is suitable for embedded collector to be used, and the industry that is particularly suitable for many interference environments, inclement condition is gathered under the occasion and used.
Description of drawings
Fig. 1 is to be that the embodiment of the invention adopts embedded collector real time data to be carried out the process flow diagram of storage means;
Fig. 2 embodiment of the invention adopts the structured flowchart of the real-time data memory system of embedded collector;
Fig. 3 is the embodiment synoptic diagram of annular coverage mode in the embedded collector method for storing real-time data of the present invention.
Embodiment
Below in conjunction with accompanying drawing the present invention is described in detail, be to be noted that described embodiment only is intended to be convenient to the understanding of the present invention, and it is not played any qualification effect.
A kind of method that adopts embedded collector that real time data is stored of the present invention, the data of a plurality of sensors of being gathered in real time by described embedded collector are as storage object; Be the special method of industry when gathering the used high reliability real-time data memory of ARM collector in the environment, adopt special storage format and way to manage, constitute by storing index and data content.
Every real time data of collector collection comprises channel number, year, month, day, hour, min, second, real time data value information, and wherein the real time data value is a single precision floating datum, by 4 byte representations.Be storage medium with ferroelectric memory and SD storage card during storage, the storage index is made of main part of index and archive index, and they have identical content, and each self-contained check informations all, be stored in the ferroelectric memory, point to the data content that is stored in the SD storage card.Main part index and archive index all are made up of index summary and index content respectively, the content of index summary comprise index content initial with finish physical address, stored record sum, SD storage card remaining space, index content is to be the information of the sensing data content of unit with the day, comprise year, month, day, data content start address and end address, wherein start address and end address adopt 4 byte integer numerical tables to show.Every data recording in the data content comprise channel number, the time, minute, second, real time data value, information of check code.
Data acquisition unit is after collecting real time data, the temporal information of collector is joined, make it be called the data recording that comprises channel number, year, month, day, hour, min, second, data value information, per diem generate index and data content again for the unit, wherein index includes year, month, day, data content comprise channel number, the time, minute, second, data value information; This index is compared with a up-to-date index of having stored, with the memory address of specified data content; Memory address according to data content judges whether that needs cover storing data, cover if desired, then will need to cover the content deletion of memory block, at this area stores data content, and the change index information, it is described that concrete covering method annular as shown in Figure 3 covers embodiment; If do not need then directly data content be stored in the memory address that from the storage index, obtains; Determine whether that according to the storage condition of data content needs upgrade index information, the index that then will store changes to new index information if desired, if do not need then to keep former index constant.
Fig. 1 is the process flow diagram that adopts embedded collector method for storing real-time data, and it has described the whole process of embedded collector data storage, and its concrete steps are:
Steps A: gather the numerical value of each sensor by collector, and needing to obtain the data content of storage after treatment; Step B: read main part of index summary info; Step C: and utilize the CRC16 cyclic check code to carry out verification to it and compare, to determine whether reading archive index information.Wherein the computing formula of CRC16 cyclic check code is:
Wherein B (X) is for wanting the n position binary sequence number of verification, G (X)=X
16+ X
15+ X
2+ 1 is fixed polynomial, and Q (X) is whole polynomial expression, and R (X) residue is a cyclic check code.Checking procedure adopts ring shift and XOR to realize that its code is identical with standard C RC16 operation part.
If the check code that main part index summary info calculates does not conform to the check code of storage then check errors is described, with regard to execution in step N, utilize archive index to carry out associative operation, illustrate that then verification is correct if conform to, with regard to execution in step D; Step D: the up-to-date pointer that from main part of index summary info, extracts main part index content; Step e: utilize the main part of up-to-date storage pointer of index in index content, to read a up-to-date index information; Step F: a up-to-date index information is carried out verification relatively, if check errors then execution in step N, if verification would be correctly then execution in step G; Step G: the up-to-date storage pointer of data content of extraction step Q from a up-to-date index information, and in the address at storage pointer place, store data content, when comprising, minute, second, channel number, numerical value and CRC16 check code in real time; Step H: calculate new index content and check code, whether arrive physics maximum storage address according to pointer and determine whether that needs carry out annular overlapping operation, then the year, month, day in the index content, memory contents start address, memory contents length information are adjusted accordingly if need to cover, and adopt coverage mode will store data with new data and replace, directly data content is stored in the corresponding memory address if need not cover then; Step I: will lead part index content and check code and store up-to-date leading in part physical address of index content pointer indication into; Step J: according to information updating master part index summary of main part index content; Step K: will lead a part index summary and be stored in former main part of index summary position; Step L: duplicate and main part of identical index content and the check code of index content, and be stored in the physical address of a up-to-date archive index content indication; Step M: storage backup index summary, finish this storage operation, and begin to re-execute by steps A; Step N: when utilizing the archive index operation, carry out the CRC16 verification relatively,, illustrate that then the data of this storer are damaged fully, utilize software approach can not continue to safeguard, then execution in step R as if the content in the archive index also check errors; If the content verification in the archive index is correct, then execution in step P; Step P: the up-to-date pointer that from the archive index summary, obtains the archive index content; Step Q: the up-to-date storage pointer of reading of data content, and execution in step G; Step R: rebulid canned data, begin to re-execute from steps A.
Adopt this storage mode and storage order, can guarantee when the software program accidental interruption, still can make an explanation to the data content:,, then when data interpretation, can not make mistakes because index information is not modified if be interrupted during in memory contents by index; If be interrupted when main part of index content of storage, because main part of index summary is also unmodified, the data before can not changing according to content when explaining make an explanation; If when main part of index summary of storage, be interrupted, then can make mistakes during the verification comparison, and since this moment archive index information also be not modified, then can utilize the data of archive index information before the data content is not changed to make an explanation.Like this, as long as physical storage medium is not damaged, according to this storage mode, certainly there is one to be complete correct information in main part index and the archive index, just can make an explanation, can not cause the whole data content that causes because of certain bar data recording storage errors can't read explanation the data content.
Technological core of the present invention is that multiple check and two indexed mode are applied in the data storage procedure, make the content of being stored have higher reliability, can be from the software reliable treatments performance of embedded collector that guarantee under rugged surroundings, to work for external action, strengthen the maintainability of data storage, improve the confidence level of historical data.It utilizes rational execution in step, avoided the not readable phenomenon of data that causes because of accidental interruption, improved the utilization ratio of storage medium, also strengthened the integrality of storage data, than general embedded file system safety and reliability, guaranteed the readability of data content under the situation that physical storage do not damage, for the long-time monitoring of industrial processes significant process parameter with write down significant.
In order to realize the method that real time data is stored of the present invention, embodiment illustrates Fig. 2 and adopts the embedded-type ARM collector typically real time data to be carried out the structured flowchart of storage system, this carries out the storage system collecting device mainly by N sensor 1 to real time data, embedded-type ARM collector 2 and computing machine 3 are formed, N sensor sheet is shown 11,12,13......1N, wherein embedded-type ARM collector 2 contains computing machine communication interface 21, ARM controller 22, ferroelectric memory 23, SD storage card 24, communication interface 25, described communication interface 25 can be RS232, RS485 or CAN interface, computing machine communication interface 21 can be RS232, USB or Ethernet interface, sensor 11,12,13......1N, be connected with embedded-type ARM collector 2 by communication bus for having the digital sensor of identical communication interface 25.The memory capacity of described SD storage card is 256MB~4GB, and the memory capacity of described ferroelectric memory is 16KB~128KB.Described embedded collector is not transplanted the active file system for the device of the transplanting embedded OS that is made of arm processor in the software of this device.
The principle of work of Fig. 2 is as follows: ARM controller 22 sends acquisition to each sensor 11,12,13.....1N successively by communication interface 25, receiving sensor 11,12,13.....1N transmit the numerical information of coming again, and generate the complete real time data content that to store according to the clock information of ARM controller 22 self, then according to the method that real time data is stored of this invention, is this real time data content resolution index information and data content, stores into respectively in ferroelectric memory 23 and the SD storage card 24.When computing machine 3 links to each other with embedded-type ARM collector 2 by computing machine communication interface 21, can read the data content that is stored in ferroelectric memory 23 and the SD storage card 24, obtain the parameter historical record that this collector 2 is monitored.
Fig. 3 is the embodiment synoptic diagram of embedded collector method for storing real-time data annular coverage mode.In order to simplify the description process, will lead part index content and the archive index content is referred to as index information in this enforcement illustration, physical storage areas that will the storage data content adopts the mode of block management, and each unit is called data block.Adopt these titles in this real-time example, identical in other titles and claims, explanation hereby.Physical storage areas by BL1, BL2 ..., BLm m data block formation altogether, comprise start address Sa and end address Ea among every index information In respectively, comprise start address Sa and what be new memory address N (being called for short the current address, down together) for current up-to-date one index information.When using storage means of the present invention, three storage index information In1 have been stored in the storer among the embodiment, In2, In3, data content is according to the storage backward successively in the memory block of physical address order from small to large, wherein index In3 is a current up-to-date index information, start address Sa that they are comprised separately and end address Ea point to the relevant position in the data field, start address Sa1 points to the initiating terminal of data block BL1, end address Ea1 and start address Sa2 point to the same address of data block BL2, end address Ea2 and start address Sa3 point to the same address of data block BL4, and the current address Na3 of index In3 has pointed to the bottom (being greatest physical memory address border) of data block BLm.This corresponding relation is constantly all used solid line.After collector collects a new data again,, legacy data must be disposed and to store new data because physical storage all is filled with.This moment, data the earliest were index In1 data block BL1 pointed, by program the current address Na3 among the index In3 is replaced with end address Ea3 earlier, again the content of data block BL1 is disposed, a newly-built then index In4, its start address Sa4 and current address Na4 point to the initiating terminal of data block BL1, and revise the initiating terminal of the start address Sa1 sensing data block BL2 of index In1.The corresponding relation of this moment all identifies with short dash line.Gather storage a period of time according to date storage method of the present invention after, the lowermost end (long dotted line sign) of data block BL1 has been pointed in the current address of index In4, and this moment, data were filled with once more, also need carry out data and cover.Collect after the new data this moment, earlier the content among the data block BL2 is disposed, the current address Na4 that revises index In4 again points to the initiating terminal of data block BL2, this moment is because the end address Ea1 of index In1 points to the centre of data block BL2, also just mean the data that do not had index In1 in the storer, In1 deletes from storer with index, and the start address Sa2 that revises index In2 points to the initiating terminal of data block BL3.The corresponding relation of this moment identifies with long dotted line.The storage mode that adopts this circulation to cover, just can guarantee all to be used in the storer with higher efficient always, and the data that can guarantee in the storer to be stored all are up-to-date data contents, have alleviated the restriction of memory-size restriction to data memory capacity.
The above; only be the embodiment among the present invention; but protection scope of the present invention is not limited thereto; anyly be familiar with the people of this technology in the disclosed technical scope of the present invention; can understand conversion or the replacement expected; all should be encompassed in of the present invention comprising within the scope, therefore, protection scope of the present invention should be as the criterion with the protection domain of claims.