26 #include <urdf/model.h>
28 #include <ros/package.h>
30 #include <libxml/encoding.h>
31 #include <libxml/xmlwriter.h>
32 #include <libxml/tree.h>
33 #include <libxml/parser.h>
34 #include <libxml/xpath.h>
35 #include <libxml/xpathInternals.h>
36 #include <libxml/xmlreader.h>
41 using namespace boost;
44 vector<shared_ptr<class_udev_control> >
devices;
59 string*
id=(
string*)data;
60 nh->setParam(
"/device_mapper/"+*
id,node);
61 cout<<
"Added device id: "<<*
id<<
" in node "<<node<<
" action: "<<action<<endl;
74 string*
id=(
string*)data;
75 nh->setParam(
"/device_mapper/"+*
id,
"Not found");
76 cout<<
"Removed device id: "<<*
id<<
" in node "<<node<<
" action: "<<action<<endl;
86 void GetName(xmlTextReaderPtr reader,
string& str)
88 xmlChar*name=xmlTextReaderName(reader);
103 xmlChar*value=xmlTextReaderValue(reader);
117 void GetAttribute(xmlTextReaderPtr reader,
const xmlChar*name,
string& str)
119 xmlChar*attribute=xmlTextReaderGetAttribute(reader,name);
120 if(!attribute)
return;
121 str=(
char*)attribute;
143 if(name==
"SENSOR" && xmlTextReaderNodeType(reader)==1)
156 if(name==
"DEVICE_INFORMATION" && xmlTextReaderNodeType(reader)==1)
160 int ret = xmlTextReaderRead(reader);
163 ret=xmlTextReaderRead(reader);
167 if(xmlTextReaderNodeType(reader)==1)
169 ret=xmlTextReaderRead(reader);
173 shared_ptr<class_udev_control> dev =
devices.back();
175 if(name==
"SUBSYSTEM")
176 dev->AddSubsystem(value);
178 dev->AddProperty(name,value);
181 if(name==
"DEVICE_INFORMATION" && xmlTextReaderNodeType(reader)==15)
188 int main(
int argc,
char** argv)
190 std::string urdf_file;
193 std::string urdf_file_default = ros::package::getPath(
"atlascar_base") +
"/urdf/atlascar_urdf_3dsmodels.xml";
196 init(argc,argv,
"device_mapper");
198 nh=
new NodeHandle(
"~");
199 nh->param(
"robot_urdf_path",urdf_file,urdf_file_default);
202 xmlTextReaderPtr reader = xmlNewTextReaderFilename(urdf_file.c_str());
207 ret=xmlTextReaderRead(reader);
211 xmlFreeTextReader(reader);
214 ROS_ERROR(
"Failed to parse file");
219 ROS_ERROR(
"Failed to parse file");
223 for(uint i=0;i<
devices.size();i++)
226 devices[i]->EnumerateDevices();
232 if (
devices[i]->GetPath()==
"Not found")
234 ROS_ERROR(
"Device Mapper Error: device %s was not found. Is the equipment connected?", (
devices[i]->GetId()).c_str());
244 for(uint i=0;i<
devices.size();i++)
NodeHandle * nh
Local node handler.
void GetName(xmlTextReaderPtr reader, string &str)
Get the name of a xml element.
void AddCallback(string action, string node, void *data)
Device add callback.
Class that simplifies the implementation of the udev library.
int main(int argc, char **argv)
void GetValue(xmlTextReaderPtr reader, string &str)
Get the value of a xml element.
void NodeHandler(xmlTextReaderPtr reader)
Handler of xml nodes, heavy duty function.
void GetAttribute(xmlTextReaderPtr reader, const xmlChar *name, string &str)
Get the value of an attribute in a xml element.
void RemoveCallback(string action, string node, void *data)
Device remove callback.
vector< shared_ptr< class_udev_control > > devices
Vector of the connected devices udev classes.
This class simplifies the implementation of the udev library.