Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose releaseAddress() for master node #244

Merged
merged 8 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized this should be spelled MESH_NOMASTER. I'll submit a commit to master to fix this.

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
Comment on lines -90 to +107
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to test this in the python wrapper (on a master and a child) to ensure I did this correctly. I know it compiles, but that doesn't indicate expected runtime behavior.

Copy link
Member Author

@2bndy5 2bndy5 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work as expected on master nodes and child nodes. However, I'm noticing problems with the overloads for getNodeId() and renewAddress() in the python wrapper.

These py bindings also don't expose the RF24Mesh::addrList & friends. So py users have no way of checking the assigned addresses on master nodes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bindings for getNodeID() and renewAddress() are fixed now.

I gave up on exposing RF24Mesh::addrList because boost.python needs to understand how to convert the returned addrListStruct* array into a python list (or tuple) of wrapped addrListStruct objects.

FYI, all of this is already done in pyrf24 package, and the get/setAddress() with the new overloaded releaseAddress(uint16_t address) can be used as a limited alternative. So, I'm not too concerned about perusing this further.

//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"]
)
],
)