Skip to content

Commit

Permalink
Add definition for file transfer packages
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianSchmid committed Jun 17, 2024
1 parent 4554c71 commit 3761380
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ An complete example which includes the parsing of the ethernet & udp headers can

## References
* [Log and Trace Protocol Specification](https://www.autosar.org/fileadmin/standards/foundation/1-3/AUTOSAR_PRS_LogAndTraceProtocol.pdf)
* [COVESA DLT Filetransfer](https://github.com/COVESA/dlt-daemon/blob/603f0e4bb87478f7d3e95c89b37790e55ff1e4e5/doc/dlt_filetransfer.md)

## License
Licensed under either of Apache License, Version 2.0 or MIT license at your option. The corresponding license texts can be found in the LICENSE-APACHE file and the LICENSE-MIT file.
Expand Down
20 changes: 20 additions & 0 deletions src/ft/dlt_ft_data_pkg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use super::*;

/// Package containing a chunk of data of a file.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct DltFtDataPkg<'a> {
/// File serial number (usually inode).
pub file_serial_number: DltFtUInt,

/// Transfered package number.
pub package_nr: DltFtUInt,

/// Transfered data.
pub data: &'a [u8],
}


impl<'a> DltFtDataPkg<'a> {
/// Verbose string at the start and end of the "DLT File Transfer Data" package.
pub const PKG_FLAG: &'static str = "FLDA";
}
13 changes: 13 additions & 0 deletions src/ft/dlt_ft_end_pkg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use super::*;

/// Package sent after a file transfer is complete.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct DltFtEndPkg {
/// File serial number (usually inode).
pub file_serial_number: DltFtUInt,
}

impl DltFtEndPkg {
/// Verbose string at the start and end of the "DLT File Transfer End" package.
pub const PKG_FLAG: &'static str = "FLFI";
}
5 changes: 5 additions & 0 deletions src/ft/dlt_ft_error_code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use super::*;

#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct DltFtErrorCode(pub DltFtInt);

35 changes: 35 additions & 0 deletions src/ft/dlt_ft_error_pkg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::*;

/// Error package sent when an error occured with an
/// existing file.
///
/// If a files does not exist
/// [`crate::ft::DltFileNotExistErrorPkg`] is sent instead.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct DltFtErrorPkg<'a, 'b> {
/// Error code.
pub error_code: DltFtErrorCode,

/// Standard linux error code.
pub linux_error_code: DltFtInt,

/// File serial number (usually inode).
pub file_serial_number: DltFtUInt,

/// Absolute path to the file.
pub file_name: &'a str,

/// Size of the file.
pub file_size: DltFtUInt,

/// File creaton date.
pub creation_date: &'b str,

/// Number of packages that will be used to transfer the file.
pub number_of_packages: DltFtUInt,
}

impl<'a, 'b> DltFtErrorPkg<'a, 'b> {
/// Verbose string at the start and end of the "DLT File Transfer Error" package.
pub const PKG_FLAG: &'static str = "FLER";
}
20 changes: 20 additions & 0 deletions src/ft/dlt_ft_file_not_exist_error_pkg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use super::*;

/// Error package sent if a file that should have been
/// transfered does not exists.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct DltFtFileNotExistErrorPkg<'a> {
/// Error code.
pub error_code: DltFtErrorCode,

/// Standard linux error code.
pub linux_error_code: DltFtInt,

/// Absolute path to the file.
pub file_name: &'a str,
}

impl<'a> DltFtFileNotExistErrorPkg<'a> {
/// Verbose string at the start and end of the "DLT File Transfer Error" package.
pub const PKG_FLAG: &'static str = "FLER";
}
28 changes: 28 additions & 0 deletions src/ft/dlt_ft_header_pkg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use super::*;

/// Packet sent at the start of a file transfer.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct DltFtHeaderPkg<'a, 'b> {
/// File serial number (usually inode).
pub file_serial_number: DltFtUInt,

/// Absolute path to the file.
pub file_name: &'a str,

/// Size of the file.
pub file_size: DltFtUInt,

