aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-10-31 19:03:30 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2016-11-26 18:56:27 +0100
commitc346ff180244de682e78f49783eab9b296c79de6 (patch)
treee4375ac47275e7181d9a3fc1ba111e3c2ec25601
parentca130e790ecc4e4502eb39e1ab550348eae9bc54 (diff)
downloadlibnitrokey-c346ff180244de682e78f49783eab9b296c79de6.tar.gz
libnitrokey-c346ff180244de682e78f49783eab9b296c79de6.tar.bz2
Code refactoring - named magic numbers (2)
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--include/device_proto.h19
-rw-r--r--include/stick20_commands.h6
2 files changed, 16 insertions, 9 deletions
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<CommandID cmd_id, typename ResponsePayload>
- 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<CommandID cmd_id, typename ResponsePayload>
+ 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
diff --git a/include/stick20_commands.h b/include/stick20_commands.h
index f816868..139dc63 100644
--- a/include/stick20_commands.h
+++ b/include/stick20_commands.h
@@ -91,9 +91,9 @@ namespace nitrokey {
};
namespace StorageCommandResponsePayload{
- static const int OUTPUT_CMD_RESULT_STICK20_STATUS_START = 25 + 1;
- static const int payload_absolute_begin = 8;
- static const int padding_size = OUTPUT_CMD_RESULT_STICK20_STATUS_START - payload_absolute_begin;
+ using namespace DeviceResponseConstants;
+ static constexpr auto padding_size =
+ storage_data_absolute_address - header_size;
struct TransmissionData{
uint8_t _padding[padding_size];