From c346ff180244de682e78f49783eab9b296c79de6 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 31 Oct 2016 19:03:30 +0100 Subject: Code refactoring - named magic numbers (2) Signed-off-by: Szczepan Zalega --- include/device_proto.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'include/device_proto.h') diff --git a/include/device_proto.h b/include/device_proto.h index 6bcbcb0..187d25c 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -90,12 +90,19 @@ namespace nitrokey { * command_id member in incoming HIDReport structure carries the command * type last used. */ - template - struct DeviceResponse { - static constexpr auto storage_status_absolute_address = 21; //magic number from firmware + namespace DeviceResponseConstants{ + //magic numbers from firmware + static constexpr auto storage_status_absolute_address = 21; + static constexpr auto storage_data_absolute_address = storage_status_absolute_address + 5; static constexpr auto header_size = 8; //from _zero to last_command_status inclusive static constexpr auto footer_size = 4; //crc - static constexpr auto boiler_size = header_size + footer_size; + static constexpr auto wrapping_size = header_size + footer_size; + } + + template + struct DeviceResponse { + static constexpr auto storage_status_padding_size = + DeviceResponseConstants::storage_status_absolute_address - DeviceResponseConstants::header_size; uint8_t _zero; uint8_t device_status; @@ -104,10 +111,10 @@ namespace nitrokey { uint8_t last_command_status; union { - uint8_t _padding[HID_REPORT_SIZE - boiler_size]; + uint8_t _padding[HID_REPORT_SIZE - DeviceResponseConstants::wrapping_size]; ResponsePayload payload; struct { - uint8_t _storage_status_padding[storage_status_absolute_address - header_size]; + uint8_t _storage_status_padding[storage_status_padding_size]; uint8_t command_counter; uint8_t command_id; uint8_t device_status; //@see stick20::device_status -- cgit v1.2.1