From 9bf17b86c67e00c74b9d04d125b81cb093865225 Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 7 Mar 2015 12:04:24 +0100 Subject: [PATCH] added getMasterAddress() and isSlaveMaster() --- src/lib/ebus/symbol.cpp | 15 +++++++++++++++ src/lib/ebus/symbol.h | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/lib/ebus/symbol.cpp b/src/lib/ebus/symbol.cpp index 10ed9d26..9e3702da 100644 --- a/src/lib/ebus/symbol.cpp +++ b/src/lib/ebus/symbol.cpp @@ -198,6 +198,21 @@ bool isMaster(unsigned char addr) { && ((addrLo == 0x0) || (addrLo == 0x1) || (addrLo == 0x3) || (addrLo == 0x7) || (addrLo == 0xF)); } +bool isSlaveMaster(unsigned char addr) { + return isMaster((unsigned char)(addr+256-5)); +} + +unsigned char getMasterAddress(unsigned char addr) { + if (isMaster(addr)) + return addr; + + addr = (unsigned char)(addr+256-5); + if (isMaster(addr)) + return addr; + + return SYN; +} + unsigned char getMasterNumber(unsigned char addr) { unsigned char addrHi = (addr & 0xF0) >> 4; unsigned char addrLo = (addr & 0x0F); diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index 69fc233d..b8d5e028 100644 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -156,6 +156,20 @@ private: */ bool isMaster(unsigned char addr); +/** + * Returns whether the address is a slave address of one of the 25 masters. + * @param addr the address to check. + * @return true if the specified address is a slave address of a master. + */ +bool isSlaveMaster(unsigned char addr); + +/** + * Returns the master address associated with the specified address (master or slave). + * @param addr the address to check. + * @return the master address, or SYN if the specified address is neither a master address nor a slave address of a master. + */ +unsigned char getMasterAddress(unsigned char addr); + /** * Returns the number of the master if the address is a valid bus address. * @param addr the bus address.