Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
4.4 KiB

  1. #include "boost/python.hpp"
  2. #include "RF24/RF24.h"
  3. #include "RF24Network/RF24Network.h"
  4. #include "RF24Mesh/RF24Mesh.h"
  5. namespace bp = boost::python;
  6. // ******************** explicit wrappers **************************
  7. // where needed, especially where buffer is involved
  8. void throw_ba_exception(void)
  9. {
  10. PyErr_SetString(PyExc_TypeError, "buf parameter must be bytes or bytearray");
  11. bp::throw_error_already_set();
  12. }
  13. char *get_bytes_or_bytearray_str(bp::object buf)
  14. {
  15. PyObject *py_ba;
  16. py_ba = buf.ptr();
  17. if (PyByteArray_Check(py_ba))
  18. return PyByteArray_AsString(py_ba);
  19. else if (PyBytes_Check(py_ba))
  20. return PyBytes_AsString(py_ba);
  21. else
  22. throw_ba_exception();
  23. return NULL;
  24. }
  25. int get_bytes_or_bytearray_ln(bp::object buf)
  26. {
  27. PyObject *py_ba;
  28. py_ba = buf.ptr();
  29. if (PyByteArray_Check(py_ba))
  30. return PyByteArray_Size(py_ba);
  31. else if (PyBytes_Check(py_ba))
  32. return PyBytes_Size(py_ba);
  33. else
  34. throw_ba_exception();
  35. return 0;
  36. }
  37. bool write_wrap1(RF24Mesh& ref, bp::object buf, uint8_t msg_type)
  38. {
  39. return ref.write(get_bytes_or_bytearray_str(buf), msg_type, get_bytes_or_bytearray_ln(buf));
  40. }
  41. bool write_wrap2(RF24Mesh& ref, bp::object buf, uint8_t msg_type, uint8_t nodeID)
  42. {
  43. return ref.write(get_bytes_or_bytearray_str(buf), msg_type, get_bytes_or_bytearray_ln(buf), nodeID);
  44. }
  45. bool write_to_node_wrap(RF24Mesh& ref, uint16_t to_node, bp::object buf, uint8_t msg_type)
  46. {
  47. return ref.write(to_node, get_bytes_or_bytearray_str(buf), msg_type, get_bytes_or_bytearray_ln(buf));
  48. }
  49. // ******************** overload wrappers **************************
  50. BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(begin_overload, RF24Mesh::begin, 0, 3)
  51. BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getNodeID_overload, RF24Mesh::getNodeID, 0, 1)
  52. BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(renewAddress_overload, RF24Mesh::renewAddress, 0, 1)
  53. // ******************** RF24Mesh exposed **************************
  54. BOOST_PYTHON_MODULE(RF24Mesh)
  55. {
  56. { //::RF24Mesh
  57. bp::class_<RF24Mesh>("RF24Mesh", bp::init<RF24&, RF24Network&>((bp::arg("_radio"), bp::arg("_network"))))
  58. //bool begin(uint8_t channel = MESH_DEFAULT_CHANNEL, rf24_datarate_e data_rate = RF24_1MBPS, uint32_t timeout=MESH_RENEWAL_TIMEOUT );
  59. .def("begin", &RF24Mesh::begin, begin_overload(bp::args("channel", "data_rate", "timeout")))
  60. //uint8_t update();
  61. .def("update", &RF24Mesh::update)
  62. //bool write(const void* data, uint8_t msg_type, size_t size, uint8_t nodeID=0);
  63. .def("write", &write_wrap1, (bp::arg("data"), bp::arg("msg_type")))
  64. .def("write", &write_wrap2, (bp::arg("data"), bp::arg("msg_type"), bp::arg("nodeID")))
  65. //bool write(uint16_t to_node, const void* data, uint8_t msg_type, size_t size );
  66. .def("write", &write_to_node_wrap, (bp::arg("to_node"), bp::arg("data"), bp::arg("msg_type"), bp::arg("size")))
  67. //void setNodeID(uint8_t nodeID);
  68. .def("setNodeID", &RF24Mesh::setNodeID, (bp::arg("nodeID")))
  69. //void DHCP();
  70. .def("DHCP", &RF24Mesh::DHCP)
  71. //int16_t getNodeID(uint16_t address=MESH_BLANK_ID);
  72. .def("getNodeID", &RF24Mesh::getNodeID, getNodeID_overload(bp::args("address")))
  73. //bool checkConnection();
  74. .def("checkConnection", &RF24Mesh::checkConnection)
  75. //uint16_t renewAddress(uint32_t timeout=MESH_RENEWAL_TIMEOUT);
  76. .def("renewAddress", &RF24Mesh::renewAddress, getNodeID_overload(bp::args("timeout")))
  77. //bool releaseAddress();
  78. .def("releaseAddress", &RF24Mesh::releaseAddress)
  79. //int16_t getAddress(uint8_t nodeID);
  80. .def("getAddress", &RF24Mesh::getAddress, (bp::arg("nodeID")))
  81. //void setChannel(uint8_t _channel);
  82. .def("setChannel", &RF24Mesh::setChannel, (bp::arg("_channel")))
  83. //void setChild(bool allow);
  84. .def("setChild", &RF24Mesh::setChild, (bp::arg("allow")))
  85. //void setAddress(uint8_t nodeID, uint16_t address);
  86. .def("setAddress", &RF24Mesh::setAddress, (bp::arg("nodeID"), bp::arg("address")))
  87. //void saveDHCP();
  88. .def("saveDHCP", &RF24Mesh::saveDHCP)
  89. //void loadDHCP();
  90. .def("loadDHCP", &RF24Mesh::loadDHCP)
  91. //void setStaticAddress(uint8_t nodeID, uint16_t address);
  92. .def("setStaticAddress", &RF24Mesh::setStaticAddress, (bp::arg("nodeID"), bp::arg("address")));
  93. }
  94. }