diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-02-04 16:13:02 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-03-11 15:41:42 +0100 |
commit | 3fcbb90176fb02816cc47ad7172b7b89bf6cb67d (patch) | |
tree | 86bc483b94dfb135c497abee8e7f1c96ce1508a3 /device.cc | |
parent | db76ae5299f3650385f66e4c596b18fd54250d38 (diff) | |
download | libnitrokey-3fcbb90176fb02816cc47ad7172b7b89bf6cb67d.tar.gz libnitrokey-3fcbb90176fb02816cc47ad7172b7b89bf6cb67d.tar.bz2 |
Make statistics about device's connection
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'device.cc')
-rw-r--r-- | device.cc | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -101,6 +101,9 @@ int Device::recv(void *packet) { Log::instance()( "Maximum retry count reached" + std::to_string(retry_count), Loglevel::WARNING); + Log::instance()( + std::string("Counter stats") + m_counters.get_as_string(), + Loglevel::DEBUG); break; } Log::instance()("Retrying... " + std::to_string(retry_count), @@ -129,6 +132,11 @@ bool Device::is_connected() { // return hid_read_timeout(mp_devhandle, buf, sizeof(buf), 20) != -1; } +void Device::show_stats() { + auto s = m_counters.get_as_string(); + Log::instance()(s, Loglevel::DEBUG_L2); +} + Stick10::Stick10(): Device(0x20a0, 0x4108, DeviceModel::PRO, 100ms, 20, 100ms) {} @@ -137,3 +145,19 @@ Stick10::Stick10(): Stick20::Stick20(): Device(0x20a0, 0x4109, DeviceModel::STORAGE, 200ms, 40, 200ms) {} + +#include <sstream> +#define p(x) ss << #x << " " << x << ", "; +std::string Device::ErrorCounters::get_as_string() { + std::stringstream ss; + p(wrong_CRC); + p(CRC_other_than_awaited); + p(busy); + p(total_retries); + p(sending_error); + p(receiving_error); + p(total_comm_runs); + p(storage_commands); + p(successful ); + return ss.str(); +} |