aboutsummaryrefslogtreecommitdiff
path: root/include/device.h
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-02-04 16:13:02 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-03-11 15:41:42 +0100
commit3fcbb90176fb02816cc47ad7172b7b89bf6cb67d (patch)
tree86bc483b94dfb135c497abee8e7f1c96ce1508a3 /include/device.h
parentdb76ae5299f3650385f66e4c596b18fd54250d38 (diff)
downloadlibnitrokey-3fcbb90176fb02816cc47ad7172b7b89bf6cb67d.tar.gz
libnitrokey-3fcbb90176fb02816cc47ad7172b7b89bf6cb67d.tar.bz2
Make statistics about device's connection
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include/device.h')
-rw-r--r--include/device.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/include/device.h b/include/device.h
index 5965f99..a23e1b3 100644
--- a/include/device.h
+++ b/include/device.h
@@ -2,7 +2,8 @@
#define DEVICE_H
#include <chrono>
#include <hidapi/hidapi.h>
-#include <stdint.h>
+#include <cstdint>
+#include <string>
#define HID_REPORT_SIZE 65
@@ -30,11 +31,26 @@ enum class DeviceModel{
class Device {
public:
+
+ struct ErrorCounters{
+ int wrong_CRC;
+ int CRC_other_than_awaited;
+ int busy;
+ int total_retries;
+ int sending_error;
+ int receiving_error;
+ int total_comm_runs;
+ int storage_commands;
+ int successful;
+ std::string get_as_string();
+ } m_counters = {};
+
+
Device(const uint16_t vid, const uint16_t pid, const DeviceModel model,
const milliseconds send_receive_delay, const int retry_receiving_count,
const milliseconds retry_timeout);
- virtual ~Device(){disconnect();}
+ virtual ~Device(){show_stats(); disconnect();}
// lack of device is not actually an error,
// so it doesn't throw
@@ -54,6 +70,8 @@ public:
bool is_connected();
+ void show_stats();
+ ErrorCounters get_stats(){ return m_counters; }
int get_retry_receiving_count() const { return m_retry_receiving_count; };
int get_retry_sending_count() const { return m_retry_sending_count; };
std::chrono::milliseconds get_retry_timeout() const { return m_retry_timeout; };