/// File creaton date.
pub creation_date: &'b str,

/// Number of packages that will be used to transfer the file.
pub number_of_packages: DltFtUInt,

/// Needed buffer size to reconsturct the file.
pub buffer_size: DltFtUInt,
}

impl<'a, 'b> DltFtHeaderPkg<'a, 'b> {
/// Verbose string at the start and end of the "DLT File Transfer Header" package.
pub const PKG_FLAG: &'static str = "FLST";
}
28 changes: 28 additions & 0 deletions src/ft/dlt_ft_info_pkg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use super::*;

/// Info packet for a file if only metadat is sent.
///
/// This packet is sent if only informations about a file
/// are sent without the file contents.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct DltFtInfoPkg<'a, 'b> {
/// File serial number (usually inode).
pub file_serial_number: DltFtUInt,

/// Absolute path to the file.
pub file_name: &'a str,

/// Size of the file.
pub file_size: DltFtUInt,

/// File creaton date.
pub creation_date: &'b str,

/// Number of packages that will be used to transfer the file.
pub number_of_packages: DltFtUInt,
}

impl<'a, 'b> DltFtInfoPkg<'a, 'b> {
/// Verbose string at the start and end of the "DLT File Transfer Info" package.
pub const PKG_FLAG: &'static str = "FLIF";
}
52 changes: 52 additions & 0 deletions src/ft/dlt_ft_int.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

/// Signed integer (either 32 or 64 bit).
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum DltFtInt {
I32(i32),
I64(i64),
}

impl From<i32> for DltFtInt {
fn from(value: i32) -> Self {
DltFtInt::I32(value)
}

Check warning on line 12 in src/ft/dlt_ft_int.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_int.rs#L10-L12

Added lines #L10 - L12 were not covered by tests
}

impl From<i64> for DltFtInt {
fn from(value: i64) -> Self {
DltFtInt::I64(value)
}

Check warning on line 18 in src/ft/dlt_ft_int.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_int.rs#L16-L18

Added lines #L16 - L18 were not covered by tests
}

#[cfg(target_pointer_width = "32")]
impl From<isize> for DltFtInt {
fn from(value: isize) -> Self {
DltFtInt::I32(value as u32)

Check failure on line 24 in src/ft/dlt_ft_int.rs

View workflow job for this annotation

GitHub Actions / cargo build and test (linux-32bit-stable)

mismatched types
}
}

#[cfg(target_pointer_width = "64")]
impl From<isize> for DltFtInt {
fn from(value: isize) -> Self {
DltFtInt::I64(value as i64)
}

Check warning on line 32 in src/ft/dlt_ft_int.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_int.rs#L30-L32

Added lines #L30 - L32 were not covered by tests
}

#[cfg(target_pointer_width = "64")]
impl From<DltFtInt> for isize {
fn from(value: DltFtInt) -> Self {
match value {
DltFtInt::I32(v) => v as isize,
DltFtInt::I64(v) => v as isize,

Check warning on line 40 in src/ft/dlt_ft_int.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_int.rs#L37-L40

Added lines #L37 - L40 were not covered by tests
}
}

Check warning on line 42 in src/ft/dlt_ft_int.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_int.rs#L42

Added line #L42 was not covered by tests
}

impl From<DltFtInt> for i64 {
fn from(value: DltFtInt) -> Self {
match value {
DltFtInt::I32(v) => v as i64,
DltFtInt::I64(v) => v,

Check warning on line 49 in src/ft/dlt_ft_int.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_int.rs#L46-L49

Added lines #L46 - L49 were not covered by tests
}
}

Check warning on line 51 in src/ft/dlt_ft_int.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_int.rs#L51

Added line #L51 was not covered by tests
}
20 changes: 20 additions & 0 deletions src/ft/dlt_ft_pkg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use super::*;

