Loading [MathJax]/jax/output/HTML-CSS/config.js
iCub-main
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
bcbBattery.h
Go to the documentation of this file.
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3// Copyright: (C) 2015 iCub Facility
4// Authors: Marco Randazzo <marco.randazzo@iit.it>
5// CopyPolicy: Released under the terms of the GNU GPL v2.0.
6
7#ifndef __BCBBATTERY_H__
8#define __BCBBATTERY_H__
9
10#include <mutex>
11#include <yarp/conf/version.h>
12#include <yarp/os/PeriodicThread.h>
13#include <yarp/dev/IBattery.h>
14#include <yarp/dev/PolyDriver.h>
15#include <yarp/dev/ISerialDevice.h>
16#include <yarp/os/ResourceFinder.h>
17#include <yarp/sig/Vector.h>
18#include <regex>
19
20// This is to provide compatibility with both YARP 3.11 and 3.12
22
23using namespace yarp::os;
24using namespace yarp::dev;
25
26class batteryReaderThread : public PeriodicThread
27{
28 public:
29 //debug
30 static const int debugTextBufferSize = 10000;
32
33 //configuration options
34 bool verboseEnable = false;
35 bool screenEnable = true;
36
37 //the buffer
38 double timeStamp;
39 static const int buff_len = 10000;
40 unsigned char tmp_buff[buff_len];
41 static const int packet_len =10;
42 unsigned char packet[packet_len];
43 std::regex r_exp;
44
45 ISerialDevice* iSerial = nullptr;
46 std::mutex datamut;
47 double battery_charge = 0;
48 double battery_voltage = 0;
49 double battery_current = 0;
50 std::string battery_info = "icub battery system v1.0";
52 IBattery::Battery_status battery_status = IBattery::Battery_status::BATTERY_OK_STANDBY;
53
54 batteryReaderThread (ISerialDevice *_iSerial, double period) :
55 PeriodicThread((double)period),
56 iSerial(_iSerial)
57 {
58 // the following regedit expressions means: search for an occurrence of the pattern:
59 // \0........\r\n which is not followed by any other occurrence of the same pattern.
60 // See for example: https://docs.pexip.com/admin/regex_reference.htm
61 //
62 // 01234567 8 9***** 01234567 8 9
63 std::string c_exp ("\\0.......\\r\\n(?!.*\\0.......\\r\\n)");
64 r_exp=c_exp;
65 }
66
67 void startTransmission();
68 void stopTransmission();
69 virtual bool threadInit() override;
70 virtual void threadRelease() override;
71 virtual void run() override;
72};
73
74class BcbBattery: public yarp::dev::IBattery, public DeviceDriver
75{
76protected:
78
79 ResourceFinder rf;
80 PolyDriver driver;
81 ISerialDevice *iSerial = nullptr;
82
83public:
86
87 virtual bool open(yarp::os::Searchable& config);
88 virtual bool close();
89
90 virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryVoltage (double &voltage) override;
91 virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryCurrent (double &current) override;
92 virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryCharge (double &charge) override;
93 virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryStatus (Battery_status &status) override;
94 virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryInfo (std::string &info) override;
95 virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryTemperature (double &temperature) override;
96};
97
98
99#endif
#define YARP_DEV_RETURN_VALUE_TYPE_CH312
virtual bool close()
ISerialDevice * iSerial
Definition bcbBattery.h:81
ResourceFinder rf
Definition bcbBattery.h:79
PolyDriver driver
Definition bcbBattery.h:80
virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryCurrent(double &current) override
virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryVoltage(double &voltage) override
virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryCharge(double &charge) override
virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryStatus(Battery_status &status) override
virtual bool open(yarp::os::Searchable &config)
batteryReaderThread * batteryReader
Definition bcbBattery.h:77
virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryInfo(std::string &info) override
virtual YARP_DEV_RETURN_VALUE_TYPE_CH312 getBatteryTemperature(double &temperature) override
IBattery::Battery_status battery_status
Definition bcbBattery.h:52
virtual void run() override
ISerialDevice * iSerial
Definition bcbBattery.h:45
virtual void threadRelease() override
virtual bool threadInit() override
unsigned char packet[packet_len]
Definition bcbBattery.h:42
batteryReaderThread(ISerialDevice *_iSerial, double period)
Definition bcbBattery.h:54
std::mutex datamut
Definition bcbBattery.h:46
char debugTextBuffer[debugTextBufferSize]
Definition bcbBattery.h:31
static const int debugTextBufferSize
Definition bcbBattery.h:30
unsigned char tmp_buff[buff_len]
Definition bcbBattery.h:40
std::string battery_info
Definition bcbBattery.h:50
static const int packet_len
Definition bcbBattery.h:41
static const int buff_len
Definition bcbBattery.h:39