File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,39 @@ pub async fn build_tcp_stream(
200
200
Ok ( StreamHandle :: from_stream ( stream) )
201
201
}
202
202
203
+ /// A helper method that uses the `btleplug` and `tokio` crates to build a BLE stream
204
+ /// that is compatible with the `StreamApi` API. This requires that the stream
205
+ /// implements `AsyncReadExt + AsyncWriteExt` traits.
206
+ ///
207
+ /// This method is intended to be used to create a `DuplexStream` instance, which is
208
+ /// then passed into the `StreamApi::connect` method.
209
+ ///
210
+ /// # Arguments
211
+ ///
212
+ /// * `ble_id` - Name or MAC address of a BLE device
213
+ ///
214
+ /// # Returns
215
+ ///
216
+ /// Returns a result that resolves to a `tokio::io::DuplexStream` instance, or
217
+ /// an error if the stream could not be created.
218
+ ///
219
+ /// # Examples
220
+ ///
221
+ /// ```
222
+ /// // Connect to a radio, identified by its MAC address
223
+ /// let duplex_stream = utils::build_ble_stream(BleId::from_mac_address("E3:44:4E:18:F7:A4").await?;
224
+ /// let decoded_listener = stream_api.connect(duplex_stream).await;
225
+ /// ```
226
+ ///
227
+ /// # Errors
228
+ ///
229
+ /// Will return an instance of `Error` in the event that the radio refuses the connection, it
230
+ /// cannot be found or if the specified address is invalid.
231
+ ///
232
+ /// # Panics
233
+ ///
234
+ /// None
235
+ ///
203
236
#[ cfg( feature = "bluetooth-le" ) ]
204
237
pub async fn build_ble_stream (
205
238
ble_id : & crate :: connections:: ble_handler:: BleId ,
You can’t perform that action at this time.
0 commit comments