Skip to content

Commit

Permalink
Add emv config diagnosis to the configure step (#18)
Browse files Browse the repository at this point in the history
* Add EMV diagnosis and .bazelversion file

Signed-off-by: Daniel-Jenkins <[email protected]>

* Only run EMV when the TID changes

Signed-off-by: Daniel-Jenkins <[email protected]>

* Add docs and remove incorrect log

Signed-off-by: Daniel-Jenkins <[email protected]>

---------

Signed-off-by: Daniel-Jenkins <[email protected]>
  • Loading branch information
d-r-jenkins authored Jan 14, 2025
1 parent 808f4ef commit 9c47655
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.4.0
35 changes: 31 additions & 4 deletions zvt_feig_terminal/src/feig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,17 @@ impl Feig {
///
/// Function does nothing if the feig-terminal has already the desired
/// terminal-id.
async fn set_terminal_id(&mut self) -> Result<()> {
///
/// Returns true if a new TID was set, and false if the requested TID is
/// already set to the terminal
async fn set_terminal_id(&mut self) -> Result<bool> {
let system_info = self.get_system_info().await?;
let config = self.socket.config();

// Set the terminal id if required.
if config.terminal_id == system_info.terminal_id {
info!("Terminal id already up-to-date");
return Ok(());
return Ok(false);
}

// Sadly the terminal_id is a int, but we communicate it as a string...
Expand All @@ -162,7 +165,7 @@ impl Feig {
continue;
};
match response {
sequences::SetTerminalIdResponse::CompletionData(_) => return Ok(()),
sequences::SetTerminalIdResponse::CompletionData(_) => return Ok(true),
sequences::SetTerminalIdResponse::Abort(data) => {
bail!(zvt::ZVTError::Aborted(data.error))
}
Expand All @@ -172,6 +175,27 @@ impl Feig {
bail!(zvt::ZVTError::IncompleteData)
}

async fn run_diagnosis(&mut self, diagnosis: packets::DiagnosisType) -> Result<()> {
let request = packets::Diagnosis {
tlv: Some(packets::tlv::Diagnosis {
diagnosis_type: Some(diagnosis as u8),
}),
};

let mut stream = sequences::Diagnosis::into_stream(request, &mut self.socket);
while let Some(response) = stream.next().await {
use sequences::DiagnosisResponse::*;
match response? {
SetTimeAndDate(data) => log::debug!("{data:#?}"),
PrintLine(data) => log::debug!("{}", data.text),
PrintTextBlock(data) => log::debug!("{data:#?}"),
IntermediateStatusInformation(_) | CompletionData(_) => (),
Abort(_) => bail!("Received Abort."),
}
}
Ok(())
}

/// Initializes the feig-terminal.
async fn initialize(&mut self) -> Result<()> {
let password = self.socket.config().feig_config.password;
Expand Down Expand Up @@ -285,7 +309,10 @@ impl Feig {
/// * Initialize the terminal.
/// * Run end-of-day job.
pub async fn configure(&mut self) -> Result<()> {
self.set_terminal_id().await?;
let tid_changed = self.set_terminal_id().await?;
if tid_changed {
self.run_diagnosis(packets::DiagnosisType::EmvConfiguration).await?;
}
self.initialize().await?;
self.end_of_day().await?;

Expand Down

0 comments on commit 9c47655

Please sign in to comment.