Disclosure of Invention
The invention provides a multiple safety verification method for key data of an ultrasonic water meter, which aims to solve the technical problems that key data of the existing ultrasonic water meter are stored in a single medium, and the data are easy to lose and damage.
The invention provides a multiple safety verification method for key data of an ultrasonic water meter, which comprises the following steps:
Step 1, key data for ensuring normal metering function of an ultrasonic water meter are stored in different media of an on-chip Flash Memory, an on-chip Information Memory and an external EEPROM, wherein the key data comprise system parameters and metering data;
step 2, powering on and loading system parameters, and reading correct system parameters;
Step 3, electrifying to load metering data and reading the metering data;
step 4, regularly storing metering data in the running process of the instrument;
And 5, when the program is abnormally interfered, if the program is abnormally reset, reading the metering data in the memory, judging whether the metering data are correct according to the checksum of the metering data, and if the metering data are not correct, reading the metering data from the on-chip Information Memory or the external EEPROM, and reloading the system parameters.
Preferably, in step 1, an on-chip Flash Memory stores system parameters, an on-chip Information Memory stores metering data, an external EEPROM stores metering data and system parameters, the system parameters comprise a table number, a caliber, a flow correction parameter, a program version, a flow data version, a temperature correction, a zero point correction and a starting flow, and the metering data comprise a forward accumulated flow, a reverse accumulated flow, a PCB power-on time, a working time, a fault time, a power-on time, a reset time and a current time.
Preferably, the step of reading the correct system parameters in step 2 is:
reading a system parameter calculation checksum stored in a Flash Memory in a chip, checking whether the checksum is correct or not, and reading data to a system parameter data structure in a Memory if the checksum is correct, and if the checksum is incorrect, performing the step (2);
Reading system parameters stored in an external EEPROM, calculating a checksum, checking whether the checksum is correct, if so, reading data to a system parameter data structure in a memory, and if not, performing the step (3);
And (3) reading an initial value of a system parameter from the Flash Memory in the chip to a system parameter data structure in the Memory.
Preferably, the step of reading the metering data in step 3 is:
Step 1), reading metering data stored in the chip Information Memory, calculating a checksum, judging whether the data are correct and valid, if so, reading a metering data structure stored in the chip InformationMemory into a memory, and if not, performing step 2);
step 2), reading the metering data stored in the external EEPROM, calculating a checksum, judging whether the data are correct and valid, and if so, reading the metering data stored in the external EEPROM into a metering data structure in the memory;
and 3) emptying the metering data structure in the memory.
Preferably, in step 4, the specific step of regularly storing the metering data is:
Step A, calculating the checksum of the metering data in the memory, writing the metering data and the checksum into a chip Information Memory, reading the data written in the chip Information Memory, calculating the checksum, judging whether the checksum is correct, and writing the metering data and the checksum into an external EEPROM if the checksum is correct;
Step B, erasing Information Memory in the chip, recalculating the checksum of the metering data in the memory, and writing InformationMemory in the chip and judging;
and C, repeating the operation steps A and B three times.
Preferably, in step 4, before the meter stores the metering data, the battery voltage is detected, the chip is powered to perform read-write operation normally, and otherwise, the data is not stored.
Preferably, the specific steps of detecting the battery voltage include using a power supply voltage monitor to detect the battery voltage greater than 2.8V before storing data, ensuring that the Flash Memory and the external EEPROM in the chip have enough power supply during read-write operation, setting SVSCTL =0x80, reading and writing the data in the unused external EEPROM space and confirming whether the data is correct, judging whether the data is correct or not and reading the SVSFG bit of SVSCTL or not, and manually clearing SVSCTL registers if SVSFG is set or the data is incorrect and not stored.
Preferably, the specific steps of step 5 include:
Step a, calculating the checksum of the metering data in the memory, judging whether the checksum is correct or not, and if the checksum is correct, the data is valid, performing the step b, otherwise, performing the step c;
The step b is to copy the metering data into the unused memory, empty the memory used by the program data, copy the metering data stored into the unused memory back to the metering data structure in the memory;
And c, reading the metering data stored in the chip Information Memory, calculating a checksum, judging whether the data is correct and valid, if so, reading the metering data stored in the chip InformationMemory to the metering data structure in the memory, if not, reading the metering data stored in the external EEPROM, calculating the checksum, judging whether the data is correct and valid, if so, reading the metering data stored in the external EEPROM to the metering data structure in the memory, and if not, clearing the metering data structure in the memory.
Preferably, the specific step of reloading the system parameters in step5 comprises:
Step (A), reading a system parameter calculation checksum stored in a Flash Memory in a chip, checking whether the checksum is correct or not, and reading data to a system parameter data structure in a Memory if the checksum is correct;
Reading system parameters stored in an external EEPROM, calculating a checksum, checking whether the checksum is correct, and reading data to a system parameter data structure in a memory if the checksum is correct;
And (C) reading default data into a system parameter data structure in the memory.
The beneficial effects of the invention are as follows:
And storing the key data in the Flash Memory, the Information Memory and the external EEPROM in different media so as to improve the security of key data storage. Meanwhile, the measurement data is ensured not to be reduced or the maximum measurement data is ensured to be reduced, and the measurement data is ensured to be real and reliable.
Detailed Description
The present invention is further described below with reference to the drawings and examples so that those skilled in the art to which the present invention pertains can easily practice the present invention.
The method comprises the following steps:
step 1, key data for ensuring normal metering function of the ultrasonic water meter are stored in Flash Memory, information Memory and external EEPROM in different media so as to improve the safety of key data storage, wherein the key data comprise system parameters and metering data. Flash memory is flash memory, information Memory is information memory, both have the property of not losing data when power is off, EEPROM is electrically erasable programmable read-only memory, 2-WIRESERIAL EEPROM. The system parameters comprise data such as a table number, a caliber, a flow correction parameter, a program version, a flow data version, temperature correction, zero point correction, starting flow and the like, and the metering data comprise data such as forward accumulated flow, reverse accumulated flow, PCB power-on time, working time, fault duration, power-on times, reset times, current time (time of year, month, day, time of second) and the like.
And 2, powering on and loading system parameters, and reading correct system parameters.
Reading the system parameter calculation checksum stored in the Flash Memory in the chip, checking whether the checksum is correct, if so, reading the system parameter data structure in the Memory (RAM), if not, reading the system parameter calculation checksum stored in the external EEPROM, checking whether the checksum is correct, if so, reading the data to the system parameter data structure in the Memory (RAM), and if not, reading the initial value of the system parameter in the Flash Memory in the chip to the system parameter data structure in the Memory (RAM).
And step 3, powering up and loading metering data, and reading proper metering data.
Reading the metering data stored in the chip Information Memory, calculating a checksum, judging whether the data is correct and valid, if so, reading the metering data stored in the chip Information Memory to a memory (RAM) to count the data structure, if not, reading the metering data stored in the external EEPROM, calculating the checksum, judging whether the data is correct and valid, if so, reading the metering data stored in the external EEPROM to count the data structure in the memory (RAM), and if not, emptying the data structure in the memory (RAM).
And 4, in operation, the meter stores metering data at regular time.
And detecting the voltage of the battery before data are stored, ensuring that the power supply of the chip is ensured, judging that the voltage is more than 2.8V, and otherwise, not storing the data.
Before data is stored, a power supply voltage monitor (Supply Voltage Supervisor) is used for detecting the voltage of the battery, and enough power supply of the Flash Memory and the external EEPROM in the chip is ensured again during read-write operation. SVSCTL =0x80 is set, whether the data is correct or not is judged by reading and writing in an unused external EEPROM space and confirming whether the data is correct or not, SVSFG bit of the read SVSCTL is set or not, and if SVSFG is set or the data is incorrect, the data is not stored, the SVSCTL register is manually cleared.
The method comprises the steps of storing metering data, calculating the checksum of the metering data in a memory (RAM), writing the metering data and the checksum into a chip Information Memory, reading the data written in the chip Information Memory, calculating the checksum, judging whether the checksum is correct or not, writing the metering data and the checksum into an external EEPROM (electrically erasable programmable read-Only memory) if the checksum is correct, erasing the chip Information Memory if the checksum is incorrect, recalculating the checksum of the metering data in the memory (RAM), writing the checksum into the chip Information Memory, judging, and repeating the operation for three times.
The method comprises the steps of storing system parameters, writing in the system parameters only when the system parameters are changed, calculating the checksum of the system parameters in a Memory (RAM), writing the system parameters and the checksum into an on-chip Flash Memory, reading data written in the on-chip Flash Memory, calculating the checksum, judging whether the checksum is correct, writing the system parameters and the checksum into an external EEPROM if the checksum is correct, erasing the on-chip Flash Memory if the checksum is incorrect, recalculating the checksum of the system parameters in the Memory (RAM), writing the checksum into the on-chip Flash Memory, and repeating the operation for three times.
And 5, when the program is abnormally interfered, resetting the program abnormally, storing the current metering data and reloading system parameters.
The method comprises the steps of metering data protection, calculating the checksum of metering data in a memory (RAM), if the checksum is the same as the checksum in a metering data structure, indicating that the metering data is not affected by interference data effectively, copying the metering data into an unused memory, clearing the memory used by the program data, and then saving the memory used by the program data into the unused memory, and copying the metering data back to the memory (RAM) to obtain the metering data structure.
When the metering data in the internal memory (RAM) is invalid, the metering data stored in the internal memory Information Memory are read and the checksum is calculated to judge whether the data are correct and valid, if yes, the metering data stored in the internal memory InformationMemory are read to the metering data structure in the internal memory (RAM), if not, the metering data stored in the external EEPROM are read and the checksum is calculated to judge whether the data are correct and valid, if yes, the metering data stored in the external EEPROM are read to the metering data structure in the internal memory (RAM), and if not, the metering data structure in the internal memory (RAM) is cleared.
The method comprises the steps of reloading system parameters, reading a system parameter calculation checksum stored in a Flash Memory in a chip, checking whether the checksum is correct or not, reading data to a system parameter data structure in a Memory (RAM) if the checksum is correct, reading a system parameter calculation checksum stored in an external EEPROM, checking whether the checksum is correct or not, reading data to the system parameter data structure in the Memory (RAM) if the checksum is incorrect, and reading default data to the system parameter data structure in the Memory (RAM) if the checksum is incorrect.
The above description is only for the preferred embodiments of the present invention and is not intended to limit the present invention, but various modifications and variations can be made to the present invention by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the scope of the claims of the present invention should fall within the protection scope of the present invention.