cerebrust/
lib.rs

1//! cerebrust is a library for interfacing with NeuroSky devices over Bluetooth.
2//! It provides functionality to configure and connect to a NeuroSky device using
3//! Bluetooth, as well as to read and parse data packets from the data stream.
4
5pub mod comm;
6pub mod device;
7
8// Re-export for convenience
9pub use comm::{DataReader, Packet, PacketVariant};
10pub use device::DeviceConfig;
11
12#[cfg(test)]
13mod tests {
14    use super::*;
15
16    /// Doing an all-in-one test to build an RFCOMM stream, read a packet, and
17    /// parse it. Unit testing each function is omitted intentionally, as it
18    /// may cause data races.
19    ///
20    /// NOTE: This test requires a NeuroSky device to be connected to the
21    /// Bluetooth adapter. The device name is assumed to be "MyndBand".
22    #[tokio::test]
23    async fn test_build_stream_and_parse() {
24        let config = DeviceConfig::default()
25            .with_adapter("hci0".to_string())
26            .with_name("MyndBand".to_string())
27            .with_channel(5);
28        let stream = config
29            .connect()
30            .await
31            .expect("Failed to build RFCOMM stream");
32        println!("Local address: {:?}", stream.as_ref().local_addr().unwrap());
33        println!("Remote address: {:?}", stream.peer_addr().unwrap());
34        println!("Security: {:?}", stream.as_ref().security().unwrap());
35        let mut data_reader = DataReader::new(stream);
36        let packet = data_reader
37            .poll_next()
38            .await
39            .expect("Failed to poll next packet");
40        println!("{:?}", packet);
41    }
42}