Skip to content

Commit

Permalink
Merge pull request #34 from pmnxis/dev/i33_otp_serial_number
Browse files Browse the repository at this point in the history
#33 Use OTP MCU features and `billmock-mptool`
  • Loading branch information
pmnxis committed Oct 22, 2023
2 parents b7325a1 + cdd2932 commit 55961cd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"rust-analyzer.cargo.target": "thumbv6m-none-eabi",
"rust-analyzer.linkedProjects": [
"Cargo.toml",
"billmock-mptool/Cargo.toml",
"billmock-plug-card/Cargo.toml",
"card-terminal-adapter/Cargo.toml",
"card-terminal-adapter/Cargo.toml"
],
}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ env_to_array = { version = "0.3.1", features = ["hex"] }
# `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

# 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" }
billmock-otp-dev-info = { git = "https://github.com/pmnxis/billmock-mptool.git" }

[build-dependencies]
git2 = "0.18" # Git library for Rust
Expand Down
12 changes: 11 additions & 1 deletion src/boards/const_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT OR Apache-2.0
*/

use billmock_otp_dev_info::OtpDeviceInfo;
use env_to_array::hex_env_to_array;

pub const PROJECT_NAME: &str = env!("PROJECT_NAME");
Expand All @@ -16,7 +17,16 @@ pub const COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
pub(crate) const COMMIT_SHORT: [u8; card_terminal_adapter::GIT_HASH_LEN] =
hex_env_to_array!("GIT_COMMIT_SHORT_HASH");

pub const SERIAL_NUMBER_WHEN_UNKNOWN: [u8; card_terminal_adapter::DEV_SN_LEN] = *b" 90000000";
pub const SERIAL_NUMBER_WHEN_UNKNOWN: [u8; card_terminal_adapter::DEV_SN_LEN] = *b" unknown";

pub const GIT_COMMIT_DATETIME: &str = env!("GIT_COMMIT_DATETIME");
pub const PRINT_BAR: &str = "+-----------------------------------------------------------+";

pub fn get_serial_number() -> &'static [u8; card_terminal_adapter::DEV_SN_LEN] {
let otp_space = OtpDeviceInfo::from_stm32g0();

match otp_space.check_and_sn() {
Err(_) => &SERIAL_NUMBER_WHEN_UNKNOWN,
Ok(_) => &otp_space.dev_sn,
}
}
1 change: 1 addition & 0 deletions src/boards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl Board {
defmt::println!("{}", const_str::PRINT_BAR);
#[rustfmt::skip]
defmt::println!("Firmware Ver : {} {=[u8]:a}", const_str::PROJECT_NAME, const_str::VERSION_STR);
defmt::println!("SerialNumber : {=[u8]:a}", *const_str::get_serial_number());
defmt::println!("Git Hash : {}", const_str::COMMIT_HASH);
#[rustfmt::skip]
defmt::println!("Git Datetime : {} | {=[u8]:a}", const_str::GIT_COMMIT_DATETIME, const_str::COMMIT_SHORT);
Expand Down
2 changes: 1 addition & 1 deletion src/components/serial_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl CardReaderDevice {
CardTerminalTxCmd::ResponseDeviceInfo => plug.response_device_info(
&mut tx_buf,
&const_str::VERSION_STR,
&const_str::SERIAL_NUMBER_WHEN_UNKNOWN, // todo! - get last MCU flash page for getting serial number
const_str::get_serial_number(),
),
CardTerminalTxCmd::PushCoinPaperAcceptorIncome(x) => {
plug.alert_coin_paper_acceptor_income(&mut tx_buf, x)
Expand Down

0 comments on commit 55961cd

Please sign in to comment.