From 5cd264c294ca6f1bf0758bb5fb0b51f3584d2795 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 29 Jul 2016 15:15:03 +0200 Subject: Set variable send_receive delay Signed-off-by: Szczepan Zalega --- device.cc | 3 ++- include/device.h | 6 +++++- include/device_proto.h | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/device.cc b/device.cc index 4f11e23..326f7f4 100644 --- a/device.cc +++ b/device.cc @@ -85,6 +85,7 @@ Stick10::Stick10() { m_vid = 0x20a0; m_pid = 0x4108; m_model = DeviceModel::PRO; + m_send_receive_delay = 10ms; } Stick20::Stick20() { @@ -92,5 +93,5 @@ Stick20::Stick20() { m_pid = 0x4109; m_retry_timeout = std::chrono::milliseconds(500); m_model = DeviceModel::STORAGE; - + m_send_receive_delay = 1000ms; } diff --git a/include/device.h b/include/device.h index 1f6d486..ffc38e5 100644 --- a/include/device.h +++ b/include/device.h @@ -10,6 +10,7 @@ namespace nitrokey { namespace device { + using namespace std::chrono_literals; enum class CommError { ERR_NO_ERROR = 0, @@ -25,7 +26,8 @@ enum class DeviceModel{ }; class Device { - public: + +public: Device(); // lack of device is not actually an error, @@ -46,6 +48,7 @@ class Device { int get_retry_count() const { return m_retry_count; }; std::chrono::milliseconds get_retry_timeout() const { return m_retry_timeout; }; + std::chrono::milliseconds get_send_receive_delay() const {return m_send_receive_delay;} int get_last_command_status() const; void set_last_command_status(uint8_t _err) { last_command_status = _err;} ; @@ -66,6 +69,7 @@ private: */ int m_retry_count; std::chrono::milliseconds m_retry_timeout; + std::chrono::milliseconds m_send_receive_delay; hid_device *mp_devhandle; }; diff --git a/include/device_proto.h b/include/device_proto.h index 7e2c0d9..6e21f9f 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -191,7 +191,7 @@ class Transaction : semantics::non_constructible { std::string("Device error while sending command ") + std::to_string((int)(status))); - std::this_thread::sleep_for(1000ms); + std::this_thread::sleep_for(dev.get_send_receive_delay()); // FIXME make checks done in device:recv here int retry = dev.get_retry_count(); -- cgit v1.2.1