Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Arpist
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
Autonomous Rocket Pointer
Arpist
Commits
090b7d8d
Commit
090b7d8d
authored
1 year ago
by
Federico Lolli
Browse files
Options
Downloads
Patches
Plain Diff
fixed workflow and implemented RTC and CTS control over communication availability
parent
b08226fe
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+40
-21
40 additions, 21 deletions
src/main.rs
with
40 additions
and
21 deletions
src/main.rs
+
40
−
21
View file @
090b7d8d
...
@@ -2,17 +2,17 @@ mod ffi;
...
@@ -2,17 +2,17 @@ mod ffi;
use
std
::
fs
::
File
;
use
std
::
fs
::
File
;
use
std
::
io
;
use
std
::
io
;
use
std
::
io
::
{
Read
,
Write
}
;
use
std
::
io
::
Read
;
use
std
::
path
::
PathBuf
;
use
std
::
path
::
PathBuf
;
use
std
::
time
::{
Duration
,
Instant
};
use
std
::
time
::{
Duration
,
Instant
};
use
clap
::
Parser
;
use
clap
::
Parser
;
use
log
::{
debug
,
error
,
info
,
trace
};
use
log
::{
debug
,
error
,
info
,
warn
};
use
serialport
::
SerialPort
;
use
serialport
::
SerialPort
;
use
ffi
::
MavlinkPayloadFlightTM
;
use
ffi
::
MavlinkPayloadFlightTM
;
const
EOT
:
u8
=
0x0
4
;
const
ACK
:
u8
=
0x0
6
;
#[derive(Debug,
Parser)]
#[derive(Debug,
Parser)]
struct
Cli
{
struct
Cli
{
...
@@ -72,15 +72,16 @@ fn main() {
...
@@ -72,15 +72,16 @@ fn main() {
let
mut
buffer
=
[
0u8
;
1000
];
let
mut
buffer
=
[
0u8
;
1000
];
let
mut
start
:
Option
<
Instant
>
=
None
;
let
mut
start
:
Option
<
Instant
>
=
None
;
let
mut
times
=
Vec
::
new
();
let
mut
times
=
Vec
::
new
();
loop
{
loop
{
match
port
.read
(
&
mut
buffer
)
{
// wait clear to send
Ok
(
t
)
=>
{
port
.write_request_to_send
(
true
)
.expect
(
"Unable to set RTS"
);
// check if we got the signal to start sending data
while
!
port
.read_clear_to_send
()
.expect
(
"Unable to read CTS"
)
{
let
eot_f
=
buffer
[
..
t
]
.contains
(
&
EOT
);
std
::
thread
::
sleep
(
Duration
::
from_millis
(
100
));
debug!
(
"waiting for CTS"
);
}
// if we got the signal to start sending data, send it
// send packet if there is one
if
eot_f
{
trace!
(
"got EOT, sending data"
);
if
let
Some
(
packet
)
=
packets
.wait_next
()
{
if
let
Some
(
packet
)
=
packets
.wait_next
()
{
if
let
Some
(
t
)
=
start
{
if
let
Some
(
t
)
=
start
{
times
.push
(
t
.elapsed
()
.as_millis
());
times
.push
(
t
.elapsed
()
.as_millis
());
...
@@ -88,13 +89,31 @@ fn main() {
...
@@ -88,13 +89,31 @@ fn main() {
start
=
Some
(
Instant
::
now
());
start
=
Some
(
Instant
::
now
());
write_port
.write_packet
(
packet
.to_owned
());
write_port
.write_packet
(
packet
.to_owned
());
debug!
(
"sent packet ({}/{})"
,
packets
.index
,
packets
.packets
.len
());
debug!
(
"sent packet ({}/{})"
,
packets
.index
,
packets
.packets
.len
());
port
.write_request_to_send
(
false
)
.expect
(
"Unable to set RTS"
);
}
else
{
}
else
{
break
;
break
;
}
}
// wait ACK
loop
{
match
port
.read
(
&
mut
buffer
)
{
Ok
(
t
)
=>
{
// if didn't get the signal then print the buffer and exit with error
if
buffer
[
..
t
]
.contains
(
&
ACK
)
{
break
;
}
else
{
warn!
(
"didn't get the signal"
);
std
::
thread
::
sleep
(
Duration
::
from_millis
(
100
));
// eprintln!("{}", String::from_utf8_lossy(&buffer[..t]));
}
}
}
}
Err
(
ref
e
)
if
e
.kind
()
==
io
::
ErrorKind
::
TimedOut
=>
(),
Err
(
ref
e
)
if
e
.kind
()
==
io
::
ErrorKind
::
TimedOut
=>
(),
Err
(
e
)
=>
error!
(
"{:?}"
,
e
),
Err
(
e
)
=>
{
error!
(
"FATAL: {:?}"
,
e
);
std
::
process
::
exit
(
1
);
}
}
}
}
}
}
...
...
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