|
28 | 28 | from digi.xbee.models.mode import OperatingMode, APIOutputMode, IPAddressingMode |
29 | 29 | from digi.xbee.models.address import XBee64BitAddress, XBee16BitAddress, XBeeIMEIAddress |
30 | 30 | from digi.xbee.models.message import XBeeMessage, ExplicitXBeeMessage, IPMessage |
31 | | -from digi.xbee.models.options import TransmitOptions, RemoteATCmdOptions, DiscoveryOptions |
| 31 | +from digi.xbee.models.options import TransmitOptions, RemoteATCmdOptions, DiscoveryOptions, XBeeLocalInterface |
32 | 32 | from digi.xbee.models.protocol import XBeeProtocol, IPProtocol |
33 | 33 | from digi.xbee.models.status import ATCommandStatus, TransmitStatus, PowerLevel, \ |
34 | 34 | ModemStatus, CellularAssociationIndicationStatus, WiFiAssociationIndicationStatus, AssociationIndicationStatus,\ |
@@ -1295,6 +1295,28 @@ def _add_user_data_relay_received_callback(self, callback): |
1295 | 1295 | """ |
1296 | 1296 | self._packet_listener.add_user_data_relay_received_callback(callback) |
1297 | 1297 |
|
| 1298 | + def _add_bluetooth_data_received_callback(self, callback): |
| 1299 | + """ |
| 1300 | + Adds a callback for the event :class:`.BluetoothDataReceived`. |
| 1301 | +
|
| 1302 | + Args: |
| 1303 | + callback (Function): the callback. Receives one argument. |
| 1304 | +
|
| 1305 | + * The Bluetooth data as a Bytearray |
| 1306 | + """ |
| 1307 | + self._packet_listener.add_bluetooth_data_received_callback(callback) |
| 1308 | + |
| 1309 | + def _add_micropython_data_received_callback(self, callback): |
| 1310 | + """ |
| 1311 | + Adds a callback for the event :class:`.MicroPythonDataReceived`. |
| 1312 | +
|
| 1313 | + Args: |
| 1314 | + callback (Function): the callback. Receives one argument. |
| 1315 | +
|
| 1316 | + * The MicroPython data as a Bytearray |
| 1317 | + """ |
| 1318 | + self._packet_listener.add_micropython_data_received_callback(callback) |
| 1319 | + |
1298 | 1320 | def _del_packet_received_callback(self, callback): |
1299 | 1321 | """ |
1300 | 1322 | Deletes a callback for the callback list of :class:`.PacketReceived` event. |
@@ -1367,6 +1389,30 @@ def _del_user_data_relay_received_callback(self, callback): |
1367 | 1389 | """ |
1368 | 1390 | self._packet_listener.del_user_data_relay_received_callback(callback) |
1369 | 1391 |
|
| 1392 | + def _del_bluetooth_data_received_callback(self, callback): |
| 1393 | + """ |
| 1394 | + Deletes a callback for the callback list of :class:`.BluetoothDataReceived` event. |
| 1395 | +
|
| 1396 | + Args: |
| 1397 | + callback (Function): the callback to delete. |
| 1398 | +
|
| 1399 | + Raises: |
| 1400 | + ValueError: if ``callback`` is not in the callback list of :class:`.BluetoothDataReceived` event. |
| 1401 | + """ |
| 1402 | + self._packet_listener.del_bluetooth_data_received_callback(callback) |
| 1403 | + |
| 1404 | + def _del_micropython_data_received_callback(self, callback): |
| 1405 | + """ |
| 1406 | + Deletes a callback for the callback list of :class:`.MicroPythonDataReceived` event. |
| 1407 | +
|
| 1408 | + Args: |
| 1409 | + callback (Function): the callback to delete. |
| 1410 | +
|
| 1411 | + Raises: |
| 1412 | + ValueError: if ``callback`` is not in the callback list of :class:`.MicroPythonDataReceived` event. |
| 1413 | + """ |
| 1414 | + self._packet_listener.del_micropython_data_received_callback(callback) |
| 1415 | + |
1370 | 1416 | def _send_packet_sync_and_get_response(self, packet_to_send): |
1371 | 1417 | """ |
1372 | 1418 | Perform all operations needed for a synchronous operation when the packet |
@@ -2161,25 +2207,65 @@ def send_data_broadcast(self, data, transmit_options=TransmitOptions.NONE.value) |
2161 | 2207 | """ |
2162 | 2208 | return self._send_data_64(XBee64BitAddress.BROADCAST_ADDRESS, data, transmit_options) |
2163 | 2209 |
|
2164 | | - def send_user_data_relay(self, relay_interface, data): |
| 2210 | + @AbstractXBeeDevice._before_send_method |
| 2211 | + def send_user_data_relay(self, local_interface, data): |
2165 | 2212 | """ |
2166 | | - Sends the given data to the given relay interface. |
| 2213 | + Sends the given data to the given XBee local interface. |
2167 | 2214 |
|
2168 | 2215 | Args: |
2169 | | - relay_interface (:class:`.UserDataRelayInterface`): Destination relay interface. |
| 2216 | + local_interface (:class:`.XBeeLocalInterface`): Destination XBee local interface. |
2170 | 2217 | data (Bytearray): Data to send. |
2171 | 2218 |
|
2172 | 2219 | Raises: |
2173 | | - ValueError: if ``relay_interface`` is ``None``. |
| 2220 | + InvalidOperatingModeException: if the XBee device's operating mode is not API or ESCAPED API. This |
| 2221 | + method only checks the cached value of the operating mode. |
| 2222 | + ValueError: if ``local_interface`` is ``None``. |
| 2223 | + XBeeException: if there is any problem sending the User Data Relay. |
2174 | 2224 |
|
2175 | 2225 | .. seealso:: |
2176 | | - | :class:`.UserDataRelayInterface` |
| 2226 | + | :class:`.XBeeLocalInterface` |
2177 | 2227 | """ |
2178 | | - if relay_interface is None: |
2179 | | - raise ValueError("Relay interface cannot be None") |
| 2228 | + if local_interface is None: |
| 2229 | + raise ValueError("Destination interface cannot be None") |
2180 | 2230 |
|
2181 | 2231 | # Send the packet asynchronously since User Data Relay frames do not receive any transmit status. |
2182 | | - self.send_packet(UserDataRelayPacket(self.get_next_frame_id(), relay_interface, data)) |
| 2232 | + self.send_packet(UserDataRelayPacket(self.get_next_frame_id(), local_interface, data)) |
| 2233 | + |
| 2234 | + def send_bluetooth_data(self, data): |
| 2235 | + """ |
| 2236 | + Sends the given data to the Bluetooth interface using a User Data Relay frame. |
| 2237 | +
|
| 2238 | + Args: |
| 2239 | + data (Bytearray): Data to send. |
| 2240 | +
|
| 2241 | + Raises: |
| 2242 | + InvalidOperatingModeException: if the XBee device's operating mode is not API or ESCAPED API. This |
| 2243 | + method only checks the cached value of the operating mode. |
| 2244 | + XBeeException: if there is any problem sending the data. |
| 2245 | +
|
| 2246 | + .. seealso:: |
| 2247 | + | :meth:`.XBeeDevice.send_micropython_data` |
| 2248 | + | :meth:`.XBeeDevice.send_user_data_relay` |
| 2249 | + """ |
| 2250 | + self.send_user_data_relay(XBeeLocalInterface.BLUETOOTH, data) |
| 2251 | + |
| 2252 | + def send_micropython_data(self, data): |
| 2253 | + """ |
| 2254 | + Sends the given data to the MicroPython interface using a User Data Relay frame. |
| 2255 | +
|
| 2256 | + Args: |
| 2257 | + data (Bytearray): Data to send. |
| 2258 | +
|
| 2259 | + Raises: |
| 2260 | + InvalidOperatingModeException: if the XBee device's operating mode is not API or ESCAPED API. This |
| 2261 | + method only checks the cached value of the operating mode. |
| 2262 | + XBeeException: if there is any problem sending the data. |
| 2263 | +
|
| 2264 | + .. seealso:: |
| 2265 | + | :meth:`.XBeeDevice.send_bluetooth_data` |
| 2266 | + | :meth:`.XBeeDevice.send_user_data_relay` |
| 2267 | + """ |
| 2268 | + self.send_user_data_relay(XBeeLocalInterface.MICROPYTHON, data) |
2183 | 2269 |
|
2184 | 2270 | def read_data(self, timeout=None): |
2185 | 2271 | """ |
@@ -2338,6 +2424,18 @@ def add_user_data_relay_received_callback(self, callback): |
2338 | 2424 | """ |
2339 | 2425 | super()._add_user_data_relay_received_callback(callback) |
2340 | 2426 |
|
| 2427 | + def add_bluetooth_data_received_callback(self, callback): |
| 2428 | + """ |
| 2429 | + Override. |
| 2430 | + """ |
| 2431 | + super()._add_bluetooth_data_received_callback(callback) |
| 2432 | + |
| 2433 | + def add_micropython_data_received_callback(self, callback): |
| 2434 | + """ |
| 2435 | + Override. |
| 2436 | + """ |
| 2437 | + super()._add_micropython_data_received_callback(callback) |
| 2438 | + |
2341 | 2439 | def del_packet_received_callback(self, callback): |
2342 | 2440 | """ |
2343 | 2441 | Override. |
@@ -2374,6 +2472,18 @@ def _del_user_data_relay_received_callback(self, callback): |
2374 | 2472 | """ |
2375 | 2473 | super()._del_user_data_relay_received_callback(callback) |
2376 | 2474 |
|
| 2475 | + def _del_bluetooth_data_received_callback(self, callback): |
| 2476 | + """ |
| 2477 | + Override. |
| 2478 | + """ |
| 2479 | + super()._del_bluetooth_data_received_callback(callback) |
| 2480 | + |
| 2481 | + def _del_micropython_data_received_callback(self, callback): |
| 2482 | + """ |
| 2483 | + Override. |
| 2484 | + """ |
| 2485 | + super()._del_micropython_data_received_callback(callback) |
| 2486 | + |
2377 | 2487 | def get_xbee_device_callbacks(self): |
2378 | 2488 | """ |
2379 | 2489 | Returns this XBee internal callbacks for process received packets. |
|
0 commit comments