Skip to content

Commit

Permalink
Pulled CLI tools into a single crate and consolidated. (#8)
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.
Also added Factory Reset for cVEND Terminals.

The update should be eventually incorporated into this one, but I ran out of time for this today.
  • Loading branch information
SirVer authored Dec 12, 2023
1 parent 8eb4a3a commit bc436f6
Show file tree
Hide file tree
Showing 18 changed files with 752 additions and 341 deletions.
261 changes: 131 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
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ uses in production in most of our charging stations.

## Getting started

Start by looking in [`status`](zvt/src/bin/status/main.rs) for a typical way of
interfacing with a terminal. A useful standalone tool is
[`feig_update`](zvt/src/bin/feig_update/main.rs) which we use in production to
update the Firmware of our cVEND plug terminals.
The [zvt_cli][zvt_cli/src/main.rs] is both a useful swiss army knife to
interacting with a payment terminal as well as the example on how you use the
library.

A useful standalone tool is [`feig_update`](zvt/src/bin/feig_update/main.rs)
which we use in production to update the Firmware of our cVEND plug terminals.
This will eventually also be folded into `zvt_cli`.
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
17 changes: 6 additions & 11 deletions zvt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@ A crate to interact with payment terminals (ECRs) that use the ZVT protocol, inc

[dependencies]
anyhow = "1.0.70"
async-stream = "0.3.5"
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" }
futures = "0.3.28"
log = "0.4.19"
env_logger = "0.10.0"
tokio-stream = "0.1.14"
pretty-hex = "0.4.0"
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"
futures = "0.3.28"
tokio-stream = "0.1.14"
zvt_builder = { version = "0.1.0", path = "../zvt_builder" }
zvt_derive = { version = "0.1.0", path = "../zvt_derive" }
158 changes: 0 additions & 158 deletions zvt/src/bin/status/main.rs

This file was deleted.

6 changes: 6 additions & 0 deletions zvt/src/feig/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// Messages for Feig specific commands
#[repr(u16)]
pub enum CVendFunctions {
SystemsInfo = 1,
FactoryReset = 0x0255,
}
1 change: 1 addition & 0 deletions zvt/src/feig/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod constants;
pub mod packets;
pub mod sequences;
10 changes: 9 additions & 1 deletion zvt/src/feig/packets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ pub struct WriteFile {
#[derive(Debug, PartialEq, Zvt)]
#[zvt_control_field(class = 0x0f, instr = 0xa1)]
pub struct CVendFunctions {
// Needed for most functions, but not enhanced system info. See table on page 19 in Feig
// specific manual.
#[zvt_bmp(length = length::Fixed<3>, encoding = encoding::Bcd)]
pub password: Option<usize>,

#[zvt_bmp( encoding = encoding::BigEndian)]
pub instr: u16,
}
Expand Down Expand Up @@ -192,7 +197,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 @@ -201,3 +201,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;
}
4 changes: 2 additions & 2 deletions zvt/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where
buf.resize(start + len, 0);
self.source.read_exact(&mut buf[start..]).await?;

log::debug!("Read {:?}", buf);
log::debug!("RX: {}", pretty_hex::simple_hex(&buf));

Ok(T::zvt_parse(&buf)?)
}
Expand All @@ -57,7 +57,7 @@ where
encoding::Default: encoding::Encoding<T>,
{
let bytes = msg.zvt_serialize();
log::debug!("Write {:?}", bytes);
log::debug!("TX: {}", pretty_hex::simple_hex(&bytes));
self.source
.write_all(&bytes)
.await
Expand Down
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
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 bc436f6

Please sign in to comment.