diff options
author | Mateusz Zalega <mateusz@appliedsourcery.com> | 2015-10-22 23:07:23 +0200 |
---|---|---|
committer | Mateusz Zalega <mateusz@appliedsourcery.com> | 2015-10-26 20:49:55 +0100 |
commit | 9b8ebc6ed1a1fdc15c404774bf102c883a34d990 (patch) | |
tree | fce9205359704dcce84a1f770878901fbc9c2b3e /device.cc | |
parent | c4aec144256e3f27fedd8f8de03e10cc08eecab8 (diff) | |
download | libnitrokey-9b8ebc6ed1a1fdc15c404774bf102c883a34d990.tar.gz libnitrokey-9b8ebc6ed1a1fdc15c404774bf102c883a34d990.tar.bz2 |
Minor fixes, working version
Diffstat (limited to 'device.cc')
-rw-r--r-- | device.cc | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -1,10 +1,14 @@ #include <chrono> #include <thread> #include <cstddef> +#include <stdexcept> #include <hidapi/hidapi.h> #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), |