9#include <yarp/os/Time.h>
10#include <yarp/os/LogStream.h>
11#include <yarp/os/Log.h>
23int test_buffer(
unsigned char* tmp_buff,
int buff_len)
27 string s =
"MMN...AABBCCD...EEFFGGH...IILL";
28 strcpy((
char*)(tmp_buff), s.c_str());
29 (tmp_buff)[03] =
'\r'; (tmp_buff)[04] =
'\n'; (tmp_buff)[05] =
'\0';
30 (tmp_buff)[13] =
'\r'; (tmp_buff)[14] =
'\n'; (tmp_buff)[15] =
'\0';
31 (tmp_buff)[23] =
'\r'; (tmp_buff)[24] =
'\n'; (tmp_buff)[25] =
'\0';
32 return (
int)(s.size());
39 yDebug(
"%s\n", config.toString().c_str());
41 Bottle& group_general = config.findGroup(
"GENERAL");
42 Bottle& group_serial = config.findGroup(
"SERIAL_PORT");
44 if (group_general.isNull())
46 yError() <<
"Insufficient parameters to BcbBattery, section GENERAL missing";
50 if (group_serial.isNull())
52 yError() <<
"Insufficient parameters to BcbBattery, section SERIAL_PORT missing";
56 int period=group_general.find(
"thread_period").asInt32();
59 std::string ps = group_serial.toString();
61 prop.put(
"device",
"serialport");
67 yError() <<
"Error opening PolyDriver check parameters";
77 yError(
"Error opening serial driver. Device not available");
115 yInfo(
"BcbBattery starting transmission");
117 yInfo(
"BcbBattery started successfully");
122 yError(
"BcbBattery iSerial == NULL");
132 double timeNow=yarp::os::Time::now();
143 yError(
"BcbBattery iSerial == NULL");
152 for (
size_t i = 0; i < recb; i++)
166 packet[i] = cmatch.str().c_str()[i];
207 struct tm * timeinfo;
209 timeinfo = localtime(&rawtime);
210 char* battery_timestamp = asctime(timeinfo);
213 yDebug(
"BcbBattery::run() log_buffer is: %s", buff);
260 temperature = std::nan(
"");
286 yError(
"BcbBattery problems starting the transmission");
299 bool ret =
iSerial->send(&c, 1);
300 if (ret ==
false) { yError(
"BcbBattery problems while stopping the transmission"); }
virtual bool getBatteryVoltage(double &voltage) override
virtual bool getBatteryTemperature(double &temperature) override
virtual bool open(yarp::os::Searchable &config)
virtual bool getBatteryInfo(std::string &info) override
virtual bool getBatteryCharge(double &charge) override
virtual bool getBatteryCurrent(double ¤t) override
batteryReaderThread * batteryReader
virtual bool getBatteryStatus(Battery_status &status) override
IBattery::Battery_status battery_status
virtual void run() override
virtual void threadRelease() override
virtual bool threadInit() override
unsigned char packet[packet_len]
char debugTextBuffer[debugTextBufferSize]
static const int debugTextBufferSize
unsigned char tmp_buff[buff_len]
static const int packet_len
static const int buff_len