The software anti-interference method that is used for electric energy meter
Technical field
The present invention relates to software technology field, specifically is the software anti-interference method that is used for electric energy meter.
Background technology
Electric energy meter generally adopts single-chip microcomputer as central processing unit, because singlechip computer system is when industry spot is used, working environment is more abominable, and interference source is more, and its reliability should be put in the first place in overal system design.Interference source can the upset system move, and makes system produce various mistakes, so when system design; Not only to carry out well-designedly to the reliability of hardware, and will the reliability of Control Software well be designed especially fault-tolerant design; So-called " fault-tolerant design " is meant when system's operation makes a mistake; Software itself has the ability of certain tolerance mistake, though i.e. system's operation the time makes a mistake, mistake is to instigate system data information to damage or lose etc.; But can shut down the modification hardware and software, the operation that system still can correct execution subscribes.When the program segment of much accomplishing specific function is combined into a big system software, often go wrong easily, system software is big more, and interrelated more between each program segment deal with more difficult more.Some mistake is hidden, and isolated the analysis is difficult for finding; Some mistake is just possibly take place under the specified conditions, and as when system's power-down rebooting or when resetting, intrasystem data message is changed probably, produces system mistake.These are because the software errors that disturb to produce can make system's fluctuation of service, and are bad during fashion, can make system data information damage or lose, and shut down and revise hardware and software and extremely bother.
Summary of the invention
Technical matters to be solved by this invention is; Provide and avoid system's fluctuation of service of causing because of external interference; System data information can not damaged or lost, and needn't shut down the modification hardware and software systems and still can correct execution subscribe the software anti-interference method that is used for electric energy meter of operation.
For solving the problems of the technologies described above, the software anti-interference method that is used for electric energy meter provided by the invention, it may further comprise the steps:
(1), when the software input data information, encrypt and constitute a record for each data message is provided with unique corresponding codes respectively, again many parts of storages of each record backup;
(2), basis reads the data message in the corresponding record the judgement of coding when reading information.
In the described step 1 is to show each byte of forming each data message to dispose unique corresponding codes and encrypt for each data message is provided with respectively that unique corresponding codes encrypts.
Described basis is to the judgement of coding, the data message in the corresponding record read be meant:
When reading stored record, at first check the coding in this record, if coding is correct, then this is recorded as correct record, the data message in the reading and recording; Incorrect if encode, then check the coding of the backup of this record, correct up to coding, then this duplicated record is correct record, reads the data message in the duplicated record; All incorrect like the coding in the duplicated record, then carry out system initialization.
Described step 2 also comprises:
When system restarted because of power down or resets, the judgement system was electrification reset or system reset, if electrification reset then carries out system initialization; If the record of storage is then read in system reset, and, the data message in the corresponding record is read according to judgement to coding.
Described judgement system is that electrification reset or system reset are to realize in the following manner:
System power on for the first time or long-time power down after power on again; Program is carried out initialization; And the flag information that powers on is set in specific RAM district, when system restarted because of power down or resets, program judged at first whether the flag information that powers on changes; Flag information changes if power on, and then system is an electrification reset; Flag information is constant if power on, and then system is system reset.
Technical scheme by the invention described above provides can find out that there is following advantage in the present invention: the present invention is provided with coding encrypting to the data message in the software, during read data information; All to verify the coding in the data message; If correct rear readable data information incorrect, then reads duplicated record and the checking of encoding; Correct up to coding, then read data information and working procedure.Whether such mode makes system owing to disturb when producing mistake, can change to data message and judge, and because duplicated record is arranged, system data information can not lose or damage, and the reliability of system is improved greatly; And set up the flag information position that powers on to judge it is electrification reset or system reset in specific RAM district, carry out system initialization or system recovery in order to decision; If need system recovery then according to judgement to respective coding; Data message in the corresponding record reads; Such mode makes when system's power-down rebooting or can judge effectively whether intrasystem data message changes when resetting; If data message changes, system initialization then makes the system can error running; If data message is constant, then can continue working procedure.Needn't detect to judge whether system is normal, needn't shut down the modification hardware and software to system.
Description of drawings
Fig. 1 is the software anti-interference method process flow diagram that the present invention is used for electric energy meter.
Embodiment
Below in conjunction with accompanying drawing and embodiment the present invention is done explanation in further detail.
The software anti-interference method process flow diagram that is used for electric energy meter by the present invention shown in Figure 1 can know that it may further comprise the steps:
Step 1 when the software input data information, is encrypted record of formation for each data message is provided with unique corresponding codes respectively, again many parts of storages of each record backup;
Step 2 according to the judgement to coding, reads the data message in the corresponding record when reading information.
In the described step 1 is to show each byte of forming each data message to dispose unique corresponding codes and encrypt for each data message is provided with respectively that unique corresponding codes encrypts.As buying electric weight EEPROM storage user, buying electric weight is two bytes, joins 5AH for each byte and encrypts record of formation, again 3 parts of storages of this record backup.
Described basis is to the judgement of coding, the data message in the corresponding record read be meant:
When reading stored record, at first check the coding in this record, if coding is correct, then this is recorded as correct record, the data message in the reading and recording; Incorrect if encode, then check the coding of the backup of this record, correct up to coding, then this duplicated record is correct record, reads the data message in the duplicated record; All incorrect like the coding in the duplicated record, then carry out system initialization.The coding of this recording setting compared when whether described judgement coding correctly was meant coding in the reading and recording and input data information, if both are identical, then coding is correct; If both are inequality, it is incorrect then to encode.
Described step 2 also comprises:
When system restarted because of power down or resets, the judgement system was electrification reset or system reset, if electrification reset then carries out system initialization; If the record of storage is then read in system reset, and, the data message in the corresponding record is read according to judgement to respective coding.When described electrification reset was meant normal energized, a series of initialization operations that this moment, single-chip microcomputer need carry out comprised initialization register, each hardware of initialization or the like.Described system reset is meant because the abnormal cause system crash after system restarts, can be collapsed preceding operation according to the information recorded recovery system.
Described judgement system is that electrification reset or system reset are to realize in the following manner:
System power on for the first time or long-time power down after power on again, program is carried out initialization, and in specific RAM district the setting flag information that powers on; The flag information that powers on is a program coding; Like 55H 0AAH 5AH 0A5H, when system restarted because of power down or resets, program judged at first whether the flag information that powers in RAM district changes; Flag information changes if power on, and then system is an electrification reset; Flag information is constant if power on, and then system is system reset.Described RAM district is meant the data storage cell in the single-chip microcomputer.
Below only use preferable instance with regard to the present invention and made explanation, but can not be interpreted as it is the restriction to claim, structure of the present invention can have other variations, is not limited to said structure.In a word, all various variations of in the protection domain of independent claims of the present invention, being done are all in protection scope of the present invention.