iCub-main
batteryInfo.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  * Author: Luca Tricerri
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #include "batteryInfo.h"
10 
11 #include <yarp/os/Log.h>
12 #include <yarp/os/LogStream.h>
13 
14 bool BatteryInfo::toEomn(eOas_battery_sensordescriptor_t& out) const
15 {
16  out.boardinfo.type = board;
17  out.canloc.addr = address;
18  out.canloc.insideindex = eobrd_caninsideindex_none;
19  out.boardinfo.firmware = {(uint8_t)majorFirmware, (uint8_t)minorFirmware, (uint8_t)buildFirmware};
20  out.boardinfo.protocol = {(uint8_t)majorProtocol, (uint8_t)minorProtocol};
21 
22  try
23  {
24  if (port == 1)
25  out.canloc.port = eOcanport1;
26  else if (port == 2)
27  out.canloc.port = eOcanport2;
28  else
29  {
30  yError() << "BatteryInfo::toEomn() invalid can port";
31  out = eOas_battery_sensordescriptor_t();
32  return false;
33  }
34  }
35  catch (const std::exception& e)
36  {
37  yError() << "BatteryInfo::toEomn() invalid can port";
38  out = eOas_battery_sensordescriptor_t();
39  return false;
40  }
41  return true;
42 }
43 
44 bool operator==(const BatteryInfo& right, const BatteryInfo& left)
45 {
46  if (right.acquisitionRate != left.acquisitionRate)
47  return false;
48  if (right.board != left.board)
49  return false;
50  if (right.port != left.port)
51  return false;
52  if (right.address != left.address)
53  return false;
54  if (right.majorProtocol != left.majorProtocol)
55  return false;
56  if (right.minorProtocol != left.minorProtocol)
57  return false;
58  if (right.majorFirmware != left.majorFirmware)
59  return false;
60  if (right.minorFirmware != left.minorFirmware)
61  return false;
62  if (right.buildFirmware != left.buildFirmware)
63  return false;
64  return true;
65 };
66 
67 bool operator!=(const BatteryInfo& right, const BatteryInfo& left)
68 {
69  return !(right == left);
70 }
bool operator!=(const BatteryInfo &right, const BatteryInfo &left)
Definition: batteryInfo.cpp:67
bool operator==(const BatteryInfo &right, const BatteryInfo &left)
Definition: batteryInfo.cpp:44
int buildFirmware
Definition: batteryInfo.h:27
int minorProtocol
Definition: batteryInfo.h:24
bool toEomn(eOas_battery_sensordescriptor_t &out) const
Definition: batteryInfo.cpp:14
eObrd_type_t board
Definition: batteryInfo.h:20
int minorFirmware
Definition: batteryInfo.h:26
uint8_t acquisitionRate
Definition: batteryInfo.h:19
int majorProtocol
Definition: batteryInfo.h:23
int majorFirmware
Definition: batteryInfo.h:25
out
Definition: sine.m:8