From 18931814841650b0e9bd0e32bd0ebd45ca849650 Mon Sep 17 00:00:00 2001 From: Manuel Pietschmann Date: Sun, 6 Feb 2022 15:03:40 +0100 Subject: [PATCH] Add missing endpointFromUniqueid() function from PR #5757 --- utils/utils.cpp | 30 ++++++++++++++++++++++++++++++ utils/utils.h | 1 + 2 files changed, 31 insertions(+) diff --git a/utils/utils.cpp b/utils/utils.cpp index 1a343058b7..b7ae27e8ba 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -315,6 +315,36 @@ quint64 extAddressFromUniqueId(const QString &uniqueId) return result; } +unsigned endpointFromUniqueId(const QString &uniqueId) +{ + unsigned result = 0; + + if (uniqueId.size() < 26) + { + return result; + } + + // 28:6d:97:00:01:06:41:79-01-0500 31 characters + + if (uniqueId.at(23) != '-') // expect delimeter before endpoint + { + return result; + } + + char buf[2 + 1]; + + buf[0] = uniqueId.at(24).toLatin1(); + buf[1] = uniqueId.at(25).toLatin1(); + buf[2] = '\0'; + + if (isHexChar(buf[0]) && isHexChar(buf[1])) + { + result = strtoull(buf, nullptr, 16); + } + + return result; +} + bool copyString(char *dst, size_t dstSize, const char *src, ssize_t srcSize) { if (!dst || dstSize == 0) diff --git a/utils/utils.h b/utils/utils.h index 20746cb307..d5a12e9182 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -107,6 +107,7 @@ decltype(auto) lessThenKeyValue(const K &key, const Cont &cont) const deCONZ::Node *getCoreNode(quint64 extAddress, deCONZ::ApsController *apsCtrl); quint64 extAddressFromUniqueId(const QString &uniqueId); +unsigned endpointFromUniqueId(const QString &uniqueId); bool copyString(char *dst, size_t dstSize, const char *src, ssize_t srcSize = -1); inline bool isEmptyString(const char *str) { return str && str[0] == '\0'; }