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

Generated for GearBox by  doxygen 1.4.5