list_devices.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include "epos_hardware/utils.h"
00003 #include "epos_library/Definitions.h"
00004 #include <boost/foreach.hpp>
00005 
00006 int main(int argc, char** argv){
00007   bool skip_rs232 = true;
00008   if(argc == 2){
00009     if(!strcmp(argv[1], "--rs232"))
00010       skip_rs232 = false;
00011     else{
00012       std::cerr << "unknown option: " << argv[1] << std::endl;
00013       return 1;
00014     }
00015   }
00016   else if(argc > 1){
00017     std::cerr << "unknown options" << std::endl;
00018     return 1;
00019   }
00020 
00021   std::string error_string;
00022   unsigned int error_code = 0;
00023 
00024   EposFactory epos_factory;
00025 
00026   std::cout << "Listing Devices:" << std::endl;
00027 
00028   std::vector<std::string> device_names;
00029   if(GetDeviceNameList(&device_names, &error_code)) {
00030     BOOST_FOREACH(const std::string& device_name, device_names) {
00031       std::cout << device_name <<std::endl;
00032 
00033       std::vector<std::string> protocol_stack_names;
00034       if(GetProtocolStackNameList(device_name, &protocol_stack_names, &error_code)) {
00035         BOOST_FOREACH(const std::string& protocol_stack_name, protocol_stack_names) {
00036           std::cout << "\t" << protocol_stack_name <<std::endl;
00037 
00038           std::vector<std::string> interface_names;
00039           if(GetInterfaceNameList(device_name, protocol_stack_name, &interface_names, &error_code)) {
00040             BOOST_FOREACH(const std::string& interface_name, interface_names) {
00041               std::cout << "\t\t" << interface_name <<std::endl;
00042               if(skip_rs232 && interface_name == "RS232"){
00043                 std::cout << "\t\t\tSkipping RS232" <<std::endl;
00044                 continue;
00045               }
00046 
00047               std::vector<std::string> port_names;
00048               if(GetPortNameList(device_name, protocol_stack_name, interface_name, &port_names, &error_code)) {
00049                 BOOST_FOREACH(const std::string& port_name, port_names) {
00050                   std::cout << "\t\t\t" << port_name <<std::endl;
00051 
00052                   std::vector<unsigned int> baudrates;
00053                   if(GetBaudrateList(device_name, protocol_stack_name, interface_name, port_name, &baudrates, &error_code)) {
00054                     std::cout << "\t\t\t\tBaudrates:" << std::endl;
00055                     BOOST_FOREACH(unsigned int baudrate, baudrates) {
00056                       std::cout << "\t\t\t\t\t" << std::dec << baudrate <<std::endl;
00057                     }
00058 
00059                     std::vector<EnumeratedNode> devices;
00060                     if(epos_factory.EnumerateNodes(device_name, protocol_stack_name, interface_name, port_name, &devices, &error_code)) {
00061                       std::cout << "\t\t\t\tDevices:" << std::endl;
00062                       BOOST_FOREACH(const EnumeratedNode& node, devices) {
00063                         std::cout << "\t\t\t\t\tNode Id: " << std::dec << node.node_id << std::endl;
00064                         std::cout << "\t\t\t\t\t\tSerial Number: 0x" << std::hex << node.serial_number << std::endl;
00065                         std::cout << "\t\t\t\t\t\tHardware Version: 0x" << std::hex << node.hardware_version << std::endl;
00066                         std::cout << "\t\t\t\t\t\tSoftware Version: 0x" << std::hex << node.software_version << std::endl;
00067                         std::cout << "\t\t\t\t\t\tApplication Number: 0x" << std::hex << node.application_number << std::endl;
00068                         std::cout << "\t\t\t\t\t\tApplication Version: 0x" << std::hex << node.application_version << std::endl;
00069                       }
00070                     }
00071                     else {
00072                       if(GetErrorInfo(error_code, &error_string)){
00073                         std::cerr << "Could not enumerate devices: " << error_string << std::endl;
00074                       } else {
00075                         std::cerr << "Could not enumerate devices" << std::endl;
00076                       }
00077                     }
00078 
00079                   }
00080                   else {
00081                     if(GetErrorInfo(error_code, &error_string)){
00082                       std::cerr << "Could not get baudrates: " << error_string << std::endl;
00083                     } else {
00084                       std::cerr << "Could not get baudrates" << std::endl;
00085                     }
00086                   }
00087 
00088                 }
00089               }
00090               else {
00091                 if(GetErrorInfo(error_code, &error_string)){
00092                   std::cerr << "Could not get port names: " << error_string << std::endl;
00093                 } else {
00094                   std::cerr << "Could not get port names" << std::endl;
00095                 }
00096               }
00097 
00098             }
00099           }
00100           else {
00101             if(GetErrorInfo(error_code, &error_string)){
00102               std::cerr << "Could not get interface names: " << error_string << std::endl;
00103             } else {
00104               std::cerr << "Could not get interface names" << std::endl;
00105             }
00106           }
00107 
00108         }
00109       }
00110       else {
00111         if(GetErrorInfo(error_code, &error_string)){
00112           std::cerr << "Could not get protocol stack names: " << error_string << std::endl;
00113         } else {
00114           std::cerr << "Could not get protocol stack names" << std::endl;
00115         }
00116       }
00117 
00118     }
00119   }
00120   else {
00121     if(GetErrorInfo(error_code, &error_string)){
00122       std::cerr << "Could not get device names: " << error_string << std::endl;
00123     } else {
00124       std::cerr << "Could not get device names" << std::endl;
00125     }
00126   }
00127 }


epos_hardware
Author(s): Mitchell Wills
autogenerated on Thu Jun 6 2019 20:43:10