9#include <yarp/os/Time.h>
10#include <yarp/os/LogStream.h>
11#include <yarp/os/Log.h>
25 yDebug(
"%s\n", config.toString().c_str());
27 Bottle& group_general = config.findGroup(
"GENERAL");
28 Bottle& group_serial = config.findGroup(
"SERIAL_PORT");
30 if (group_general.isNull())
32 yError() <<
"Insufficient parameters to BmsBattery, section GENERAL missing";
36 if (group_serial.isNull())
38 yError() <<
"Insufficient parameters to BmsBattery, section SERIAL_PORT missing";
42 int period=config.find(
"thread_period").asInt32();
43 setPeriod((
double)period/1000.0);
46 std::string ps = group_serial.toString();
48 prop.put(
"device",
"serialport");
54 yError() <<
"Error opening PolyDriver check parameters";
64 yError(
"Error opening serial driver. Device not available");
71 this->
verboseEnable = group_general.check(
"verbose", Value(0),
"enable/disable the verbose mode").asBool();
72 this->
screenEnable = group_general.check(
"screen", Value(0),
"enable/disable the screen output").asBool();
73 this->
debugEnable = group_general.check(
"debug", Value(0),
"enable/disable the debug mode").asBool();
75 PeriodicThread::start();
82 PeriodicThread::stop();
102bool BmsBattery::verify_checksum(
int& raw_battery_current,
int& raw_battery_voltage,
int& raw_battery_charge,
int& raw_battery_checksum)
104 if (raw_battery_checksum == raw_battery_current + raw_battery_voltage + raw_battery_charge)
111 double timeNow=yarp::os::Time::now();
112 lock_guard<mutex> lck(
mtx);
133 bool reading_ok =
false;
137 int raw_battery_current = 0;
138 int raw_battery_voltage = 0;
139 int raw_battery_charge = 0;
140 int raw_battery_checksum = 0;
141 pars = sscanf(
serial_buff,
"%*s %d %*s %d %*s %d %*s %d", &raw_battery_current, &raw_battery_voltage, &raw_battery_charge, &raw_battery_checksum);
145 if (verify_checksum(raw_battery_current, raw_battery_voltage, raw_battery_charge, raw_battery_checksum))
148 struct tm * timeinfo;
150 timeinfo = localtime(&rawtime);
160 yError(
"checksum error while reading battery data\n");
165 yError(
"error reading battery data: %d\n", pars);
174 yDebug(
"BmsBattery::run() log_buffer is: %s", buff);
180 lock_guard<mutex> lck(
mtx);
187 lock_guard<mutex> lck(
mtx);
194 lock_guard<mutex> lck(
mtx);
213 lock_guard<mutex> lck(
mtx);
220 yTrace(
"BmsBattery Thread released\n");
virtual bool getBatteryVoltage(double &voltage)
virtual bool getBatteryTemperature(double &temperature)
virtual bool getBatteryStatus(Battery_status &status)
virtual void threadRelease()
virtual bool open(yarp::os::Searchable &config)
virtual bool getBatteryInfo(std::string &info)
virtual bool threadInit()
virtual bool getBatteryCharge(double &charge)
double battery_temperature
virtual bool getBatteryCurrent(double ¤t)