From 9b8ebc6ed1a1fdc15c404774bf102c883a34d990 Mon Sep 17 00:00:00 2001 From: Mateusz Zalega Date: Thu, 22 Oct 2015 23:07:23 +0200 Subject: Minor fixes, working version --- device.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'device.cc') diff --git a/device.cc b/device.cc index c954cb7..e1a5615 100644 --- a/device.cc +++ b/device.cc @@ -1,10 +1,14 @@ #include #include #include +#include #include #include "device.h" +#include "log.h" +#include "misc.h" -using namespace device; +using namespace nitrokey::device; +using namespace nitrokey::log; Device::Device() : m_vid(0), m_pid(0), @@ -13,13 +17,19 @@ Device::Device() mp_devhandle(NULL) {} bool Device::connect() { - hid_init(); + Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); + hid_init(); mp_devhandle = hid_open(m_vid, m_pid, NULL); return mp_devhandle != NULL; } CommError Device::send(const void *packet) { + Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); + + if (mp_devhandle == NULL) + throw std::runtime_error("Attempted HID send on an invalid descriptor."); + return (CommError)( hid_send_feature_report(mp_devhandle, (const unsigned char *)(packet), HID_REPORT_SIZE)); @@ -29,6 +39,11 @@ CommError Device::recv(void *packet) { CommError status; int retry_count = 0; + Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); + + if (mp_devhandle == NULL) + throw std::runtime_error("Attempted HID receive on an invalid descriptor."); + for(;;) { status = (CommError)( hid_get_feature_report(mp_devhandle, (unsigned char *)(packet), -- cgit v1.2.1