Skip to content

Commit

Permalink
Add missing endpointFromUniqueid() function from PR #5757
Browse files Browse the repository at this point in the history
  • Loading branch information
manup committed Feb 6, 2022
1 parent a806a64 commit 1893181
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions utils/utils.cpp
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions utils/utils.h
Expand Up @@ -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'; }
Expand Down

0 comments on commit 1893181

Please sign in to comment.