Skip to content
Snippets Groups Projects
Commit 97499239 authored by Federico Lolli's avatar Federico Lolli
Browse files

added definitions for read and write and a macro for warning debug

parent 8e7083e3
Branches
Tags
No related merge requests found
...@@ -16,12 +16,20 @@ lazy_static::lazy_static! { ...@@ -16,12 +16,20 @@ lazy_static::lazy_static! {
} }
/// this compiles only in debug mode /// this compiles only in debug mode
fn warn(msg: &str) {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
warning("serialbridge:debug", msg); macro_rules! warn_debug {
($msg:literal, $($arg:expr),*) => {
warning("serialbridge:debug", format!($msg, $($arg),*));
};
}
#[cfg(not(debug_assertions))]
macro_rules! warn_debug {
() => {};
} }
struct Args<'a>(Rhs<'a, 'a>); struct Args<'a>(Rhs<'a, 'a>);
struct Output<'a>(Lhs<'a>);
impl<'a> Args<'a> { impl<'a> Args<'a> {
fn new(rhs: Rhs<'a, 'a>) -> Self { fn new(rhs: Rhs<'a, 'a>) -> Self {
...@@ -43,24 +51,20 @@ impl<'a> Args<'a> { ...@@ -43,24 +51,20 @@ impl<'a> Args<'a> {
#[rustmex::entrypoint] #[rustmex::entrypoint]
fn serialbridge(lhs: Lhs, rhs: Rhs) -> rustmex::Result<()> { fn serialbridge(lhs: Lhs, rhs: Rhs) -> rustmex::Result<()> {
// if let Some(r) = lhs.get_mut(0) {
// let res = TEST.read().unwrap().to_matlab();
// r.replace(res);
// };
let args = Args::new(rhs); let args = Args::new(rhs);
let out = Output(lhs);
// Get the mode argument ("Open", "Close", "Read", "Write") // Get the mode argument ("Open", "Close", "Read", "Write")
let mode = get_mode(args.get(0, Error::MissingSerialMode)?)?; let mode = get_mode(args.get(0, Error::MissingSerialMode)?)?;
println!("Mode: {:?}", mode); warn_debug!("Mode: {:?}", mode);
// Dispatch to the appropriate function // Dispatch to the appropriate function
match mode { match mode {
Mode::Open => open_serial(args)?, Mode::Open => open_serial(args)?,
Mode::Close => close_serial(args)?, Mode::Close => close_serial(args)?,
Mode::Read => todo!(), Mode::Read => read_from_serial(out, args)?,
Mode::Write => todo!(), Mode::Write => write_to_serial(args)?,
} }
Ok(()) Ok(())
...@@ -95,10 +99,7 @@ fn open_serial(args: Args<'_>) -> SResult<()> { ...@@ -95,10 +99,7 @@ fn open_serial(args: Args<'_>) -> SResult<()> {
} }
let baudrate = arg2 as u32; let baudrate = arg2 as u32;
warn(&format!( warn_debug!("Open serial port {} with baudrate {}", port, baudrate);
"Open serial port {} with baudrate {}",
port, baudrate
));
SERIAL.lock().unwrap().open(&port, baudrate)?; SERIAL.lock().unwrap().open(&port, baudrate)?;
...@@ -111,3 +112,19 @@ fn close_serial(args: Args<'_>) -> SResult<()> { ...@@ -111,3 +112,19 @@ fn close_serial(args: Args<'_>) -> SResult<()> {
SERIAL.lock().unwrap().close()?; SERIAL.lock().unwrap().close()?;
Ok(()) Ok(())
} }
fn read_from_serial(outputs: Output<'_>, args: Args<'_>) -> SResult<()> {
args.assert_params_max_len(1)?;
todo!();
Ok(())
}
fn write_to_serial(args: Args<'_>) -> SResult<()> {
args.assert_params_max_len(1)?;
todo!();
Ok(())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment