diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-09-20 12:54:01 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-09-20 12:54:01 +0200 |
commit | 7a04ee7dd3fad10e30581d22956234aeff2b2f3a (patch) | |
tree | 99770ff5bebd0816fd74e830e4308276b960dc9f /include/device_proto.h | |
parent | 8f7435e4553916e6cc431e4b5316cc5861fd9063 (diff) | |
parent | a83419fe4a13bc77005d455dd89685b8c1443d96 (diff) | |
download | libnitrokey-7a04ee7dd3fad10e30581d22956234aeff2b2f3a.tar.gz libnitrokey-7a04ee7dd3fad10e30581d22956234aeff2b2f3a.tar.bz2 |
Merge branch 'osx-communication_issues' into OSX_merge_cleaned
Diffstat (limited to 'include/device_proto.h')
-rw-r--r-- | include/device_proto.h | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/include/device_proto.h b/include/device_proto.h index b557384..bb14b42 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -37,6 +37,9 @@ namespace nitrokey { namespace proto { + extern std::mutex send_receive_mtx; + + /* * POD types for HID proto commands * Instances are meant to be __packed. @@ -215,7 +218,6 @@ namespace nitrokey { using namespace ::nitrokey::log; using namespace std::chrono_literals; - static std::mutex send_receive_mtx; std::lock_guard<std::mutex> guard(send_receive_mtx); LOG(__FUNCTION__, Loglevel::DEBUG_L2); @@ -306,12 +308,13 @@ namespace nitrokey { } if (resp.device_status == static_cast<uint8_t>(stick10::device_status::busy)) { dev->m_counters.busy++; - if (busy_counter++<10) { + if (busy_counter++<3) { receiving_retry_counter++; LOG("Status busy, not decreasing receiving_retry_counter counter: " + std::to_string(receiving_retry_counter), Loglevel::DEBUG_L2); } else { retry_timeout *= 2; + retry_timeout = std::min(retry_timeout, 300ms); busy_counter = 0; LOG("Status busy, decreasing receiving_retry_counter counter: " + std::to_string(receiving_retry_counter) + ", current delay:" @@ -352,12 +355,6 @@ namespace nitrokey { clear_packet(outp); - if (!resp.isCRCcorrect()) - LOGD(std::string("Accepting response from device with invalid CRC. ") - + "Command ID: " + std::to_string(resp.command_id) + " " + - commandid_to_string(static_cast<CommandID>(resp.command_id)) - ); - if (status <= 0) { dev->m_counters.receiving_error++; @@ -398,6 +395,14 @@ namespace nitrokey { dev->m_counters.successful_storage_commands++; } + if (!resp.isCRCcorrect()) + LOG(std::string("Accepting response from device with invalid CRC. ") + + "Command ID: " + std::to_string(resp.command_id) + " " + + commandid_to_string(static_cast<CommandID>(resp.command_id)) + " " + + "Reported and calculated: " + std::to_string(resp.crc) + "!=" + std::to_string(resp.calculate_CRC()), + Loglevel::WARNING + ); + // See: DeviceResponse return resp; } |