For the software anti-interference method of electric energy meter
Technical field
The present invention relates to software technology field, is specifically the software anti-interference method for electric energy meter.
Background technology
Electric energy meter generally adopts single-chip microcomputer as central processing unit, and because singlechip computer system is in the time that industry spot is used, working environment is more severe, and interference source is more, and its reliability should be put in the first place in overal system design.Interference source can upset system move; make system produce various mistakes; so in the time of system; not only to carry out well-designed to the reliability of hardware; and to well design the reliability of controlling software; especially fault-tolerant design; so-called " fault-tolerant design " refers to when system operation makes a mistake; software itself has the ability of certain tolerance mistake; though make a mistake while being system operation; mistake is to instigate the damage of system data information or loss etc., but can shut down modification hardware and software, and system still can correctly be carried out the operation of reservation.When the program segment that much completes specific function is combined into a large system software, often easily go wrong, system software is larger, and interrelated between each program segment deal with more difficult more.Some mistake is hidden, and isolated analysis is difficult for finding; Some mistake is just may occur under specified conditions, and as in the time that system power failure is restarted or reset, intrasystem data message is probably changed, and produces system mistake.These are because the software error that interference produces can make system fluctuation of service, bad when fashion, can make system data information damage or lose, and shutdown modification hardware and software extremely bothers.
Summary of the invention
Technical matters to be solved by this invention is; provide and avoid the system fluctuation of service that causes because of external interference; system data information can not be damaged or be lost, and needn't shut down modification hardware and software systems and still can correctly carry out the software anti-interference method for electric energy meter of subscribing operation.
For solving the problems of the technologies described above, the software anti-interference method for electric energy meter provided by the invention, it comprises the following steps:
(1), in the time of software input data information, the coding that unique correspondence is set respectively for each data message is encrypted and forms a record, then many parts of storages of each record backup;
(2), when reading information according to the judgement to coding, the data message in corresponding record is read.
Described according to the judgement to coding, the data message in corresponding record is read and referred to:
While reading stored record, first check the coding in this record, if coding is correct, this is recorded as correct record, reads the data message in record; Incorrect if encoded, check the coding of the backup of this record, until it is correct to encode, this duplicated record is correct record, reads the data message in duplicated record; As all incorrect in the coding in duplicated record, carry out system initialization.
It is the coding encrypting that each byte of showing the each data message of composition configures unique correspondence that the coding that unique correspondence is set respectively for each data message in described step 1 is encrypted.
Described step 2 also comprises:
In the time that system restarts or resets because of power down, judgement system is electrification reset or system reset, if electrification reset carries out system initialization; If system reset reads the record of storage, and according to the judgement to coding, the data message in corresponding record is read.
Described judgement system is that electrification reset or system reset are achieved in the following ways:
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, in the time that system restarts or resets because of power down, first program judges whether the flag information that powers on changes, if powered on, flag information changes, and system is electrification reset; If powered on, flag information is constant, and system is system reset.
As seen from the above technical solution provided by the invention, there is following advantage in the present invention: the present invention arranges coding encrypting to the data message in software, when read data information, all to verify the coding in data message, correct rear readable data information, if incorrect, reads duplicated record and the checking of encoding, until coding is correct, read data information working procedure.When such mode makes system wrong because interference produces, can whether data message be changed and be judged, and owing to there being duplicated record, system data information can not lose or damage, the reliability of system is improved; And set up the flag information position that powers on to judge it is electrification reset or system reset in specific RAM district, in order to determine to carry out system initialization or system recovery; If needing system recovers according to the judgement to corresponding coding, data message in corresponding record is read, such mode makes can effectively judge in the time that system power failure is restarted or reset whether intrasystem data message changes, if data message changes, system initialization, makes the system can error running; If data message is constant, can continue working procedure.Needn't detect to judge that whether system is normal to system, needn't shut down modification hardware and software.
Accompanying drawing explanation
Fig. 1 is the software anti-interference method process flow diagram of the present invention for electric energy meter.
Embodiment
Below in conjunction with the drawings and specific embodiments, the present invention is described in more detail.
The present invention is known for the software anti-interference method process flow diagram of electric energy meter as shown in Figure 1, and it comprises the following steps:
Step 1, in the time of software input data information, the coding that unique correspondence is set respectively for each data message is encrypted a record of formation, then many parts of storages of each record backup;
Step 2, according to the judgement to coding, reads the data message in corresponding record when reading information.
It is the coding encrypting that each byte of showing the each data message of composition configures unique correspondence that the coding that unique correspondence is set respectively for each data message in described step 1 is encrypted.As bought electric weight EEPROM storage user, buying electric weight is two bytes, join 5AH to each byte and encrypt a record of formation, then 3 parts of storages of this record backup.
Described according to the judgement to coding, the data message in corresponding record is read and referred to:
While reading stored record, first check the coding in this record, if coding is correct, this is recorded as correct record, reads the data message in record; Incorrect if encoded, check the coding of the backup of this record, until it is correct to encode, this duplicated record is correct record, reads the data message in duplicated record; As all incorrect in the coding in duplicated record, carry out system initialization.Described judge whether coding correctly refers to that the coding of this record setting compares when reading coding in record with input data information, if both are identical, coding correctly; If both are not identical, encode incorrect.
Described step 2 also comprises:
In the time that system restarts or resets because of power down, judgement system is electrification reset or system reset, if electrification reset carries out system initialization; If system reset reads the record of storage, and according to the judgement to corresponding coding, the data message in corresponding record is read.Described electrification reset refers to while normally switching on power, and a series of initialization operations that now single-chip microcomputer need to carry out, comprise initialization register, each hardware of initialization etc.Described system reset refers to due to abnormal cause system crash, after system is restarted, and can be according to the operation before the information recovery system collapse of record.
Described judgement system is that electrification reset or system reset are achieved in the following ways:
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, the flag information that powers on is program coding, as 55H0AAH5AH0A5H, in the time that system restarts or resets because of power down, first program judges whether the flag information that powers in RAM district changes, if powered on, flag information changes, and system is electrification reset; If powered on, flag information is constant, and system is system reset.Described RAM district refers to the data storage cell in single-chip microcomputer.
Below only apply preferably example with regard to the present invention and made explanation, but can not be interpreted as it is limitations on claims, structure of the present invention can have other to change, and is not limited to said structure.In a word, all various variations of doing in the protection domain of independent claims of the present invention are all in protection scope of the present invention.