teo_battery_monitor_driver.cpp
Go to the documentation of this file.
00001 #include "teo_battery_monitor_driver.h"
00002 #include "exceptions.h"
00003 
00004 TeoBatteryMonitorDriver::TeoBatteryMonitorDriver(void)
00005 {
00006   //setDriverId(driver string id);
00007   this->battery=NULL;
00008   this->serial_num="";
00009 }
00010 
00011 bool TeoBatteryMonitorDriver::openDriver(void)
00012 {
00013   //setDriverId(driver string id);
00014   if(this->serial_num!="")
00015   {
00016     try{
00017       ROS_INFO("opening");
00018       this->battery=new CSegway_Battery(this->serial_num);
00019       // add the default alarms
00020       this->low_capacity="low_capacity_alarm";
00021       this->low_capacity_event_id=this->battery->create_alarm(low_capacity,this->low_capacity_condition);
00022       return true;
00023     }catch(CException &e){
00024       ROS_INFO("[teo_battery_monitor] - %s",e.what().c_str());
00025       return false;
00026     }
00027   }
00028   else
00029     return false;
00030 }
00031 
00032 bool TeoBatteryMonitorDriver::closeDriver(void)
00033 {
00034   if(this->battery!=NULL)
00035   {
00036     delete this->battery;
00037     this->battery=NULL;
00038   }
00039 
00040   return true;
00041 }
00042 
00043 bool TeoBatteryMonitorDriver::startDriver(void)
00044 {
00045   return true;
00046 }
00047 
00048 bool TeoBatteryMonitorDriver::stopDriver(void)
00049 {
00050   return true;
00051 }
00052 
00053 void TeoBatteryMonitorDriver::config_update(Config& new_cfg, uint32_t level)
00054 {
00055   this->lock();
00056   
00057   // depending on current state
00058   // update driver with new_cfg data
00059   switch(this->getState())
00060   {
00061     case TeoBatteryMonitorDriver::CLOSED:
00062       this->serial_num=new_cfg.serial_num;
00063       break;
00064 
00065     case TeoBatteryMonitorDriver::OPENED:
00066       break;
00067 
00068     case TeoBatteryMonitorDriver::RUNNING:
00069       break;
00070   }
00071 
00072   // save the current configuration
00073   this->config_=new_cfg;
00074 
00075   this->unlock();
00076 }
00077 
00078 bool TeoBatteryMonitorDriver::check_alarms(void)
00079 {
00080   CEventServer *event_server=CEventServer::instance();
00081 
00082   if(event_server->event_is_set(this->low_capacity_event_id))
00083     return true;
00084   else
00085     return false;
00086 }
00087 
00088 void TeoBatteryMonitorDriver::get_battery_info(TBatteryInfo *info)
00089 {
00090   this->battery->get_battery_info(info);  
00091 }
00092 
00093 bool TeoBatteryMonitorDriver::low_capacity_condition(TBatteryInfo *info)
00094 {
00095   if(info->rem_capacity<1000)
00096     return true;
00097   else
00098     return false;
00099 }
00100 
00101 TeoBatteryMonitorDriver::~TeoBatteryMonitorDriver(void)
00102 {
00103 }


teo_battery_monitor
Author(s): Sergi Hernandez Juan
autogenerated on Fri Dec 6 2013 23:09:52