aboutsummaryrefslogtreecommitdiff
path: root/include/device_proto.h
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-10-18 15:16:39 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-10-19 16:40:25 +0200
commit98a9730783268b01d8f55b8b323bb70fdd964a11 (patch)
tree58e0eb442a51b0e79a9115d75290015479135474 /include/device_proto.h
parent056228aae33642013053288a932a65c93271b0be (diff)
downloadlibnitrokey-98a9730783268b01d8f55b8b323bb70fdd964a11.tar.gz
libnitrokey-98a9730783268b01d8f55b8b323bb70fdd964a11.tar.bz2
Code refactoring: replacing magic numbers
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include/device_proto.h')
-rw-r--r--include/device_proto.h34
1 files changed, 18 insertions, 16 deletions
diff --git a/include/device_proto.h b/include/device_proto.h
index 81cf93e..bf78d29 100644
--- a/include/device_proto.h
+++ b/include/device_proto.h
@@ -235,27 +235,29 @@ namespace nitrokey {
status = dev.recv(&resp);
if (dev.get_device_model() == DeviceModel::STORAGE &&
- resp.command_id >= 0x20 &&
- resp.command_id < 0x60
- ) {
+ resp.command_id >= stick20::CMD_START_VALUE &&
+ resp.command_id < stick20::CMD_END_VALUE ) {
Log::instance()(std::string("Detected storage device cmd, status: ") +
std::to_string(resp.StorageStatus.Status_u8), Loglevel::DEBUG_L2);
- resp.last_command_status = 0;
- switch (resp.StorageStatus.Status_u8) {
- case 0:
- case 1:
- resp.last_command_status = 0;
- resp.device_status = 0;
+ resp.last_command_status = static_cast<uint8_t>(stick10::command_status::ok);
+ switch (static_cast<stick20::device_status>(resp.StorageStatus.Status_u8)) {
+ case stick20::device_status::idle :
+ case stick20::device_status::ok:
+ resp.device_status = static_cast<uint8_t>(stick10::device_status::ok);
break;
- case 2:
- resp.last_command_status = 0;
- resp.device_status = 1; //pro busy
+ case stick20::device_status::busy:
+ case stick20::device_status::busy_progressbar: //TODO this will be modified later for getting progressbar status
+ resp.device_status = static_cast<uint8_t>(stick10::device_status::busy);
break;
- case 3:
- case 4:
- resp.last_command_status = 4;
- resp.device_status = 0;
+ case stick20::device_status::wrong_password:
+ resp.last_command_status = static_cast<uint8_t>(stick10::device_status::wrong_password);
+ resp.device_status = static_cast<uint8_t>(stick10::device_status::ok);
+ break;
+ default:
+ Log::instance()(std::string("Unknown storage device status, cannot translate: ") +
+ std::to_string(resp.StorageStatus.Status_u8), Loglevel::DEBUG);
+ resp.device_status = resp.StorageStatus.Status_u8;
break;
};
}