📄 instance_battery.cpp
字号:
else { return; } //Only first implementation to see that it works within framework ret = pThis->GetBatteryInstances( &DeviceList ); //TODO optimize code, pull Devicelist out as a global if(ret == 0){ if(DeviceList.Device[index].Tag !=0) { //we do have a battery installed inthe battery slot BatteryDevice = &DeviceList.Device[index]; ret = pThis->GetBatteryCriticalBias( BatteryDevice, &CriticalBias ); if(ret ==0) { value = CriticalBias; //printf("CriticalBias value %d\n",value); //fordebugging only this->SetValueImpl( value ); } else { //raise error //TODO this->SetNull( true ); } } else { //raise error //TODO this->SetNull( true ); } } else{ //raise error //TODO this->SetNull( true ); }*/}void BatteryCycleCountClass::GetValueImpl (){ DefaultBatteryInstanceObject* pThis = (DefaultBatteryInstanceObject*)this->_pThis; if (pThis->__battery->isInit) { this->SetValueImpl( pThis->__battery->batteryinfo.CriticalBias ); } else { //raise error //TODO this->SetNull( true ); }}void BatteryDesignedCapacityClass::GetValueImpl (){ DefaultBatteryInstanceObject* pThis = (DefaultBatteryInstanceObject*)this->_pThis; if (pThis->__battery->isInit) { this->SetValueImpl( pThis->__battery->batteryinfo.DesignedCapacity ); } else { //raise error //TODO this->SetNull( true ); }}void BatteryEstimatedTimeRemainingClass::GetValueImpl ( ){ // current implementation provides the same data as TimeRemainingAtCurrentRate //TODO implement an adhanced version based on moving averages DefaultBatteryInstanceObject* pThis = (DefaultBatteryInstanceObject*)this->_pThis; DWORD value; int ret=GetEstimatedTimeRemaining(pThis->__battery,&value); if(!ret) { this->SetValueImpl((ULONG) value ); } else { //raise error Battery rate unknows //TODO this->SetNull( true ); }/* ULONG value = 0; int index; BATTERY_DEVICE_LIST DeviceList; ULONG Time; BATTERY_DEVICE * BatteryDevice; DWORD ret; if(!pThis->Index.IsNull()) { index = pThis->Index.GetValue(); } else { return; } //Only first implementation to see that it works within framework ret = pThis->GetBatteryInstances( &DeviceList ); //TODO optimize code, pull Devicelist out as a global if( ret == 0 ) { if(DeviceList.Device[index].Tag !=0) { //we do have a battery installed inthe battery slot BatteryDevice = &DeviceList.Device[index]; ret = pThis->GetBatteryTimeRemainingAtCurrentRate( BatteryDevice , &Time); if( ret == 0 ) { value = Time; //printf("Voltage value %d\n",value); //fordebugging only if(Time == BATTERY_UNKNOWN_TIME){ //raise error Battery rate unknows //TODO this->SetNull( true ); } else{ this->SetValueImpl( value ); } } else { //raise error Battery rate unknows //TODO this->SetNull( true ); } } else { //raise error //TODO this->SetNull( true ); } } else { //raise error //TODO this->SetNull( true ); }*/}void BatteryFullCapacityClass::GetValueImpl ( ){ DefaultBatteryInstanceObject* pThis = (DefaultBatteryInstanceObject*)this->_pThis; if (pThis->__battery->isInit) { this->SetValueImpl( pThis->__battery->batteryinfo.FullChargedCapacity ); } else { //raise error //TODO this->SetNull( true ); }/* ULONG value = 0; int index; BATTERY_DEVICE_LIST DeviceList; ULONG FullChargedCapacity; BATTERY_DEVICE * BatteryDevice; DWORD ret; if(!pThis->Index.IsNull()) { index = pThis->Index.GetValue(); } else { return; } //Only first implementation to see that it works within framework ret = pThis->GetBatteryInstances( &DeviceList ); //TODO optimize code, pull Devicelist out as a global if (ret == 0) { if(DeviceList.Device[index].Tag !=0) { //we do have a battery installed inthe battery slot BatteryDevice = &DeviceList.Device[index]; ret = pThis->GetBatteryFullChargedCapacity( BatteryDevice, &FullChargedCapacity ); if (ret == 0) { value = FullChargedCapacity; //printf("FullChargedCapacity value %d\n",value); //fordebugging only this->SetValueImpl( value ); } else { //raise error Battery rate unknows //TODO this->SetNull( true ); } } else { //raise error Battery rate unknows //TODO this->SetNull( true ); } } else { //raise error Battery rate unknows //TODO this->SetNull( true ); }*/}void BatteryStateUpdateIntervalClass::GetValueImpl ( ){ // dummy function,will either be replaced by actual function or //TODO --- New feature that requires a separte thread for constant sampling and analysis of the collected data (required already for optimized implementation of battery) // will be implemented in the next phase // Data needs to be persistant (use of XML file details TBD) // // return E_NOTIMPL; DefaultBatteryInstanceObject* pThis = (DefaultBatteryInstanceObject*)this->_pThis; if ( pThis->m_InternalStatusUpdateInterval == 0 ) this->SetNull( true ); else this->SetValue( pThis->m_InternalStatusUpdateInterval );}void BatteryPercentRemainingClass::GetValueImpl ( ){ DefaultBatteryInstanceObject* pThis = (DefaultBatteryInstanceObject*)this->_pThis; LONG value; int ret=GetLifePercentRemaining(pThis->__battery,&value); if(!ret) { this->SetValueImpl((ULONG) value ); } else { //raise error Battery rate unknows //TODO this->SetNull( true ); }/* LONG value = 0; int index; BATTERY_DEVICE_LIST DeviceList; LONG PercentRemaining; BATTERY_DEVICE * BatteryDevice; DWORD ret; if(!pThis->Index.IsNull()) { index = pThis->Index.GetValue(); } else { return; } //Only first implementation to see that it works within framework ret = pThis->GetBatteryInstances( &DeviceList ); //TODO optimize code, pull Devicelist out as a global if ( ret == 0) { if(DeviceList.Device[index].Tag !=0) { //we do have a battery installed inthe battery slot BatteryDevice = &DeviceList.Device[index]; ret = pThis->GetBatteryLifePercentRemaining( BatteryDevice , &LifePercentRemaining ); if ( ret == 0 ) { value = LifePercentRemaining; if ( value > 100 ) value = 100; else if ( value < 0 ) value = 0; //printf("LifePercentRemaining value %d\n",value); //fordebugging only this->SetValueImpl( value ); } else { //raise error //TODO this->SetNull( true ); } } else { //raise error //TODO this->SetNull( true ); } } else { //raise error //TODO this->SetNull( true ); }*/}void BatteryManufactureDateClass::GetValueImpl ( ) { DefaultBatteryInstanceObject* pThis = (DefaultBatteryInstanceObject*)this->_pThis;/* if (pThis->__battery->isInit) { this->SetValueImpl( pThis->__battery->batteryinfo.ManufactureDate ); } else { //raise error //TODO this->SetNull( true ); }*//* DWORD value = 0; char tmp_string[MAX_PATH]; LONG Day, Month, Year; int index; BATTERY_DEVICE_LIST DeviceList; BATTERY_DEVICE * BatteryDevice; DWORD ret; //struct tm tm_date; time_t result; if(!pThis->Index.IsNull()) { index = pThis->Index.GetValue(); } else { return; } //Only first implementation to see that it works within framework ret = pThis->GetBatteryInstances( &DeviceList ); //TODO optimize code, pull Devicelist out as a global if ( ret == 0) { if(DeviceList.Device[index].Tag !=0) { //we do have a battery installed inthe battery slot BatteryDevice = &DeviceList.Device[index]; ret = pThis->GetBatteryManufactureDate( BatteryDevice , &Day, &Month, &Year, tmp_string ); //ret = 0; Day= 29; Month= 2; Year = 1984; //used for debugging if ( ret == 0 ) { SYSTEMTIME st; //st.wYear = (WORD)Year; // st.wMonth = (WORD)Month; // st.wDay = (WORD)Day; // st.wDayOfWeek = st.wHour=st.wMinute=st.wSecond= st.wMilliseconds = 0;*/ /* if ( false == SystemTime2UnixTime(&st, &result) ) this->SetNull( true ); else { DATE value = timet2date(result); if ( value == 0 ) { this->SetNull( true ); } else { this->SetValueImpl( value ); } }*/ //time( &date ); //hack set the date to now and then change the day, month, year to get a valid tm structure //tm_date= *localtime( &date ); //part of the hack //tm_date.tm_mday = (int) Day; //tm_date.tm_mon = (int) Month; //tm_date.tm_year = (int) Year - 1900; //need to subtract 1900 to get proper year according to tm definition //if( (result = mktime( &tm_date )) != (time_t)-1 ){ // // printf( "Date %s\n", asctime( &tm_date ) ); //debugging only // //this->SetValueImpl( result ); // DATE value1 = timet2date(result); // this->SetValueImpl( value1 ); //} //else{ // this->SetNull( true ); //}/* } else { //raise error //TODO this->SetNull( true ); } } else { //raise error //TODO this->SetNull( true ); } } else { //raise error //TODO this->SetNull( true ); }*/}void BatteryManufacturerClass::GetValueImpl ( ) { DefaultBatteryInstanceObject* pThis = (DefaultBatteryInstanceObject*)this->_pThis; if (pThis->__battery->isInit) { IntelMobileChar manu[256]; #ifdef _UNICODE mbstowcs(manu,pThis->__battery->batteryinfo.Manufacturer,256); #else strncpy(manu,pThis->__battery->batteryinfo.Manufacturer,256); #endif this->SetValueImpl( manu ); } else { //raise error //TODO this->SetNull( true ); }/* int index; BATTERY_DEVICE_LIST DeviceList; BATTERY_DEVICE * BatteryDevice; DWORD ret; char Manufacturer[MAX_PATH]; // BSTR value = NULL; IntelMobileChar value[256]; if(!pThis->Index.IsNull()) { index = pThis->Index.GetValue(); } else { return; } //Only first implementation to see that it works within framework ret = pThis->GetBatteryInstances( &DeviceList ); //TODO optimize code, pull Devicelist out as a global if ( ret == 0) { if(DeviceList.Device[index].Tag !=0) { //we do have a battery installed in the battery slot BatteryDevice = &DeviceList.Device[index]; ret = pThis->GetBatteryManufactureName( BatteryDevice, Manufacturer ); if ( ret == 0) { ///printf("value %s\n",Manufacturer); used for debugging only // value = _com_util::ConvertStringToBSTR( Manufacturer ); mbstowcs(value,Manufacturer,256);// this->SetValueImpl( static_cast<IntelMobileChar*>( value ) ); //::SysFreeString( value ); //Leak fixed. } else { //raise error //TODO this->SetNull( true ); } } else { //raise error //TODO this->SetNull( true ); } } else { //raise error //TODO this->SetNull( true ); }*/ }/*void BatteryMaximumChargeRateClass::GetValueImpl ( ){ // dummy function,will either be replaced by actual function // it is a static property //TODO --- New feature that requires information from OEM or has been obtained from a onetime setup step // Data likely to be read from a XML configuration file (need to synchup process with other device implementation // // return E_NOTIMPL; this->SetNull( true );}void BatteryMaximumDischargeRateClass::GetValueImpl ( ){ // dummy function,will either be replaced by actual function // it is a static property //TODO --- New feature that requires information from OEM or has been obtained from a onetime setup step // Data likely to be read from a XML configuration file (need to synchup process with other device implementation // // return E_NOTIMPL; this->SetNull( true );}void BatteryMaximumObservedChargeRateClass::GetValueImpl ( ){ // dummy function,will either be replaced by actual function //TODO --- New feature that requires a separte thread for constant sampling (required already for optimized implementation of battery) // will be implemented in the next phase // Data needs to be persistant (use of XML file details TBD) // // return E_NOTIMPL; this->SetNull( true );} void BatteryMaximumObservedDischargeRateClass::GetValueImpl ( ){ // dummy function,will either be replaced by actual function //TODO --- New feature that requires a separte thread for constant sampling (required already for optimized implementation of battery) // will be implemented in the next phase // Data needs to be persistant (use of XML file details TBD) // // return E_NOTIMPL; this->SetNull( true );}void BatteryMaximumTemperatureClass::GetValueImpl ( ){ // dummy function,will either be replaced by actual function // it is a static property //TODO --- New feature that requires information from OEM // Data likely to be read from a XML configuration file (need to synchup process with other device implementation // // return E_NOTIMPL; this->SetNull( true );}*/void BatteryNameClass::GetValueImpl ( ) { DefaultBatteryInstanceObject* pThis = (DefaultBatteryInstanceObject*)this->_pThis; if (pThis->__battery->isInit) { IntelMobileChar name[256]; #ifdef _UNICODE mbstowcs(name,pThis->__battery->batteryinfo.Name,256); #else strncpy(name,pThis->__battery->batteryinfo.Name,256); #endif this->SetValueImpl( name ); } else { //raise error //TODO this->SetNull( true ); }/* int index ; BATTERY_DEVICE_LIST DeviceList; BATTERY_DEVICE * BatteryDevice; DWORD ret; char Name[MAX_PATH]; // BSTR value = NULL; IntelMobileChar value[256]; if(!pThis->Index.IsNull()) { index = pThis->Index.GetValue(); } else { return ; } //Only first implementation to see that it works within framework ret = pThis->GetBatteryInstances( &DeviceList ); //TODO optimize code, pull Devicelist out as a global if ( ret == 0) { if(DeviceList.Device[index].Tag !=0) { //we do have a battery installed in the battery slot BatteryDevice = &DeviceList.Device[index]; ret = pThis->GetBatteryName( BatteryDevice, Name ); if ( ret == 0) { ///printf("Name value %s\n",Manufacturer); used for debugging only // value = _com_util::ConvertStringToBSTR( Name );mbstowcs(value,Name,256); this->SetValueImpl( static_cast<IntelMobileChar*>( value ) ); //::SysFreeString( value ); //Leak fixed. } else { //raise error //TODO this->SetNull( true ); } } else { //raise error //TODO this->SetNull( true ); } } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -