From 99599a6c21eb38bcb249af0d368a77fdd1f5e652 Mon Sep 17 00:00:00 2001 From: "ishak jmilou.ishak" Date: Tue, 21 Jan 2025 12:23:20 +0100 Subject: [PATCH] refactor: change portname parameter to const char* in startCommunication and improve USB device check logic --- src/C++/Driver/src/KobukiDriver/CKobuki.h | 2 +- src/C++/Driver/src/main.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/C++/Driver/src/KobukiDriver/CKobuki.h b/src/C++/Driver/src/KobukiDriver/CKobuki.h index f4df897..18c93c4 100755 --- a/src/C++/Driver/src/KobukiDriver/CKobuki.h +++ b/src/C++/Driver/src/KobukiDriver/CKobuki.h @@ -59,7 +59,7 @@ public: long loop(void *user_data, TKobukiData &Kobuki_data); - void startCommunication(char *portname,bool CommandsEnabled,void *userDataL); + void startCommunication(const char *portname,bool CommandsEnabled,void *userDataL); int measure(); //thread function, contains an infinite loop and reads data void setLed(int led1 = 0, int led2 = 0); //led1 green/red 2/1, //led2 green/red 2/1 void setTranslationSpeed(int mmpersec); diff --git a/src/C++/Driver/src/main.cpp b/src/C++/Driver/src/main.cpp index 9cb483a..379404d 100644 --- a/src/C++/Driver/src/main.cpp +++ b/src/C++/Driver/src/main.cpp @@ -77,10 +77,9 @@ void checkKobukiConnection() std::lock_guard lock(connectionMutex); std::string port = findKobukiPort(); - // Controleer of het apparaat beschikbaar is - if (!std::ifstream("/dev/ttyUSB0")){ - if (kobuki_connected){ - cout << "Kobuki disconnected: USB device not found." << endl; + if (port.empty()) { + if (kobuki_connected) { + cout << "Kobuki disconnected: No USB device found." << endl; kobuki_connected = false; } std::this_thread::sleep_for(std::chrono::seconds(5)); @@ -95,7 +94,7 @@ void checkKobukiConnection() } cout << "Attempting to reconnect Kobuki..." << endl; - robot.startCommunication(const_cast(port.c_str()), true, nullptr); + robot.startCommunication((port.c_str()), true, nullptr); if (robot.isConnected()){ cout << "Kobuki reconnected successfully!" << endl;