Skip to content

Commit

Permalink
Pulled CLI tools into a single crate and consolidated.
Browse files Browse the repository at this point in the history
Moved the CLI tools into a single crate to reduce dependencies overall. Also exploded status into a cmdline tool that can address functionality individually from the cmdline. This is now a swiss army knife to talking to terminals.

The update should be eventually incorporated into this one, but I ran out of time for this today.
  • Loading branch information
SirVer committed Dec 7, 2023
1 parent 5664021 commit 2c60cdc
Show file tree
Hide file tree
Showing 15 changed files with 726 additions and 336 deletions.
254 changes: 124 additions & 130 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"zvt",
"zvt_builder",
"zvt_cli",
"zvt_derive",
]

Expand Down
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ crates_repository(
"//:Cargo.toml",
"//zvt:Cargo.toml",
"//zvt_builder:Cargo.toml",
"//zvt_cli:Cargo.toml",
"//zvt_derive:Cargo.toml",
],
)
Expand Down
19 changes: 1 addition & 18 deletions zvt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,14 @@ load("@crate_index//:defs.bzl", "all_crate_deps")

rust_library(
name = "zvt",
srcs = glob(
["src/**/*.rs"],
exclude = ["src/main.rs"],
),
srcs = glob(["src/**/*.rs"]),
crate_name = "zvt",
edition = "2021",
proc_macro_deps = all_crate_deps(proc_macro = True) + ["//zvt_derive"],
visibility = ["//visibility:public"],
deps = all_crate_deps() + ["//zvt_builder"],
)

rust_binary(
name = "status",
srcs = glob(["src/bin/status/main.rs"]),
edition = "2021",
deps = all_crate_deps() + [":zvt"],
)

rust_binary(
name = "feig_update",
srcs = glob(["src/bin/feig_update/main.rs"]),
edition = "2021",
deps = all_crate_deps() + [":zvt"],
)

rust_test(
name = "zvt_test",
srcs = [],
Expand Down
18 changes: 6 additions & 12 deletions zvt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ A crate to interact with payment terminals (ECRs) that use the ZVT protocol, inc

[dependencies]
anyhow = "1.0.70"
chrono = "0.4.24"
clap = { version = "4.2.4", features = ["derive"] }
hex = "0.4.3"
yore = "1.0.2"
zvt_derive = { version = "0.1.0", path = "../zvt_derive" }
zvt_builder = { version = "0.1.0", path = "../zvt_builder" }
log = "0.4.19"
env_logger = "0.10.0"
tokio-stream = "0.1.14"
tokio = { version = "1.29.1", features = ["net", "io-util", "rt-multi-thread", "macros"] }
async-stream = "0.3.5"
serde = { version = "1.0.185", features = ["derive"] }
serde_json = "1.0.105"
chrono = "0.4.24"
futures = "0.3.28"
log = "0.4.19"
pretty-hex = "0.4.0"
tokio = { version = "1.29.1", features = ["net", "io-util", "rt-multi-thread", "macros"] }
tokio-stream = "0.1.14"
zvt_builder = { version = "0.1.0", path = "../zvt_builder" }
zvt_derive = { version = "0.1.0", path = "../zvt_derive" }
157 changes: 0 additions & 157 deletions zvt/src/bin/status/main.rs

This file was deleted.

11 changes: 10 additions & 1 deletion zvt/src/feig/packets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ pub struct WriteFile {
#[derive(Debug, PartialEq, Zvt)]
#[zvt_control_field(class = 0x0f, instr = 0xa1)]
pub struct CVendFunctions {
#[zvt_bmp(length = length::Fixed<3>, encoding = encoding::Bcd)]
pub password: Option<usize>,

#[zvt_bmp( encoding = encoding::BigEndian)]
pub instr: u16,
}

pub const CVEND_FUNCTIONS_ENHANCED_SYSTEMS_INFO: u16 = 1;
pub const CVEND_FUNCTIONS_ENHANCED_FACTORY_RESET: u16 = 0x0255;

#[derive(Debug, PartialEq, Zvt)]
#[zvt_control_field(class = 0x80, instr = 0x00)]
pub struct WriteData {
Expand Down Expand Up @@ -192,7 +198,10 @@ mod test {
#[test]
fn test_cvend_functions() {
let bytes = get_bytes("1680761818.690979000_ecr_pt.blob");
let expected = CVendFunctions { instr: 0x01 };
let expected = CVendFunctions {
password: None,
instr: 0x01,
};
assert_eq!(CVendFunctions::zvt_deserialize(&bytes).unwrap().0, expected);
assert_eq!(bytes, expected.zvt_serialize());
}
Expand Down
12 changes: 12 additions & 0 deletions zvt/src/feig/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,15 @@ impl WriteFile {
Box::pin(s)
}
}

pub struct FactoryReset;

#[derive(Debug, ZvtEnum)]
pub enum FactoryResetResponse {
CompletionData(packets::CompletionData),
}

impl Sequence for FactoryReset {
type Input = super::packets::CVendFunctions;
type Output = FactoryResetResponse;
}
10 changes: 10 additions & 0 deletions zvt/src/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ pub struct Diagnosis {
pub tlv: Option<tlv::Diagnosis>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum DiagnosisType {
Line = 1,
Extended = 2,
Configuration = 3,
EmvConfiguration = 4,
Ep2Configuration = 5,
}

#[derive(Debug, PartialEq, Zvt)]
#[zvt_control_field(class = 0x06, instr = 0x93)]
pub struct Initialization {
Expand Down
2 changes: 1 addition & 1 deletion zvt/src/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{encoding, ZvtEnum, ZvtParser, ZvtSerializer};
use anyhow::Result;
use async_stream::try_stream;
use futures::Stream;
use log::{log_enabled, debug, Level::Debug};
use log::{debug, log_enabled, Level::Debug};
use std::boxed::Box;
use std::marker::Unpin;
use std::pin::Pin;
Expand Down
16 changes: 16 additions & 0 deletions zvt_cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
load("@crate_index//:defs.bzl", "all_crate_deps")

rust_binary(
name = "zvt_cli",
srcs = glob(["src/main.rs"]),
edition = "2021",
deps = all_crate_deps() + ["//zvt"],
)

rust_binary(
name = "feig_update",
srcs = glob(["src/bin/feig_update/main.rs"]),
edition = "2021",
deps = all_crate_deps() + ["//zvt"],
)
23 changes: 23 additions & 0 deletions zvt_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "zvt_cli"
edition = "2021"
authors.workspace = true
categories.workspace = true
keywords.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true
description = """
A crate to interact with payment terminals (ECRs) that use the ZVT protocol, including stand alone commandline tools to interact with the devices.
"""

[dependencies]
anyhow = "1.0.70"
argh = "0.1.12"
env_logger = "0.10.0"
log = "0.4.19"
serde = { version = "1.0.185", features = ["derive"] }
serde_json = "1.0.105"
tokio = { version = "1.29.1", features = ["net", "io-util", "rt-multi-thread", "macros"] }
tokio-stream = "0.1.14"
zvt = { version = "0.1.0", path = "../zvt" }
Loading

0 comments on commit 2c60cdc

Please sign in to comment.