Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Enhanced Ground Software
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
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
Skyward Enhanced Ground Software
Commits
12558c28
Commit
12558c28
authored
5 months ago
by
Federico Lolli
Browse files
Options
Downloads
Patches
Plain Diff
Added sealed module to suppress warnings
parent
96287274
No related branches found
No related tags found
1 merge request
!13
Refactored Mavlink Communication for Improved Reliability
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/communication.rs
+107
-91
107 additions, 91 deletions
src/communication.rs
src/communication/ethernet.rs
+4
-1
4 additions, 1 deletion
src/communication/ethernet.rs
src/communication/serial.rs
+4
-1
4 additions, 1 deletion
src/communication/serial.rs
with
115 additions
and
93 deletions
src/communication.rs
+
107
−
91
View file @
12558c28
...
...
@@ -8,6 +8,25 @@ mod error;
pub
mod
ethernet
;
pub
mod
serial
;
use
std
::
sync
::{
Arc
,
atomic
::{
AtomicBool
,
Ordering
},
};
use
ring_channel
::{
RingReceiver
,
TryRecvError
};
use
sealed
::
MessageTransceiver
;
use
skyward_mavlink
::
mavlink
::
MavFrame
;
use
crate
::
mavlink
::{
MavMessage
,
TimedMessage
};
// Re-exports
pub
use
error
::{
CommunicationError
,
ConnectionError
};
pub
use
ethernet
::
EthernetConfiguration
;
pub
use
serial
::
SerialConfiguration
;
const
MAX_STORED_MSGS
:
usize
=
1000
;
// e.g., 192 bytes each = 192 KB
mod
sealed
{
use
std
::{
num
::
NonZeroUsize
,
sync
::{
...
...
@@ -17,7 +36,7 @@ use std::{
};
use
enum_dispatch
::
enum_dispatch
;
use
ring_channel
::
{
RingReceiver
,
TryRecvError
,
ring_channel
}
;
use
ring_channel
::
ring_channel
;
use
skyward_mavlink
::
mavlink
::{
MavFrame
,
error
::{
MessageReadError
,
MessageWriteError
},
...
...
@@ -28,33 +47,15 @@ use crate::{
mavlink
::{
MavMessage
,
TimedMessage
},
};
use
ethernet
::
EthernetTransceiver
;
use
serial
::
SerialTransceiver
;
// Re-exports
pub
use
error
::{
CommunicationError
,
ConnectionError
};
pub
use
ethernet
::
EthernetConfiguration
;
pub
use
serial
::
SerialConfiguration
;
const
MAX_STORED_MSGS
:
usize
=
1000
;
// e.g., 192 bytes each = 192 KB
/// Trait to abstract common configuration types.
pub
trait
TransceiverConfig
:
TransceiverConfigSealed
{}
trait
TransceiverConfigSealed
{}
impl
<
T
:
TransceiverConfigSealed
>
TransceiverConfig
for
T
{}
impl
<
T
:
Connectable
>
TransceiverConfigSealed
for
T
{}
use
super
::{
CommunicationError
,
Connection
,
ConnectionError
,
MAX_STORED_MSGS
,
ethernet
::
EthernetTransceiver
,
serial
::
SerialTransceiver
,
};
/// Extension trait to open a connection directly from a configuration.
pub
trait
TransceiverConfigExt
:
Connectable
{
/// Opens a connection and returns a handle to it.
fn
open_connection
(
&
self
)
->
Result
<
Connection
,
ConnectionError
>
{
Ok
(
self
.connect
()
?
.open_listening_connection
())
}
}
impl
<
T
:
Connectable
>
TransceiverConfigExt
for
T
{}
pub
trait
TransceiverConfigSealed
{}
/// Trait representing an entity that can be connected.
trait
Connectable
{
pub
trait
Connectable
{
type
Connected
:
MessageTransceiver
;
/// Establishes a connection based on the configuration.
...
...
@@ -66,7 +67,7 @@ trait Connectable {
/// It also provides a default implementation for opening a listening connection, while
/// being transparent to the actual Transceiver type.
#[enum_dispatch(Transceivers)]
trait
MessageTransceiver
:
Send
+
Sync
+
Into
<
Transceivers
>
{
pub
trait
MessageTransceiver
:
Send
+
Sync
+
Into
<
Transceivers
>
{
/// Blocks until a valid message is received.
fn
wait_for_message
(
&
self
)
->
Result
<
TimedMessage
,
MessageReadError
>
;
...
...
@@ -115,14 +116,29 @@ trait MessageTransceiver: Send + Sync + Into<Transceivers> {
/// Enum representing the different types of transceivers.
#[enum_dispatch]
enum
Transceivers
{
pub
(
super
)
enum
Transceivers
{
Serial
(
SerialTransceiver
),
Ethernet
(
EthernetTransceiver
),
}
}
/// Trait to abstract common configuration types.
pub
trait
TransceiverConfig
:
sealed
::
TransceiverConfigSealed
{}
impl
<
T
:
sealed
::
TransceiverConfigSealed
>
TransceiverConfig
for
T
{}
impl
<
T
:
sealed
::
Connectable
>
sealed
::
TransceiverConfigSealed
for
T
{}
/// Extension trait to open a connection directly from a configuration.
pub
trait
TransceiverConfigExt
:
sealed
::
Connectable
{
/// Opens a connection and returns a handle to it.
fn
open_connection
(
&
self
)
->
Result
<
Connection
,
ConnectionError
>
{
Ok
(
self
.connect
()
?
.open_listening_connection
())
}
}
impl
<
T
:
sealed
::
Connectable
>
TransceiverConfigExt
for
T
{}
/// Represents an active connection with buffered messages.
pub
struct
Connection
{
transceiver
:
Arc
<
Transceivers
>
,
transceiver
:
Arc
<
sealed
::
Transceivers
>
,
rx_ring_channel
:
RingReceiver
<
TimedMessage
>
,
running_flag
:
Arc
<
AtomicBool
>
,
}
...
...
This diff is collapsed.
Click to expand it.
src/communication/ethernet.rs
+
4
−
1
View file @
12558c28
...
...
@@ -14,7 +14,10 @@ use tracing::{debug, trace};
use
crate
::
mavlink
::{
MAX_MSG_SIZE
,
MavMessage
,
TimedMessage
,
peek_reader
::
PeekReader
};
use
super
::{
Connectable
,
ConnectionError
,
MessageTransceiver
};
use
super
::{
ConnectionError
,
sealed
::{
Connectable
,
MessageTransceiver
},
};
/// Configuration for an Ethernet connection.
#[derive(Debug,
Clone)]
...
...
This diff is collapsed.
Click to expand it.
src/communication/serial.rs
+
4
−
1
View file @
12558c28
...
...
@@ -18,7 +18,10 @@ use crate::{
mavlink
::{
MavMessage
,
TimedMessage
,
peek_reader
::
PeekReader
},
};
use
super
::{
Connectable
,
ConnectionError
,
MessageTransceiver
};
use
super
::{
ConnectionError
,
sealed
::{
Connectable
,
MessageTransceiver
},
};
const
SERIAL_PORT_TIMEOUT_MS
:
u64
=
100
;
pub
const
DEFAULT_BAUD_RATE
:
u32
=
115200
;
...
...
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