Skip to content

Commit

Permalink
expose releaseAddress() for master node (#244)
Browse files Browse the repository at this point in the history
* resolves #219
* expose mesh_address in python wrapper
* fix py bindings for getNodeID() and renewAddress()
* don't expose addrList due to unsatisfied  implementation details
  • Loading branch information
2bndy5 authored Jun 20, 2024
1 parent 7827e87 commit dc29068
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
22 changes: 17 additions & 5 deletions RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ uint8_t ESBMesh<network_t, radio_t>::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
Expand Down Expand Up @@ -288,6 +284,22 @@ bool ESBMesh<network_t, radio_t>::releaseAddress()

/*****************************************************/

#ifndef MESH_NO_MASTER
template<class network_t, class radio_t>
bool ESBMesh<network_t, radio_t>::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<class network_t, class radio_t>
uint16_t ESBMesh<network_t, radio_t>::renewAddress(uint32_t timeout)
{
Expand Down
12 changes: 12 additions & 0 deletions RF24Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,18 @@ class ESBMesh
addrListStruct* addrList;
/** @brief The number of entries in the addrListStruct of assigned addresses. */
uint8_t addrListTop;

/**
* 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 notifying the nodes that
* might be appropriating them.
*
* @param address The address to release from any mesh node.
* @return True if successfully released, otherwise false.
*/
bool releaseAddress(uint16_t address);
#endif
/**@}*/

Expand Down
35 changes: 30 additions & 5 deletions pyRF24Mesh/pyRF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(renewAddress_overload, RF24Mesh::renewAdd
// ******************** RF24Mesh exposed **************************
BOOST_PYTHON_MODULE(RF24Mesh)
{
{ //::RF24Mesh
{
/* Binding this class is useless unless we can properly expose RF24Mesh::addrList.
A converter from addrListStruct[] to bp::list<AddrListStruct> needs to be implemented.
// ::RF24Mesh::addrListStruct
bp::class_<RF24Mesh::addrListStruct>("addrListStruct", bp::init<>())
.def_readonly("nodeID", &RF24Mesh::addrListStruct::nodeID)
.def_readwrite("address", &RF24Mesh::addrListStruct::address);
*/

//::RF24Mesh
bp::class_<RF24Mesh>("RF24Mesh", bp::init<RF24&, RF24Network&>((bp::arg("_radio"), bp::arg("_network"))))
//bool begin(uint8_t channel = MESH_DEFAULT_CHANNEL, rf24_datarate_e data_rate = RF24_1MBPS, uint32_t timeout=MESH_RENEWAL_TIMEOUT );
.def("begin", &RF24Mesh::begin, begin_overload(bp::args("channel", "data_rate", "timeout")))
Expand All @@ -80,14 +89,22 @@ BOOST_PYTHON_MODULE(RF24Mesh)
.def("setNodeID", &RF24Mesh::setNodeID, (bp::arg("nodeID")))
//void DHCP();
.def("DHCP", &RF24Mesh::DHCP)
//int16_t getNodeID(uint16_t address=MESH_BLANK_ID);
//int16_t getNodeID(uint16_t address);
.def("getNodeID", &RF24Mesh::getNodeID, getNodeID_overload(bp::args("address")))
//int16_t getNodeID(); where address arg defaults to MESH_BLANK_ID
.def("getNodeID", &RF24Mesh::getNodeID, getNodeID_overload())
//bool checkConnection();
.def("checkConnection", &RF24Mesh::checkConnection)
//uint16_t renewAddress(uint32_t timeout=MESH_RENEWAL_TIMEOUT);
.def("renewAddress", &RF24Mesh::renewAddress, getNodeID_overload(bp::args("timeout")))
//uint16_t renewAddress(uint32_t timeout);
.def("renewAddress", &RF24Mesh::renewAddress, renewAddress_overload(bp::args("timeout")))
//uint16_t renewAddress(); where timeout arg defaults to MESH_RENEWAL_TIMEOUT
.def("renewAddress", &RF24Mesh::renewAddress, renewAddress_overload())
//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);
Expand All @@ -100,6 +117,14 @@ BOOST_PYTHON_MODULE(RF24Mesh)
.def("saveDHCP", &RF24Mesh::saveDHCP)
//void loadDHCP();
.def("loadDHCP", &RF24Mesh::loadDHCP)
// mesh_address
.def_readwrite("mesh_address", &RF24Mesh::mesh_address)

// Returning an array of wrapped addrListStruct objects in boost.python is non-trivial.
// I'm commenting out the members related to the RF24Mesh::addrList until a solution can be found.
// .def_readonly("addrListTop", &RF24Mesh::addrListTop)
// .def_readonly("addrList", &RF24Mesh::addrList)

//void setStaticAddress(uint8_t nodeID, uint16_t address);
.def("setStaticAddress", &RF24Mesh::setStaticAddress, (bp::arg("nodeID"), bp::arg("address")));
}
Expand Down
1 change: 0 additions & 1 deletion pyRF24Mesh/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"RF24Mesh",
sources=["pyRF24Mesh.cpp"],
libraries=["rf24mesh", "rf24network", "rf24", BOOST_LIB],
extra_compile_args=["-DRF24_NO_INTERRUPT"]
)
],
)

0 comments on commit dc29068

Please sign in to comment.