aboutsummaryrefslogtreecommitdiff
path: root/device.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-03-29 12:22:37 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2017-03-29 12:49:14 +0200
commitc196b45789377dc2cb76a203853695928872dbb4 (patch)
treebaa78ecddf5e0a8f5ab7485227aa6706d407cfd5 /device.cc
parent887929bfdefd5894bce2de6821a948b205915fcc (diff)
downloadlibnitrokey-c196b45789377dc2cb76a203853695928872dbb4.tar.gz
libnitrokey-c196b45789377dc2cb76a203853695928872dbb4.tar.bz2
Allow to change device commands delays runtime
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'device.cc')
-rw-r--r--device.cc37
1 files changed, 35 insertions, 2 deletions
diff --git a/device.cc b/device.cc
index 4cb492d..97197ee 100644
--- a/device.cc
+++ b/device.cc
@@ -8,6 +8,7 @@
#include "include/log.h"
#include <mutex>
#include "DeviceCommunicationExceptions.h"
+#include "device.h"
std::mutex mex_dev_com;
@@ -16,6 +17,7 @@ using namespace nitrokey::log;
using namespace std::chrono;
std::atomic_int Device::instances_count{0};
+std::chrono::milliseconds Device::default_delay {0} ;
Device::Device(const uint16_t vid, const uint16_t pid, const DeviceModel model,
const milliseconds send_receive_delay, const int retry_receiving_count,
@@ -172,14 +174,33 @@ Device::~Device() {
instances_count--;
}
+void Device::set_default_device_speed(int delay) {
+ default_delay = std::chrono::duration<int, std::milli>(delay);
+}
+
+
+void Device::set_receiving_delay(const std::chrono::milliseconds delay){
+ std::lock_guard<std::mutex> lock(mex_dev_com);
+ m_send_receive_delay = delay;
+}
+
+void Device::set_retry_delay(const std::chrono::milliseconds delay){
+ std::lock_guard<std::mutex> lock(mex_dev_com);
+ m_retry_timeout = delay;
+}
+
Stick10::Stick10():
Device(0x20a0, 0x4108, DeviceModel::PRO, 100ms, 5, 100ms)
- {}
+ {
+ setDefaultDelay();
+ }
Stick20::Stick20():
Device(0x20a0, 0x4109, DeviceModel::STORAGE, 20ms, 20, 20ms)
- {}
+ {
+ setDefaultDelay();
+ }
#include <sstream>
#define p(x) ss << #x << " " << x << ", ";
@@ -206,4 +227,16 @@ std::string Device::ErrorCounters::get_as_string() {
p(receiving_error);
return ss.str();
}
+
+void Device::setDefaultDelay() {
+ LOG(__FUNCTION__, Loglevel::DEBUG_L2);
+
+ auto count = default_delay.count();
+ if (count != 0){
+ LOG("Setting default delay to " + std::to_string(count), Loglevel::DEBUG_L2);
+ m_retry_timeout = default_delay;
+ m_send_receive_delay = default_delay;
+ }
+}
+
#undef p