From 2faa8f6782a2e6294ed8849048a281d12d60da1c Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 4 Dec 2017 16:29:56 +0100 Subject: Initial support for multiple devices with C++ and test Signed-off-by: Szczepan Zalega --- device.cc | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'device.cc') diff --git a/device.cc b/device.cc index ac31b1d..5a83e2e 100644 --- a/device.cc +++ b/device.cc @@ -20,6 +20,7 @@ */ #include +#include #include #include #include @@ -92,12 +93,20 @@ bool Device::_connect() { LOG(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); // hid_init(); // done automatically on hid_open - mp_devhandle = hid_open(m_vid, m_pid, nullptr); + if (m_path.empty()){ + mp_devhandle = hid_open(m_vid, m_pid, nullptr); + } else { + mp_devhandle = hid_open_path(m_path.c_str()); + } const bool success = mp_devhandle != nullptr; LOG(std::string("Connection success: ") + std::to_string(success), Loglevel::DEBUG_L2); return success; } +void Device::set_path(const std::string path){ + m_path = path; +} + int Device::send(const void *packet) { LOG(__FUNCTION__, Loglevel::DEBUG_L2); std::lock_guard lock(mex_dev_com); @@ -160,6 +169,24 @@ int Device::recv(void *packet) { return status; } +std::vector Device::enumerate(){ + //TODO make static + auto pInfo = hid_enumerate(m_vid, m_pid); + auto pInfo_ = pInfo; + std::vector res; + while (pInfo != nullptr){ + std::string a (pInfo->path); + res.push_back(a); + pInfo = pInfo->next; + } + + if (pInfo_ != nullptr){ + hid_free_enumeration(pInfo_); + } + + return res; +} + bool Device::could_be_enumerated() { LOG(__FUNCTION__, Loglevel::DEBUG_L2); std::lock_guard lock(mex_dev_com); -- cgit v1.2.1 From 47b2406684683bdee02cc79ae0e0d8ce9c5d3320 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 8 Dec 2017 10:56:09 +0100 Subject: Show connection success/failure on DEBUG_L1 Clarify disconnection log message Signed-off-by: Szczepan Zalega --- device.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'device.cc') diff --git a/device.cc b/device.cc index 5a83e2e..9321d2a 100644 --- a/device.cc +++ b/device.cc @@ -69,7 +69,7 @@ bool Device::_disconnect() { LOG(std::string(__FUNCTION__) + std::string(m_model == DeviceModel::PRO ? "PRO" : "STORAGE"), Loglevel::DEBUG_L2); LOG(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); - LOG(std::string("Disconnection success: ") + std::to_string(mp_devhandle == nullptr), Loglevel::DEBUG_L2); + LOG(std::string("Disconnection: handle already freed: ") + std::to_string(mp_devhandle == nullptr) + " ("+m_path+")", Loglevel::DEBUG_L1); if(mp_devhandle == nullptr) return false; hid_close(mp_devhandle); @@ -99,7 +99,7 @@ bool Device::_connect() { mp_devhandle = hid_open_path(m_path.c_str()); } const bool success = mp_devhandle != nullptr; - LOG(std::string("Connection success: ") + std::to_string(success), Loglevel::DEBUG_L2); + LOG(std::string("Connection success: ") + std::to_string(success) + " ("+m_path+")", Loglevel::DEBUG_L1); return success; } -- cgit v1.2.1 From 38c3b4c58e6c6b86d6241183be1814bac2e037d2 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 16 Feb 2018 15:17:47 +0100 Subject: Log current device ID Allow logger to set global prefix Used to indicate current device Store USB path when used to connection as well Signed-off-by: Szczepan Zalega --- device.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'device.cc') diff --git a/device.cc b/device.cc index 9321d2a..da5345b 100644 --- a/device.cc +++ b/device.cc @@ -248,7 +248,7 @@ Stick10::Stick10(): Stick20::Stick20(): - Device(0x20a0, 0x4109, DeviceModel::STORAGE, 40ms, 25, 40ms) + Device(0x20a0, 0x4109, DeviceModel::STORAGE, 40ms, 55, 40ms) { setDefaultDelay(); } -- cgit v1.2.1