Summary of the invention
The technical problem to be solved is: provide a kind of safe and reliable upgrading mode, makes electric energy meter upgrading i.e. by operator control, ensures again ease for operation when implementing and safety.
For solving above-mentioned technical problem, the present invention adopts the following technical scheme that
A kind of IC card electric energy meter online upgrading method, said method comprising the steps of:
Step S1: will insert at the scene in IC card electric energy meter with the IC-card encrypting program to be upgraded, described IC card electric energy meter and this IC-card carry out authentication, if authentication success, then carry out step S2, otherwise exit upgrading;
Step S2: described IC card electric energy meter reads the program to be upgraded in IC-card and is decrypted, and described program to be upgraded is written to ROMPaq backup area;
Step S3: described IC card electric energy meter read from ROMPaq backup area described program to be upgraded and be written to CPU self program storage application area in;
Step S4: the program to be upgraded in described application area that performs completes IC card electric energy meter upgrading.
Further, also include before described step S1: program to be upgraded is encrypted and is written in IC-card by writer.
Further, described step S1 specifically includes:
Step S101: will insert at the scene in IC card electric energy meter with the IC-card encrypting program to be upgraded, after described IC card electric energy meter recognizes IC-card insertion, described IC card electric energy meter and this IC-card carry out authentication;
Step S102: if authentication success, then read the version number of program to be upgraded in this IC-card, otherwise exit;
Step S103: whether the relatively version number of described program to be upgraded is higher than the current version number of IC card electric energy meter, if then performing step 2, otherwise being exited upgrading, and being upgraded unsuccessfully by the liquid crystal display screen display notice of IC card electric energy meter.
Further, described step S2 specifically includes:
Step S201: described IC card electric energy meter once reads the first unit byte data in IC-card, and the data read is decrypted by its encryption/decryption module;
Step S202: the first unit byte data N1 after above-mentioned deciphering is carried out CRC check by described IC card electric energy meter, if verification by; carry out step S203, otherwise by the liquid crystal display screen display notice escalation process error in data of IC card electric energy meter, need again to upgrade;
Step S203: by verification by after the first unit byte data N1 be saved in ROMPaq backup area;
Step S204: repeat above-mentioned steps S201, step S202 and step S203, until all reading routine datas to be upgraded all in IC-card in ROMPaq backup area.
Further, described first unit byte data is chosen for 128 bytes.
Further, self program storage of described CPU also includes BOOT district, described BOOT district is for detecting whether the program that there is a need to update is written in application area, if having, then the data in described ROMPaq backup area are written in application area, then perform the program code in described application area, the most directly perform the program code in described application area.
Further, described step S3 specifically includes:
Step S301: program upgrading mark is set and restarts CPU, perform the program in described BOOT district;
After step S302:CPU runs the program in BOOT district, reading program upgrading mark, mark set of upgrading, read the second unit byte data from described ROMPaq backup area and be written to application area;
Step S303: repeat above-mentioned steps S301 and step S302, until being written to routine datas to be upgraded all in described ROMPaq backup area in described application area.
Further, described second unit byte data is chosen for 512 bytes.
Further, described step S4 specifically includes:
Step S401: remove upgrading mark, restarts CPU and performs the program in BOOT district;
After step S402:CPU runs the program in BOOT district, reading program upgrading mark, upgrading mark is eliminated, performs the program to be upgraded in application area, completes IC card electric energy meter upgrading.
Further, described ROMPaq backup area space is 1.2 times of space, application area.
The present invention also provides for a kind of IC card electric energy meter online upgrade system, including IC card electric energy meter and insert at the scene described IC card electric energy meter with encrypting the IC-card of program to be upgraded, described IC card electric energy meter includes:
The authentication module of authentication is carried out for described IC card electric energy meter and this IC-card;
It is connected to described authentication module, after described IC card electric energy meter with this IC-card authentication, reads the program to be upgraded in IC-card the encryption/decryption module being decrypted;
It is connected to described encryption/decryption module, for the program to be upgraded after deciphering being written to the ROMPaq backup area writing module of ROMPaq backup area;
It is connected to described ROMPaq backup area writing module, application area writing module in reading described program to be upgraded from ROMPaq backup area and being written to the application area of CPU program memory;
It is connected to described application area writing module, completes the ROMPaq execution module that IC card electric energy meter is upgraded for the program to be upgraded performing in described application area.
IC card electric energy meter online upgrading method and system of the present invention are by being encrypted the IC-card ROMPaq of electric energy meter, authentication is carried out again by electric energy meter in field upgrade and IC-card, again IC-card ROMPaq is progressively write in electric energy meter after authentication success, both ensure that the safety that IC card electric energy meter is upgraded, save again the required human and material resources expended of upgrading and financial resources, reduce cost.
Detailed description of the invention
Describe the preferred embodiment of the present invention a kind of IC card electric energy meter online upgrading method below in conjunction with the accompanying drawings in detail.
The present invention a kind of IC card electric energy meter online upgrading method is by being encrypted the IC-card ROMPaq of electric energy meter, authentication is carried out again by electric energy meter in field upgrade and IC-card, again IC-card ROMPaq is progressively write in electric energy meter after authentication success, both ensure that the safety that IC card electric energy meter is upgraded, save again the required human and material resources expended of upgrading and financial resources, reduce cost.
Refer to the schematic flow sheet that Fig. 1, Fig. 1 are IC card electric energy meter online upgrading embodiment of the method for the present invention.IC card electric energy meter online upgrading method of the present invention comprises the following steps:
Step S1: will insert at the scene in IC card electric energy meter with the IC-card encrypting program to be upgraded, described IC card electric energy meter and this IC-card carry out authentication, if authentication success, then carry out step S2, otherwise exit upgrading;
Step S2: described IC card electric energy meter reads the program to be upgraded in IC-card and is decrypted, and described program to be upgraded is written to ROMPaq backup area;
Step S3: described IC card electric energy meter read from ROMPaq backup area described program to be upgraded and be written to CPU program memory application area in;
Step S4: the program to be upgraded in described application area that performs completes IC card electric energy meter upgrading.
Wherein, also include before described step S1: program to be upgraded is encrypted and is written in IC-card by writer.This step S1 is generally completed by IC card electric energy meter operator.
In order to technical solutions according to the invention are described, illustrate below by specific embodiment.
Referring to Fig. 2, described step S1 specifically includes:
Step S101: will insert at the scene in IC card electric energy meter with the IC-card encrypting program to be upgraded, after described IC card electric energy meter recognizes IC-card insertion, described IC card electric energy meter and this IC-card carry out authentication.
The step of described authentication is specific as follows:
(1) from the security module of IC card electric energy meter, obtain the random number (Rand8) of 8 bytes, and from this IC-card, obtain the card information data (IC_Info8) of 8 bytes;
(2) the card information data of described 8 bytes are sent to security module, generate temporary key;Described security module uses this temporary key encrypted random number, obtains the first encryption data K1 of 8 bytes;
(3) described IC-card uses the second encryption data K2 of this generating random number 8 byte;
(4) relatively described first encryption data K1 and the second encryption data K2 are the most identical, the most then authentication success, otherwise failure.
Step S102: if authentication success, then read the version number of program to be upgraded in this IC-card, otherwise exit;
Step S103: whether the relatively version number of described program to be upgraded is higher than the current version number of IC card electric energy meter, if then performing step 2, otherwise being exited upgrading, and being upgraded unsuccessfully by the liquid crystal display screen display notice of IC card electric energy meter.
Referring to Fig. 3, described step S2 specifically includes:
Step S201: described IC card electric energy meter once reads the first unit byte data N1 in IC-card, and the data read is decrypted by its encryption/decryption module.
Wherein, described encryption/decryption module is used for deciphering IC-card data, is the requisite interfaces of IC card electric energy meter.In view of the effectiveness of data in the present embodiment, described first unit byte data N1 is chosen for 128 bytes.
Step S202: the first unit byte data N1 after above-mentioned deciphering is carried out CRC check by described IC card electric energy meter, if verification by; carry out step S203, otherwise by the liquid crystal display screen display notice escalation process error in data of IC card electric energy meter, need again to upgrade;
Step S203: by verification by after the first unit byte data N1 be saved in ROMPaq backup area;
Wherein, the program of described IC card electric energy meter is placed in the program storage of CPU self (usually flash), and CPU self program storage is divided into BOOT district, application area and ROMPaq backup area by the present invention, as shown in Figure 4.Described BOOT district is for detecting whether the program that there is a need to update is written in application area, if having, then the data in described ROMPaq backup area are written in application area, then perform the program code in described application area, the most directly perform the program code in described application area.
Step S204: repeat above-mentioned steps S201, step S202 and step S203, until all reading routine datas to be upgraded all in IC-card in ROMPaq backup area.
Referring to Fig. 5, described step S3 specifically includes:
Step S301: program upgrading mark is set and restarts CPU, perform the program in described BOOT district;
After step S302:CPU runs the program in BOOT district, reading program upgrading mark, mark set of upgrading, read the second unit byte data N2 from described ROMPaq backup area and be written to application area;
Wherein, in view of the effectiveness of data in the present embodiment, described second unit byte data N2 is chosen for 512 bytes.
Step S303: repeat above-mentioned steps S301 and step S302, until being written to routine datas to be upgraded all in described ROMPaq backup area in described application area.
Wherein, the IC-card data form with program to be upgraded is as follows:
Initial |
Order |
Address |
Length |
Data field |
Verification |
Terminate |
Initial: 1 byte, it is fixed as $ symbol, starts mark for serial data;
Order: 1 byte, 01H is for reading card order, and 81H is card acknowledgement command;
Address: 2 bytes, reads the address of card content;
Length: 1 byte, represents the data length that expectation is read, represents the data length unit byte of data field when command code is 81H when command code is 01H;
Data field: do not exist when command code is 01H, when command code is 81H, represents the actual data read;
Verification: 2 bytes, uses CRC check;
Terminate: 1 byte, be fixed as 6BH.
Referring to Fig. 6, described step S4 specifically includes:
Step S401: remove upgrading mark, restarts CPU and performs the program in BOOT district;
After step S402:CPU runs the program in BOOT district, reading program upgrading mark, upgrading mark is eliminated, performs the program to be upgraded in application area, completes IC card electric energy meter upgrading.
In the present invention, the program in BOOT district is only used for monitoring upgrading mark and by the data-moving in ROMPaq district to application area, realize fairly simple operation the most reliable, the space that ROMPaq backup area uses is at least identical with the space that application program uses, and in order to meet extensibility suggestion, the space of ROMPaq backup area is set to 1.2 times of application space.
Refer to Fig. 7, the present invention also provides for a kind of IC card electric energy meter online upgrade system, including IC card electric energy meter 10 and insert at the scene described IC card electric energy meter 10 with encrypting the IC-card 20 of program to be upgraded, described IC card electric energy meter 10 includes that authentication module 102, encryption/decryption module 104, ROMPaq backup area writing module 106, application area writing module 108 and ROMPaq perform module 109.
Described authentication module 102 carries out authentication for described IC card electric energy meter and this IC-card;Described encryption/decryption module 104 is connected to described authentication module 102, reads the program to be upgraded in IC-card and be decrypted after described IC card electric energy meter with this IC-card authentication;Described ROMPaq backup area writing module 106 is connected to encryption/decryption module 104, for the program to be upgraded after deciphering is written to ROMPaq backup area;Described application area writing module 108 is connected to ROMPaq backup area writing module 106, in reading described program to be upgraded from ROMPaq backup area and being written to the application area of CPU program memory;Described ROMPaq performs module 109 and is connected to described application area writing module 108, completes IC card electric energy meter upgrading for the program to be upgraded performed in described application area.
The present invention uses IC-card to upgrade to electric energy meter, had both reduced upgrade cost and in turn ensure that the safety of upgrading.Operator can carry out dress operation under key before to user installation IC card electric energy meter to ammeter, the key of electric energy meter will be made into formal key state by open status maintenance, being in the electric energy meter under formal key state can not operate with the IC-card beyond operator.When need upgrading time operator program to be upgraded is written in IC-card, send related personnel that electric energy meter is upgraded the most again, both ensure that program upgrading completely by power office's control and also in turn ensure that the safety of upgrading.
Here description of the invention and application is illustrative, is not wishing to limit the scope of the invention in above-described embodiment.The deformation of embodiments disclosed herein and change are possible, and for those skilled in the art, embodiment is replaced and the various parts of equivalence are known.It should be appreciated by the person skilled in the art that in the case of without departing from the spirit or essential characteristics of the present invention, the present invention can in other forms, structure, layout, ratio, and realize with other assembly, material and parts.In the case of without departing from scope and spirit of the present invention, embodiments disclosed herein can be carried out other deformation and change.