converters/info.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Aldebaran
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 /*
19 * LOCAL includes
20 */
21 #include "info.hpp"
22 #include "../tools/from_any_value.hpp"
23 
24 /*
25 * BOOST includes
26 */
27 #include <boost/assign/list_of.hpp>
28 #include <boost/foreach.hpp>
29 #define for_each BOOST_FOREACH
30 
31 namespace naoqi
32 {
33 namespace converter
34 {
35 
36 InfoConverter::InfoConverter( const std::string& name, float frequency, const qi::SessionPtr& session )
37  : BaseConverter( name, frequency, session ),
38  p_memory_( session->service("ALMemory") )
39 {
40  keys_.push_back("RobotConfig/Head/FullHeadId");
41  keys_.push_back("Device/DeviceList/ChestBoard/BodyId");
42  keys_.push_back("RobotConfig/Body/Type");
43  keys_.push_back("RobotConfig/Body/BaseVersion");
44  keys_.push_back("RobotConfig/Body/Device/LeftArm/Version");
45  keys_.push_back("RobotConfig/Body/Device/RightArm/Version");
46  keys_.push_back("RobotConfig/Body/Device/Hand/Left/Version");
47  keys_.push_back("RobotConfig/Body/Version");
48  keys_.push_back("RobotConfig/Body/SoftwareRequirement");
49  keys_.push_back("RobotConfig/Body/Device/Legs/Version");
50  if(robot_ == robot::PEPPER)
51  {
52  keys_.push_back("Device/DeviceList/BatteryFuelGauge/SerialNumber");
53  keys_.push_back("Device/DeviceList/BatteryFuelGauge/FirmwareVersion");
54  keys_.push_back("RobotConfig/Body/Device/Platform/Version");
55  keys_.push_back("RobotConfig/Body/Device/Brakes/Version");
56  keys_.push_back("RobotConfig/Body/Device/Wheel/Version");
57  }
58 }
59 
61 {
62 }
63 
65 {
66  callbacks_[action] = cb;
67 }
68 
69 void InfoConverter::callAll( const std::vector<message_actions::MessageAction>& actions )
70 {
71  std::vector<std::string> values;
72  try {
73  qi::AnyValue anyvalues = p_memory_.call<qi::AnyValue>("getListData", keys_);
74  tools::fromAnyValueToStringVector(anyvalues, values);
75  } catch (const std::exception& e) {
76  std::cerr << "Exception caught in InfoConverter: " << e.what() << std::endl;
77  return;
78  }
79 
80  naoqi_bridge_msgs::StringStamped msg;
81 
82  msg.header.stamp = ros::Time::now();
83  for(size_t i = 0; i < keys_.size(); ++i)
84  {
85  msg.data += keys_[i] + ": " + values[i];
86  if (i != keys_.size()-1)
87  msg.data += " ; ";
88  }
90  {
91  callbacks_[action](msg);
92  }
93 }
94 
95 } // converter
96 } //naoqi
msg
void registerCallback(const message_actions::MessageAction action, Callback_t cb)
std::vector< std::string > fromAnyValueToStringVector(qi::AnyValue &value, std::vector< std::string > &result)
std::vector< double > values
InfoConverter(const std::string &name, float frequency, const qi::SessionPtr &sessions)
std::map< message_actions::MessageAction, Callback_t > callbacks_
action
boost::function< void(naoqi_bridge_msgs::StringStamped)> Callback_t
std::vector< std::string > keys_
void callAll(const std::vector< message_actions::MessageAction > &actions)
static Time now()
#define for_each


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sat Feb 15 2020 03:24:26