diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 81dbcfc..1ea694b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -49,8 +49,9 @@ jobs: - name: Build package for docs extraction and linting examples run: | - python3 setup.py sdist bdist_wheel - python3 -m pip install dist/pyrf24-*.whl + python -m pip install build + python -m build + python -m pip install dist/pyrf24-*.whl - name: check python typing run: mypy src diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dab9043..ccbf2cc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,7 +45,9 @@ jobs: - name: build source distributable wheel # sdist for non-supprted platforms will serve as a stub lib install - run: python setup.py sdist + run: | + python -m pip install build + python -m build -s - name: Save distributable wheels as artifacts uses: actions/upload-artifact@v4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2224c75..9cac101 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.15) project(pyrf24) if(SKBUILD) - message(STATUS "This project is being built using scikit-build & pybind11") + message(STATUS "This project is being built using scikit-build & pybind11") endif() set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) @@ -14,112 +14,61 @@ include(cmake/using_flags.cmake) add_subdirectory(pybind11) include(RF24/cmake/AutoConfig_RF24_DRIVER.cmake) add_subdirectory(RF24/utility) # configure the RF24_DRIVER + if(NOT "${RF24_LINKED_DRIVER}" STREQUAL "") message(STATUS "Linking to utility driver '${RF24_LINKED_DRIVER}'") endif() -# suplement our copy of linux/gpio.h into SPIDEV & RPi driver sources +# suplement our copy of linux/gpio.h into SPIDEV driver sources set(SUPPLEMENT_LINUX_GPIO_H FALSE) + if("${RF24_DRIVER}" STREQUAL "SPIDEV") set(SUPPLEMENT_LINUX_GPIO_H TRUE) message(STATUS "Supplementing ${RF24_DRIVER} driver with linux/gpio.h") - # file(COPY src/linux/gpio.h DESTINATION RF24/utility/${RF24_DRIVER}/linux) list(APPEND RF24_DRIVER_SOURCES src/linux/gpio.h) endif() -### Build C++ RF24 stack as shared libraries (resulting in isolated binary drivers) - -################################# RF24 C++ ######################### -add_library(cpp_rf24 SHARED +# ## Build python bindings for RF24 stack into 1 binary +pybind11_add_module(pyrf24 RF24/RF24.cpp ${RF24_DRIVER_SOURCES} -) -if(SUPPLEMENT_LINUX_GPIO_H) - target_include_directories(cpp_rf24 PUBLIC src) -endif() -target_include_directories(cpp_rf24 PUBLIC utility) -if(NOT "${RF24_LINKED_DRIVER}" STREQUAL "") - if("${RF24_DRIVER}" STREQUAL "wiringPi") - target_link_libraries(cpp_rf24 PUBLIC rt crypt ${RF24_LINKED_DRIVER}) - else() - target_link_libraries(cpp_rf24 PUBLIC ${RF24_LINKED_DRIVER}) - endif() -endif() -apply_flags(cpp_rf24) - -################################# RF24Network C++ ######################### -add_library(cpp_rf24_network SHARED RF24Network/RF24Network.cpp -) -# don't let source look for an installed RF24 lib -target_compile_definitions(cpp_rf24_network PUBLIC USE_RF24_LIB_SRC) -target_include_directories(cpp_rf24_network PUBLIC - RF24 - RF24/utility - RF24/utility/${RF24_DRIVER} - RF24Network -) -target_link_libraries(cpp_rf24_network PUBLIC cpp_rf24) -apply_flags(cpp_rf24_network) - -################################# RF24Mesh C++ ######################### -add_library(cpp_rf24_mesh SHARED RF24Mesh/RF24Mesh.cpp -) -# don't let source look for an installed RF24 lib -target_compile_definitions(cpp_rf24_mesh PUBLIC USE_RF24_LIB_SRC) -target_include_directories(cpp_rf24_mesh PUBLIC - RF24 - RF24/utility - RF24/utility/${RF24_DRIVER} - RF24Network - RF24Mesh -) -target_link_libraries(cpp_rf24_mesh PUBLIC cpp_rf24_network) -apply_flags(cpp_rf24_mesh) - -### Build python bindings for RF24 stack and link to shared C++ lib binaries - -################################# RF24 ############################# -pybind11_add_module(rf24 src/pyRF24.cpp) -target_link_libraries(rf24 PUBLIC cpp_rf24) -target_include_directories(rf24 PUBLIC - RF24 - RF24/utility - RF24/utility/${RF24_DRIVER} + src/pyRF24.cpp + src/pyRF24Network.cpp + src/pyRF24Mesh.cpp + src/glue.cpp ) -################################# RF24NETWORK ############################# -pybind11_add_module(rf24_network src/pyRF24Network.cpp) -target_link_libraries(rf24_network PUBLIC cpp_rf24_network) -target_include_directories(rf24_network PUBLIC - RF24 - RF24/utility - RF24/utility/${RF24_DRIVER} - RF24Network -) # don't let source look for an installed RF24 lib -target_compile_definitions(rf24_network PUBLIC USE_RF24_LIB_SRC) +target_compile_definitions(pyrf24 PUBLIC USE_RF24_LIB_SRC) + +if(SUPPLEMENT_LINUX_GPIO_H) + target_include_directories(pyrf24 PUBLIC src) +endif() -################################# RF24MESH ############################# -pybind11_add_module(rf24_mesh src/pyRF24Mesh.cpp) -target_link_libraries(rf24_mesh PUBLIC cpp_rf24_mesh) -target_include_directories(rf24_mesh PUBLIC +target_include_directories(pyrf24 PUBLIC RF24 RF24/utility RF24/utility/${RF24_DRIVER} RF24Network RF24Mesh ) -# don't let source look for an installed RF24 lib -target_compile_definitions(rf24_mesh PUBLIC USE_RF24_LIB_SRC) +if(NOT "${RF24_LINKED_DRIVER}" STREQUAL "") + if("${RF24_DRIVER}" STREQUAL "wiringPi") + target_link_libraries(pyrf24 PUBLIC rt crypt ${RF24_LINKED_DRIVER}) + else() + target_link_libraries(pyrf24 PUBLIC ${RF24_LINKED_DRIVER}) + endif() +endif() + +apply_flags(pyrf24) -################################ INSTALL RULES #################################### -# these are needed for scikit builds since the resulting .so files are copied into +# ############################### INSTALL RULES #################################### +# these are needed since the resulting .so files are copied into # the binary distribution wheels (.whl files) for python. -install(TARGETS rf24 rf24_network rf24_mesh DESTINATION .) -install(TARGETS cpp_rf24 cpp_rf24_network cpp_rf24_mesh DESTINATION .) +install(TARGETS pyrf24 DESTINATION .) -# uncomment to show compiler args used in build logs +# ## uncomment to show compiler args used in build logs # set(CMAKE_VERBOSE_MAKEFILE ON) diff --git a/cmake/using_flags.cmake b/cmake/using_flags.cmake index 69a7d5c..88116cc 100644 --- a/cmake/using_flags.cmake +++ b/cmake/using_flags.cmake @@ -1,10 +1,9 @@ +# ###################### DEBUG (& EXTRA) FLAGS ###################### -####################### DEBUG (& EXTRA) FLAGS ###################### +# ## RF24 core specific options +# option(RF24_DEBUG "enable/disable debugging output for RF24 lib" OFF) -# RF24 core specific options -option(RF24_DEBUG "enable/disable debugging output for RF24 lib" OFF) - -# RF24Network specific options +# ## RF24Network specific options option(SERIAL_DEBUG "enable/disable debugging output for RF24Network lib" OFF) option(SERIAL_DEBUG_MINIMAL "enable/disable minimal debugging output for RF24Network lib" OFF) option(SERIAL_DEBUG_ROUTING @@ -21,126 +20,146 @@ option(SERIAL_DEBUG_FRAGMENTATION_L2 ) option(DISABLE_FRAGMENTATION "disable message fragmentation for RF24Network lib" OFF) option(DISABLE_DYNAMIC_PAYLOADS "force usage of static payload size for RF24Network lib" OFF) -# options with default values: + +# ### options with default values: + # SLOW_ADDR_POLL_RESPONSE -# This can be useful to set a custom delay (in microseconds) for the master node when a -# connecting child node is slow to execute. +# This can be useful to set a custom delay (in microseconds) for the master node when a +# connecting child node is slow to execute. + # MAX_PAYLOAD_SIZE -# This can be used to increase/decrease the maximum size of a message (before fragmentation). -# A value <= 24 is a less efficient alternative to DISABLE_FRAGMENTATION option. +# This can be used to increase/decrease the maximum size of a message (before fragmentation). +# A value <= 24 is a less efficient alternative to DISABLE_FRAGMENTATION option. -# RF24Mesh specific options +# ## RF24Mesh specific options option(MESH_NOMASTER "exclude compiling code that is strictly for master nodes for RF24Mesh lib" OFF) option(MESH_DEBUG "enable/disable debugging output for RF24Mesh lib" OFF) option(MESH_DEBUG_MINIMAL "enable/disable minimal debugging output for RF24Mesh lib" OFF) -# options with default values: + +# ### options with default values: + # MESH_MAX_CHILDREN -# This can be used to prevent mesh child nodes from occupying all available pipes on network layers. -# Only recommended if combining RF24Network nodes w/ RF24Mesh nodes on the same network. +# This can be used to prevent mesh child nodes from occupying all available pipes on network layers. +# Only recommended if combining RF24Network nodes w/ RF24Mesh nodes on the same network. + # MESH_DEFAULT_CHANNEL -# A compile time alternative to using radio.setChannel() at runtime. Accepted values range [0, 125]. +# A compile time alternative to using radio.setChannel() at runtime. Accepted values range [0, 125]. + # MESH_RENEWAL_TIMEOUT -# A compile time alternative to using the timeout parameter to mesh.renew_address() at runtime. +# A compile time alternative to using the timeout parameter to mesh.renew_address() at runtime. + # MESH_MEM_ALLOC_SIZE -# Advanced usage only! This controls the initial allocated memory for the master node's DHCP list. +# Advanced usage only! This controls the initial allocated memory for the master node's DHCP list. + # MESH_LOOKUP_TIMEOUT -# This can be used to increase/decrease the time spent waiting for master node's respond to -# a lookup message. -# MESH_WRITE_TIMEOUT -# This can be used to increase/decrease the time spent ensuring success during -# mesh.write() (only when using node_id instead of a node's logical address). -# This is cumulative to MESH_LOOKUP_TIMEOUT. +# This can be used to increase/decrease the time spent waiting for master node's respond to +# a lookup message. +# MESH_WRITE_TIMEOUT +# This can be used to increase/decrease the time spent ensuring success during +# mesh.write() (only when using node_id instead of a node's logical address). +# This is cumulative to MESH_LOOKUP_TIMEOUT. -############################################### +# ############################################## # function to apply flags to applicable targets function(apply_flags target) # apply RF24 flags to cpp_rf24 target - if("${target}" STREQUAL "cpp_rf24") - if(RF24_DEBUG) - message(STATUS "RF24_DEBUG asserted for ${target}") - target_compile_definitions(${target} PUBLIC SERIAL_DEBUG) - endif() - endif() + # if(RF24_DEBUG) + # message(STATUS "RF24_DEBUG asserted for ${target}") + # target_compile_definitions(${target} PUBLIC SERIAL_DEBUG) + # endif() - # pass driver used to expose as a constant in rf24 module. + # pass driver used to expose as a constant in rf24 module. target_compile_definitions(${target} PUBLIC RF24_DRIVER="${RF24_DRIVER}") # apply RF24Network flags to cpp_rf24_network target - if("${target}" STREQUAL "cpp_rf24_network") - if(SERIAL_DEBUG) - message(STATUS "SERIAL_DEBUG asserted for ${target}") - target_compile_definitions(${target} PUBLIC SERIAL_DEBUG) - endif() - if(SERIAL_DEBUG_MINIMAL) - message(STATUS "SERIAL_DEBUG_MINIMAL asserted for ${target}") - target_compile_definitions(${target} PUBLIC SERIAL_DEBUG_MINIMAL) - endif() - if(SERIAL_DEBUG_ROUTING) - message(STATUS "SERIAL_DEBUG_ROUTING asserted for ${target}") - target_compile_definitions(${target} PUBLIC SERIAL_DEBUG_ROUTING) - endif() - if(SERIAL_DEBUG_FRAGMENTATION) - message(STATUS "SERIAL_DEBUG_FRAGMENTATION asserted for ${target}") - target_compile_definitions(${target} PUBLIC SERIAL_DEBUG_FRAGMENTATION) - endif() - if(SERIAL_DEBUG_FRAGMENTATION_L2) - message(STATUS "SERIAL_DEBUG_FRAGMENTATION_L2 asserted for ${target}") - target_compile_definitions(${target} PUBLIC SERIAL_DEBUG_FRAGMENTATION_L2) - endif() - if(DISABLE_FRAGMENTATION) - message(STATUS "DISABLE_FRAGMENTATION asserted for ${target}") - target_compile_definitions(${target} PUBLIC DISABLE_FRAGMENTATION) - endif() - # for MAX_PAYLOAD_SIZE, we let the default be configured in source code - if(DEFINED MAX_PAYLOAD_SIZE) # don't use CMake's `option()` for this one - message(STATUS "MAX_PAYLOAD_SIZE set to ${MAX_PAYLOAD_SIZE} for ${target}") - target_compile_definitions(${target} PUBLIC MAX_PAYLOAD_SIZE=${MAX_PAYLOAD_SIZE}) - endif() - if(DEFINED SLOW_ADDR_POLL_RESPONSE) - message(STATUS "SLOW_ADDR_POLL_RESPONSE set to ${SLOW_ADDR_POLL_RESPONSE} for ${target}") - target_compile_definitions(${target} PUBLIC SLOW_ADDR_POLL_RESPONSE=${SLOW_ADDR_POLL_RESPONSE}) - endif() + if(SERIAL_DEBUG) + # this flag also applies to RF24 lib because + # the samme macro name is used to enable debug output in RF24 + message(STATUS "SERIAL_DEBUG asserted for ${target}") + target_compile_definitions(${target} PUBLIC SERIAL_DEBUG) + endif() + + if(SERIAL_DEBUG_MINIMAL) + message(STATUS "SERIAL_DEBUG_MINIMAL asserted for ${target}") + target_compile_definitions(${target} PUBLIC SERIAL_DEBUG_MINIMAL) + endif() + + if(SERIAL_DEBUG_ROUTING) + message(STATUS "SERIAL_DEBUG_ROUTING asserted for ${target}") + target_compile_definitions(${target} PUBLIC SERIAL_DEBUG_ROUTING) + endif() + + if(SERIAL_DEBUG_FRAGMENTATION) + message(STATUS "SERIAL_DEBUG_FRAGMENTATION asserted for ${target}") + target_compile_definitions(${target} PUBLIC SERIAL_DEBUG_FRAGMENTATION) + endif() + + if(SERIAL_DEBUG_FRAGMENTATION_L2) + message(STATUS "SERIAL_DEBUG_FRAGMENTATION_L2 asserted for ${target}") + target_compile_definitions(${target} PUBLIC SERIAL_DEBUG_FRAGMENTATION_L2) + endif() + + if(DISABLE_FRAGMENTATION) + message(STATUS "DISABLE_FRAGMENTATION asserted for ${target}") + target_compile_definitions(${target} PUBLIC DISABLE_FRAGMENTATION) + endif() + + # for MAX_PAYLOAD_SIZE, we let the default be configured in source code + if(DEFINED MAX_PAYLOAD_SIZE) # don't use CMake's `option()` for this one + message(STATUS "MAX_PAYLOAD_SIZE set to ${MAX_PAYLOAD_SIZE} for ${target}") + target_compile_definitions(${target} PUBLIC MAX_PAYLOAD_SIZE=${MAX_PAYLOAD_SIZE}) + endif() + + if(DEFINED SLOW_ADDR_POLL_RESPONSE) + message(STATUS "SLOW_ADDR_POLL_RESPONSE set to ${SLOW_ADDR_POLL_RESPONSE} for ${target}") + target_compile_definitions(${target} PUBLIC SLOW_ADDR_POLL_RESPONSE=${SLOW_ADDR_POLL_RESPONSE}) endif() # apply RF24Mesh flags to cpp_rf24_mesh target - if("${target}" STREQUAL "cpp_rf24_mesh") - if(MESH_NOMASTER) - message(STATUS "MESH_NOMASTER asserted for ${target}") - target_compile_definitions(${target} PUBLIC MESH_NOMASTER) - endif() - if(MESH_DEBUG) - message(STATUS "MESH_DEBUG asserted for ${target}") - target_compile_definitions(${target} PUBLIC MESH_DEBUG) - endif() - if(MESH_DEBUG_MINIMAL) - message(STATUS "MESH_DEBUG_MINIMAL asserted for ${target}") - target_compile_definitions(${target} PUBLIC MESH_DEBUG_MINIMAL) - endif() - # for the following, we let the default be configured in source code - if(DEFINED MESH_MAX_CHILDREN) - message(STATUS "MESH_MAX_CHILDREN set to ${MESH_MAX_CHILDREN} for ${target}") - target_compile_definitions(${target} PUBLIC MESH_MAX_CHILDREN=${MESH_MAX_CHILDREN}) - endif() - if(DEFINED MESH_DEFAULT_CHANNEL) - message(STATUS "MESH_DEFAULT_CHANNEL set to ${MESH_DEFAULT_CHANNEL} for ${target}") - target_compile_definitions(${target} PUBLIC MESH_DEFAULT_CHANNEL=${MESH_DEFAULT_CHANNEL}) - endif() - if(DEFINED MESH_RENEWAL_TIMEOUT) - message(STATUS "MESH_RENEWAL_TIMEOUT set to ${MESH_RENEWAL_TIMEOUT} for ${target}") - target_compile_definitions(${target} PUBLIC MESH_RENEWAL_TIMEOUT=${MESH_RENEWAL_TIMEOUT}) - endif() - if(DEFINED MESH_MEM_ALLOC_SIZE) - message(STATUS "MESH_MEM_ALLOC_SIZE set to ${MESH_MEM_ALLOC_SIZE} for ${target}") - target_compile_definitions(${target} PUBLIC MESH_MEM_ALLOC_SIZE=${MESH_MEM_ALLOC_SIZE}) - endif() - if(DEFINED MESH_LOOKUP_TIMEOUT) - message(STATUS "MESH_LOOKUP_TIMEOUT set to ${MESH_LOOKUP_TIMEOUT} for ${target}") - target_compile_definitions(${target} PUBLIC MESH_LOOKUP_TIMEOUT=${MESH_LOOKUP_TIMEOUT}) - endif() - if(DEFINED MESH_WRITE_TIMEOUT) - message(STATUS "MESH_WRITE_TIMEOUT set to ${MESH_WRITE_TIMEOUT} for ${target}") - target_compile_definitions(${target} PUBLIC MESH_WRITE_TIMEOUT=${MESH_WRITE_TIMEOUT}) - endif() + if(MESH_NOMASTER) + message(STATUS "MESH_NOMASTER asserted for ${target}") + target_compile_definitions(${target} PUBLIC MESH_NOMASTER) + endif() + + if(MESH_DEBUG) + message(STATUS "MESH_DEBUG asserted for ${target}") + target_compile_definitions(${target} PUBLIC MESH_DEBUG) + endif() + + if(MESH_DEBUG_MINIMAL) + message(STATUS "MESH_DEBUG_MINIMAL asserted for ${target}") + target_compile_definitions(${target} PUBLIC MESH_DEBUG_MINIMAL) + endif() + + # for the following, we let the default be configured in source code + if(DEFINED MESH_MAX_CHILDREN) + message(STATUS "MESH_MAX_CHILDREN set to ${MESH_MAX_CHILDREN} for ${target}") + target_compile_definitions(${target} PUBLIC MESH_MAX_CHILDREN=${MESH_MAX_CHILDREN}) + endif() + + if(DEFINED MESH_DEFAULT_CHANNEL) + message(STATUS "MESH_DEFAULT_CHANNEL set to ${MESH_DEFAULT_CHANNEL} for ${target}") + target_compile_definitions(${target} PUBLIC MESH_DEFAULT_CHANNEL=${MESH_DEFAULT_CHANNEL}) + endif() + + if(DEFINED MESH_RENEWAL_TIMEOUT) + message(STATUS "MESH_RENEWAL_TIMEOUT set to ${MESH_RENEWAL_TIMEOUT} for ${target}") + target_compile_definitions(${target} PUBLIC MESH_RENEWAL_TIMEOUT=${MESH_RENEWAL_TIMEOUT}) + endif() + + if(DEFINED MESH_MEM_ALLOC_SIZE) + message(STATUS "MESH_MEM_ALLOC_SIZE set to ${MESH_MEM_ALLOC_SIZE} for ${target}") + target_compile_definitions(${target} PUBLIC MESH_MEM_ALLOC_SIZE=${MESH_MEM_ALLOC_SIZE}) + endif() + + if(DEFINED MESH_LOOKUP_TIMEOUT) + message(STATUS "MESH_LOOKUP_TIMEOUT set to ${MESH_LOOKUP_TIMEOUT} for ${target}") + target_compile_definitions(${target} PUBLIC MESH_LOOKUP_TIMEOUT=${MESH_LOOKUP_TIMEOUT}) + endif() + + if(DEFINED MESH_WRITE_TIMEOUT) + message(STATUS "MESH_WRITE_TIMEOUT set to ${MESH_WRITE_TIMEOUT} for ${target}") + target_compile_definitions(${target} PUBLIC MESH_WRITE_TIMEOUT=${MESH_WRITE_TIMEOUT}) endif() endfunction() diff --git a/docs/ble_api.rst b/docs/ble_api.rst index b1929fd..801e671 100644 --- a/docs/ble_api.rst +++ b/docs/ble_api.rst @@ -38,14 +38,14 @@ Restricted RF24 functionality The following `RF24` functionality should not be used when `FakeBLE` objects are instantiated with an `RF24` object: -- :py:attr:`~pyrf24.rf24.RF24.dynamic_payloads` -- :py:attr:`~pyrf24.rf24.RF24.data_rate` -- :py:attr:`~pyrf24.rf24.RF24.address_width` -- :py:meth:`~pyrf24.rf24.RF24.set_auto_ack()` -- :py:attr:`~pyrf24.rf24.RF24.ack_payloads` -- :py:attr:`~pyrf24.rf24.RF24.crc_length` -- :py:meth:`~pyrf24.rf24.RF24.open_rx_pipe()` -- :py:meth:`~pyrf24.rf24.RF24.open_tx_pipe()` +- :py:attr:`~pyrf24.RF24.dynamic_payloads` +- :py:attr:`~pyrf24.RF24.data_rate` +- :py:attr:`~pyrf24.RF24.address_width` +- :py:meth:`~pyrf24.RF24.set_auto_ack()` +- :py:attr:`~pyrf24.RF24.ack_payloads` +- :py:attr:`~pyrf24.RF24.crc_length` +- :py:meth:`~pyrf24.RF24.open_rx_pipe()` +- :py:meth:`~pyrf24.RF24.open_tx_pipe()` Service related classes diff --git a/docs/conf.py b/docs/conf.py index f878872..bdaf813 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -175,7 +175,7 @@ ] python_type_aliases = { - "pyrf24.rf24.rf24_datarate_e": "rf24_datarate_e", + "pyrf24.rf24_datarate_e": "rf24_datarate_e", } # Set link name generated in the top bar. diff --git a/docs/rf24_api.rst b/docs/rf24_api.rst index 4b3d467..279ceac 100644 --- a/docs/rf24_api.rst +++ b/docs/rf24_api.rst @@ -3,37 +3,37 @@ RF24 API ======== -.. automodule:: pyrf24.rf24 +.. currentmodule:: pyrf24 - .. autoattribute:: pyrf24.rf24.RF24_DRIVER +.. autoattribute:: pyrf24.RF24_DRIVER - This `str` describes the backend driver used to build the pyrf24 package. - If installed from pypi, then this value should be ``"SPIDEV"``. - - All other drivers imply that the pyrf24 package was built from source - :ref:`using-specific-driver`. + This `str` describes the backend driver used to build the pyrf24 package. + If installed from pypi, then this value should be ``"SPIDEV"``. + + All other drivers imply that the pyrf24 package was built from source + :ref:`using-specific-driver`. - .. hint:: + .. hint:: - Use this attribute to determine programmatically which pin numbers to use. - Drivers like ``wiringPi`` and ``MRAA`` use their own pin numbering scheme. + Use this attribute to determine programmatically which pin numbers to use. + Drivers like ``wiringPi`` and ``MRAA`` use their own pin numbering scheme. Enum classes ------------ -.. autoclass:: pyrf24.rf24.rf24_crclength_e +.. autoclass:: pyrf24.rf24_crclength_e :members: RF24_CRC_DISABLED, RF24_CRC_8, RF24_CRC_16 -.. autoclass:: pyrf24.rf24.rf24_datarate_e +.. autoclass:: pyrf24.rf24_datarate_e :members: RF24_1MBPS, RF24_2MBPS, RF24_250KBPS -.. autoclass:: pyrf24.rf24.rf24_pa_dbm_e +.. autoclass:: pyrf24.rf24_pa_dbm_e :members: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX RF24 class ---------- -.. autoclass:: pyrf24.rf24.RF24 +.. autoclass:: pyrf24.RF24 Basic RF24 API ************** diff --git a/docs/rf24_mesh_api.rst b/docs/rf24_mesh_api.rst index bc51e2f..528c14d 100644 --- a/docs/rf24_mesh_api.rst +++ b/docs/rf24_mesh_api.rst @@ -3,12 +3,12 @@ RF24Mesh API ============ -.. automodule:: pyrf24.rf24_mesh +.. currentmodule:: pyrf24 RF24Mesh class ************** -.. autoclass:: pyrf24.rf24_mesh.RF24Mesh +.. autoclass:: pyrf24.RF24Mesh Basic RF24Mesh API ------------------ @@ -43,7 +43,7 @@ successful connection to a child node. The `AddrListStruct` class supports the python "magic method" :py:func:`repr()`. So, you can easily pass an instantiated `AddrListStruct` object to the :py:func:`print()` function. -.. autoclass:: pyrf24.rf24_mesh.AddrListStruct +.. autoclass:: pyrf24.AddrListStruct .. autoattribute:: node_id .. autoattribute:: address @@ -53,14 +53,14 @@ Mesh Constants These are the pre-defined constants provided for convenience and code readability. -.. autoattribute:: pyrf24.rf24_mesh.MESH_DEFAULT_ADDRESS +.. autoattribute:: pyrf24.MESH_DEFAULT_ADDRESS A reserved valid address for use with RF24Mesh (when a mesh node requests an assigned address) Reserved System Message Types ----------------------------- -.. autoattribute:: pyrf24.rf24_mesh.MESH_ADDR_LOOKUP +.. autoattribute:: pyrf24.MESH_ADDR_LOOKUP This message type is used to fetch (from the master node) an allocated Logical Address (`mesh_address`) corresponding to specified a mesh node's @@ -68,7 +68,7 @@ Reserved System Message Types This is exclusively used by `get_address()`. -.. autoattribute:: pyrf24.rf24_mesh.MESH_ID_LOOKUP +.. autoattribute:: pyrf24.MESH_ID_LOOKUP This message type is used to fetch (from the master node) a mesh node's :py:attr:`~RF24Mesh.node_id` corresponding to an specified Logical Address @@ -76,7 +76,7 @@ Reserved System Message Types This is exclusively used by `get_node_id()`. -.. autoattribute:: pyrf24.rf24_mesh.MESH_ADDR_RELEASE +.. autoattribute:: pyrf24.MESH_ADDR_RELEASE This message type is used when mesh nodes are consciously disconnecting from the network. It is used to unassign the Logical Address allocated the mesh node's diff --git a/docs/rf24_network_api.rst b/docs/rf24_network_api.rst index b99db96..053ebc3 100644 --- a/docs/rf24_network_api.rst +++ b/docs/rf24_network_api.rst @@ -3,13 +3,13 @@ RF24Network API =============== -.. automodule:: pyrf24.rf24_network +.. currentmodule:: pyrf24 RF24Network class ----------------- -.. autoclass:: pyrf24.rf24_network.RF24Network +.. autoclass:: pyrf24.RF24Network Basic RF24Network API ********************* @@ -36,8 +36,8 @@ RF24Network class External Systems or Applications ******************************** -.. autoattribute:: pyrf24.rf24_network.RF24Network.return_sys_msgs -.. autoattribute:: pyrf24.rf24_network.RF24Network.network_flags +.. autoattribute:: pyrf24.RF24Network.return_sys_msgs +.. autoattribute:: pyrf24.RF24Network.network_flags RF24NetworkHeader class ----------------------- @@ -46,7 +46,7 @@ RF24NetworkHeader class The `RF24NetworkHeader` class supports the python "magic method" :py:func:`repr()`. So, you can easily pass an instantiated `RF24NetworkHeader` object to the :py:func:`print()` function. -.. autoclass:: pyrf24.rf24_network.RF24NetworkHeader +.. autoclass:: pyrf24.RF24NetworkHeader .. autoattribute:: to_node .. autoattribute:: type @@ -66,11 +66,11 @@ Constants The following are predefined module-level constants that can be used for comparisons and code readability. -.. autoattribute:: pyrf24.rf24_network.MAX_USER_DEFINED_HEADER_TYPE +.. autoattribute:: pyrf24.MAX_USER_DEFINED_HEADER_TYPE The maximum of user defined message types. -.. autoattribute:: pyrf24.rf24_network.MAX_PAYLOAD_SIZE +.. autoattribute:: pyrf24.MAX_PAYLOAD_SIZE Maximum size of fragmented network frames and fragmentation cache. @@ -87,7 +87,7 @@ The network will determine whether to automatically acknowledge payloads based o System types can also contain message data. -.. autoattribute:: pyrf24.rf24_network.NETWORK_ADDR_RESPONSE +.. autoattribute:: pyrf24.NETWORK_ADDR_RESPONSE A ``NETWORK_ADDR_RESPONSE`` type is utilized to manually route custom messages containing a single RF24Network address. @@ -100,32 +100,32 @@ System types can also contain message data. This allows nodes to forward multicast messages to the master node, receive a response, and forward it back to the requester. -.. autoattribute:: pyrf24.rf24_network.NETWORK_PING +.. autoattribute:: pyrf24.NETWORK_PING Messages of type ``NETWORK_PING`` will be dropped automatically by the recipient. A `NETWORK_ACK` or automatic radio-ack will indicate to the sender whether the payload was successful. The time it takes to successfully send a ``NETWORK_PING`` is the round-trip-time. -.. autoattribute:: pyrf24.rf24_network.EXTERNAL_DATA_TYPE +.. autoattribute:: pyrf24.EXTERNAL_DATA_TYPE External data types are used to define messages that will be passed to an external data system. This allows RF24Network to route and pass any type of data, such as TCP/IP frames, while still being able to utilize standard RF24Network messages etc. -.. autoattribute:: pyrf24.rf24_network.NETWORK_FIRST_FRAGMENT +.. autoattribute:: pyrf24.NETWORK_FIRST_FRAGMENT Messages of this type designate the first of two or more message fragments, and will be re-assembled automatically. -.. autoattribute:: pyrf24.rf24_network.NETWORK_MORE_FRAGMENTS +.. autoattribute:: pyrf24.NETWORK_MORE_FRAGMENTS Messages of this type indicate a fragmented payload with two or more message fragments. -.. autoattribute:: pyrf24.rf24_network.NETWORK_LAST_FRAGMENT +.. autoattribute:: pyrf24.NETWORK_LAST_FRAGMENT Messages of this type indicate the last fragment in a sequence of message fragments. Messages of this type do not receive a `NETWORK_ACK`. -.. autoattribute:: pyrf24.rf24_network.NETWORK_ACK +.. autoattribute:: pyrf24.NETWORK_ACK Messages of this type signal the sender that a network-wide transmission has been completed. @@ -161,7 +161,7 @@ System types can also contain message data. ie: When node ``0o0`` sends an instigating message to node ``0o11``, node ``0o1`` will send the ``NETWORK_ACK`` message to ``0o0`` upon successful delivery of instigating message to node ``0o11``. -.. autoattribute:: pyrf24.rf24_network.NETWORK_POLL +.. autoattribute:: pyrf24.NETWORK_POLL Used by RF24Mesh. @@ -169,7 +169,7 @@ System types can also contain message data. Any node receiving a NETWORK_POLL sent to a multicast address will respond directly to the sender with a blank message, indicating the address of the available node via the header. -.. autoattribute:: pyrf24.rf24_network.NETWORK_REQ_ADDRESS +.. autoattribute:: pyrf24.NETWORK_REQ_ADDRESS Used by RF24Mesh @@ -179,13 +179,13 @@ System types can also contain message data. Network flag mnemonics *********************** -.. autoattribute:: pyrf24.rf24_network.FLAG_FAST_FRAG +.. autoattribute:: pyrf24.FLAG_FAST_FRAG This flag (when asserted in :py:attr:`~RF24Network.network_flags`) prevents repetitively configuring the radio during transmission of fragmented messages. -.. autoattribute:: pyrf24.rf24_network.FLAG_NO_POLL +.. autoattribute:: pyrf24.FLAG_NO_POLL This flag (when asserted in :py:attr:`~RF24Network.network_flags`) prevents a node from responding to - mesh nodes looking to connect to the network. Calling :py:func:`~pyrf24.rf24_mesh.RF24Mesh.set_child()` uses this flag + mesh nodes looking to connect to the network. Calling :py:func:`~pyrf24.RF24Mesh.set_child()` uses this flag accordingly. diff --git a/docs/topology.rst b/docs/topology.rst index 29945df..1383e0b 100644 --- a/docs/topology.rst +++ b/docs/topology.rst @@ -113,7 +113,7 @@ For a message to travel from node ``0o124`` to node ``0o3``, it must be passed t network levels. So, the message flows ``0o124`` -> ``0o24`` -> ``0o4`` -> ``0o0`` -> ``0o3``. A single network can potentially have a maximum of 781 nodes (all operating on the same -:attr:`~pyrf24.rf24.RF24.channel`), but for readability reasons, the following +:attr:`~pyrf24.RF24.channel`), but for readability reasons, the following graph only demonstrates - the master node (level 0) and it's 5 children (level 1) @@ -216,7 +216,7 @@ Physical addresses vs Logical addresses number ``0`` .. tip:: - Use the :py:meth:`~pyrf24.rf24_network.RF24Network.is_address_valid()` + Use the :py:meth:`~pyrf24.RF24Network.is_address_valid()` function to programmatically check a Logical Address for validity. .. note:: @@ -295,7 +295,7 @@ RF24Mesh connecting process As noted above, a single network *can* have up to 781 nodes. This number also includes up to 255 RF24Mesh nodes. The key difference from the user's perspective is that RF24Mesh API does not publicly use a `Logical Address `. Instead the RF24Mesh API -relies on a :attr:`~pyrf24.rf24_mesh.RF24Mesh.node_id` number to identify a RF24Mesh node +relies on a :attr:`~pyrf24.RF24Mesh.node_id` number to identify a RF24Mesh node that may use a different `Logical Address ` (which can change based on the node's physical location). @@ -305,17 +305,17 @@ the node's physical location). is layered on top of the RF24Network API. To better explain the difference between a node's `mesh_address` vs a node's -:attr:`~pyrf24.rf24_mesh.RF24Mesh.node_id`, we will examine the connecting process for a +:attr:`~pyrf24.RF24Mesh.node_id`, we will examine the connecting process for a RF24Mesh node. These are the steps performed when calling `renew_address()`: 1. Any RF24Mesh node not connected to a network will use the `Logical Address ` ``0o4444`` (that's ``2340`` in decimal). It is up to the network administrator to ensure that - each RF24Mesh node has a unique :attr:`~pyrf24.rf24_mesh.RF24Mesh.node_id` (which is limited + each RF24Mesh node has a unique :attr:`~pyrf24.RF24Mesh.node_id` (which is limited to the range [0, 255]). .. hint:: Remember that ``0`` is reserved the master node's - :attr:`~pyrf24.rf24_mesh.RF24Mesh.node_id`. + :attr:`~pyrf24.RF24Mesh.node_id`. 2. To get assigned a `Logical Address `, an unconnected node must poll the network for a response (using a `NETWORK_POLL` message). Initially this happens on the network level 0, but consecutive attempts will poll higher network levels (in order of low to @@ -329,7 +329,7 @@ RF24Mesh node. These are the steps performed when calling `renew_address()`: respond with an invalid `Logical Address `. 5. Once the requesting node receives the address response (and the assigned address is valid), it assumes that as the `mesh_address` while maintaining its - :attr:`~pyrf24.rf24_mesh.RF24Mesh.node_id`. + :attr:`~pyrf24.RF24Mesh.node_id`. - The connecting node will verify its new address by calling `check_connection()`. - If the assigned address is invalid or `check_connection()` returns `False`, then diff --git a/examples/scanner.py b/examples/scanner.py index d5e8159..a3695a0 100644 --- a/examples/scanner.py +++ b/examples/scanner.py @@ -103,7 +103,6 @@ def scan(timeout: int = 30): if endl: signals = [0] * 126 # reset the signal counts for new line - # finish printing results and end with a new line while curr_channel < len(signals) - 1: curr_channel += 1 diff --git a/src/glue.cpp b/src/glue.cpp new file mode 100644 index 0000000..831d922 --- /dev/null +++ b/src/glue.cpp @@ -0,0 +1,14 @@ +/* The main module that allows compiling all bindings into 1 python extension. */ +#include "pyRF24.h" +#include "pyRF24Network.h" +#include "pyRF24Mesh.h" + +PYBIND11_MODULE(pyrf24, m) +{ + m.doc() = "A Python module that wraps all RF24 C++ library's API"; + py::options options; + options.disable_function_signatures(); + init_rf24(m); + init_rf24network(m); + init_rf24mesh(m); +} \ No newline at end of file diff --git a/src/pyRF24.cpp b/src/pyRF24.cpp index 0f7d2fa..79b0627 100644 --- a/src/pyRF24.cpp +++ b/src/pyRF24.cpp @@ -1,7 +1,41 @@ #include #include "pyRF24.h" -PYBIND11_MODULE(rf24, m) +void throw_ba_exception(void) +{ + PyErr_SetString(PyExc_TypeError, "buf parameter must be bytes or bytearray"); + py::error_already_set(); +} + +char* get_bytes_or_bytearray_str(py::object buf) +{ + PyObject* py_ba; + py_ba = buf.ptr(); + if (PyByteArray_Check(py_ba)) + return PyByteArray_AsString(py_ba); + else if (PyBytes_Check(py_ba)) + return PyBytes_AsString(py_ba); + else + throw_ba_exception(); + + return NULL; +} + +int get_bytes_or_bytearray_ln(py::object buf) +{ + PyObject* py_ba; + py_ba = buf.ptr(); + if (PyByteArray_Check(py_ba)) + return PyByteArray_Size(py_ba); + else if (PyBytes_Check(py_ba)) + return PyBytes_Size(py_ba); + else + throw_ba_exception(); + + return 0; +} + +void init_rf24(py::module& m) { m.doc() = "A Python module that wraps all RF24 C++ library's API"; m.attr("RF24_DRIVER") = RF24_DRIVER; @@ -68,8 +102,6 @@ PYBIND11_MODULE(rf24, m) .export_values(); // ******************** RF24 class ************************** - py::options options; - options.disable_function_signatures(); py::class_(m, "RF24") // ***************************************************************************** @@ -103,7 +135,7 @@ PYBIND11_MODULE(rf24, m) // ***************************************************************************** .def("getCRCLength", &RF24Wrapper::getCRCLength, R"docstr( - getCRCLength() -> pyrf24.rf24.rf24_crclength_e + getCRCLength() -> pyrf24.rf24_crclength_e Get the current setting of the radio's CRC Length. )docstr") @@ -119,7 +151,7 @@ PYBIND11_MODULE(rf24, m) // ***************************************************************************** .def("getDataRate", &RF24Wrapper::getDataRate, R"docstr( - getDataRate() -> pyrf24.rf24.rf24_datarate_e + getDataRate() -> pyrf24.rf24_datarate_e Get the current setting of the radio's Data Rate. )docstr") @@ -139,7 +171,7 @@ PYBIND11_MODULE(rf24, m) // ***************************************************************************** .def("getPALevel", &RF24Wrapper::getPALevel, R"docstr( - getPALevel() -> pyrf24.rf24.rf24_pa_dbm_e + getPALevel() -> pyrf24.rf24_pa_dbm_e Get the current setting of the radio's Power Amplitude Level. )docstr") @@ -302,7 +334,7 @@ PYBIND11_MODULE(rf24, m) Verify the configured pin numbers are indeed valid. :Returns: `True` if the radio's CE & CSN pins have been configured (using the - RF24 class' constructor or :py:meth:`~pyrf24.rf24.RF24.begin()` function) + RF24 class' constructor or :py:meth:`~pyrf24.RF24.begin()` function) )docstr") // ***************************************************************************** @@ -348,7 +380,7 @@ PYBIND11_MODULE(rf24, m) Calling this function also clears all status flags and resets the IRQ pin to inactive high. .. seealso:: - :py:meth:`~pyrf24.rf24.RF24.mask_irq()` + :py:meth:`~pyrf24.RF24.mask_irq()` )docstr") .def("whatHappened", &RF24Wrapper::what_happened, R"docstr( @@ -360,7 +392,7 @@ PYBIND11_MODULE(rf24, m) .def("available_pipe", &RF24Wrapper::available_pipe, R"docstr( available_pipe() -> Tuple[bool, int] - Similar to :py:meth:`~pyrf24.rf24.RF24.available()`, but additionally returns the pipe + Similar to :py:meth:`~pyrf24.RF24.available()`, but additionally returns the pipe number that received the next available payload. :Returns: A 2-tuple in which @@ -405,9 +437,9 @@ PYBIND11_MODULE(rf24, m) .. seealso:: - - :py:meth:`~pyrf24.rf24.RF24.set_pa_level()` - - :py:attr:`~pyrf24.rf24.RF24.pa_level` - - :py:attr:`~pyrf24.rf24.RF24.data_rate` + - :py:meth:`~pyrf24.RF24.set_pa_level()` + - :py:attr:`~pyrf24.RF24.pa_level` + - :py:attr:`~pyrf24.RF24.data_rate` )docstr", py::arg("level"), py::arg("speed"), py::arg("lna_enable") = true) @@ -603,9 +635,9 @@ PYBIND11_MODULE(rf24, m) .. seealso:: - - :py:attr:`~pyrf24.rf24.RF24.payload_size` - - :py:meth:`~pyrf24.rf24.RF24.get_dynamic_payload_size()` - - :py:meth:`~pyrf24.rf24.RF24.available()` + - :py:attr:`~pyrf24.RF24.payload_size` + - :py:meth:`~pyrf24.RF24.get_dynamic_payload_size()` + - :py:meth:`~pyrf24.RF24.available()` )docstr", py::arg("length") = 0) @@ -631,7 +663,7 @@ PYBIND11_MODULE(rf24, m) configured, the ``ce_pin`` and ``csn_pin`` parameters can be omitted. .. important:: If dynamically configuring the pin numbers, then they must be set using - the overloaded :py:meth:`~pyrf24.rf24.RF24.begin()` function. + the overloaded :py:meth:`~pyrf24.RF24.begin()` function. )docstr", py::arg("spi_speed") = 10000000) @@ -666,7 +698,7 @@ PYBIND11_MODULE(rf24, m) :Returns: `True` if there is a payload in the radio's RX FIFO, otherwise `False`. .. seealso:: - Use :py:meth:`~pyrf24.rf24.RF24.available_pipe()` to get the pipe number that received the + Use :py:meth:`~pyrf24.RF24.available_pipe()` to get the pipe number that received the next available payload. )docstr") @@ -900,18 +932,18 @@ PYBIND11_MODULE(rf24, m) .. hint:: - 1. Be sure to call :py:meth:`~pyrf24.rf24.RF24.open_rx_pipe()` before - setting :py:attr:`~pyrf24.rf24.RF24.listen` to `True`. - 2. Do not call :py:meth:`~pyrf24.rf24.RF24.write()` while in RX mode, without - first setting :py:attr:`~pyrf24.rf24.RF24.listen` to `False`. - 3. Call :py:meth:`~pyrf24.rf24.RF24.available()` to check for incoming traffic, - and use :py:meth:`~pyrf24.rf24.RF24.read()` to get it. + 1. Be sure to call :py:meth:`~pyrf24.RF24.open_rx_pipe()` before + setting :py:attr:`~pyrf24.RF24.listen` to `True`. + 2. Do not call :py:meth:`~pyrf24.RF24.write()` while in RX mode, without + first setting :py:attr:`~pyrf24.RF24.listen` to `False`. + 3. Call :py:meth:`~pyrf24.RF24.available()` to check for incoming traffic, + and use :py:meth:`~pyrf24.RF24.read()` to get it. .. important:: - If there was a call to :py:meth:`~pyrf24.rf24.RF24.open_rx_pipe()` + If there was a call to :py:meth:`~pyrf24.RF24.open_rx_pipe()` about pipe 0 prior to setting this attribute to `False`, then this attribute will re-write the address that was last set to RX pipe 0. - This is because :py:meth:`~pyrf24.rf24.RF24.open_tx_pipe()` + This is because :py:meth:`~pyrf24.RF24.open_tx_pipe()` will overwrite the address to RX pipe 0 for proper auto-ack functionality. .. note:: @@ -1011,7 +1043,7 @@ PYBIND11_MODULE(rf24, m) .def_property_readonly("is_chip_connected", &RF24Wrapper::isChipConnected, R"docstr( Check if the SPI bus is working with the radio. This read-only `bool` attribute assumes that - :py:meth:`~pyrf24.rf24.RF24.begin()` returned `True`. + :py:meth:`~pyrf24.RF24.begin()` returned `True`. )docstr") .def("isChipConnected", &RF24Wrapper::isChipConnected, R"docstr( diff --git a/src/pyRF24.h b/src/pyRF24.h index 584ac11..da45b44 100644 --- a/src/pyRF24.h +++ b/src/pyRF24.h @@ -1,42 +1,15 @@ +#ifndef PYRF24_H +#define PYRF24_H #include #include #include namespace py = pybind11; -void throw_ba_exception(void) -{ - PyErr_SetString(PyExc_TypeError, "buf parameter must be bytes or bytearray"); - py::error_already_set(); -} - -char* get_bytes_or_bytearray_str(py::object buf) -{ - PyObject* py_ba; - py_ba = buf.ptr(); - if (PyByteArray_Check(py_ba)) - return PyByteArray_AsString(py_ba); - else if (PyBytes_Check(py_ba)) - return PyBytes_AsString(py_ba); - else - throw_ba_exception(); - - return NULL; -} - -int get_bytes_or_bytearray_ln(py::object buf) -{ - PyObject* py_ba; - py_ba = buf.ptr(); - if (PyByteArray_Check(py_ba)) - return PyByteArray_Size(py_ba); - else if (PyBytes_Check(py_ba)) - return PyBytes_Size(py_ba); - else - throw_ba_exception(); - - return 0; -} +void throw_ba_exception(void); +char* get_bytes_or_bytearray_str(py::object buf); +int get_bytes_or_bytearray_ln(py::object buf); +void init_rf24(py::module& m); class RF24Wrapper : public RF24 { @@ -240,3 +213,5 @@ class RF24Wrapper : public RF24 stopListening(); } }; + +#endif // PYRF24_H diff --git a/src/pyRF24Mesh.cpp b/src/pyRF24Mesh.cpp index b4dbddf..3979b10 100644 --- a/src/pyRF24Mesh.cpp +++ b/src/pyRF24Mesh.cpp @@ -1,11 +1,7 @@ #include "pyRF24Mesh.h" -PYBIND11_MODULE(rf24_mesh, m) +void init_rf24mesh(py::module& m) { - m.doc() = "A Python module that wraps the RF24Mesh C++ library's API"; - py::options options; - options.disable_function_signatures(); - m.attr("MESH_DEFAULT_ADDRESS") = MESH_DEFAULT_ADDRESS; m.attr("MESH_ADDR_LOOKUP") = MESH_ADDR_LOOKUP; m.attr("MESH_ADDR_RELEASE") = MESH_ADDR_RELEASE; @@ -40,10 +36,10 @@ PYBIND11_MODULE(rf24_mesh, m) // ***************************************************************************** .def("begin", &RF24MeshWrapper::begin, R"docstr( - begin(channel: int = 97, data_rate: pyrf24.rf24.rf24_datarate_e = RF24_1MBPS, timeout: int = 7500) -> bool + begin(channel: int = 97, data_rate: pyrf24.rf24_datarate_e = RF24_1MBPS, timeout: int = 7500) -> bool - :param int channel: The :py:attr:`~pyrf24.rf24.RF24.channel` to use for the network. - :param ~pyrf24.rf24.rf24_datarate_e data_rate: The :py:attr:`~pyrf24.rf24.RF24.data_rate` + :param int channel: The :py:attr:`~pyrf24.RF24.channel` to use for the network. + :param ~pyrf24.rf24_datarate_e data_rate: The :py:attr:`~pyrf24.RF24.data_rate` to use for the network. :param int timeout: The timeout to use when connecting to the mesh network. This value is equivalent to the ``timeout`` parameter in `renew_address()` @@ -64,7 +60,7 @@ PYBIND11_MODULE(rf24_mesh, m) Keep the mesh network layer current. This function should be called regularly in the application. For applications that have a long-running operations in 1 "loop"/iteration, then it is advised to call this function more than once. - :Returns: the `int` of the last received header's :py:attr:`~pyrf24.rf24_network.RF24NetworkHeader.type` + :Returns: the `int` of the last received header's :py:attr:`~pyrf24.RF24NetworkHeader.type` )docstr") // ***************************************************************************** @@ -74,7 +70,7 @@ PYBIND11_MODULE(rf24_mesh, m) write(to_node_address: int, buf: Union[bytes, bytearray], message_type: int) -> bool :param bytes,bytearray buf: The message to transmit. - :param int message_type: The :py:attr:`~pyrf24.rf24_network.RF24NetworkHeader.type` to + :param int message_type: The :py:attr:`~pyrf24.RF24NetworkHeader.type` to be used in the frame's header. :Returns: `True` if the message was successfully sent, otherwise `False` @@ -103,7 +99,7 @@ PYBIND11_MODULE(rf24_mesh, m) Only call this function on a mesh network's master node to manually assign a logical address to a unique `node_id`. This function is meant to include RF24Network nodes in - mesh networks' :attr:`~pyrf24.rf24_mesh.RF24Mesh.addr_list` list. + mesh networks' :attr:`~pyrf24.RF24Mesh.addr_list` list. .. code-block:: py @@ -175,7 +171,7 @@ PYBIND11_MODULE(rf24_mesh, m) Keep the master node's list of assigned addresses up-to-date. .. tip:: This function should be called on a mesh network's master node immediately - after calling :py:meth:`~pyrf24.rf24_mesh.RF24Mesh.update()`. + after calling :py:meth:`~pyrf24.RF24Mesh.update()`. )docstr") .def("DHCP", &RF24MeshWrapper::DHCP, R"docstr( @@ -309,7 +305,7 @@ PYBIND11_MODULE(rf24_mesh, m) Translates a `node_id` into the corresponding `mesh_address` :param int node_id: The identifying number of the mesh node for which to fetch the - corresponding :py:attr:`~pyrf24.rf24_network.RF24Network.node_address`. + corresponding :py:attr:`~pyrf24.RF24Network.node_address`. :Returns: @@ -332,7 +328,7 @@ PYBIND11_MODULE(rf24_mesh, m) set_channel(channel: int) This function controls the radio's configured `channel` (AKA frequency). - :param int channel: The desired :py:attr:`~pyrf24.rf24.RF24.channel` to be used for the network. + :param int channel: The desired :py:attr:`~pyrf24.RF24.channel` to be used for the network. )docstr", py::arg("channel")) diff --git a/src/pyRF24Mesh.h b/src/pyRF24Mesh.h index 193d654..214dbc6 100644 --- a/src/pyRF24Mesh.h +++ b/src/pyRF24Mesh.h @@ -1,8 +1,10 @@ +#ifndef PYRF24MESH_H +#define PYRF24MESH_H #include -#include "pyRF24Network.cpp" +#include "pyRF24Network.h" #include -namespace py = pybind11; +void init_rf24mesh(py::module& m); class RF24MeshWrapper : public RF24Mesh { @@ -47,3 +49,5 @@ class RF24MeshWrapper : public RF24Mesh return list; } }; + +#endif // PYRF24MESH_H diff --git a/src/pyRF24Network.cpp b/src/pyRF24Network.cpp index 20c88b6..fab7308 100644 --- a/src/pyRF24Network.cpp +++ b/src/pyRF24Network.cpp @@ -1,11 +1,7 @@ #include "pyRF24Network.h" -PYBIND11_MODULE(rf24_network, m) +void init_rf24network(py::module& m) { - m.doc() = "A Python module that wraps the RF24Network C++ library's API"; - py::options options; - options.disable_function_signatures(); - // **************** Module level constants ********************* // m.attr("MAX_USER_DEFINED_HEADER_TYPE") = MAX_USER_DEFINED_HEADER_TYPE; @@ -127,7 +123,7 @@ PYBIND11_MODULE(rf24_network, m) // ***************************************************************************** .def_readwrite("header", &RF24NetworkFrameWrapper::header, R"docstr( - The :py:class:`~pyrf24.rf24_network.RF24NetworkHeader` object about the frame's message. + The :py:class:`~pyrf24.RF24NetworkHeader` object about the frame's message. )docstr") // ***************************************************************************** @@ -140,7 +136,7 @@ PYBIND11_MODULE(rf24_network, m) .def_readonly("message_size", &RF24NetworkFrameWrapper::message_size, R"docstr( A read-only attribute that returns the length of the message. This is set accordingly - when the :py:attr:`~pyrf24.rf24_network.RF24NetworkFrame.message_buffer` is changed. + when the :py:attr:`~pyrf24.RF24NetworkFrame.message_buffer` is changed. )docstr"); */ @@ -182,7 +178,7 @@ PYBIND11_MODULE(rf24_network, m) :param int channel: The desired channel used by the network. Using this parameter is the deprecated form of this function. - .. seealso:: Use :py:attr:`~pyrf24.rf24.RF24.channel` attribute to change the radio + .. seealso:: Use :py:attr:`~pyrf24.RF24.channel` attribute to change the radio channel. )docstr", py::arg("channel"), py::arg("node_address")) @@ -215,7 +211,7 @@ PYBIND11_MODULE(rf24_network, m) :param int maxlen: The maximum length of the frame's message to be returned. If this parameter is unspecified or greater than the actual frame's message size, then only the frame's full message size is used. Defaults to - :py:attr:`~pyrf24.rf24_network.MAX_PAYLOAD_SIZE`. + :py:attr:`~pyrf24.MAX_PAYLOAD_SIZE`. :Returns: A `tuple` in which @@ -243,7 +239,7 @@ PYBIND11_MODULE(rf24_network, m) :param int maxlen: The maximum length of the message to fetch. If this parameter is unspecified or greater than the actual frame's message size, then only the frame's full message size is used. Defaults to - :py:attr:`~pyrf24.rf24_network.MAX_PAYLOAD_SIZE`. + :py:attr:`~pyrf24.MAX_PAYLOAD_SIZE`. :Returns: A 2-tuple containing the frame's header (of type `RF24NetworkHeader`) and the frame's message (of type `bytearray`). )docstr", @@ -257,7 +253,7 @@ PYBIND11_MODULE(rf24_network, m) Keep the network layer current. This function should be called regularly in the application. For applications that have a long-running operations in 1 "loop"/iteration, then it is advised to call this function more than once. - :Returns: The `int` of the last received header's :py:attr:`~pyrf24.rf24_network.RF24NetworkHeader.type` + :Returns: The `int` of the last received header's :py:attr:`~pyrf24.RF24NetworkHeader.type` )docstr") // ***************************************************************************** @@ -362,7 +358,7 @@ PYBIND11_MODULE(rf24_network, m) // ***************************************************************************** .def_readwrite("return_sys_msgs", &RF24Network::returnSysMsgs, R"docstr( - This `bool` attribute is used by RF24Mesh to force :py:meth:`~pyrf24.rf24_network.RF24Network.update()` + This `bool` attribute is used by RF24Mesh to force :py:meth:`~pyrf24.RF24Network.update()` to return when handling a frame containing a system message. When this attribute is enabled, the following system messages are not returned because they are handled @@ -371,11 +367,11 @@ PYBIND11_MODULE(rf24_network, m) .. csv-table:: :header: Message Name, Numeric Value, Additional Context - :py:attr:`~pyrf24.rf24_network.NETWORK_ADDR_RESPONSE`, 128, - :py:attr:`~pyrf24.rf24_network.NETWORK_ACK`, 193, - :py:attr:`~pyrf24.rf24_network.NETWORK_PING`, 130, - :py:attr:`~pyrf24.rf24_network.NETWORK_POLL`, 194, With multicast enabled (which is enabled by default) - :py:attr:`~pyrf24.rf24_network.NETWORK_REQ_ADDRESS`, 195, + :py:attr:`~pyrf24.NETWORK_ADDR_RESPONSE`, 128, + :py:attr:`~pyrf24.NETWORK_ACK`, 193, + :py:attr:`~pyrf24.NETWORK_PING`, 130, + :py:attr:`~pyrf24.NETWORK_POLL`, 194, With multicast enabled (which is enabled by default) + :py:attr:`~pyrf24.NETWORK_REQ_ADDRESS`, 195, .. seealso:: There's a more complete list (with behavioral descriptions) of the :ref:`reserved_sys_msgs`. @@ -387,7 +383,7 @@ PYBIND11_MODULE(rf24_network, m) /// TODO: need to write a custom type caster for std::queue to expose the external_queue member // .def_readwrite("external_queue", &RF24NetworkWrapper::external_queue, R"docstr( - // Data with a header type of :py:attr:`~pyrf24.rf24_network.EXTERNAL_DATA_TYPE` will be loaded into a separate queue. + // Data with a header type of :py:attr:`~pyrf24.EXTERNAL_DATA_TYPE` will be loaded into a separate queue. // )docstr") // ***************************************************************************** @@ -402,8 +398,8 @@ PYBIND11_MODULE(rf24_network, m) .. csv-table:: :header: Flags, Value, Description - :py:attr:`~pyrf24.rf24_network.FLAG_FAST_FRAG`, 4 (bit 2 asserted), INTERNAL: Allows for faster transfers between directly connected nodes. - :py:attr:`~pyrf24.rf24_network.FLAG_NO_POLL`, 8 (bit 3 asserted), EXTERNAL/USER: Disables :py:attr:`~pyrf24.rf24_network.NETWORK_POLL` responses on a node-by-node basis. + :py:attr:`~pyrf24.FLAG_FAST_FRAG`, 4 (bit 2 asserted), INTERNAL: Allows for faster transfers between directly connected nodes. + :py:attr:`~pyrf24.FLAG_NO_POLL`, 8 (bit 3 asserted), EXTERNAL/USER: Disables :py:attr:`~pyrf24.NETWORK_POLL` responses on a node-by-node basis. )docstr") .def_readwrite("networkFlags", &RF24Network::networkFlags); diff --git a/src/pyRF24Network.h b/src/pyRF24Network.h index 2aca942..7428f3f 100644 --- a/src/pyRF24Network.h +++ b/src/pyRF24Network.h @@ -1,10 +1,12 @@ +#ifndef PYRF24NETWORK_H +#define PYRF24NETWORK_H #include #include "pyRF24.h" #include // #include // #include -namespace py = pybind11; +void init_rf24network(py::module& m); /* namespace pybind11 { @@ -116,3 +118,5 @@ class RF24NetworkWrapper : public RF24Network return RF24Network::node_address; } }; + +#endif // PYRF24NETWORK_H diff --git a/src/pyrf24/__init__.py b/src/pyrf24/__init__.py index b13db18..a283007 100644 --- a/src/pyrf24/__init__.py +++ b/src/pyrf24/__init__.py @@ -1,18 +1,19 @@ -from .rf24 import ( +from .pyrf24 import ( # type: ignore RF24, + rf24_crclength_e, RF24_CRC_DISABLED, RF24_CRC_8, RF24_CRC_16, + rf24_datarate_e, RF24_1MBPS, RF24_2MBPS, RF24_250KBPS, + rf24_pa_dbm_e, RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_DRIVER, -) -from .rf24_network import ( RF24Network, RF24NetworkHeader, # RF24NetworkFrame, @@ -29,8 +30,6 @@ NETWORK_REQ_ADDRESS, FLAG_FAST_FRAG, FLAG_NO_POLL, -) -from .rf24_mesh import ( RF24Mesh, MESH_DEFAULT_ADDRESS, MESH_ADDR_LOOKUP, @@ -59,12 +58,15 @@ __all__ = [ "RF24", + "rf24_crclength_e", "RF24_CRC_DISABLED", "RF24_CRC_8", "RF24_CRC_16", + "rf24_datarate_e", "RF24_1MBPS", "RF24_2MBPS", "RF24_250KBPS", + "rf24_pa_dbm_e", "RF24_PA_MIN", "RF24_PA_LOW", "RF24_PA_HIGH", diff --git a/src/pyrf24/fake_ble.py b/src/pyrf24/fake_ble.py index 4ef7a6b..d132208 100644 --- a/src/pyrf24/fake_ble.py +++ b/src/pyrf24/fake_ble.py @@ -50,23 +50,23 @@ GHz, 2.426 GHz, and 2.480 GHz. We have provided a tuple of these specific channels for convenience (See `BLE_FREQ` and :py:func:`~pyrf24.fake_ble.FakeBLE.hop_channel()`). - 3. :py:attr:`~pyrf24.rf24.RF24.crc_length` is disabled in the + 3. :py:attr:`~pyrf24.RF24.crc_length` is disabled in the nRF24L01 firmware because BLE specifications require 3 bytes (:py:func:`~pyrf24.fake_ble.crc24_ble()`), and the nRF24L01 firmware can only handle a maximum of 2. Thus, we have appended the required 3 bytes of CRC24 into the payload. - 4. :py:attr:`~pyrf24.rf24.RF24.address_width` of BLE + 4. :py:attr:`~pyrf24.RF24.address_width` of BLE packet only uses 4 bytes, so we have set that accordingly. 5. The auto-ack (automatic acknowledgment) feature of the nRF24L01 is useless when transmitting to BLE devices, thus it is disabled as well as automatic - re-transmit (:py:meth:`~pyrf24.rf24.RF24.get_arc()`) and custom ACK - payloads (:py:attr:`~pyrf24.rf24.RF24.ack_payloads`) features + re-transmit (:py:meth:`~pyrf24.RF24.get_arc()`) and custom ACK + payloads (:py:attr:`~pyrf24.RF24.ack_payloads`) features which both depend on the automatic acknowledgments feature. - 6. The :py:attr:`~pyrf24.rf24.RF24.dynamic_payloads` + 6. The :py:attr:`~pyrf24.RF24.dynamic_payloads` feature of the nRF24L01 isn't compatible with BLE specifications. Thus, we have disabled it. 7. BLE specifications only allow using 1 Mbps RF - :py:attr:`~pyrf24.rf24.RF24.data_rate`, so that too has + :py:attr:`~pyrf24.RF24.data_rate`, so that too has been hard coded. 8. Only the "on data sent" & "on data ready" events will have an effect on the interrupt (IRQ) pin. The "on data fail" is never @@ -77,7 +77,7 @@ from os import urandom import struct from typing import Union, List, Optional -from .rf24 import ( +from .pyrf24 import ( # type: ignore RF24, RF24_CRC_DISABLED, RF24_PA_HIGH, @@ -341,7 +341,7 @@ class FakeBLE: """A class to implement BLE advertisements using the nRF24L01. Per the limitations of this technique, only some of underlying - :py:class:`~pyrf24.rf24.RF24` functionality is + :py:class:`~pyrf24.RF24` functionality is available for configuration when implementing BLE transmissions. See the `Restricted RF24 functionality`_ for more details. @@ -349,7 +349,7 @@ class FakeBLE: hardware. .. seealso:: - See the :py:class:`~pyrf24.rf24.RF24` class' constructor documentation. + See the :py:class:`~pyrf24.RF24` class' constructor documentation. """ def __init__(self, radio: RF24): @@ -386,7 +386,7 @@ def begin( ) -> bool: """Initialize the radio using BLE specifications. - Internally, this function also calls :meth:`~pyrf24.rf24.RF24.begin()`, so + Internally, this function also calls :meth:`~pyrf24.RF24.begin()`, so there's no need to initialized the radio's hardware before calling this function. @@ -466,7 +466,7 @@ def name(self, _name): @property def show_pa_level(self) -> bool: """If this attribute is `True`, the payload will automatically include - the nRF24L01's :py:attr:`~pyrf24.rf24.RF24.pa_level` in the + the nRF24L01's :py:attr:`~pyrf24.RF24.pa_level` in the advertisement. The default value of `False` will exclude this optional information. diff --git a/src/pyrf24/rf24.pyi b/src/pyrf24/pyrf24.pyi similarity index 54% rename from src/pyrf24/rf24.pyi rename to src/pyrf24/pyrf24.pyi index ed723a7..5f8428c 100644 --- a/src/pyrf24/rf24.pyi +++ b/src/pyrf24/pyrf24.pyi @@ -1,4 +1,6 @@ -from typing import Tuple, Union, overload, Optional, Literal +from typing import Tuple, Union, overload, Optional, Literal, List + +######### stubs for RF24 bindings ########################################### RF24_DRIVER: Literal["SPIDEV", "wiringPi", "pigpio", "MRAA", "RPi"] @@ -234,3 +236,222 @@ class RF24: def rpd(self) -> bool: ... @property def rx_fifo_full(self) -> bool: ... + +######### stubs for RF24Network bindings ########################################### + +MAX_USER_DEFINED_HEADER_TYPE: int = 127 +MAX_PAYLOAD_SIZE: int = 1514 +NETWORK_ADDR_RESPONSE: int = 128 +NETWORK_PING: int = 130 +EXTERNAL_DATA_TYPE: int = 131 +NETWORK_FIRST_FRAGMENT: int = 148 +NETWORK_MORE_FRAGMENTS: int = 149 +NETWORK_LAST_FRAGMENT: int = 150 +NETWORK_ACK: int = 193 +NETWORK_POLL: int = 194 +NETWORK_REQ_ADDRESS: int = 195 +FLAG_FAST_FRAG: int = 4 +FLAG_NO_POLL: int = 8 + +class RF24NetworkHeader: + @overload + def __init__(self, to_node: int, type: int = 0) -> None: ... + @overload + def __init__(self) -> None: ... + def to_string(self) -> str: ... + def toString(self) -> str: ... + @property + def to_node(self) -> int: ... + @to_node.setter + def to_node(self, value: int) -> None: ... + @property + def type(self) -> int: ... + @type.setter + def type(self, value: int) -> None: ... + @property + def id(self) -> int: ... + @id.setter + def id(self, value: int) -> None: ... + @property + def from_node(self) -> int: ... + @from_node.setter + def from_node(self, value: int) -> None: ... + @property + def reserved(self) -> int: ... + @reserved.setter + def reserved(self, value: int) -> None: ... + @property + def next_id(self) -> int: ... + +# RF24NetworkFrame is not exposed as it is not needed +# class RF24NetworkFrame: +# def __init__( +# self, header: RF24NetworkHeader = None, message: Union[bytes, bytearray] = None +# ) -> None: ... +# @property +# def header(self) -> RF24NetworkHeader: ... +# @header.setter +# def header(self, head: RF24NetworkHeader) -> None: ... +# @property +# def message_buffer(self) -> bytearray: ... +# @message_buffer.setter +# def message_buffer(self, message: Union[bytes, bytearray]) -> None: ... +# @property +# def message_size(self) -> int: ... + +class RF24Network: + def __init__(self, radio: RF24) -> None: ... + @overload + def begin(self, node_address: int) -> None: ... + @overload + def begin(self, channel: int, node_address: int) -> None: ... + def is_address_valid(self, address: int) -> bool: ... + def is_valid_address(self, address: int) -> bool: ... + def multicast( + self, header: RF24NetworkHeader, buf: Union[bytes, bytearray], level: int = 7 + ) -> bool: ... + def multicastLevel(self, level: int) -> None: ... + # @overload + # def parent(self) -> int: ... + @overload + def peek(self, header: RF24NetworkHeader) -> int: ... + @overload + def peek( + self, maxlen: int = MAX_PAYLOAD_SIZE + ) -> Tuple[RF24NetworkHeader, bytearray]: ... + def read( + self, maxlen: int = MAX_PAYLOAD_SIZE + ) -> Tuple[RF24NetworkHeader, bytearray]: ... + def set_multicast_level(self, level: int) -> None: ... + def update(self) -> int: ... + def available(self) -> int: ... + def write( + self, header: RF24NetworkHeader, buf: Union[bytearray, bytes] + ) -> bool: ... + @property + def multicast_relay(self) -> bool: ... + @multicast_relay.setter + def multicast_relay(self, enable: bool) -> None: ... + @property + def multicastRelay(self) -> bool: ... + @multicastRelay.setter + def multicastRelay(self, enable: bool) -> None: ... + @property + def multicast_level(self) -> int: ... + @multicast_level.setter + def multicast_level(self, level: int) -> None: ... + @property + def network_flags(self) -> int: ... + @network_flags.setter + def network_flags(self, flags: int) -> None: ... + @property + def networkFlags(self) -> int: ... + @networkFlags.setter + def networkFlags(self, flags: int) -> None: ... + @property + def node_address(self) -> int: ... + @node_address.setter + def node_address(self, address: int) -> None: ... + @property + def parent(self) -> int: ... + @property + def return_sys_msgs(self) -> bool: ... + @return_sys_msgs.setter + def return_sys_msgs(self, enable: bool) -> None: ... + @property + def returnSysMsgs(self) -> bool: ... + @returnSysMsgs.setter + def returnSysMsgs(self, enable: bool) -> None: ... + @property + def route_timeout(self) -> int: ... + @route_timeout.setter + def route_timeout(self, timeout: int) -> None: ... + @property + def routeTimeout(self) -> int: ... + @routeTimeout.setter + def routeTimeout(self, timeout: int) -> None: ... + @property + def tx_timeout(self) -> int: ... + @tx_timeout.setter + def tx_timeout(self, timeout: int) -> int: ... + @property + def txTimeout(self) -> int: ... + @txTimeout.setter + def txTimeout(self, timeout: int) -> int: ... + # @property + # def external_queue(self) -> List[RF24NetworkFrame]: ... + +######### stubs for RF24Mesh bindings ########################################### + +MESH_DEFAULT_ADDRESS: int = 0o4444 +MESH_ADDR_LOOKUP: int = 196 +MESH_ADDR_RELEASE: int = 197 +MESH_ID_LOOKUP: int = 198 + +class AddrListStruct: + def __init__(self): ... + @property + def node_id(self) -> int: ... + @property + def address(self) -> int: ... + +class RF24Mesh: + def __init__(self, radio: RF24, network: RF24Network) -> None: ... + def begin( + self, + channel: int = 97, + data_rate: rf24_datarate_e = rf24_datarate_e.RF24_1MBPS, + timeout: int = 7500, + ) -> bool: ... + def check_connection(self) -> bool: ... + def checkConnection(self) -> bool: ... + def dhcp(self) -> None: ... + def DHCP(self) -> None: ... + def save_dhcp(self) -> None: ... + def saveDHCP(self) -> None: ... + def load_dhcp(self) -> None: ... + def loadDHCP(self) -> None: ... + def get_address(self, node_id: int) -> int: ... + def getAddress(self, node_id: int) -> int: ... + def set_address( + self, node_id: int, address: int, search_by_address: bool = False + ): ... + def setAddress( + self, node_id: int, address: int, search_by_address: bool = False + ): ... + def setStaticAddress(self, node_id: int, address: int) -> None: ... + def set_node_id(self) -> None: ... + def setNodeID(self) -> None: ... + def get_node_id(self, address: int) -> int: ... + def getNodeID(self, address: int) -> int: ... + def release_address(self) -> bool: ... + def releaseAddress(self) -> bool: ... + def renew_address(self, timeout: int = 7500) -> int: ... + def renewAddress(self, timeout: int = 7500) -> int: ... + def set_channel(self, channel: int) -> None: ... + def setChannel(self, channel: int) -> None: ... + def set_child(self, allow: bool) -> None: ... + def setChild(self, allow: bool) -> None: ... + def update(self) -> int: ... + @overload + def write( + self, buf: Union[bytes, bytearray], message_type: int, to_node_id: int = 0 + ) -> bool: ... + @overload + def write( + self, to_node: int, buf: Union[bytes, bytearray], message_type: int + ) -> bool: ... + @property + def mesh_address(self) -> int: ... + @property + def node_id(self) -> int: ... + @node_id.setter + def node_id(self, number: int) -> None: ... + @property + def _nodeID(self) -> int: ... + @_nodeID.setter + def _nodeID(self, number: int) -> None: ... + @property + def addr_list(self) -> List[AddrListStruct]: ... + @property + def addrList(self) -> List[AddrListStruct]: ... diff --git a/src/pyrf24/rf24_mesh.pyi b/src/pyrf24/rf24_mesh.pyi deleted file mode 100644 index 326eaf7..0000000 --- a/src/pyrf24/rf24_mesh.pyi +++ /dev/null @@ -1,76 +0,0 @@ -from typing import Union, overload, List -from .rf24 import RF24, rf24_datarate_e -from .rf24_network import RF24Network - -MESH_DEFAULT_ADDRESS: int = 0o4444 -MESH_ADDR_LOOKUP: int = 196 -MESH_ADDR_RELEASE: int = 197 -MESH_ID_LOOKUP: int = 198 - -class AddrListStruct: - def __init__(self): ... - @property - def node_id(self) -> int: ... - @property - def address(self) -> int: ... - -class RF24Mesh: - def __init__(self, radio: RF24, network: RF24Network) -> None: ... - def begin( - self, - channel: int = 97, - data_rate: rf24_datarate_e = rf24_datarate_e.RF24_1MBPS, - timeout: int = 7500, - ) -> bool: ... - def check_connection(self) -> bool: ... - def checkConnection(self) -> bool: ... - def dhcp(self) -> None: ... - def DHCP(self) -> None: ... - def save_dhcp(self) -> None: ... - def saveDHCP(self) -> None: ... - def load_dhcp(self) -> None: ... - def loadDHCP(self) -> None: ... - def get_address(self, node_id: int) -> int: ... - def getAddress(self, node_id: int) -> int: ... - def set_address( - self, node_id: int, address: int, search_by_address: bool = False - ): ... - def setAddress( - self, node_id: int, address: int, search_by_address: bool = False - ): ... - def setStaticAddress(self, node_id: int, address: int) -> None: ... - def set_node_id(self) -> None: ... - def setNodeID(self) -> None: ... - def get_node_id(self, address: int) -> int: ... - def getNodeID(self, address: int) -> int: ... - def release_address(self) -> bool: ... - def releaseAddress(self) -> bool: ... - def renew_address(self, timeout: int = 7500) -> int: ... - def renewAddress(self, timeout: int = 7500) -> int: ... - def set_channel(self, channel: int) -> None: ... - def setChannel(self, channel: int) -> None: ... - def set_child(self, allow: bool) -> None: ... - def setChild(self, allow: bool) -> None: ... - def update(self) -> int: ... - @overload - def write( - self, buf: Union[bytes, bytearray], message_type: int, to_node_id: int = 0 - ) -> bool: ... - @overload - def write( - self, to_node: int, buf: Union[bytes, bytearray], message_type: int - ) -> bool: ... - @property - def mesh_address(self) -> int: ... - @property - def node_id(self) -> int: ... - @node_id.setter - def node_id(self, number: int) -> None: ... - @property - def _nodeID(self) -> int: ... - @_nodeID.setter - def _nodeID(self, number: int) -> None: ... - @property - def addr_list(self) -> List[AddrListStruct]: ... - @property - def addrList(self) -> List[AddrListStruct]: ... diff --git a/src/pyrf24/rf24_network.pyi b/src/pyrf24/rf24_network.pyi deleted file mode 100644 index 9d47f85..0000000 --- a/src/pyrf24/rf24_network.pyi +++ /dev/null @@ -1,144 +0,0 @@ -from typing import Tuple, Union, overload -from .rf24 import RF24 - -MAX_USER_DEFINED_HEADER_TYPE: int = 127 -MAX_PAYLOAD_SIZE: int = 1514 -NETWORK_ADDR_RESPONSE: int = 128 -NETWORK_PING: int = 130 -EXTERNAL_DATA_TYPE: int = 131 -NETWORK_FIRST_FRAGMENT: int = 148 -NETWORK_MORE_FRAGMENTS: int = 149 -NETWORK_LAST_FRAGMENT: int = 150 -NETWORK_ACK: int = 193 -NETWORK_POLL: int = 194 -NETWORK_REQ_ADDRESS: int = 195 -FLAG_FAST_FRAG: int = 4 -FLAG_NO_POLL: int = 8 - -class RF24NetworkHeader: - @overload - def __init__(self, to_node: int, type: int = 0) -> None: ... - @overload - def __init__(self) -> None: ... - def to_string(self) -> str: ... - def toString(self) -> str: ... - @property - def to_node(self) -> int: ... - @to_node.setter - def to_node(self, value: int) -> None: ... - @property - def type(self) -> int: ... - @type.setter - def type(self, value: int) -> None: ... - @property - def id(self) -> int: ... - @id.setter - def id(self, value: int) -> None: ... - @property - def from_node(self) -> int: ... - @from_node.setter - def from_node(self, value: int) -> None: ... - @property - def reserved(self) -> int: ... - @reserved.setter - def reserved(self, value: int) -> None: ... - @property - def next_id(self) -> int: ... - -# RF24NetworkFrame is not exposed as it is not needed -# class RF24NetworkFrame: -# def __init__( -# self, header: RF24NetworkHeader = None, message: Union[bytes, bytearray] = None -# ) -> None: ... -# @property -# def header(self) -> RF24NetworkHeader: ... -# @header.setter -# def header(self, head: RF24NetworkHeader) -> None: ... -# @property -# def message_buffer(self) -> bytearray: ... -# @message_buffer.setter -# def message_buffer(self, message: Union[bytes, bytearray]) -> None: ... -# @property -# def message_size(self) -> int: ... - -class RF24Network: - def __init__(self, radio: RF24) -> None: ... - @overload - def begin(self, node_address: int) -> None: ... - @overload - def begin(self, channel: int, node_address: int) -> None: ... - def is_address_valid(self, address: int) -> bool: ... - def is_valid_address(self, address: int) -> bool: ... - def multicast( - self, header: RF24NetworkHeader, buf: Union[bytes, bytearray], level: int = 7 - ) -> bool: ... - def multicastLevel(self, level: int) -> None: ... - # @overload - # def parent(self) -> int: ... - @overload - def peek(self, header: RF24NetworkHeader) -> int: ... - @overload - def peek( - self, maxlen: int = MAX_PAYLOAD_SIZE - ) -> Tuple[RF24NetworkHeader, bytearray]: ... - def read( - self, maxlen: int = MAX_PAYLOAD_SIZE - ) -> Tuple[RF24NetworkHeader, bytearray]: ... - def set_multicast_level(self, level: int) -> None: ... - def update(self) -> int: ... - def available(self) -> int: ... - def write( - self, header: RF24NetworkHeader, buf: Union[bytearray, bytes] - ) -> bool: ... - @property - def multicast_relay(self) -> bool: ... - @multicast_relay.setter - def multicast_relay(self, enable: bool) -> None: ... - @property - def multicastRelay(self) -> bool: ... - @multicastRelay.setter - def multicastRelay(self, enable: bool) -> None: ... - @property - def multicast_level(self) -> int: ... - @multicast_level.setter - def multicast_level(self, level: int) -> None: ... - @property - def network_flags(self) -> int: ... - @network_flags.setter - def network_flags(self, flags: int) -> None: ... - @property - def networkFlags(self) -> int: ... - @networkFlags.setter - def networkFlags(self, flags: int) -> None: ... - @property - def node_address(self) -> int: ... - @node_address.setter - def node_address(self, address: int) -> None: ... - @property - def parent(self) -> int: ... - @property - def return_sys_msgs(self) -> bool: ... - @return_sys_msgs.setter - def return_sys_msgs(self, enable: bool) -> None: ... - @property - def returnSysMsgs(self) -> bool: ... - @returnSysMsgs.setter - def returnSysMsgs(self, enable: bool) -> None: ... - @property - def route_timeout(self) -> int: ... - @route_timeout.setter - def route_timeout(self, timeout: int) -> None: ... - @property - def routeTimeout(self) -> int: ... - @routeTimeout.setter - def routeTimeout(self, timeout: int) -> None: ... - @property - def tx_timeout(self) -> int: ... - @tx_timeout.setter - def tx_timeout(self, timeout: int) -> int: ... - @property - def txTimeout(self) -> int: ... - @txTimeout.setter - def txTimeout(self, timeout: int) -> int: ... - # @property - # def external_queue(self) -> List[RF24NetworkFrame]: ...