10 #include <yarp/os/Log.h>
11 #include <yarp/os/LogStream.h>
19 Bottle propertyCanBoard = Bottle(property.findGroup(
"CANBOARDS"));
20 if (propertyCanBoard.isNull())
22 yError() <<
"ServiceParserCanBattery::check() cannot find PROPERTIES.CANBOARDS";
26 Bottle propertyCanBoardType = propertyCanBoard.findGroup(
"type");
27 if (propertyCanBoardType.isNull())
29 yError() <<
"ServiceParserCanBattery::check() cannot find "
30 "PROPERTIES.CANBOARDS.type";
34 Bottle propertyCanBoardProtocol = Bottle(propertyCanBoard.findGroup(
"PROTOCOL"));
35 if (propertyCanBoardProtocol.isNull())
37 yError() <<
"ServiceParserCanBattery::check() cannot find "
38 "PROPERTIES.CANBOARDS.PROTOCOL";
42 Bottle propertyCanBoardProtocolMajor = Bottle(propertyCanBoardProtocol.findGroup(
"major"));
43 if (propertyCanBoardProtocolMajor.isNull())
45 yError() <<
"ServiceParserCanBattery::check() cannot find "
46 "PROPERTIES.CANBOARDS.PROTOCOL.major";
50 Bottle propertyCanBoardProtocolMinor = Bottle(propertyCanBoardProtocol.findGroup(
"minor"));
51 if (propertyCanBoardProtocolMinor.isNull())
53 yError() <<
"ServiceParserCanBattery::check() cannot find "
54 "PROPERTIES.CANBOARDS.PROTOCOL.minor";
58 Bottle propertyCanBoardFirmware = Bottle(propertyCanBoard.findGroup(
"FIRMWARE"));
59 if (propertyCanBoardFirmware.isNull())
61 yError() <<
"ServiceParserCanBattery::check() cannot find "
62 "PROPERTIES.CANBOARDS.FIRMWARE";
66 Bottle propertyCanBoardFirmwareMajor = Bottle(propertyCanBoardFirmware.findGroup(
"major"));
67 if (propertyCanBoardFirmwareMajor.isNull())
69 yError() <<
"ServiceParserCanBattery::check() cannot find "
70 "PROPERTIES.CANBOARDS.FIRMWARE.major";
74 Bottle propertyCanBoardFirmwareMinor = Bottle(propertyCanBoardFirmware.findGroup(
"minor"));
75 if (propertyCanBoardFirmwareMinor.isNull())
77 yError() <<
"ServiceParserCanBattery::check() cannot find "
78 "PROPERTIES.CANBOARDS.FIRMWARE.minor";
82 Bottle propertyCanBoardFirmwareBuild = Bottle(propertyCanBoardFirmware.findGroup(
"build"));
83 if (propertyCanBoardFirmwareBuild.isNull())
85 yError() <<
"ServiceParserCanBattery::check() cannot find "
86 "PROPERTIES.CANBOARDS.FIRMWARE.build";
91 if (propertyCanBoardType.size() != 2)
93 yError() <<
"ServiceParserCanBattery::checkPropertyCanBoards --> protocol type size";
96 if (propertyCanBoardProtocolMajor.size() != 2)
98 yError() <<
"ServiceParserCanBattery::checkPropertyCanBoards --> protocol major size";
101 if (propertyCanBoardProtocolMinor.size() != 2)
103 yError() <<
"ServiceParserCanBattery::checkPropertyCanBoards --> firmware minor size";
106 if (propertyCanBoardFirmwareMajor.size() != 2)
108 yError() <<
"ServiceParserCanBattery::checkPropertyCanBoards --> firmware major size";
111 if (propertyCanBoardFirmwareMinor.size() != 2)
113 yError() <<
"ServiceParserCanBattery::checkPropertyCanBoards --> firmware minor size";
116 if (propertyCanBoardFirmwareBuild.size() != 2)
118 yError() <<
"ServiceParserCanBattery::checkPropertyCanBoards --> firmware build size";
122 std::string boardType = propertyCanBoardType.get(1).asString();
125 if (currentBoard == eobrd_unknown)
139 Bottle propertySensors = Bottle(property.findGroup(
"SENSORS"));
140 if (propertySensors.isNull())
142 yError() <<
"ServiceParserCanBattery::checkPropertySensors() cannot find "
143 "PROPERTIES.SENSORS";
147 Bottle propertySensorsId = Bottle(propertySensors.findGroup(
"id"));
148 if (propertySensorsId.isNull())
150 yError() <<
"ServiceParserCanBattery::checkPropertySensors() cannot find "
151 "PROPERTIES.SENSORS.id";
155 Bottle propertySensorsBoard = Bottle(propertySensors.findGroup(
"board"));
156 if (propertySensorsBoard.isNull())
158 yError() <<
"ServiceParserCanBattery::checkPropertySensors() cannot find "
159 "PROPERTIES.SENSORS.type";
163 Bottle propertySensorsLocation = Bottle(propertySensors.findGroup(
"location"));
164 if (propertySensorsLocation.isNull())
166 yError() <<
"ServiceParserCanBattery::checkPropertySensors() cannot find "
167 "PROPERTIES.SENSORS.location";
172 if (propertySensorsId.size() != 2)
174 yError() <<
"ServiceParserCanBattery::checkPropertySensors --> id size";
177 if (propertySensorsBoard.size() != 2)
179 yError() <<
"ServiceParserCanBattery::checkPropertySensors --> board size";
182 if (propertySensorsLocation.size() != 2)
184 yError() <<
"ServiceParserCanBattery::checkPropertySensors --> location size";
188 std::string
id = propertySensorsId.get(1).asString();
189 std::string
board = propertySensorsBoard.get(1).asString();
191 if (currentBoard == eobrd_unknown)
193 std::string location = propertySensorsLocation.get(1).asString();
199 catch (
const std::exception &)
201 yError() <<
"ServiceParser::checkPropertySensors() invalid can port";
208 catch (
const std::exception &)
210 yError() <<
"ServiceParser::checkPropertySensors() invalid can address";
221 Bottle settings = Bottle(service.findGroup(
"SETTINGS"));
222 if (settings.isNull())
224 yError() <<
"ServiceParserCanBattery::checkSettings() cannot find SETTINGS";
228 Bottle settingsBatteryPeriod = Bottle(settings.findGroup(
"acquisitionRate"));
229 if (settingsBatteryPeriod.isNull())
231 yError() <<
"ServiceParserCanBattery::checkSettings() cannot find "
232 "SETTINGS.acquisitionRate";
236 Bottle settingsEnabledSensors = Bottle(settings.findGroup(
"enabledSensors"));
237 if (settingsEnabledSensors.isNull())
239 yError() <<
"ServiceParserCanBattery::checkSettings() cannot find "
240 "SETTINGS.enabledSensors";
245 int tmp = settingsBatteryPeriod.size();
246 std::string s = settingsBatteryPeriod.toString();
247 if (settingsEnabledSensors.size() != 2)
249 yError() <<
"ServiceParserCanBattery::checkSettings --> enabledSensors";
252 if (settingsBatteryPeriod.size() != 2)
254 yError() <<
"ServiceParserCanBattery::checkSettings --> acquisitionRate"
255 "temperaturePeriod size";
259 uint8_t acquisitionRate = (uint8_t)settingsBatteryPeriod.get(1).asInt8();
266 if (
false == service.check(
"type"))
268 yError() <<
"ServiceParserCanBattery::check() cannot find SERVICE.type";
271 std::string serviceType = service.find(
"type").asString();
272 eOmn_serv_type_t serviceTypeEomn = eomn_string2servicetype(serviceType.c_str());
274 if (eomn_serv_AS_battery != serviceTypeEomn)
276 yError() <<
"ServiceParserCanBattery::check() has found wrong SERVICE.type = " << serviceType <<
"it must be eomn_serv_AS_battery";
284 Bottle service(config.findGroup(
"SERVICE"));
285 if (service.isNull())
287 yError() <<
"ServiceParser::check() cannot find SERVICE group";
291 Bottle properties = Bottle(service.findGroup(
"PROPERTIES"));
292 if (properties.isNull())
294 yError() <<
"ServiceParser::check() cannot find PROPERTIES";
315 EOarray *ar = eo_array_New(eOas_battery_sensors_maxnumber,
sizeof(eOas_battery_sensordescriptor_t), (
void *)(&(
out.arrayofsensors)));
317 eOas_battery_sensordescriptor_t item;
320 yError() <<
"ServiceParserCanBattery::toEomn() wrong data for sensor";
323 eo_array_PushBack(ar, &item);
335 eObrd_type_t type = eoboards_string2type2(boardType.c_str(), eobool_true);
336 if (!eoas_battery_isboardvalid(eoboards_type2cantype(type)))
338 type = eoboards_string2type2(boardType.c_str(), eobool_false);
339 if (!eoas_battery_isboardvalid(eoboards_type2cantype(type)))
341 yError() <<
"checkBoardType --> unsupported board type:" << boardType;
bool toEomn(eOas_battery_sensordescriptor_t &out) const
ServiceParserCanBattery()
virtual bool checkSettings(const Bottle &settings)
bool parse(const yarp::os::Searchable &config)
virtual bool checkPropertySensors(const Bottle &property)
BatteryInfo & getBatteryInfo()
bool toEomn(eOmn_serv_config_data_as_battery_t &out) const
virtual eObrd_type_t checkBoardType(const std::string &boardType)
virtual bool checkServiceType(const Bottle &service)
virtual bool checkPropertyCanBoards(const Bottle &bPropertiesCanBoards)