From 7747a20540abe95c19e699eefecdd357d80f4a69 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Tue, 18 Jun 2024 03:13:05 -0700 Subject: [PATCH] expose releaseAddress() for master node resolves #219 --- RF24Mesh.cpp | 22 +++++++++++++++++----- RF24Mesh.h | 8 ++++++++ pyRF24Mesh/pyRF24Mesh.cpp | 6 +++++- pyRF24Mesh/setup.py | 1 - 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/RF24Mesh.cpp b/RF24Mesh.cpp index c9ec79c4..7d094044 100644 --- a/RF24Mesh.cpp +++ b/RF24Mesh.cpp @@ -89,11 +89,7 @@ uint8_t ESBMesh::update() } else if (type == MESH_ADDR_RELEASE) { uint16_t* fromAddr = (uint16_t*)network.frame_buffer; - for (uint8_t i = 0; i < addrListTop; i++) { - if (addrList[i].address == *fromAddr) { - addrList[i].address = 0; - } - } + releaseAddress(*fromAddr); } } #endif //!NO_MASTER @@ -288,6 +284,22 @@ bool ESBMesh::releaseAddress() /*****************************************************/ +#ifndef MESH_NO_MASTER +template +bool ESBMesh::releaseAddress(uint16_t address) +{ + for (uint8_t i = 0; i < addrListTop; ++i) { + if (addrList[i].address == address) { + addrList[i].address = 0; + return true; + } + } + return false; +} +#endif + +/*****************************************************/ + template uint16_t ESBMesh::renewAddress(uint32_t timeout) { diff --git a/RF24Mesh.h b/RF24Mesh.h index a1223ea9..ff56be7b 100644 --- a/RF24Mesh.h +++ b/RF24Mesh.h @@ -296,6 +296,14 @@ class ESBMesh /** @deprecated For backward compatibility with older code. Use the synonymous setAddress() instead. */ void setStaticAddress(uint8_t nodeID, uint16_t address); + /** + * Releases the specified address if leased to a mesh node's ID. This is specific to master nodes, so + * network administrators can manage assigned addresses without involving a transaction with nodes that + * might be appropriating them. + * @return True if successfully released, otherwise false. + */ + bool releaseAddress(uint16_t address); + #endif // !defined(MESH_NOMASTER) /**@}*/ diff --git a/pyRF24Mesh/pyRF24Mesh.cpp b/pyRF24Mesh/pyRF24Mesh.cpp index 15e41691..417763e3 100644 --- a/pyRF24Mesh/pyRF24Mesh.cpp +++ b/pyRF24Mesh/pyRF24Mesh.cpp @@ -87,7 +87,11 @@ BOOST_PYTHON_MODULE(RF24Mesh) //uint16_t renewAddress(uint32_t timeout=MESH_RENEWAL_TIMEOUT); .def("renewAddress", &RF24Mesh::renewAddress, getNodeID_overload(bp::args("timeout"))) //bool releaseAddress(); - .def("releaseAddress", &RF24Mesh::releaseAddress) + .def("releaseAddress", (bool (RF24Mesh::*)())&RF24Mesh::releaseAddress) +#ifndef MESH_NO_MASTER + //bool releaseAddress(uint16_t address); + .def("releaseAddress", (bool (RF24Mesh::*)(uint16_t))&RF24Mesh::releaseAddress, (bp::args("address"))) +#endif //int16_t getAddress(uint8_t nodeID); .def("getAddress", &RF24Mesh::getAddress, (bp::arg("nodeID"))) //void setChannel(uint8_t _channel); diff --git a/pyRF24Mesh/setup.py b/pyRF24Mesh/setup.py index 12d8d6b4..ce1c0378 100755 --- a/pyRF24Mesh/setup.py +++ b/pyRF24Mesh/setup.py @@ -45,7 +45,6 @@ "RF24Mesh", sources=["pyRF24Mesh.cpp"], libraries=["rf24mesh", "rf24network", "rf24", BOOST_LIB], - extra_compile_args=["-DRF24_NO_INTERRUPT"] ) ], )