Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tudelft-serial-upload
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer and Embedded Systems Engineering
Embedded Systems Lab
tudelft-serial-upload
Commits
5a37e60e
Verified
Commit
5a37e60e
authored
Dec 21, 2022
by
Jana Dönszelmann
Browse files
Options
Downloads
Patches
Plain Diff
dry run
parent
a98a0d9e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#783147
passed
Dec 21, 2022
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/selector.rs
+1
-3
1 addition, 3 deletions
src/selector.rs
src/upload.rs
+34
-16
34 additions, 16 deletions
src/upload.rs
with
35 additions
and
19 deletions
src/selector.rs
+
1
−
3
View file @
5a37e60e
...
...
@@ -61,9 +61,7 @@ pub fn find_available_serial_port_by_id() -> Result<String> {
.collect
();
if
ports
.is_empty
()
{
return
Err
(
eyre!
(
"No serial port to choose from"
)
.suggestion
(
"Make sure the usb is plugged in"
)
);
Err
(
eyre!
(
"No serial port to choose from"
)
.suggestion
(
"Make sure the usb is plugged in"
))
}
else
if
ports
.len
()
>
1
{
internal_choose_interactive
(
ports
)
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/upload.rs
+
34
−
16
View file @
5a37e60e
...
...
@@ -49,16 +49,20 @@ fn read_file(file: &Path) -> Result<Vec<u8>> {
/// Exit with an exit code of 1 when the upload fails.
///
/// Returns a path to a serial port over which uploading happened. This path can be used to communicate with the board.
pub
fn
upload_file_or_stop
(
port
:
PortSelector
,
file
:
impl
AsRef
<
Path
>
)
->
PathBuf
{
pub
fn
upload_file_or_stop
(
port
:
PortSelector
,
file
:
Option
<
impl
AsRef
<
Path
>>
)
->
PathBuf
{
if
let
Some
(
file
)
=
file
{
match
read_file
(
file
.as_ref
())
.wrap_err_with
(||
format!
(
"failed to read from file {:?}"
,
file
.as_ref
()))
{
Ok
(
i
)
=>
upload_or_stop
(
port
,
i
),
Ok
(
i
)
=>
upload_or_stop
(
port
,
i
,
false
),
Err
(
e
)
=>
{
eprintln!
(
"{e:?}"
);
exit
(
1
);
}
}
}
else
{
upload_or_stop
(
port
,
[],
true
)
}
}
/// Upload a file to a connected board. Select which serial port the board is on with the [`PortSelector`]
...
...
@@ -66,11 +70,17 @@ pub fn upload_file_or_stop(port: PortSelector, file: impl AsRef<Path>) -> PathBu
/// Returns an error when the upload fails.
///
/// Returns a path to a serial port over which uploading happened. This path can be used to communicate with the board.
pub
fn
upload_file
(
port
:
PortSelector
,
file
:
impl
AsRef
<
Path
>
)
->
Result
<
PathBuf
>
{
pub
fn
upload_file
(
port
:
PortSelector
,
file
:
Option
<
impl
AsRef
<
Path
>
>
)
->
Result
<
PathBuf
>
{
upload
(
port
,
read_file
(
file
.as_ref
())
.wrap_err_with
(||
format!
(
"failed to read from file {:?}"
,
file
.as_ref
()))
?
,
file
.as_ref
()
.map
(|
f
|
{
read_file
(
f
.as_ref
())
.wrap_err_with
(||
format!
(
"failed to read from file {:?}"
,
f
.as_ref
()))
})
.transpose
()
?
.unwrap_or_default
(),
file
.is_none
(),
)
}
...
...
@@ -80,8 +90,8 @@ pub fn upload_file(port: PortSelector, file: impl AsRef<Path>) -> Result<PathBuf
/// Exit with an exit code of 1 when the upload fails.
///
/// Returns a path to a serial port over which uploading happened. This path can be used to communicate with the board.
pub
fn
upload_or_stop
(
port
:
PortSelector
,
file
:
impl
AsRef
<
[
u8
]
>
)
->
PathBuf
{
match
upload
(
port
,
file
.as_ref
())
{
pub
fn
upload_or_stop
(
port
:
PortSelector
,
file
:
impl
AsRef
<
[
u8
]
>
,
dry_run
:
bool
)
->
PathBuf
{
match
upload
(
port
,
file
.as_ref
()
,
dry_run
)
{
Err
(
e
)
=>
{
eprintln!
(
"{e:?}"
);
exit
(
1
);
...
...
@@ -96,11 +106,15 @@ pub fn upload_or_stop(port: PortSelector, file: impl AsRef<[u8]>) -> PathBuf {
/// Returns an error when the upload fails.
///
/// Returns a path to a serial port over which uploading happened. This path can be used to communicate with the board.
pub
fn
upload
(
port
:
PortSelector
,
file
:
impl
AsRef
<
[
u8
]
>
)
->
Result
<
PathBuf
>
{
upload_internal
(
port
,
file
.as_ref
())
pub
fn
upload
(
port
:
PortSelector
,
file
:
impl
AsRef
<
[
u8
]
>
,
dry_run
:
bool
)
->
Result
<
PathBuf
>
{
upload_internal
(
port
,
file
.as_ref
(),
dry_run
)
}
fn
upload_internal
(
port
:
PortSelector
<
'_
>
,
file
:
&
[
u8
],
dry_run
:
bool
)
->
Result
<
PathBuf
>
{
if
dry_run
&&
matches!
(
port
,
PortSelector
::
SearchAll
)
{
bail!
(
"can't use dry_run in SearchAll mode"
);
}
fn
upload_internal
(
port
:
PortSelector
<
'_
>
,
file
:
&
[
u8
])
->
Result
<
PathBuf
>
{
let
(
ports_to_try
,
stop_after_first_error
):
(
Vec
<
Result
<
Serial
>>
,
bool
)
=
match
port
{
PortSelector
::
SearchFirst
=>
(
selector
::
all_serial_ports
()
...
...
@@ -145,6 +159,10 @@ fn upload_internal(port: PortSelector<'_>, file: &[u8]) -> Result<PathBuf> {
}
};
if
dry_run
{
return
Ok
(
port
.path
);
}
if
let
Err
(
e
)
=
port
.try_do_upload
(
file
)
.wrap_err_with
(||
format!
(
"failed to upload to port {:?}"
,
port
.path
))
...
...
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
sign in
to comment