Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Serial Bridge
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Serial Bridge
Commits
97499239
Commit
97499239
authored
1 year ago
by
Federico Lolli
Browse files
Options
Downloads
Patches
Plain Diff
added definitions for read and write and a macro for warning debug
parent
8e7083e3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib.rs
+32
-15
32 additions, 15 deletions
src/lib.rs
with
32 additions
and
15 deletions
src/lib.rs
+
32
−
15
View file @
97499239
...
@@ -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
(())
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment