Skip to content

Commit

Permalink
Merge pull request #29 from pmnxis/dev/23_disp_rom_read_tid_serial_re…
Browse files Browse the repository at this point in the history
…facto

#23 `card-terminal-adapter` for new features and KICC spec
  • Loading branch information
pmnxis committed Oct 19, 2023
2 parents b6b5e3e + 881e2c6 commit 14dd320
Show file tree
Hide file tree
Showing 31 changed files with 1,024 additions and 974 deletions.
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ DEFMT_LOG = "trace"
# the project follows a re-patching approach for incorporating the library source code
# from the local environment into the actual open-source build.
[patch.'https://github.com/pmnxis/billmock-app-rs.git']
serial-arcade-pay = { path = "serial-arcade-pay" }
serial-arcade-pay-impl = { path = "serial-arcade-example" }
card-terminal-adapter = { path = "card-terminal-adapter" }
billmock-plug-card = { path = "billmock-plug-card" }

# Custom println! To use formatting, use the latest branch.
# [patch.crates-io]
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"rust-analyzer.cargo.target": "thumbv6m-none-eabi",
"rust-analyzer.linkedProjects": [
"Cargo.toml",
"serial-arcade-pay/Cargo.toml",
"serial-arcade-example/Cargo.toml",
"billmock-plug-card/Cargo.toml",
"card-terminal-adapter/Cargo.toml",
],
}
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ hw_mini_0v4 = ["eeprom"]
embassy-sync = { version = "0.3.0", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["defmt"] }
embassy-executor = { version = "0.3.0", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
embassy-futures = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["defmt"] }
embassy-time = { version = "0.1.3", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-time = { version = "0.1.5", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-stm32 = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["nightly", "defmt", "time-driver-any", "stm32g030c8", "memory-x", "unstable-pac", "exti", "unstable-traits"] } # "unstable-traits" for use InputPin trait for gpio
embassy-embedded-hal = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", rev = "d94b9fe6fb6adee82c1427e72450f77a0d0973c3", features = ["nightly"] }
defmt = "0.3"
Expand All @@ -39,20 +39,23 @@ num_enum = { version = "0.7.0", default-features = false } # Application specifi
bit_field = "0.10"
nonmax = { version = "0.5.3", default-features = false, features = [] } # to use common NonMax
static_assertions = "1.1.0"
env_to_array = { version = "0.3.1", features = ["hex"] }

# Application specific library

# serial-arcade-pay = { path = "serial-arcade-pay" }
# serial-arcade-pay-impl = { path = "serial-arcade-example" }
# card-terminal-adapter = { path = "card-terminal-adapter" }
# billmock-plug-card = { path = "serial-arcade-example" }

# The above dependency configurations are intentionally set to an external address in this repository
# for the purpose of compiling both the original and NDA code simultaneously.
# However, in reality, during a regular build, due to the patched content in `.cargo/config.toml`,
# the code accesses the locally stored directory directly without connecting to the URL.
# `serial-arcade-pay-impl` would be replaced to NDA library that working on real field with dependency injection
# `billmock-plug-card` would be replaced to NDA library that working on real field with dependency injection
# details : https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section
serial-arcade-pay = { git = "https://github.com/pmnxis/billmock-app-rs.git" }
serial-arcade-pay-impl = { git = "https://github.com/pmnxis/billmock-app-rs.git" }

# uncoment later
card-terminal-adapter = { git = "https://github.com/pmnxis/billmock-app-rs.git" }
billmock-plug-card = { git = "https://github.com/pmnxis/billmock-app-rs.git" }

[build-dependencies]
git2 = "0.18" # Git library for Rust
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: CC0-1.0

[package]
name = "serial-arcade-pay-impl"
name = "billmock-plug-card"
version = "0.1.0"
edition = "2021"
authors = ["Jinwoo Park <[email protected]>"]
Expand All @@ -15,7 +15,7 @@ description = "Example implementation of serial arcade payment method for billmo
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serial-arcade-pay = { path = "../serial-arcade-pay" } # Import generic interface for billmock-app-rs
card-terminal-adapter = { path = "../card-terminal-adapter" } # Import generic interface for billmock-app-rs

defmt = "0.3"
defmt-test = "0.3.0"
Expand Down
13 changes: 13 additions & 0 deletions billmock-plug-card/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* SPDX-FileCopyrightText: © 2023 Jinwoo Park ([email protected])
*
* SPDX-License-Identifier: MIT OR Apache-2.0
*/

pub(crate) const KICC_STX: u8 = 0x02;
pub(crate) const KICC_ACK: u8 = 0x06;
pub(crate) const KICC_NACK: u8 = 0x15;
pub(crate) const KICC_ETX: u8 = 0x03;

pub(crate) const RAW_DATA_ACK: [u8; 3] = [KICC_ACK, KICC_ACK, KICC_ACK];
pub(crate) const RAW_DATA_NACK: [u8; 3] = [KICC_NACK, KICC_NACK, KICC_NACK];
146 changes: 146 additions & 0 deletions billmock-plug-card/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* SPDX-FileCopyrightText: © 2023 Jinwoo Park ([email protected])
*
* SPDX-License-Identifier: MIT OR Apache-2.0
*/

#![no_std]
#![feature(const_trait_impl)]

#[cfg(test)] // for the print out internnal log in test code
extern crate std;

#[allow(unused)]
mod common;

use card_terminal_adapter::types::*;
use card_terminal_adapter::*;

// #[cfg(any(build, test))]
// mod helper;

pub struct KiccEd785Plug {}

impl CardTerminalConst for KiccEd785Plug {
fn is_nda() -> bool {
false
}
}

impl CardTerminalRxParse for KiccEd785Plug {
fn pre_parse_common(&self, _raw: &[u8]) -> Result<CardTerminalRxCmd, CardTerminalError> {
// implement me for actual usage
Err(CardTerminalError::UnsupportedSpec)
}

fn post_parse_response_sale_slot_info(
&self,
_raw: &[u8],
) -> Result<CardReaderPortBackup, CardTerminalError> {
// implement me for actual usage
Err(CardTerminalError::UnsupportedSpec)
}

fn post_parse_response_terminal_info(
&self,
_raw: &[u8],
) -> Result<(TerminalVersion, RawTerminalId), CardTerminalError> {
// implement me for actual usage
Err(CardTerminalError::UnsupportedSpec)
}
}

impl CardTerminalTxGen for KiccEd785Plug {
fn response_ack<'a>(&self, _buffer: &'a mut [u8]) -> &'a [u8] {
// KICC common ACK spec
&common::RAW_DATA_ACK
}

fn response_nack<'a>(&self, _buffer: &'a mut [u8]) -> &'a [u8] {
// KICC common NACK spec
&common::RAW_DATA_NACK
}

fn response_device_info<'a>(
&self,
buffer: &'a mut [u8],
_model_version: &'a [u8; FW_VER_LEN],
_serial_number: &'a [u8; DEV_SN_LEN],
) -> &'a [u8] {
// implement me for actual usage
&buffer[0..0]
}

fn alert_coin_paper_acceptor_income<'a>(
&self,
buffer: &'a mut [u8],
_income: RawU24IncomeArcade,
) -> &'a [u8] {
// implement me for actual usage
&buffer[0..0]
}

fn push_sale_slot_info<'a>(
&self,
buffer: &'a mut [u8],
_port_backup: &'a CardReaderPortBackup,
) -> &'a [u8] {
// implement me for actual usage
&buffer[0..0]
}

fn push_sale_slot_info_partial_inhibit<'a>(
&self,
buffer: &'a mut [u8],
_port_backup: &'a CardReaderPortBackup,
) -> &'a [u8] {
// implement me for actual usage
&buffer[0..0]
}

fn request_sale_slot_info<'a>(&self, buffer: &'a mut [u8]) -> &'a [u8] {
// implement me for actual usage
&buffer[0..0]
}

fn request_terminal_info<'a>(&self, buffer: &'a mut [u8]) -> &'a [u8] {
// implement me for actual usage
&buffer[0..0]
}

fn display_rom<'a>(
&self,
buffer: &'a mut [u8],
_git_hash: &'a [u8; GIT_HASH_LEN],
_terminal_id: &[u8; TID_LEN],
_p1_card: u32,
_p2_card: u32,
_p1_coin: u32,
_p2_coin: u32,
) -> &'a [u8] {
// implement me for actual usage
&buffer[0..0]
}

fn display_hw_info<'a>(
&self,
buffer: &'a mut [u8],
_model_version: &'a [u8; FW_VER_LEN],
_serial_number: &'a [u8; DEV_SN_LEN],
_terminal_id: &[u8; TID_LEN],
_hw_boot_cnt: u32,
_uptime_minutes: u32,
) -> &'a [u8] {
// implement me for actual usage
&buffer[0..0]
}

fn display_warning<'a>(
&self,
buffer: &'a mut [u8],
_warn_kind: CardTerminalDisplayWarning,
) -> &'a [u8] {
// implement me for actual usage
&buffer[0..0]
}
}
4 changes: 2 additions & 2 deletions book/src/dev/dependency_injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ build, run or any other `cargo` command.
```sh
# dependency injection from git repository
# CAUTION , this should be work but not working
--config "patch.'https://github.com/pmnxis/billmock-app-rs.git'.serial-arcade-pay-impl.git = \"https://github.com/user_name/repo_name.git\""
--config "patch.'https://github.com/pmnxis/billmock-app-rs.git'.billmock-plug-card.git = \"https://github.com/user_name/repo_name.git\""

# dependency injection from local repository
# this works
--config "patch.'https://github.com/pmnxis/billmock-app-rs.git'.serial-arcade-pay-impl.path = \"../repo_name\""
--config "patch.'https://github.com/pmnxis/billmock-app-rs.git'.billmock-plug-card.path = \"../repo_name\""
```

In this repository, experimentally utilize dependency injection that the 'patch' function of 'cargo' to coexist both NDA code and open source example code.
29 changes: 23 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ use git2::Repository;

const IGNORE_PATH_DEP_INJ: &str = ".cargo/config.toml";

pub fn format_continuous(v: Vec<u8>) -> String {
let mut s = String::new();
for a in v {
s.push_str(format!("{:02X}", a).as_str());
}

s
}

fn main() -> Result<(), Error> {
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
Expand All @@ -21,13 +30,19 @@ fn main() -> Result<(), Error> {

if let Some(package) = metadata.packages.first() {
let project_name = &package.name;
let project_version = &package.version.to_string();
let project_version = package.version.to_string();

println!("cargo:rustc-env=PROJECT_NAME={}", project_name);
println!("cargo:rustc-env=PROJECT_VERSION={}", project_version);
println!(
"cargo:rustc-env=PROJECT_VERSION={}",
format_continuous(project_version.into())
);
} else {
println!("cargo:rustc-env=PROJECT_NAME=unkown");
println!("cargo:rustc-env=PROJECT_VERSION=unknown");
println!(
"cargo:rustc-env=PROJECT_VERSION={}",
format_continuous(b"?.?.?".into())
);
}

// Get the Git commit hash
Expand Down Expand Up @@ -64,7 +79,7 @@ fn main() -> Result<(), Error> {
let (dirty_str, short_dirty_str) = if is_dirty {
("-dirty".to_owned(), "-d".to_owned())
} else {
("".to_owned(), "".to_owned())
("".to_owned(), " ".to_owned())
};

let output = Command::new("git")
Expand All @@ -74,14 +89,16 @@ fn main() -> Result<(), Error> {
let commit_datetime = String::from_utf8_lossy(&output.stdout);

// Output the version and commit hash to a file
// This is u8 array

println!(
"cargo:rustc-env=GIT_COMMIT_HASH={}{}",
commit_hash, dirty_str
);

println!(
"cargo:rustc-env=GIT_COMMIT_SHORT_HASH={}{}",
commit_short_hash, short_dirty_str
"cargo:rustc-env=GIT_COMMIT_SHORT_HASH={}",
format_continuous(format!("{}{}", commit_short_hash, short_dirty_str).into())
);
println!("cargo:rustc-env=GIT_COMMIT_DATETIME={}", commit_datetime);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# SPDX-FileCopyrightText: © 2023 Jinwoo Park ([email protected])
#
# SPDX-License-Identifier: CC0-1.0

[package]
name = "serial-arcade-pay"
name = "card-terminal-adapter"
version = "0.1.0"
edition = "2021"
authors = ["Jinwoo Park <[email protected]>"]
license = "MIT OR Apache-2.0"
description = "Common arcade serial type payment method interface for billmock-app-rs"
description = "Card terminal interface adapte for billmock-app-rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
defmt = "0.3"
static_assertions = "1.1.0"
defmt = "0.3"
zeroable = "0.2.0"
Loading

0 comments on commit 14dd320

Please sign in to comment.