/// DLT file transfer package.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum DltFtPkg<'a, 'b> {
/// Packet sent at the start of a file transfer.
Header(DltFtHeaderPkg<'a, 'b>),
/// Package containing a chunk of data of a file.
Data(DltFtDataPkg<'a>),
/// Package sent after a file transfer is complete.
End(DltFtEndPkg),
/// Info packet for a file if only metadat is sent.
Info(DltFtInfoPkg<'a, 'b>),
/// Error package sent when an error occured with an
/// existing file.
Error(DltFtErrorPkg<'a, 'b>),
/// Error package sent if a file that should have been
/// transfered does not exists.
FileNotExistsError(DltFtFileNotExistErrorPkg<'a>),
}
52 changes: 52 additions & 0 deletions src/ft/dlt_ft_uint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

/// Unsigned integer (either 32 or 64 bit).
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum DltFtUInt {
U32(u32),
U64(u64),
}

impl From<u32> for DltFtUInt {
fn from(value: u32) -> Self {
DltFtUInt::U32(value)
}

Check warning on line 12 in src/ft/dlt_ft_uint.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_uint.rs#L10-L12

Added lines #L10 - L12 were not covered by tests
}

impl From<u64> for DltFtUInt {
fn from(value: u64) -> Self {
DltFtUInt::U64(value)
}

Check warning on line 18 in src/ft/dlt_ft_uint.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_uint.rs#L16-L18

Added lines #L16 - L18 were not covered by tests
}

#[cfg(target_pointer_width = "32")]
impl From<usize> for DltFtUInt {
fn from(value: usize) -> Self {
DltFtUInt::U32(value as u32)
}
}

#[cfg(target_pointer_width = "64")]
impl From<usize> for DltFtUInt {
fn from(value: usize) -> Self {
DltFtUInt::U64(value as u64)
}

Check warning on line 32 in src/ft/dlt_ft_uint.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_uint.rs#L30-L32

Added lines #L30 - L32 were not covered by tests
}

#[cfg(target_pointer_width = "64")]
impl From<DltFtUInt> for usize {
fn from(value: DltFtUInt) -> Self {
match value {
DltFtUInt::U32(v) => v as usize,
DltFtUInt::U64(v) => v as usize,

Check warning on line 40 in src/ft/dlt_ft_uint.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_uint.rs#L37-L40

Added lines #L37 - L40 were not covered by tests
}
}

Check warning on line 42 in src/ft/dlt_ft_uint.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_uint.rs#L42

Added line #L42 was not covered by tests
}

impl From<DltFtUInt> for u64 {
fn from(value: DltFtUInt) -> Self {
match value {
DltFtUInt::U32(v) => v as u64,
DltFtUInt::U64(v) => v,

Check warning on line 49 in src/ft/dlt_ft_uint.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_uint.rs#L46-L49

Added lines #L46 - L49 were not covered by tests
}
}

Check warning on line 51 in src/ft/dlt_ft_uint.rs

View check run for this annotation

Codecov / codecov/patch

src/ft/dlt_ft_uint.rs#L51

Added line #L51 was not covered by tests
}
29 changes: 29 additions & 0 deletions src/ft/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
mod dlt_ft_data_pkg;
pub use dlt_ft_data_pkg::*;

mod dlt_ft_end_pkg;
pub use dlt_ft_end_pkg::*;

mod dlt_ft_error_code;
pub use dlt_ft_error_code::*;

mod dlt_ft_error_pkg;
pub use dlt_ft_error_pkg::*;

mod dlt_ft_file_not_exist_error_pkg;
pub use dlt_ft_file_not_exist_error_pkg::*;

mod dlt_ft_header_pkg;
pub use dlt_ft_header_pkg::*;

mod dlt_ft_info_pkg;
pub use dlt_ft_info_pkg::*;

mod dlt_ft_int;
pub use dlt_ft_int::*;

mod dlt_ft_pkg;
pub use dlt_ft_pkg::*;

mod dlt_ft_uint;
pub use dlt_ft_uint::*;
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ pub mod control;
/// Errors that can be returned by functions in dlt_parse.
pub mod error;

/// DLT file transfer related structs & functions (used to tranfer files via DLT).
pub mod ft;

/// Module containing "verbose DLT" encoding & decoding structs & functions.
pub mod verbose;

Expand Down

0 comments on commit 3761380

Please sign in to comment.