Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
balloon-tx-monolith
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
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
Stephen D
balloon-tx-monolith
Commits
7b9fd244
Commit
7b9fd244
authored
1 year ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
uart improvements
parent
29687ee1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/control.rs
+9
-6
9 additions, 6 deletions
src/control.rs
src/packet.rs
+2
-1
2 additions, 1 deletion
src/packet.rs
src/radio.rs
+22
-18
22 additions, 18 deletions
src/radio.rs
with
33 additions
and
25 deletions
src/control.rs
+
9
−
6
View file @
7b9fd244
...
...
@@ -79,22 +79,25 @@ impl Controller {
}
// manages our transceiver
// TODO currently very hacky, because we're going to rip
// most of this out when we stop using a lobotomized NPR-70
// and move to just accessing the RF4463 directly over SPI
fn
tx_thread
(
image_rx
:
Receiver
<
FecPacket
>
,
telem_rx
:
Receiver
<
Packet
>
)
{
let
mut
radio
=
UartRadio
::
new
(
"/dev/ttyA
CM0
"
);
let
mut
radio
=
UartRadio
::
new
(
"/dev/ttyA
MA0"
)
.expect
(
"Could not initialize radio
"
);
let
mut
text_msg_id
=
0
;
loop
{
while
let
Ok
(
tm
)
=
telem_rx
.try_recv
()
{
let
tm
=
tm
.into_raw
(
&
mut
text_msg_id
)
.into
();
radio
.send_packet
(
&
tm
);
if
let
Err
(
e
)
=
radio
.send_packet
(
&
tm
)
{
eprintln!
(
"Could not send packet: {}"
,
e
);
}
}
if
let
Ok
(
img
)
=
image_rx
.try_recv
()
{
radio
.send_packet
(
&
img
);
println!
(
"start send packet"
);
if
let
Err
(
e
)
=
radio
.send_packet
(
&
img
)
{
eprintln!
(
"Could not send packet: {}"
,
e
);
}
println!
(
"end send packet"
);
}
else
{
thread
::
sleep
(
Duration
::
from_millis
(
5
));
}
...
...
This diff is collapsed.
Click to expand it.
src/packet.rs
+
2
−
1
View file @
7b9fd244
...
...
@@ -3,6 +3,7 @@ use crc::{Crc, CRC_16_IBM_3740};
use
crate
::
ldpc
::
ldpc_encode
;
const
TEXT_MESSAGE_LEN
:
usize
=
252
;
const
FEC_PACKET_LEN
:
usize
=
256
+
2
+
65
;
pub
enum
Packet
{
TextMessage
(
u8
,
[
u8
;
TEXT_MESSAGE_LEN
]),
...
...
@@ -55,7 +56,7 @@ impl Packet {
pub
struct
RawPacket
(
pub
[
u8
;
256
]);
pub
struct
FecPacket
(
pub
[
u8
;
256
+
2
+
65
]);
pub
struct
FecPacket
(
pub
[
u8
;
FEC_PACKET_LEN
]);
impl
From
<
RawPacket
>
for
FecPacket
{
fn
from
(
value
:
RawPacket
)
->
Self
{
...
...
This diff is collapsed.
Click to expand it.
src/radio.rs
+
22
−
18
View file @
7b9fd244
use
serial
::{
unix
::
TTYPort
,
BaudRate
::
BaudOther
,
SerialPort
};
use
std
::{
io
::{
Read
,
Write
},
thread
::
sleep
,
time
::
Duration
,
};
...
...
@@ -8,33 +9,36 @@ use crate::packet::FecPacket;
// Used for talking to an RF4463 via a microcontroller
// The microcontroller takes in packet data over UART and sends it to the RF4463
// Note that this is a little hacky. It's only intended to be used
// for debugging, and not for an actual balloon flight
pub
struct
UartRadio
{
uart
:
TTYPort
,
}
impl
UartRadio
{
pub
fn
new
(
uart
:
&
str
)
->
Self
{
let
mut
uart
=
serial
::
open
(
uart
)
.unwrap
();
uart
.reconfigure
(
&
|
settings
|
settings
.set_baud_rate
(
BaudOther
(
921600
)))
.unwrap
();
uart
.set_timeout
(
Duration
::
from_millis
(
5
))
.unwrap
();
pub
fn
new
(
uart
:
&
str
)
->
anyhow
::
Result
<
Self
>
{
let
mut
uart
=
serial
::
open
(
uart
)
?
;
uart
.reconfigure
(
&
|
settings
|
settings
.set_baud_rate
(
BaudOther
(
921_600
)))
?
;
Self
{
uart
}
Ok
(
Self
{
uart
}
)
}
pub
fn
send_packet
(
&
mut
self
,
packet
:
&
FecPacket
)
{
self
.uart
.write_all
(
&
packet
.0
)
.unwrap
();
let
mut
buf
=
[
0
;
1
];
if
let
Ok
(
1
)
=
self
.uart
.read
(
&
mut
buf
)
{
if
buf
[
0
]
==
b'F'
{
// uC is full. Need to wait until we receive
// the empty signal
while
buf
[
0
]
!=
b'E'
{
let
_
=
self
.uart
.read
(
&
mut
buf
);
}
pub
fn
send_packet
(
&
mut
self
,
packet
:
&
FecPacket
)
->
anyhow
::
Result
<
()
>
{
loop
{
self
.uart
.write_all
(
&
[
0x00
])
?
;
self
.uart
.flush
()
?
;
let
mut
buf
=
[
0
;
1
];
self
.uart
.read_exact
(
&
mut
buf
)
?
;
if
buf
==
[
0x02
]
{
break
;
// enough space for packet
}
else
{
sleep
(
Duration
::
from_millis
(
10
));
}
}
self
.uart
.write_all
(
&
[
0x01
])
?
;
self
.uart
.write_all
(
&
packet
.0
)
?
;
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