INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

smartbattery.h

00001 /*
00002  * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
00003  *               http://gearbox.sf.net/
00004  * Copyright (c) 2004-2010 Tobias Kaupp
00005  *
00006  * This distribution is licensed to you under the terms described in
00007  * the LICENSE file included in this distribution.
00008  *
00009  */
00010 
00011 #ifndef GBX_SMARTBATTERY_H
00012 #define GBX_SMARTBATTERY_H
00013 
00014 #include <stdint.h>
00015 
00016 #include <vector>
00017 #include <string>
00018 #include <assert.h>
00019 
00020 namespace gbxsmartbatteryacfr {
00021 
00024 enum SmartBatteryDataField 
00025 {
00026     ManufacturerAccess = 0,
00027     RemainingCapacityAlarm,
00028     RemainingTimeAlarm,
00029     BatteryMode,
00030     AtRate,
00031     AtRateTimeToFull,
00032     AtRateTimeToEmpty,
00033     AtRateOk,
00034     Temperature,
00035     Voltage,
00036     Current,
00037     AverageCurrent,
00038     MaxError,
00039     RelativeStateOfCharge,
00040     AbsoluteStateOfCharge,
00041     RemainingCapacity,
00042     FullChargeCapacity,
00043     RunTimeToEmpty,
00044     AverageTimeToEmpty,
00045     AverageTimeToFull,
00046     ChargingCurrent,
00047     ChargingVoltage,
00048     BatteryStatus,
00049     CycleCount,
00050     DesignCapacity,
00051     DesignVoltage,
00052     SpecificationInfo,
00053     ManufactureDate,
00054     SerialNumber,
00055     ManufacturerName,
00056     DeviceName,
00057     DeviceChemistry,
00058     ManufacturerData,
00059     NUM_SMARTBATTERY_FIELDS
00060 };
00061     
00064 SmartBatteryDataField keyToSmartField( const std::string &key );
00065     
00069 class SmartBattery 
00070 {
00071     public:
00072         SmartBattery() : has_(NUM_SMARTBATTERY_FIELDS)
00073         { std::fill( has_.begin(), has_.end(), false ); };
00074         
00075         bool has( SmartBatteryDataField field ) const;
00076         
00077         uint16_t manufacturerAccess() const { assert(has_[ManufacturerAccess]); return manufacturerAccess_; };
00078         void setManufacturerAccess( uint16_t manufacturerAccess ) { has_[ManufacturerAccess] = true; manufacturerAccess_ = manufacturerAccess; };       
00079          
00080         int remainingCapacityAlarm() const { assert(has_[RemainingCapacityAlarm]); return remainingCapacityAlarm_; };
00081         void setRemainingCapacityAlarm( int remainingCapacityAlarm ) { has_[RemainingCapacityAlarm] = true; remainingCapacityAlarm_ = remainingCapacityAlarm; };
00082         
00083         int remainingTimeAlarm() const { assert(has_[RemainingTimeAlarm]); return remainingTimeAlarm_; };
00084         void setRemainingTimeAlarm( int remainingTimeAlarm ) { has_[RemainingTimeAlarm] = true; remainingTimeAlarm_ = remainingTimeAlarm; };     
00085         
00086         uint16_t batteryMode() const { assert(has_[BatteryMode]); return batteryMode_; };
00087         void setBatteryMode( uint16_t batteryMode ) { has_[BatteryMode] = true; batteryMode_ = batteryMode; };       
00088          
00089         int atRate() const { assert(has_[AtRate]); return atRate_; };
00090         void setAtRate( int atRate ) { has_[AtRate] = true; atRate_ = atRate; };         
00091         
00092         int atRateTimeToFull() const { assert(has_[AtRateTimeToFull]); return atRateTimeToFull_; };
00093         void setAtRateTimeToFull( int atRateTimeToFull ) { has_[AtRateTimeToFull] = true; atRateTimeToFull_ = atRateTimeToFull; };  
00094            
00095         int atRateTimeToEmpty() const { assert(has_[AtRateTimeToEmpty]); return atRateTimeToEmpty_; };
00096         void setAtRateTimeToEmpty( int atRateTimeToEmpty ) { has_[AtRateTimeToEmpty] = true; atRateTimeToEmpty_ = atRateTimeToEmpty; };  
00097            
00098         bool atRateOk() const { assert(has_[AtRateOk]); return atRateOk_; };
00099         void setAtRateOk( bool atRateOk ) { has_[AtRateOk] = true; atRateOk_ = atRateOk; };  
00100         
00101         double temperature() const { assert(has_[Temperature]); return temperature_; };
00102         void setTemperature( double temperature ) { has_[Temperature] = true; temperature_ = temperature; };
00103         
00104         double voltage() const { assert(has_[Voltage]); return voltage_; };
00105         void setVoltage( double voltage ) { has_[Voltage] = true; voltage_ = voltage; };
00106         
00107         double current() const { assert(has_[Current]); return current_; };
00108         void setCurrent( double current ) { has_[Current] = true; current_ = current; };
00109         
00110         double averageCurrent() const { assert(has_[AverageCurrent]); return averageCurrent_; };
00111         void setAverageCurrent( double averageCurrent ) { has_[AverageCurrent] = true; averageCurrent_ = averageCurrent; };
00112         
00113         int maxError() const { assert(has_[MaxError]); return maxError_; };
00114         void setMaxError( int maxError ) { has_[MaxError] = true; maxError_ = maxError; };    
00115               
00116         int relativeStateOfCharge() const { assert(has_[RelativeStateOfCharge]); return relativeStateOfCharge_; };
00117         void setRelativeStateOfCharge( int relativeStateOfCharge ) { has_[RelativeStateOfCharge] = true; relativeStateOfCharge_ = relativeStateOfCharge; };  
00118                 
00119         int absoluteStateOfCharge() const { assert(has_[AbsoluteStateOfCharge]); return absoluteStateOfCharge_; };
00120         void setAbsoluteStateOfCharge( int absoluteStateOfCharge ) { has_[AbsoluteStateOfCharge] = true; absoluteStateOfCharge_ = absoluteStateOfCharge; };  
00121         
00122         int remainingCapacity() const { assert(has_[RemainingCapacity]); return remainingCapacity_; };
00123         void setRemainingCapacity( int remainingCapacity ) { has_[RemainingCapacity] = true; remainingCapacity_ = remainingCapacity; };      
00124           
00125         int fullChargeCapacity() const { assert(has_[FullChargeCapacity]); return fullChargeCapacity_; };
00126         void setFullChargeCapacity( int fullChargeCapacity ) { has_[FullChargeCapacity] = true; fullChargeCapacity_ = fullChargeCapacity; };
00127                
00128         int runTimeToEmpty() const { assert(has_[RunTimeToEmpty]); return runTimeToEmpty_; };
00129         void setRunTimeToEmpty( int runTimeToEmpty ) { has_[RunTimeToEmpty] = true; runTimeToEmpty_ = runTimeToEmpty; };                
00130          
00131         int averageTimeToEmpty() const { assert(has_[AverageTimeToEmpty]); return averageTimeToEmpty_; };
00132         void setAverageTimeToEmpty( int averageTimeToEmpty ) { has_[AverageTimeToEmpty] = true; averageTimeToEmpty_ = averageTimeToEmpty; };  
00133            
00134         int averageTimeToFull() const { assert(has_[AverageTimeToFull]); return averageTimeToFull_; };
00135         void setAverageTimeToFull( int averageTimeToFull ) { has_[AverageTimeToFull] = true; averageTimeToFull_ = averageTimeToFull; };  
00136             
00137         double chargingCurrent() const { assert(has_[ChargingCurrent]); return chargingCurrent_; };
00138         void setChargingCurrent( double chargingCurrent ) { has_[ChargingCurrent] = true; chargingCurrent_ = chargingCurrent; };      
00139             
00140         double chargingVoltage() const { assert(has_[ChargingVoltage]); return chargingVoltage_; };
00141         void setChargingVoltage( double chargingVoltage ) { has_[ChargingVoltage] = true; chargingVoltage_ = chargingVoltage; };      
00142    
00143         uint16_t batteryStatus() const { assert(has_[BatteryStatus]); return batteryStatus_; };
00144         void setBatteryStatus( uint16_t batteryStatus ) { has_[BatteryStatus] = true; batteryStatus_ = batteryStatus; };       
00145              
00146         int cycleCount() const { assert(has_[CycleCount]); return cycleCount_; };
00147         void setCycleCount( int cycleCount ) { has_[CycleCount] = true; cycleCount_ = cycleCount; };  
00148              
00149         int designCapacity() const { assert(has_[DesignCapacity]); return designCapacity_; };
00150         void setDesignCapacity( int designCapacity ) { has_[DesignCapacity] = true; designCapacity_ = designCapacity; };      
00151                
00152         double designVoltage() const { assert(has_[DesignVoltage]); return designVoltage_; };
00153         void setDesignVoltage( double designVoltage ) { has_[DesignVoltage] = true; designVoltage_ = designVoltage; };   
00154            
00155         uint16_t specificationInfo() const { assert(has_[SpecificationInfo]); return specificationInfo_; };
00156         void setSpecificationInfo( uint16_t specificationInfo ) { has_[SpecificationInfo] = true; specificationInfo_ = specificationInfo; };       
00157             
00158         uint16_t manufactureDate() const { assert(has_[ManufactureDate]); return manufactureDate_; };
00159         void setManufactureDate ( uint16_t manufactureDate ) { has_[ManufactureDate] = true; manufactureDate_ = manufactureDate; };       
00160               
00161         int serialNumber() const { assert(has_[SerialNumber]); return serialNumber_; };
00162         void setSerialNumber( int serialNumber ) { has_[SerialNumber] = true; serialNumber_ = serialNumber; };  
00163         
00164         const std::string manufacturerName() const { assert(has_[ManufacturerName]); return manufacturerName_; };
00165         void setManufacturerName( std::string manufacturerName ) { has_[ManufacturerName] = true;  manufacturerName_ = manufacturerName; };
00166            
00167         const std::string deviceName() const { assert(has_[DeviceName]); return deviceName_; };
00168         void setDeviceName( std::string deviceName ) { has_[DeviceName] = true;  deviceName_ = deviceName; };
00169              
00170         const std::string deviceChemistry() const { assert(has_[DeviceChemistry]); return deviceChemistry_; };
00171         void setDeviceChemistry( std::string deviceChemistry ) { has_[DeviceChemistry] = true;  deviceChemistry_ = deviceChemistry; };
00172                   
00173         uint16_t manufacturerData() const { assert(has_[ManufacturerData]); return manufacturerData_; };
00174         void setManufacturerData( uint16_t manufacturerData ) { has_[ManufacturerData] = true; manufacturerData_ = manufacturerData; };       
00175       
00176     private:
00177         
00178         std::vector<bool> has_;
00179         
00180         uint16_t manufacturerAccess_;       // manufacturer specific
00181         int remainingCapacityAlarm_;        // mAh or 10 mWh
00182         int remainingTimeAlarm_;            // min
00183         uint16_t batteryMode_;              // flags, see specs
00184         int atRate_;                        // mA or 10 mW
00185         int atRateTimeToFull_;              // min
00186         int atRateTimeToEmpty_;             // min
00187         bool atRateOk_;                     // bool
00188         double temperature_;                // Celsius
00189         double voltage_;                    // V
00190         double current_;                    // A
00191         double averageCurrent_;             // A
00192         int maxError_;                      // percent
00193         int relativeStateOfCharge_;         // percent
00194         int absoluteStateOfCharge_;         // percent
00195         int remainingCapacity_;             // mAh or 10 mWh
00196         int fullChargeCapacity_;            // mAh or 10 mWh
00197         int runTimeToEmpty_;                // min
00198         int averageTimeToEmpty_;            // min
00199         int averageTimeToFull_;             // min
00200         double chargingCurrent_;            // A
00201         double chargingVoltage_;            // V
00202         uint16_t batteryStatus_;            // flags, see specs
00203         int cycleCount_;                    // count
00204         int designCapacity_;                // mAh or 10 mWh
00205         double designVoltage_;              // V
00206         uint16_t specificationInfo_;        // flags, see specs
00207         uint16_t manufactureDate_;          // raw, see specs
00208         int serialNumber_;                  // number
00209         std::string manufacturerName_;
00210         std::string deviceName_;
00211         std::string deviceChemistry_;
00212         uint16_t manufacturerData_;         // manufacturer specific
00213         
00214         
00215 };
00216 
00218 std::string toString( const SmartBattery &b );
00219 
00221 std::string toLogString( const SmartBattery &b );
00222 
00223 }
00224 
00225 #endif
00226 
 

Generated for GearBox by  doxygen 1.4.5