Disclosure of Invention
In view of the foregoing problems, an object of the present invention is to provide a method, an apparatus, a device, and a storage medium for writing water card data to prevent data loss, which can ensure that the water card data is not lost.
In a first aspect, an embodiment of the present invention provides a water card data writing method for preventing data loss, including:
reading a current approaching water card through an NFC module; the water card is provided with a data area for storing current water quantity information, a card number area for storing card number information, a first backup area and a second backup area; the data area, the first backup area and the second backup area are used for storing effective identification for identifying whether water consumption data are effective or not, water consumption data and a water card state;
judging whether the effective identification of the data area of the water card is effective or not;
when the valid identifier of the data area of the water card is judged to be valid, reading the current first water data of the data area, writing the first water data into the first backup area, writing the second water data to be written into the second backup area, and locally storing the current first water card state of the data area of the water card;
setting the valid identifier of the data area of the water card as invalid, writing the second water data into the data area of the water card, and updating the first water card state of the data area into a second water card state;
and setting the valid identifier of the data area of the water card to be valid so as to complete the writing of the water card data.
Preferably, when the valid identifier of the data area of the water card is judged to be invalid, the current water card state of the data area of the water card and a first water card state stored locally are acquired;
when the current water card state of the data area is judged to be consistent with a first water card state stored locally, reading water consumption data in a first backup area, writing the water consumption data into the data area, and setting the effective identification of the data area of the water card to be effective;
and when the water card state of the data area is judged to be inconsistent with the first local water card state stored locally, reading the water consumption data in the second backup area, writing the water consumption data into the data area, and setting the effective identification of the data area of the water card to be effective.
Preferably, the valid identifier is a string of special character strings for identifying whether the water consumption data stored in each area is valid; the water card status includes: an invalid state, a card writing-free state, a card data emptying state and a card writing-in data state; the water use data comprises: the amount of water available and the unit price of the water.
Preferably, before setting the valid identifier of the data area of the water card to be valid to complete the writing of the water card data, the method further includes:
comparing whether the third water data of the data area is consistent with the second water data after writing;
setting the valid identifier of the data area of the water card to be valid so as to complete the writing of the water card data:
and when the third water data written into the data area is judged to be consistent with the second water data to be written, setting the valid identifier of the data area of the water card to be valid so as to finish the writing of the water card data.
In a second aspect, an embodiment of the present invention further provides a water card data writing device for preventing data loss, including:
the water card reading unit is used for reading a water card which is close to the current position through the NFC module; the water card is provided with a data area for storing current water quantity information, a card number area for storing card number information, a first backup area and a second backup area; the data area, the first backup area and the second backup area are used for storing effective identification for identifying whether water consumption data are effective or not, water consumption data and a water card state;
the effective identification judging unit is used for judging whether the effective identification of the data area of the water card is effective or not;
the water consumption data reading unit is used for reading current first water data of the data area, writing the first water data into the first backup area, writing second water data to be written into the second backup area and locally storing the current first water card state of the data area of the water card when the effective identifier of the data area of the water card is judged to be effective;
the water card state updating unit is used for setting the valid identifier of the data area of the water card to be invalid, writing the second water data into the data area of the water card, and updating the first water card state of the data area to be a second water card state;
and the water card data writing unit is used for setting the valid identifier of the data area of the water card to be valid so as to complete the writing of the water card data.
Preferably, the method comprises the following steps:
the water card state acquisition unit is used for acquiring the current water card state of the data area of the water card and a first water card state stored locally when the valid identifier of the data area of the water card is judged to be invalid;
the first backup area water consumption data reading unit is used for reading the water consumption data in the first backup area and writing the water consumption data into the data area when the current water card state of the data area is judged to be consistent with the first water card state stored locally, and meanwhile, setting the effective identification of the data area of the water card to be effective;
and the second backup area water consumption data reading unit is used for reading the water consumption data in the second backup area and writing the water consumption data into the data area when the water card state of the data area is judged to be inconsistent with the first local water card state stored locally, and meanwhile, setting the valid identifier of the data area of the water card to be valid.
Preferably, the valid identifier is a string of special character strings for identifying whether the water consumption data stored in each area is valid; the water card status includes: an invalid state, a card writing-free state, a card data emptying state and a card writing-in data state; the water use data comprises: the amount of water available and the unit price of the water.
Preferably, the method further comprises the following steps:
the water use data comparison unit is used for comparing whether the third water use data written in the data area is consistent with the second water use data;
and the water card data writing unit is also used for setting the valid identifier of the data area of the water card to be valid when judging that the third water data written into the data area is consistent with the second water data to be written, so as to finish the writing of the water card data.
An embodiment of the present invention further provides a water card data writing device for preventing data loss, which includes a processor, a memory, and a computer program stored in the memory, where the computer program is executable by the processor to implement the water card data writing method for preventing data loss according to the first aspect.
The embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium includes a stored computer program, and when the computer program runs, the apparatus where the computer-readable storage medium is located is controlled to execute the above-mentioned water card data writing method for preventing data loss.
In the embodiment, the water card is provided with a data area for storing current water quantity information, a card number area for storing card number information, a first backup area and a second backup area, and each area is stored with data for identifying whether water consumption data is effective or not, water consumption data and a water card state; then through setting up the effective sign of the data area of water card when effective, just can carry out the reading of the water data of water card and write in operation, simultaneously through writing in first water data first backup area to and write in the second water data that will wait to write in second backup area ensures that water card data can not lead to writing in data mistake, lose and write in incomplete problem because of electromagnetism, water pump interference and the influence that operates the irregularity at the in-process of writing in the card, in order to avoid water card data loss and guarantee water card data integrality.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
For better understanding of the technical solutions of the present invention, the following detailed descriptions of the embodiments of the present invention are provided with reference to the accompanying drawings.
It should be understood that the described embodiments are only some embodiments of the invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terminology used in the embodiments of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the examples of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be understood that the term "and/or" as used herein is merely one type of association that describes an associated object, meaning that three relationships may exist, e.g., a and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination" or "in response to a detection", depending on the context. Similarly, the phrases "if determined" or "if detected (a stated condition or event)" may be interpreted as "when determined" or "in response to a determination" or "when detected (a stated condition or event)" or "in response to a detection (a stated condition or event)", depending on the context.
In the embodiments, the references to "first \ second" are merely to distinguish similar objects and do not represent a specific ordering for the objects, and it is to be understood that "first \ second" may be interchanged with a specific order or sequence, where permitted. It should be understood that "first \ second" distinct objects may be interchanged under appropriate circumstances such that the embodiments described herein may be practiced in sequences other than those illustrated or described herein.
The first embodiment is as follows:
referring to fig. 1, a first embodiment of the present invention provides a method for writing data into a water card to prevent data loss, which is performed by a water card data writing device (hereinafter referred to as "data writing device") to prevent data loss, and in particular, is performed by one or more processors in the card data writing device, and includes at least the following steps:
s101, reading a current approaching water card through an NFC module; the water card is provided with a data area for storing current water quantity information, a card number area for storing card number information, a first backup area and a second backup area; the data area, the first backup area and the second backup area are used for storing effective identification used for identifying whether the water consumption data are effective or not, the water consumption data and the water card state.
In this embodiment, the data writing device exchanges data with the water card through the NFC module, and when the water card is close to the NFC module, the NFC module reads the water card information in the water card and writes the water card information into the data writing device, or the NFC module writes back the available water volume information stored in the device into the water card.
Wherein the water card status comprises: an invalid state, a card writing-free state, a card data emptying state and a card writing-in data state; the water use data comprises: the amount of water available and the unit price of the water.
Table 1:
s102, judging whether the valid identification of the data area of the water card is valid.
In this embodiment, an effective identifier of a string of special character strings is provided in each region, and is used to identify whether the water consumption data stored in each region is effective, specifically, when the read special character string in the data region is inconsistent with the pre-agreed special character string, it indicates that the water consumption data stored in the data region is invalid and the water consumption data in the data region cannot be read, and only when the read special character string in the data region is consistent with the pre-agreed special character string, the water consumption data in the data region can be read, for example, when the read special character string in the data region is H, T @ -% I { T-, D @ H) - — I [ P ^ Z $ V }, and the pre-agreed special character string is H, T @ -% H { F }, w @ Z) - -L [ E- - [ N $ I }, then judge that the effective sign of the data area of disconnected water card is invalid, if a string of special character in the data area who reads is H, T @ -% H { F- -, W @ Z) - -L [ E- - [ N $ I }, the special character string agreed in advance is H, T @ -% H { F- -, W @ Z) - -L [ E- - [ N $ I }, then judge that the effective sign of the data area of disconnected water card is valid.
S103, when the valid identifier of the data area of the water card is judged to be valid, reading the current first water data of the data area, writing the first water data into the first backup area, writing the second water data to be written into the second backup area, and locally storing the current first water card state of the data area of the water card.
In this embodiment, in order to ensure that the problems of data writing errors, data loss and incomplete writing caused by electromagnetic interference, water pump interference, incomplete writing and irregular operation of the water card data in the card writing process are avoided, the current first water data of the data area is written into the first backup area for storage, the current second water data to be written is written into the second backup area for storage, and the current first water card state of the data area of the water card is locally stored, so that the water data in the data area can be selected to be restored from the first backup area or the second backup area according to actual conditions, and the water card data loss is avoided.
It should be noted that, the first water card state at this time may be, for example, a card-write-free state.
And S104, setting the valid identifier of the data area of the water card to be invalid, writing the second water data into the data area of the water card, and updating the first water card state of the data area to be the second water card state.
In this embodiment, by setting the valid identifier of the data area of the water card to be invalid, the data area can only be written with the water consumption data and cannot read or use the water consumption data of the data area.
Wherein, the second water card state can be a card writing state, for example.
And S105, setting the valid identifier of the data area of the water card to be valid so as to complete the writing of the water card data.
In this embodiment, in order to verify the integrity of the water card data, the method further includes comparing whether the third water data in the data area after writing is consistent with the second water data; and when the third water data written into the data area is judged to be consistent with the second water data to be written, setting the valid identifier of the data area of the water card to be valid so as to finish the writing of the water card data.
In summary, the water card is provided with a data area for storing current water quantity information, a card number area for storing card number information, a first backup area and a second backup area, and each area is stored with data for identifying whether water consumption data is valid, water consumption data and a water card state; then through setting up the effective sign of the data area of water card when effective, just can carry out the reading of the water data of water card and write in operation, simultaneously through writing in first water data first backup area to and write in the second water data that will wait to write in second backup area ensures that water card data can not lead to writing in data mistake, lose and write in incomplete problem because of electromagnetism, water pump interference and the influence that operates the irregularity at the in-process of writing in the card, in order to avoid water card data loss and guarantee water card data integrality.
On the basis of the above embodiment, in a preferred embodiment of the present invention, the method further includes:
when the valid identifier of the data area of the water card is judged to be invalid, acquiring the current water card state of the data area of the water card and a first water card state stored locally;
when the current water card state of the data area is judged to be consistent with a first water card state stored locally, reading water consumption data in a first backup area, writing the water consumption data into the data area, and setting the effective identification of the data area of the water card to be effective;
and when the water card state of the data area is judged to be inconsistent with the first local water card state stored locally, reading the water consumption data in the second backup area, writing the water consumption data into the data area, and setting the effective identification of the data area of the water card to be effective.
According to the above embodiment, in step S104, the valid identifier of the data area of the water card is set to be invalid, that is, the water card cannot use the water use data of the data area until the writing in S105 is completed, and the valid identifier of the data area of the water card is set to be valid again. If the user removes the water card during the data writing process or the data cannot be written due to interference, the valid identification set of the data area of the water card is kept invalid, that is, the water card cannot be used, and the actual water consumption data of the water card may be lost or abnormal.
For this reason, in this embodiment, when the valid identifier of the data area of the water card is found to be invalid, the water use data for restoring the data area from the first backup area or the second backup area is selected according to the card status of the data area of the water card.
According to the step S103, the first water card state is stored in the equipment. In S104, if the water card is removed when the device has not written the second water data into the data area of the water card, the card status of the data area of the water card at this time remains the first water card status, that is, consistent with the local storage of the device. And if the water card is removed after the equipment writes the second water data into the data area of the water card, updating the card state of the data area of the water card to be the second water card state, namely inconsistent with the local storage of the equipment.
Therefore, when the current water card state of the data area is judged to be consistent with the first water card state stored locally, the data are not written successfully by the equipment, at the moment, the water consumption data in the first backup area are read, the water consumption data are written into the data area, and meanwhile, the effective identification of the data area of the water card is set to be effective;
and when the water card state of the data area is judged to be inconsistent with the first local water card state stored locally, the data is indicated to be written successfully, at the moment, the water consumption data in the second backup area is read, the water consumption data is written into the data area, and meanwhile, the effective identification of the data area of the water card is set to be effective.
So, can guarantee that the water data accuracy of data area just can not lose, the effective sign of the data area of water card just can be automatic from invalid setting for effective when punching the card moreover, the user can reuse the water card, and need not to make things convenient for user's use to experience and the pressure of backstage through relevant personnel change at the backstage again greatly.
Second embodiment of the invention:
referring to fig. 2, a second embodiment of the present invention further provides a water card data writing device for preventing data loss, including:
a watercard reading unit 100, configured to read a currently approaching water card through an NFC module; the water card is provided with a data area for storing current water quantity information, a card number area for storing card number information, a first backup area and a second backup area; the data area, the first backup area and the second backup area are used for storing effective identification for identifying whether water consumption data are effective or not, water consumption data and a water card state;
a valididentifier determining unit 200, configured to determine whether a valid identifier of the data area of the water card is valid;
a waterdata reading unit 300, configured to, when it is determined that the valid identifier of the data area of the water card is valid, read current first water data of the data area, write the first water data into the first backup area, write second water data to be written into the second backup area, and locally store a current first water card state of the data area of the water card;
the water cardstate updating unit 400 is configured to set the valid identifier of the data area of the water card to be invalid, write the second water data into the data area of the water card, and update the first water card state of the data area to be the second water card state;
and the water carddata writing unit 500 is used for setting the valid identifier of the data area of the water card to be valid so as to complete the writing of the water card data.
On the basis of the above embodiments, a preferred embodiment of the present invention includes:
the water card state acquisition unit is used for acquiring the current water card state of the data area of the water card and a first water card state stored locally when the valid identifier of the data area of the water card is judged to be invalid;
the first backup area water consumption data reading unit is used for reading the water consumption data in the first backup area and writing the water consumption data into the data area when the current water card state of the data area is judged to be consistent with the first water card state stored locally, and meanwhile, setting the effective identification of the data area of the water card to be effective;
and the second backup area water consumption data reading unit is used for reading the water consumption data in the second backup area and writing the water consumption data into the data area when the water card state of the data area is judged to be inconsistent with the first local water card state stored locally, and meanwhile, setting the valid identifier of the data area of the water card to be valid.
On the basis of the foregoing embodiment, in a preferred embodiment of the present invention, the valid identifier is a string of special character strings, and is used to identify whether the water consumption data stored in each area is valid; the water card status includes: an invalid state, a card writing-free state, a card data emptying state and a card writing-in data state; the water use data comprises: the amount of water available and the unit price of the water.
On the basis of the above embodiment, in a preferred embodiment of the present invention, the method further includes:
the water use data comparison unit is used for comparing whether the third water use data written in the data area is consistent with the second water use data;
the water carddata writing unit 500 is further configured to set the valid identifier of the data area of the water card to be valid when it is determined that the third water data written into the data area is consistent with the second water data to be written, so as to complete the writing of the water card data this time.
A third embodiment of the present invention provides a water card data writing device for preventing data loss, which includes a processor, a memory, and a computer program stored in the memory, where the computer program is executable by the processor to implement the water card data writing method for preventing data loss as described above.
A fourth embodiment of the present invention provides a computer-readable storage medium, where the computer-readable storage medium includes a stored computer program, where when the computer program runs, the apparatus where the computer-readable storage medium is located is controlled to execute the above-mentioned water card data writing method for preventing data loss.
Illustratively, the computer program may be divided into one or more units, which are stored in the memory and executed by the processor to accomplish the present invention. The one or more units may be a series of instruction segments of the computer program capable of performing specific functions, and the instruction segments are used for describing the execution process of the computer program in the water card data writing device for preventing data loss.
The data writing device may include, but is not limited to, a processor, a memory. It will be understood by those skilled in the art that the schematic diagram is merely an example of the data loss prevention water card data writing device, and does not constitute a limitation of the data loss prevention water card data writing device, and may include more or less components than those shown, or combine some components, or different components, for example, the data loss prevention water card data writing device may further include an input-output device, a network access device, a bus, etc.
The Processor may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. The general purpose processor may be a microprocessor or the processor may be any conventional processor or the like, the control center of the data writing device connecting the various parts of the overall data writing device using various interfaces and lines.
The memory may be used to store the computer programs and/or modules, and the processor may implement various functions of the data writing apparatus by executing or executing the computer programs and/or modules stored in the memory and calling data stored in the memory. The memory may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data (such as audio data, a phonebook, etc.) created according to the use of the cellular phone, and the like. In addition, the memory may include high speed random access memory, and may also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), at least one magnetic disk storage device, a Flash memory device, or other volatile solid state storage device.
The unit integrated with the water card data writing device for preventing data loss can be stored in a computer readable storage medium if the unit is realized in the form of a software functional unit and sold or used as an independent product. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
It should be noted that the above-described device embodiments are merely illustrative, where the units described as separate parts may or may not be physically separate, and the parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. In addition, in the drawings of the embodiment of the apparatus provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, and may be specifically implemented as one or more communication buses or signal lines. One of ordinary skill in the art can understand and implement it without inventive effort.
While the foregoing is directed to the preferred embodiment of the present invention, it will be understood by those skilled in the art that various changes and modifications may be made without departing from the spirit and scope of the invention.