-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add definition for file transfer packages
- Loading branch information
1 parent
4554c71
commit 3761380
Showing
13 changed files
with
306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
|
||
impl From<i64> for DltFtInt { | ||
fn from(value: i64) -> Self { | ||
DltFtInt::I64(value) | ||
} | ||
} | ||
|
||
#[cfg(target_pointer_width = "32")] | ||
impl From<isize> for DltFtInt { | ||
fn from(value: isize) -> Self { | ||
DltFtInt::I32(value as u32) | ||
} | ||
} | ||
|
||
#[cfg(target_pointer_width = "64")] | ||
impl From<isize> for DltFtInt { | ||
fn from(value: isize) -> Self { | ||
DltFtInt::I64(value as i64) | ||
} | ||
} | ||
|
||
#[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, | ||
} | ||
} | ||
} | ||
|
||
impl From<DltFtInt> for i64 { | ||
fn from(value: DltFtInt) -> Self { | ||
match value { | ||
DltFtInt::I32(v) => v as i64, | ||
DltFtInt::I64(v) => v, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
|
||
impl From<u64> for DltFtUInt { | ||
fn from(value: u64) -> Self { | ||
DltFtUInt::U64(value) | ||
} | ||
} | ||
|
||
#[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) | ||
} | ||
} | ||
|
||
#[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, | ||
} | ||
} | ||
} | ||
|
||
impl From<DltFtUInt> for u64 { | ||
fn from(value: DltFtUInt) -> Self { | ||
match value { | ||
DltFtUInt::U32(v) => v as u64, | ||
DltFtUInt::U64(v) => v, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters