From 8ce7f56883366a69fc660e7e89d3f4cb80b29a58 Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 3 Dec 2016 07:30:57 +0100 Subject: [PATCH] simplified isMaster() --- src/lib/ebus/symbol.cpp | 52 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/lib/ebus/symbol.cpp b/src/lib/ebus/symbol.cpp index 96c82ef0..6789b229 100644 --- a/src/lib/ebus/symbol.cpp +++ b/src/lib/ebus/symbol.cpp @@ -190,12 +190,32 @@ void SymbolString::addCRC(const unsigned char value) { -bool isMaster(unsigned char addr) { - unsigned char addrHi = (addr & 0xF0) >> 4; - unsigned char addrLo = (addr & 0x0F); +/** + * Return the index of the upper or lower 4 bits of a master address. + * @param bits the upper or lower 4 bits of the address. + * @return the 1-based index of the upper or lower 4 bits of a master address (1 to 5), or 0. + */ +unsigned char getMasterPartIndex(unsigned char bits) { + switch (bits) + { + case 0x0: + return 1; + case 0x1: + return 2; + case 0x3: + return 3; + case 0x7: + return 4; + case 0xF: + return 5; + default: + return 0; + } +} - return ((addrHi == 0x0) || (addrHi == 0x1) || (addrHi == 0x3) || (addrHi == 0x7) || (addrHi == 0xF)) - && ((addrLo == 0x0) || (addrLo == 0x1) || (addrLo == 0x3) || (addrLo == 0x7) || (addrLo == 0xF)); +bool isMaster(unsigned char addr) { + return getMasterPartIndex(addr & 0x0F)>0 + && getMasterPartIndex((addr & 0xF0) >> 4)>0; } bool isSlaveMaster(unsigned char addr) { @@ -223,28 +243,6 @@ unsigned char getMasterAddress(unsigned char addr) { return SYN; } -/** - * Returns the index of the upper or lower 4 bits of a master address. - * @param bits the upper or lower 4 bits of the address. - * @return the 1-based index of the upper or lower 4 bits of a master address (1 to 5), or 0. - */ -unsigned char getMasterPartIndex(unsigned char bits) { - switch (bits) - { - case 0x0: - return 1; - case 0x1: - return 2; - case 0x3: - return 3; - case 0x7: - return 4; - case 0xF: - return 5; - default: - return 0; - } -} unsigned char getMasterNumber(unsigned char addr) { unsigned char priority = getMasterPartIndex(addr & 0x0F); if (priority==0) {