Added some documentation
This commit is contained in:
parent
d4c0cc19a7
commit
835894e7e2
2 changed files with 27 additions and 0 deletions
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# hackrf
|
||||
|
||||
Safe rust bindings for [libhackrf](https://github.com/greatscottgadgets/hackrf/tree/master/host/libhackrf).
|
24
src/lib.rs
24
src/lib.rs
|
@ -103,6 +103,9 @@ pub enum UsbBoardId {
|
|||
Rad10,
|
||||
}
|
||||
|
||||
/**
|
||||
* List of Hackrf compatible devices
|
||||
*/
|
||||
pub struct DeviceList {
|
||||
device_list: *mut hackrf_device_list_t,
|
||||
devices: Vec<DeviceListEntry>,
|
||||
|
@ -131,6 +134,9 @@ pub struct DeviceListEntry {
|
|||
}
|
||||
|
||||
impl DeviceListEntry {
|
||||
/**
|
||||
* Open the specified device for sending and receiving
|
||||
*/
|
||||
pub fn open(&self) -> Result<Device, HackrfError> {
|
||||
let mut device = MaybeUninit::uninit();
|
||||
unsafe {
|
||||
|
@ -160,6 +166,9 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the default device
|
||||
*/
|
||||
pub fn open() -> Result<Device, HackrfError> {
|
||||
let mut device = MaybeUninit::uninit();
|
||||
unsafe {
|
||||
|
@ -169,6 +178,9 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a device by specifying a serial number
|
||||
*/
|
||||
pub fn open_by_serial(serial_number: &str) -> Result<Device, HackrfError> {
|
||||
let mut device = MaybeUninit::uninit();
|
||||
let serial_number = std::ffi::CString::new(serial_number).unwrap();
|
||||
|
@ -181,6 +193,9 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start receiving mode with the supplied callback.
|
||||
*/
|
||||
pub fn start_rx<F: FnMut(&mut Device, &[u8]) -> Result<(), HackrfError> + 'static>(
|
||||
&mut self,
|
||||
callback: F,
|
||||
|
@ -197,6 +212,9 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop receiving mode
|
||||
*/
|
||||
pub fn stop_rx(&mut self) -> Result<(), HackrfError> {
|
||||
unsafe {
|
||||
HackrfError::from_ctype(hackrf_stop_rx(self.device))?;
|
||||
|
@ -205,6 +223,9 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start sending mode with the specified callback
|
||||
*/
|
||||
pub fn start_tx<F: FnMut(&mut Device) -> Result<(), HackrfError> + 'static>(
|
||||
&mut self,
|
||||
callback: F,
|
||||
|
@ -221,6 +242,9 @@ impl Device {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop sending mode
|
||||
*/
|
||||
pub fn stop_tx(&mut self) -> Result<(), HackrfError> {
|
||||
unsafe {
|
||||
HackrfError::from_ctype(hackrf_stop_tx(self.device))?;
|
||||
|
|
Reference in a new issue