1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
extern crate soapysdr_sys;
extern crate num_complex;
#[cfg(feature="log")] #[macro_use] extern crate log;
mod args;
pub use args::{Args, ArgsIterator};
mod arginfo;
pub use arginfo::ArgInfo;
mod device;
pub use device::{enumerate, Device, RxStream, TxStream, Error, ErrorCode, Direction, Range};
mod format;
pub use format::{Format, StreamSample};
#[cfg(feature="log")]
pub fn configure_logging() {
use log::Level;
use soapysdr_sys::*;
use std::os::raw::c_char;
use std::ffi::CStr;
extern "C" fn soapy_log(level: SoapySDRLogLevel, message: *const c_char) {
#![allow(non_upper_case_globals)]
let level = match level {
SoapySDRLogLevel_SOAPY_SDR_FATAL => Level::Error,
SoapySDRLogLevel_SOAPY_SDR_CRITICAL => Level::Error,
SoapySDRLogLevel_SOAPY_SDR_ERROR => Level::Error,
SoapySDRLogLevel_SOAPY_SDR_WARNING => Level::Warn,
SoapySDRLogLevel_SOAPY_SDR_NOTICE => Level::Info,
SoapySDRLogLevel_SOAPY_SDR_INFO => Level::Info,
SoapySDRLogLevel_SOAPY_SDR_DEBUG => Level::Debug,
SoapySDRLogLevel_SOAPY_SDR_TRACE => Level::Trace,
SoapySDRLogLevel_SOAPY_SDR_SSI => Level::Info, _ => Level::Error,
};
let msg = unsafe { CStr::from_ptr(message) };
log!(level, "{}", msg.to_string_lossy().trim_start_matches(&['\r', '\n'][..]));
}
unsafe {
SoapySDR_registerLogHandler(Some(soapy_log));
}
}