From 49a5d209aef1ff965cfd6e5a07e9e7c7e3dcadae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= <donal.murray@cern.ch> Date: Wed, 29 Apr 2020 17:13:36 +0100 Subject: [PATCH] Use enum cast instead of switch to simplify and generalise addressing --- arduino/common/lib/CommsControl/CommsCommon.h | 2 +- arduino/common/lib/CommsControl/CommsControl.cpp | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/arduino/common/lib/CommsControl/CommsCommon.h b/arduino/common/lib/CommsControl/CommsCommon.h index 3566a177..6ab31419 100644 --- a/arduino/common/lib/CommsControl/CommsCommon.h +++ b/arduino/common/lib/CommsControl/CommsCommon.h @@ -40,7 +40,7 @@ #define PACKET_SET 0x20 //set vs get ? // enum of all transfer types -enum PRIORITY { +enum PRIORITY : uint8_t { DATA = PACKET_DATA, CMD = PACKET_CMD, ALARM = PACKET_ALARM, diff --git a/arduino/common/lib/CommsControl/CommsControl.cpp b/arduino/common/lib/CommsControl/CommsControl.cpp index 02ff4fa4..58f6a213 100644 --- a/arduino/common/lib/CommsControl/CommsControl.cpp +++ b/arduino/common/lib/CommsControl/CommsControl.cpp @@ -275,16 +275,8 @@ void CommsControl::finishPacket(PRIORITY &type) { } PRIORITY CommsControl::getInfoType(uint8_t &address) { - switch (address & PACKET_TYPE) { - case PACKET_ALARM: - return PRIORITY::ALARM; - case PACKET_CMD: - return PRIORITY::CMD; - case PACKET_DATA: - return PRIORITY::DATA; - default: - return PRIORITY::UNSET; - } + // return enum element corresponding to the address + return (PRIORITY)(address & PACKET_TYPE); } // get link to queue according to packet format -- GitLab