The content of the invention
In view of above-mentioned the deficiencies in the prior art, it is an object of the invention to provide a kind of simulation of simulated battery charged state
Device and its implementation, it is intended to which solving battery is related to charger in existing mobile terminal development process software development can not
Operated in software program, development efficiency be low the problem of.
Technical scheme is as follows:
A kind of simulator implementation method of simulated battery charged state, wherein, including:
Set one to include analog-driven and simulate the simulator of UI modules, the analog-driven is supplied to application program first
Interface and be supplied to simulation UI module second interfaces;
After the simulation UI modules receive simulated action instruction, write by second interface to analog-driven;
The application program reads simulated action instruction by the first interface from the analog-driven, and according to institute
State simulated action instruction to be acted accordingly, realize the simulation to battery charging state.
The simulator implementation method of described simulated battery charged state, wherein, in addition to:
It is used for the data structure for representing battery charging state defined in analog-driven in advance.
The simulator implementation method of described simulated battery charged state, wherein, the simulation UI modules include following choosing
:AC external power supply sockets, USB external power supply sockets, external power supply state, battery electric quantity and power supply status display field, it is each
The corresponding member value that option corresponds in data structure.
It is a kind of to use the simulator that method simulated battery charged state is implemented as described above, wherein, the simulator includes simulation
Driving and simulation UI modules;
The analog-driven, for being supplied to application program first interface and being supplied to simulation UI module second interfaces;
The simulation UI modules, write for the simulated action received to be instructed by second interface to analog-driven,
The application program reads simulated action instruction by the first interface from the analog-driven, and dynamic according to the simulation
Make instruction to be acted accordingly, realize the simulation to battery charging state.
The simulator of the simulated battery charged state, wherein, the first interface includes being used to obtain battery charging shape
The interface of state, battery charging state therein include:Whether powered, whether powered by USB by AC, battery electric quantity height, have it is outer
Connect the state and battery capacity under power supply.
The simulator of the simulated battery charged state, wherein, the simulation UI modules realize that module includes:
Object Creation module, show for creating the object of a battery, and for handling when battery charging state changes
Show in simulation UI modules.
The simulator of the simulated battery charged state, wherein, the simulation UI modules realize that module also includes:
Battery status memory module, for storing present battery charged state.
The simulator of the simulated battery charged state, wherein, the simulation UI modules realize that module also includes:
Simulated action instructs writing module, and simulated action instruction is written into mould for the first interface by analog-driven
In the data structure for intending driving.
Beneficial effect:The present invention is supplied to using journey by setting analog-driven and simulation UI modules by the analog-driven
Sequence first interface and simulation UI module second interfaces are supplied to, application program reads simulated action from the analog-driven and refer to
Order, and acted accordingly according to simulated action instruction, realize the simulation to battery status.Pass through the present invention, application
The developer of program can carry out software development independently of the battery apparatus of reality, operate very convenient, and mould
It is true to nature to intend effect, it is only necessary to ensure that first interface is consistent with the software function of the first interface in real hardware, you can ensureing should
Can also be realized in real battery apparatus with program, even if so the present invention simulator replaced by real hardware, the simulation
The difference of device and real hardware also can be neglected so that the application program after exploitation need not modify in the later stage, so as to improve
The development efficiency of application program.
Embodiment
The present invention provides a kind of simulator and its implementation of simulated battery charged state, for make the purpose of the present invention,
Technical scheme and effect are clearer, clear and definite, and the present invention is described in more detail below.It is it should be appreciated that described herein
Specific embodiment only to explain the present invention, is not intended to limit the present invention.
A kind of simulator implementation method of simulated battery charged state of the present invention, as shown in figure 1, including step:
S101, set one to include analog-driven and simulate the simulator of UI modules, the analog-driven is supplied to using journey
Sequence first interface and be supplied to simulation UI module second interfaces;
After S102, the simulation UI modules receive simulated action instruction, write by second interface to analog-driven;
S103, the application program read simulated action instruction by the first interface from the analog-driven, and
Acted accordingly according to simulated action instruction, realize the simulation to battery charging state.
The simulator implementation method of the present invention is to realize that the related application program of battery apparatus can be simulated in software
Debugged and developed on device, so as to improve development efficiency.
With reference to the simulator, the present invention will be described in detail.
Referring to Fig. 2, Fig. 2 is a kind of structured flowchart of the simulator of simulated battery charged state of the present invention, as illustrated,
The simulator 100 includes:
Analog-driven 120 and simulation UI modules 110, the analog-driven 120 are used to be supplied to application program 130 first to connect
Mouthful and be supplied to the second interface of simulation UI modules 110, the simulation UI modules 110, which instruct the simulated action received, to be passed through
Second interface is write to analog-driven 120, and the application program 130 is by the first interface from the analog-driven 120
Simulated action instruction is read, and is acted accordingly according to simulated action instruction, realizes the mould to battery charging state
Intend.
The software function of interface on the first interface and actual hardware of the present invention is consistent, and the first interface is root
Formulated according to the software of actual development, as long as first interface keeps consistent with the interface of actual hardware, then if using journey
Sequence can be operated on simulator, and same application program can be also operated on actual hardware, so as to realize simulation actual hardware
Function.Simulated battery charged state driving as electronic equipment input equipment one kind, on the whole for be supplied to application
The character device interface of program standard, only it need to provide basic operation(Mainly manage the information of battery charging state)With
Just charged state can be fed back to application program in time.
And the second interface in the present invention can then be modified as needed, originally driving and the connection of hardware with
And the connection and communication become for analog-driven and simulation UI modules is linked up, so analog-driven needs to provide extra interface
Simulation UI modules are given, simulation UI modules is simulated the effect similar to actual hardware.
In the present embodiment, it is used for defined in analog-driven the data structure for representing battery charging state in advance, uses
Situation is possible to represent battery charging state, the data structure is as follows:
struct PowerStatus {
unsigned int ACPluged:1;// whether by AC power supplies 1:It is;0:It is no
unsigned int USBPluged:1;// whether by USB chargings 1:It is;0:It is no
unsigned int LowBAT:1;// battery electric quantity mark 1:low(It is low);0:high(It is high)
unsigned int BatteryChargeStatus:3;// there is state 1 under external power supply:full
charge(It is fully charged) 2:normal charge(Charge normal) 3:not charge(It is uncharged)
unsigned int PowerMV:16;// battery capacity(mAh)
};
struct PowerStatus CurrentPowerStatus = { 0, 0, 0, 3, 2000 };// silent
Recognize power supply status, that is, represent the power supply status of acquiescence.
So above-mentioned data structure has represented the index of battery charging state:Whether powered, whether powered by USB by AC,
Battery electric quantity height, there are state and battery capacity under external power supply.
The interface of the data structure is controlled by ioctl (), ioctl orders:
SET_POWERSTATUS (It is worth for 0):Battery charging state is set, and ioctl the 3rd parameter type is representative electricity
(the struct PowerStatus*) of pond charged state, this interface use only for simulation UI modules, actual to drive and do not need.
GET_POWERSTATUS (It is worth for 1):Battery charging state is obtained, ioctl the 3rd parameter type is representative electricity
(the struct PowerStatus*) of pond charged state, this interface is first interface, there is provided is used to application program.
Simulation UI modules in the present invention, its interface can as shown in figure 3,
AC external power supply sockets therein, corresponding to the member value in data structure:unsigned int ACPluged;
USB external power supply sockets therein, corresponding to the member value in data structure:unsigned int
USBPluged;
External power supply state options therein, corresponding to the member value in data structure:unsigned int
BatteryChargeStatus;
Battery capacity option therein, corresponding to the member value in data structure:unsigned int PowerMV;
Power supply status display field therein, it is to determine to show according to above-mentioned member value and unsigned int LowBAT
Show content.
Each option in simulation UI modules is briefly described below.
AC external power supply sockets:If hook is stamped thereon, then it represents that now there is external AC to charge battery;
USB external power supply sockets:If hook is stamped thereon, then it represents that now there is circumscribed USB line to charge battery
External power supply state options:If both the above option does not all select, this is invalid, otherwise has 2 kinds of options to be available for selecting
Select:full charge;nomal charge;
Battery capacity option:Scope 0 ~ 2000, here 2000 be battery capacity, can be set according to actual conditions
Put;
Power supply status display field:When there is any one external power supply socket to be chosen, charged is shown!, otherwise show
not charged。
Simulation UI modules realize that module includes:Power.h, power.cpp, simphone.h, simphone.cpp, its
In, cpp and h are the types of program file, and the realization of function is all placed in cpp files, and h files are " header file ", function
Definition etc. is all placed in h files.
Simphone.h is used for the object for creating a battery, i.e. Object Creation module, works as battery charging shape for handling
State is shown in when changing in simulation UI modules;Power.h, for storing present battery charged state, i.e. battery status storage mould
Block;Simphone.cpp is used for the data knot that simulated action instruction is written to analog-driven by the first interface of analog-driven
In structure, i.e., simulated action instructs writing module.
Simphone calls the system that needs to use in analog-driven and has been encapsulated into inside a class, with convenient use,
This is by power.h and power.cpp realizations.The following member function for needing to use defined in power.h and
Filec descriptor fd:
class TPower
{
public:
static int openPower();
static void closePower();
static int readPower();
static int writePower(const struct PowerStatus);// will utilize
Ioctl systems, which are called, writes battery status in buffering area buffer
static int getFD();The filec descriptor fd for the device file that // acquisition is opened
private:
static int m_fd;
};
The various signals that simphonebase.cpp files change the battery status simulated in all simulation UI modules pass
Defeated to arrive corresponding treatment trough powerStatusChanged (), this treatment trough is Virtual Function, simphone.cpp
(Main classes in simphone.cpp inherits the main classes in simphonebase.cpp)In also define corresponding treatment trough, it is real
The treatment trough defined in simphone.cpp can be performed in the operation of border, these treatment troughs are responsible for present battery charged state to write
Into the respective data structures of analog-driven.
In treatment trough powerStatusChanged (), the data set in simulation UI modules are read first, are then beaten
Open power device files:
TPower::openPower();
Then present battery charged state is written in analog-driven:
TPower::writePower(currentPowerStatus);The charged state of // battery is all stored in data
In structure currentPowerStatus
It is then switched off this device file:
TPower::closePower();
Finally the charged state of battery is reacted on the interface in module UI modules.
Illustrate how to determine each member in data structure PowerStatus according to the option in simulation UI module interfaces below
Value:
unsigned int ACPluged :It is otherwise 0 for 1 if stamping hook before AC In external power supply sockets;
unsigned int USBPluged :It is otherwise 0 for 1 if stamping hook before USB external power supply sockets;
unsigned int BatteryChargeStatus:If above-mentioned two option does not all select, for 3, otherwise when outer
It is 1 when meeting power supply status option selection full charge, for 2 during selection nomal charge;
unsigned int PowerMV:Value set by storage battery capacity option;
In summary, the present invention is supplied to using journey by setting analog-driven and simulation UI modules by the analog-driven
Sequence first interface and simulation UI module second interfaces are supplied to, application program reads simulated action from the analog-driven and refer to
Order, and acted accordingly according to simulated action instruction, realize the simulation to battery status.Pass through the present invention, application
The developer of program can carry out software development independently of the battery apparatus of reality, operate very convenient, and mould
It is true to nature to intend effect, it is only necessary to ensure that first interface is consistent with the software function of the first interface in real hardware, you can ensureing should
Can also be realized in real battery apparatus with program, even if so the present invention simulator replaced by real hardware, the simulation
The difference of device and real hardware also can be neglected so that the application program after exploitation need not modify in the later stage, so as to improve
The development efficiency of application program.
It should be appreciated that the application of the present invention is not limited to above-mentioned citing, for those of ordinary skills, can
To be improved or converted according to the above description, all these modifications and variations should all belong to the guarantor of appended claims of the present invention
Protect scope.