diff --git a/lib-artnet/include/artnetpolltable.h b/lib-artnet/include/artnetpolltable.h index 7787d8afa..70d18b9be 100644 --- a/lib-artnet/include/artnetpolltable.h +++ b/lib-artnet/include/artnetpolltable.h @@ -39,40 +39,40 @@ static constexpr uint32_t POLL_INTERVAL_MILLIS = (POLL_INTERVAL_SECONDS * 1000U) static constexpr uint32_t POLL_TABLE_SIZE_ENRIES = 255; static constexpr uint32_t POLL_TABLE_SIZE_NODE_UNIVERSES = 64; static constexpr uint32_t POLL_TABLE_SIZE_UNIVERSES = 512; -} // namespace artnet -struct TArtNetNodeEntryUniverse { +struct NodeEntryUniverse { uint8_t ShortName[artnet::SHORT_NAME_LENGTH]; uint32_t nLastUpdateMillis; uint16_t nUniverse; }; -struct TArtNetNodeEntry { +struct NodeEntry { uint32_t IPAddress; uint8_t Mac[artnet::MAC_SIZE]; uint8_t LongName[artnet::LONG_NAME_LENGTH]; uint16_t nUniversesCount; - struct TArtNetNodeEntryUniverse Universe[artnet::POLL_TABLE_SIZE_NODE_UNIVERSES]; + struct NodeEntryUniverse Universe[artnet::POLL_TABLE_SIZE_NODE_UNIVERSES]; }; -struct TArtNetPollTableUniverses { +struct PollTableUniverses { uint16_t nUniverse; uint16_t nCount; uint32_t *pIpAddresses; }; -struct TArtNetPollTableClean { +struct PollTableClean { uint32_t nTableIndex; uint16_t nUniverseIndex; bool bOffLine; }; +} // namespace artnet class ArtNetPollTable { public: ArtNetPollTable(); ~ArtNetPollTable(); - const TArtNetNodeEntry *GetPollTable() const { + const artnet::NodeEntry *GetPollTable() const { return m_pPollTable; } @@ -83,21 +83,21 @@ class ArtNetPollTable { void Add(const struct artnet::ArtPollReply *ptArtPollReply); void Clean(); - const struct TArtNetPollTableUniverses *GetIpAddress(uint16_t nUniverse) const; + const struct artnet::PollTableUniverses *GetIpAddress(uint16_t nUniverse) const; void Dump(); void DumpTableUniverses(); private: - void ProcessUniverse(uint32_t nIpAddress, uint16_t nUniverse); - void RemoveIpAddress(uint16_t nUniverse, uint32_t nIpAddress); + void ProcessUniverse(const uint32_t nIpAddress, const uint16_t nUniverse); + void RemoveIpAddress(const uint16_t nUniverse, const uint32_t nIpAddress); private: - TArtNetNodeEntry *m_pPollTable; - uint32_t m_nPollTableEntries{0}; - TArtNetPollTableUniverses *m_pTableUniverses; - uint32_t m_nTableUniversesEntries{0}; - TArtNetPollTableClean m_tTableClean; + artnet::NodeEntry *m_pPollTable; + artnet::PollTableUniverses *m_pTableUniverses; + uint32_t m_nPollTableEntries { 0 }; + uint32_t m_nTableUniversesEntries { 0 }; + artnet::PollTableClean m_PollTableClean; }; #endif /* ARTNETPOLLTABLE_H_ */ diff --git a/lib-artnet/src/controller/artnetcontroller.cpp b/lib-artnet/src/controller/artnetcontroller.cpp index 7f30e863f..39ac27b16 100644 --- a/lib-artnet/src/controller/artnetcontroller.cpp +++ b/lib-artnet/src/controller/artnetcontroller.cpp @@ -281,7 +281,7 @@ void ArtNetController::HandleDmxOut(uint16_t nUniverse, const uint8_t *pDmxData, #endif uint32_t nCount = 0; - auto IpAddresses = const_cast(GetIpAddress(nUniverse)); + auto IpAddresses = const_cast(GetIpAddress(nUniverse)); if (m_bUnicast && !m_bForceBroadcast) { if (IpAddresses != nullptr) { diff --git a/lib-artnet/src/controller/artnetpolltable.cpp b/lib-artnet/src/controller/artnetpolltable.cpp index 2d58d4b75..8b0251a19 100644 --- a/lib-artnet/src/controller/artnetpolltable.cpp +++ b/lib-artnet/src/controller/artnetpolltable.cpp @@ -26,8 +26,6 @@ * THE SOFTWARE. */ -#undef NDEBUG - #if !defined(__clang__) // Needed for compiling on MacOS # if __GNUC__ < 9 # pragma GCC diagnostic push @@ -47,39 +45,40 @@ #include "debug.h" -using namespace artnet; - union uip { uint32_t u32; uint8_t u8[4]; } static ip; ArtNetPollTable::ArtNetPollTable() { - m_pPollTable = new TArtNetNodeEntry[POLL_TABLE_SIZE_ENRIES]; + DEBUG_ENTRY + + m_pPollTable = new artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES]; assert(m_pPollTable != nullptr); - memset(m_pPollTable, 0, sizeof(TArtNetNodeEntry[POLL_TABLE_SIZE_ENRIES])); + memset(m_pPollTable, 0, sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])); - m_pTableUniverses = new TArtNetPollTableUniverses[POLL_TABLE_SIZE_UNIVERSES]; + m_pTableUniverses = new artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES]; assert(m_pTableUniverses != nullptr); - memset(m_pTableUniverses, 0, sizeof(TArtNetPollTableUniverses[POLL_TABLE_SIZE_UNIVERSES])); + memset(m_pTableUniverses, 0, sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])); - for (uint32_t nIndex = 0; nIndex < POLL_TABLE_SIZE_UNIVERSES; nIndex++) { - m_pTableUniverses[nIndex].pIpAddresses = new uint32_t[POLL_TABLE_SIZE_ENRIES]; + for (uint32_t nIndex = 0; nIndex < artnet::POLL_TABLE_SIZE_UNIVERSES; nIndex++) { + m_pTableUniverses[nIndex].pIpAddresses = new uint32_t[artnet::POLL_TABLE_SIZE_ENRIES]; assert(m_pTableUniverses[nIndex].pIpAddresses != nullptr); } -// DEBUG_PRINTF("TArtNetNodeEntry[%d] = %u bytes [%u Kb]", ARTNET_POLL_TABLE_SIZE_ENRIES, (sizeof(TArtNetNodeEntry[ARTNET_POLL_TABLE_SIZE_ENRIES])), (sizeof(TArtNetNodeEntry[ARTNET_POLL_TABLE_SIZE_ENRIES])) / 1024); -// DEBUG_PRINTF("TArtNetPollTableUniverses[%d] = %u bytes [%u Kb]", ARTNET_POLL_TABLE_SIZE_UNIVERSES, (sizeof(TArtNetPollTableUniverses[ARTNET_POLL_TABLE_SIZE_UNIVERSES])), (sizeof(TArtNetPollTableUniverses[ARTNET_POLL_TABLE_SIZE_UNIVERSES])) / 1024); + m_PollTableClean.nTableIndex = 0; + m_PollTableClean.nUniverseIndex = 0; + m_PollTableClean.bOffLine = true; - m_tTableClean.nTableIndex = 0; - m_tTableClean.nUniverseIndex = 0; - m_tTableClean.bOffLine = true; + DEBUG_PRINTF("NodeEntry[%d] = %u bytes [%u Kb]", artnet::POLL_TABLE_SIZE_ENRIES, static_cast(sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])), static_cast(sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])) / 1024U); + DEBUG_PRINTF("PollTableUniverses[%d] = %u bytes [%u Kb]", artnet::POLL_TABLE_SIZE_UNIVERSES, static_cast(sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])), static_cast(sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])) / 1024U); + DEBUG_EXIT } ArtNetPollTable::~ArtNetPollTable() { - for (uint32_t nIndex = 0; nIndex < POLL_TABLE_SIZE_UNIVERSES; nIndex++) { + for (uint32_t nIndex = 0; nIndex < artnet::POLL_TABLE_SIZE_UNIVERSES; nIndex++) { delete[] m_pTableUniverses[nIndex].pIpAddresses; m_pTableUniverses[nIndex].pIpAddresses = nullptr; } @@ -91,14 +90,14 @@ ArtNetPollTable::~ArtNetPollTable() { m_pPollTable = nullptr; } -const struct TArtNetPollTableUniverses *ArtNetPollTable::GetIpAddress(uint16_t nUniverse) const { +const struct artnet::PollTableUniverses *ArtNetPollTable::GetIpAddress(uint16_t nUniverse) const { if (m_nTableUniversesEntries == 0) { return nullptr; } // FIXME Universe lookup for (uint32_t nEntry = 0; nEntry < m_nTableUniversesEntries; nEntry++) { - TArtNetPollTableUniverses *pTableUniverses = &m_pTableUniverses[nEntry]; + artnet::PollTableUniverses *pTableUniverses = &m_pTableUniverses[nEntry]; assert(pTableUniverses != nullptr); if (pTableUniverses->nUniverse == nUniverse) { @@ -110,7 +109,7 @@ const struct TArtNetPollTableUniverses *ArtNetPollTable::GetIpAddress(uint16_t n } -void ArtNetPollTable::RemoveIpAddress(uint16_t nUniverse, uint32_t nIpAddress) { +void ArtNetPollTable::RemoveIpAddress(const uint16_t nUniverse, const uint32_t nIpAddress) { if (m_nTableUniversesEntries == 0) { return; } @@ -119,7 +118,7 @@ void ArtNetPollTable::RemoveIpAddress(uint16_t nUniverse, uint32_t nIpAddress) { // FIXME Universe lookup for (nEntry = 0; nEntry < m_nTableUniversesEntries; nEntry++) { - TArtNetPollTableUniverses *pTableUniverses = &m_pTableUniverses[nEntry]; + artnet::PollTableUniverses *pTableUniverses = &m_pTableUniverses[nEntry]; assert(pTableUniverses != nullptr); if (pTableUniverses->nUniverse == nUniverse) { @@ -132,7 +131,7 @@ void ArtNetPollTable::RemoveIpAddress(uint16_t nUniverse, uint32_t nIpAddress) { return; } - TArtNetPollTableUniverses *pTableUniverses = &m_pTableUniverses[nEntry]; + artnet::PollTableUniverses *pTableUniverses = &m_pTableUniverses[nEntry]; assert(pTableUniverses->nCount > 0); uint32_t nIpAddressIndex = 0; @@ -158,7 +157,7 @@ void ArtNetPollTable::RemoveIpAddress(uint16_t nUniverse, uint32_t nIpAddress) { if (pTableUniverses->nCount == 0) { DEBUG_PRINTF("Delete Universe -> m_nTableUniversesEntries=%u, nEntry=%u", m_nTableUniversesEntries, nEntry); - TArtNetPollTableUniverses *p = m_pTableUniverses; + artnet::PollTableUniverses *p = m_pTableUniverses; for (i = static_cast(nEntry); i < static_cast(m_nTableUniversesEntries) - 1; i++) { p[i].nUniverse = p[i + 1].nUniverse; @@ -173,10 +172,10 @@ void ArtNetPollTable::RemoveIpAddress(uint16_t nUniverse, uint32_t nIpAddress) { } } -void ArtNetPollTable::ProcessUniverse(uint32_t nIpAddress, uint16_t nUniverse) { +void ArtNetPollTable::ProcessUniverse(const uint32_t nIpAddress, const uint16_t nUniverse) { DEBUG_ENTRY - if (POLL_TABLE_SIZE_UNIVERSES == m_nTableUniversesEntries) { + if (artnet::POLL_TABLE_SIZE_UNIVERSES == m_nTableUniversesEntries) { DEBUG_PUTS("m_pTableUniverses is full"); DEBUG_EXIT return; @@ -187,7 +186,7 @@ void ArtNetPollTable::ProcessUniverse(uint32_t nIpAddress, uint16_t nUniverse) { uint32_t nEntry = 0; for (nEntry = 0; nEntry < m_nTableUniversesEntries; nEntry++) { - TArtNetPollTableUniverses *pTableUniverses = &m_pTableUniverses[nEntry]; + auto *pTableUniverses = &m_pTableUniverses[nEntry]; assert(pTableUniverses != nullptr); if (pTableUniverses->nUniverse == nUniverse) { @@ -197,8 +196,7 @@ void ArtNetPollTable::ProcessUniverse(uint32_t nIpAddress, uint16_t nUniverse) { } } - TArtNetPollTableUniverses *pTableUniverses = &m_pTableUniverses[nEntry]; - + auto *pTableUniverses = &m_pTableUniverses[nEntry]; auto bFoundIp = false; uint32_t nCount = 0; @@ -219,7 +217,7 @@ void ArtNetPollTable::ProcessUniverse(uint32_t nIpAddress, uint16_t nUniverse) { } if (!bFoundIp) { - if (pTableUniverses->nCount < POLL_TABLE_SIZE_ENRIES) { + if (pTableUniverses->nCount < artnet::POLL_TABLE_SIZE_ENRIES) { pTableUniverses->pIpAddresses[pTableUniverses->nCount] = nIpAddress; pTableUniverses->nCount++; DEBUG_PUTS("It is a new IP for the Universe"); @@ -261,7 +259,7 @@ void ArtNetPollTable::Add(const struct artnet::ArtPollReply *ptArtPollReply) { } if (!bFound) { - if (m_nPollTableEntries == POLL_TABLE_SIZE_ENRIES) { + if (m_nPollTableEntries == artnet::POLL_TABLE_SIZE_ENRIES) { DEBUG_PUTS("Full"); return; } @@ -275,13 +273,13 @@ void ArtNetPollTable::Add(const struct artnet::ArtPollReply *ptArtPollReply) { assert(nLow >= 0); for (int32_t i = static_cast(m_nPollTableEntries) - 1;i >= nLow; i--) { - const struct TArtNetNodeEntry *pSrc = &pArtNetNodeEntry[i]; - struct TArtNetNodeEntry *pDst = &pArtNetNodeEntry[i + 1]; - memcpy(pDst, pSrc, sizeof(struct TArtNetNodeEntry)); + const struct artnet::NodeEntry *pSrc = &pArtNetNodeEntry[i]; + struct artnet::NodeEntry *pDst = &pArtNetNodeEntry[i + 1]; + memcpy(pDst, pSrc, sizeof(struct artnet::NodeEntry)); } auto *pDst = &pArtNetNodeEntry[nLow]; - memset(pDst, 0, sizeof(struct TArtNetNodeEntry)); + memset(pDst, 0, sizeof(struct artnet::NodeEntry)); i = nLow; } else { @@ -318,7 +316,7 @@ void ArtNetPollTable::Add(const struct artnet::ArtPollReply *ptArtPollReply) { if (nIndexUniverse == m_pPollTable[i].nUniversesCount) { // Not found - if (m_pPollTable[i].nUniversesCount < POLL_TABLE_SIZE_NODE_UNIVERSES) { + if (m_pPollTable[i].nUniversesCount < artnet::POLL_TABLE_SIZE_NODE_UNIVERSES) { m_pPollTable[i].nUniversesCount++; m_pPollTable[i].Universe[nIndexUniverse].nUniverse = nUniverse; const uint8_t *pSrc = ptArtPollReply->ShortName; @@ -343,36 +341,36 @@ void ArtNetPollTable::Clean() { return; } - assert(m_tTableClean.nTableIndex < m_nPollTableEntries); - assert(m_tTableClean.nUniverseIndex < POLL_TABLE_SIZE_NODE_UNIVERSES); + assert(m_PollTableClean.nTableIndex < m_nPollTableEntries); + assert(m_PollTableClean.nUniverseIndex < artnet::POLL_TABLE_SIZE_NODE_UNIVERSES); - if (m_tTableClean.nUniverseIndex == 0) { - m_tTableClean.bOffLine = true; + if (m_PollTableClean.nUniverseIndex == 0) { + m_PollTableClean.bOffLine = true; } - auto *pArtNetNodeEntryBind = &m_pPollTable[m_tTableClean.nTableIndex].Universe[m_tTableClean.nUniverseIndex]; + auto *pArtNetNodeEntryBind = &m_pPollTable[m_PollTableClean.nTableIndex].Universe[m_PollTableClean.nUniverseIndex]; if (pArtNetNodeEntryBind->nLastUpdateMillis != 0) { - if ((Hardware::Get()->Millis() - pArtNetNodeEntryBind->nLastUpdateMillis) > (1.5 * POLL_INTERVAL_MILLIS)) { + if ((Hardware::Get()->Millis() - pArtNetNodeEntryBind->nLastUpdateMillis) > (1.5 * artnet::POLL_INTERVAL_MILLIS)) { pArtNetNodeEntryBind->nLastUpdateMillis = 0; - RemoveIpAddress(pArtNetNodeEntryBind->nUniverse, m_pPollTable[m_tTableClean.nTableIndex].IPAddress); + RemoveIpAddress(pArtNetNodeEntryBind->nUniverse, m_pPollTable[m_PollTableClean.nTableIndex].IPAddress); } else { - m_tTableClean.bOffLine = false; + m_PollTableClean.bOffLine = false; } } - m_tTableClean.nUniverseIndex++; + m_PollTableClean.nUniverseIndex++; - if (m_tTableClean.nUniverseIndex == POLL_TABLE_SIZE_NODE_UNIVERSES) { - if (m_tTableClean.bOffLine) { + if (m_PollTableClean.nUniverseIndex == artnet::POLL_TABLE_SIZE_NODE_UNIVERSES) { + if (m_PollTableClean.bOffLine) { DEBUG_PUTS("Node is off-line"); auto *pArtNetNodeEntry = m_pPollTable; // Move - for (uint32_t i = m_tTableClean.nTableIndex; i < (m_nPollTableEntries - 1); i++) { + for (uint32_t i = m_PollTableClean.nTableIndex; i < (m_nPollTableEntries - 1); i++) { const auto *pSrc = &pArtNetNodeEntry[i + 1]; auto *pDst = &pArtNetNodeEntry[i]; - memcpy(pDst, pSrc, sizeof(struct TArtNetNodeEntry)); + memcpy(pDst, pSrc, sizeof(struct artnet::NodeEntry)); } m_nPollTableEntries--; @@ -380,18 +378,18 @@ void ArtNetPollTable::Clean() { auto *pDst = &pArtNetNodeEntry[m_nPollTableEntries]; pDst->IPAddress = 0; pDst->nUniversesCount = 0; - memset(pDst->Universe, 0, sizeof(struct TArtNetNodeEntryUniverse[POLL_TABLE_SIZE_NODE_UNIVERSES])); + memset(pDst->Universe, 0, sizeof(struct artnet::NodeEntryUniverse[artnet::POLL_TABLE_SIZE_NODE_UNIVERSES])); #ifndef NDEBUG - memset(pDst->Mac, 0, artnet::MAC_SIZE + artnet::SHORT_NAME_LENGTH + artnet::LONG_NAME_LENGTH); + memset(pDst->Mac, 0, artnet::MAC_SIZE + artnet::LONG_NAME_LENGTH); #endif } - m_tTableClean.nUniverseIndex = 0; - m_tTableClean.bOffLine = true; - m_tTableClean.nTableIndex++; + m_PollTableClean.nUniverseIndex = 0; + m_PollTableClean.bOffLine = true; + m_PollTableClean.nTableIndex++; - if (m_tTableClean.nTableIndex >= m_nPollTableEntries) { - m_tTableClean.nTableIndex = 0; + if (m_PollTableClean.nTableIndex >= m_nPollTableEntries) { + m_PollTableClean.nTableIndex = 0; } } } diff --git a/lib-artnet/src/controller/json_get_polltable.cpp b/lib-artnet/src/controller/json_get_polltable.cpp index 0aa5f71b2..d0b976e48 100755 --- a/lib-artnet/src/controller/json_get_polltable.cpp +++ b/lib-artnet/src/controller/json_get_polltable.cpp @@ -39,8 +39,7 @@ namespace remoteconfig { namespace artnet { namespace controller { - -static uint32_t get_port(const struct TArtNetNodeEntryUniverse *pArtNetNodeEntryUniverse, char *pOutBuffer, const uint32_t nOutBufferSize) { +static uint32_t get_port(const struct ::artnet::NodeEntryUniverse *pArtNetNodeEntryUniverse, char *pOutBuffer, const uint32_t nOutBufferSize) { const auto nLength = static_cast(snprintf(pOutBuffer, nOutBufferSize, "{\"name\":\"%s\",\"universe\":%u},", pArtNetNodeEntryUniverse->ShortName, pArtNetNodeEntryUniverse->nUniverse)); @@ -74,7 +73,6 @@ static uint32_t get_entry(const uint32_t nIndex, char *pOutBuffer, const uint32_ } uint32_t json_get_polltable(char *pOutBuffer, const uint32_t nOutBufferSize) { - const auto nBufferSize = nOutBufferSize - 2U; pOutBuffer[0] = '[';