From 585af1bbea6b41a4de8f599d0948dcacd835901a Mon Sep 17 00:00:00 2001
From: Raphael Grimm <raphael.grimm@kit.edu>
Date: Tue, 13 Oct 2020 14:18:59 +0200
Subject: [PATCH] Output debug info

---
 .../libraries/ArmarXEtherCAT/EtherCAT.cpp     | 34 +++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/source/RobotAPI/libraries/ArmarXEtherCAT/EtherCAT.cpp b/source/RobotAPI/libraries/ArmarXEtherCAT/EtherCAT.cpp
index 4722be8e0..d5f96c40a 100644
--- a/source/RobotAPI/libraries/ArmarXEtherCAT/EtherCAT.cpp
+++ b/source/RobotAPI/libraries/ArmarXEtherCAT/EtherCAT.cpp
@@ -31,6 +31,7 @@
 #include <ethercatmain.h>
 #include <ethercatbase.h>
 #include <ArmarXCore/core/util/OnScopeExit.h>
+#include <ArmarXCore/util/CPPUtility/Iterator.h>
 
 //EtherCAT definitions only used for the ethercat stuff
 #define SDO_READ_TIMEOUT 100000
@@ -439,18 +440,44 @@ std::pair<std::vector<ControlDevicePtr>, std::vector<SensorDevicePtr>> EtherCAT:
     {
         throw LocalException("no robot Container set! set a robotContainer before you start the bus!");
     }
+    //dump infos about the device container
+    {
+        ARMARX_DEBUG << "device container:\n#functional devices"
+                     << deviceContainerPtr->getAllFunctionalDevices().size()
+                     << ARMARX_STREAM_PRINTER
+        {
+            const auto devs = deviceContainerPtr->getAllFunctionalDevices();
+            for (const auto& [idx, dev] : MakeIndexedContainer(devs))
+            {
+                out << "\n    idx " << idx
+                    << " initialized " << dev->isInitialized()
+                    << " class: " << dev->getClassName()
+                    << "\n        cfg nodes:";
+                for (const auto& c : dev->getNode().getChildPaths())
+                {
+                    out << "\n            " << c;
+                }
+            }
+        };
+    }
+
     auto etherCATFactoryNames = EtherCATDeviceFactory::getAvailableClasses();
-    ARMARX_INFO << "PPP: " << etherCATFactoryNames;
+    ARMARX_INFO << "etherCATFactoryNames: " << etherCATFactoryNames;
     std::map<std::string, std::vector<uint16_t>> devicesOfType;
     for (uint16_t currentSlaveIndex = 1; currentSlaveIndex <= ec_slavecount; currentSlaveIndex++)
     {
+        ARMARX_TRACE;
         const std::string messageSlaveIdentifier = "[Slave index: " + std::to_string(currentSlaveIndex) + "] ";
         //DEBUG for EtherCAT HUB
         //check the device type to identify the EtherCAT Hub
         //        uint32 deviceType = ETHTERCAT_HUB_DEVICE_TYPE;
         //uint32 vendorID = 0;
-        ARMARX_INFO << messageSlaveIdentifier << " device type: " <<  ec_slave[currentSlaveIndex].Dtype << "\n itype: " << std::hex << ec_slave[currentSlaveIndex].Itype <<
-                    "\neep_id: " << ec_slave[currentSlaveIndex].eep_id << "\neep_man: " << ec_slave[currentSlaveIndex].eep_man << "\neep_rev: " << ec_slave[currentSlaveIndex].eep_rev;
+        ARMARX_INFO << messageSlaveIdentifier << '\n'
+                    << "device type: " << std::hex << "0x" << ec_slave[currentSlaveIndex].Dtype   << std::dec << " (dec: " << ec_slave[currentSlaveIndex].Dtype   << ")\n"
+                    << "itype:       " << std::hex << "0x" << ec_slave[currentSlaveIndex].Itype   << std::dec << " (dec: " << ec_slave[currentSlaveIndex].Itype   << ")\n"
+                    << "eep_id:      " << std::hex << "0x" << ec_slave[currentSlaveIndex].eep_id  << std::dec << " (dec: " << ec_slave[currentSlaveIndex].eep_id  << ")\n"
+                    << "eep_man:     " << std::hex << "0x" << ec_slave[currentSlaveIndex].eep_man << std::dec << " (dec: " << ec_slave[currentSlaveIndex].eep_man << ")\n"
+                    << "eep_rev:     " << std::hex << "0x" << ec_slave[currentSlaveIndex].eep_rev << std::dec << " (dec: " << ec_slave[currentSlaveIndex].eep_rev << ")\n";
         ARMARX_INFO << messageSlaveIdentifier << "CoE details " << (int)(ec_slave[currentSlaveIndex].mbx_proto & ECT_MBXPROT_COE);
 
         bool foundDevice = false;
@@ -460,6 +487,7 @@ std::pair<std::vector<ControlDevicePtr>, std::vector<SensorDevicePtr>> EtherCAT:
             {
                 ARMARX_INFO << "Trying factory " << facName;
                 auto device = EtherCATDeviceFactory::fromName(facName, std::make_tuple(this, currentSlaveIndex, deviceContainerPtr));
+                ARMARX_INFO << "Device is " << device.get();
                 if (device)
                 {
                     devicesOfType[device->getClassName()].emplace_back(currentSlaveIndex);
-- 
GitLab