#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Manufacturer {
AardvarkEmbeddedSolutions,
Alberici,
AlfaNetInformatika,
AstroSystems,
Azkoyen,
ComesteroGroup,
CraneCashCodeCompany,
CranePaymentSolutions,
Encopim,
GamingTechnologyDistribution,
Himecs,
IndustriasLorenzo,
InnovativeTechnology,
IntegratedTechnology,
InternationalCurrencyTechnologies,
JapanCashMachine,
Jofemar,
Kuky,
MarsElectronicsInternational,
MicrosystemControls,
MoneyControlsInternational,
NationalRejectorsInc,
PhoenixMecanoDigital,
StarpointElectrics,
TelequipCrane,
WeavefutureInc,
WHMunzprufer,
INOTEK,
}
impl Manufacturer {
pub const fn full_name(&self) -> &'static str {
match self {
Manufacturer::AardvarkEmbeddedSolutions => "Aardvark Embedded Solutions Ltd",
Manufacturer::Alberici => "Alberici",
Manufacturer::AlfaNetInformatika => "AlfaNet informatika d.o.o",
Manufacturer::AstroSystems => "AstroSystems Ltd",
Manufacturer::Azkoyen => "Azkoyen",
Manufacturer::ComesteroGroup => "Comestero Group",
Manufacturer::CraneCashCodeCompany => "Crane CashCode Company",
Manufacturer::CranePaymentSolutions => "Crane Payment Solutions",
Manufacturer::Encopim => "Encopim SL",
Manufacturer::GamingTechnologyDistribution => "Gaming Technology Distribution",
Manufacturer::Himecs => "Himecs",
Manufacturer::IndustriasLorenzo => "Industrias Lorenzo",
Manufacturer::InnovativeTechnology => "Innovative Technology Ltd",
Manufacturer::IntegratedTechnology => "Intergrated Technology Ltd",
Manufacturer::InternationalCurrencyTechnologies => {
"International Currency Technologies"
}
Manufacturer::JapanCashMachine => "Japan Cash Machine",
Manufacturer::Jofemar => "Jofemar",
Manufacturer::Kuky => "Kuky",
Manufacturer::MarsElectronicsInternational => "Mars Electronics International",
Manufacturer::MicrosystemControls => "Microsystem Controls Pty. Ltd.",
Manufacturer::MoneyControlsInternational => "Money Controls (International)",
Manufacturer::NationalRejectorsInc => "National Rejectors Inc",
Manufacturer::PhoenixMecanoDigital => "Phoenix Mecano Digital",
Manufacturer::StarpointElectrics => "Starpoint Electrics Ltd",
Manufacturer::TelequipCrane => "Telequip / Crane",
Manufacturer::WeavefutureInc => "Weavefuture Inc",
Manufacturer::WHMunzprufer => "WH Münzprüfer",
Manufacturer::INOTEK => "iNOTEK",
}
}
pub const fn abbreviated_name(&self) -> &'static str {
match self {
Manufacturer::AardvarkEmbeddedSolutions => "AES",
Manufacturer::Alberici => "ALB",
Manufacturer::AlfaNetInformatika => "ANI",
Manufacturer::AstroSystems => "AST",
Manufacturer::Azkoyen => "AZK",
Manufacturer::ComesteroGroup => "CMG",
Manufacturer::CraneCashCodeCompany => "CCC",
Manufacturer::CranePaymentSolutions => "CPS",
Manufacturer::Encopim => "ECP",
Manufacturer::GamingTechnologyDistribution => "GTD",
Manufacturer::Himecs => "HIM",
Manufacturer::IndustriasLorenzo => "IL",
Manufacturer::InnovativeTechnology => "ITL",
Manufacturer::IntegratedTechnology => "INT",
Manufacturer::InternationalCurrencyTechnologies => "ICT",
Manufacturer::JapanCashMachine => "JCM",
Manufacturer::Jofemar => "JOF",
Manufacturer::Kuky => "KUK",
Manufacturer::MarsElectronicsInternational => "MEI",
Manufacturer::MicrosystemControls => "MSC",
Manufacturer::MoneyControlsInternational => "MCI",
Manufacturer::NationalRejectorsInc => "NRI",
Manufacturer::PhoenixMecanoDigital => "PMD",
Manufacturer::StarpointElectrics => "SEL",
Manufacturer::TelequipCrane => "TQP",
Manufacturer::WeavefutureInc => "WFT",
Manufacturer::WHMunzprufer => "WHM",
Manufacturer::INOTEK => "INK",
}
}
pub const fn all() -> &'static [Manufacturer] {
&[
Manufacturer::AardvarkEmbeddedSolutions,
Manufacturer::Alberici,
Manufacturer::AlfaNetInformatika,
Manufacturer::AstroSystems,
Manufacturer::Azkoyen,
Manufacturer::ComesteroGroup,
Manufacturer::CraneCashCodeCompany,
Manufacturer::CranePaymentSolutions,
Manufacturer::Encopim,
Manufacturer::GamingTechnologyDistribution,
Manufacturer::Himecs,
Manufacturer::IndustriasLorenzo,
Manufacturer::InnovativeTechnology,
Manufacturer::IntegratedTechnology,
Manufacturer::InternationalCurrencyTechnologies,
Manufacturer::JapanCashMachine,
Manufacturer::Jofemar,
Manufacturer::Kuky,
Manufacturer::MarsElectronicsInternational,
Manufacturer::MicrosystemControls,
Manufacturer::MoneyControlsInternational,
Manufacturer::NationalRejectorsInc,
Manufacturer::PhoenixMecanoDigital,
Manufacturer::StarpointElectrics,
Manufacturer::TelequipCrane,
Manufacturer::WeavefutureInc,
Manufacturer::WHMunzprufer,
Manufacturer::INOTEK,
]
}
pub fn from_full_name(name: &str) -> Option<Self> {
Self::all()
.iter()
.find(|manufacturer| manufacturer.full_name() == name)
.copied()
}
pub fn from_abbreviated_name(name: &str) -> Option<Self> {
Self::all()
.iter()
.find(|manufacturer| manufacturer.abbreviated_name() == name)
.copied()
}
pub fn from_name(name: &str) -> Option<Self> {
Self::from_full_name(name).or_else(|| Self::from_abbreviated_name(name))
}
}
impl core::fmt::Display for Manufacturer {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.full_name())
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ManufacturerIdentifier {
Known(Manufacturer),
#[cfg(not(feature = "std"))]
Unknown(heapless::String<64>),
#[cfg(feature = "std")]
Unknown(std::string::String), }
impl ManufacturerIdentifier {
pub fn new(name: &str) -> Self {
match Manufacturer::from_name(name) {
Some(manufacturer) => ManufacturerIdentifier::Known(manufacturer),
None => {
#[cfg(not(feature = "std"))]
{
match heapless::String::try_from(name) {
Ok(unknown) => ManufacturerIdentifier::Unknown(unknown),
Err(_) => {
let truncated = &name[..name.len().min(64)];
let truncated_string = heapless::String::try_from(truncated)
.unwrap_or_else(|_| heapless::String::new());
ManufacturerIdentifier::Unknown(truncated_string)
}
}
}
#[cfg(feature = "std")]
{
use std::string::ToString;
ManufacturerIdentifier::Unknown(name.to_string())
}
}
}
}
pub fn name(&self) -> &str {
match self {
ManufacturerIdentifier::Known(manufacturer) => manufacturer.full_name(),
ManufacturerIdentifier::Unknown(name) => name.as_str(),
}
}
pub fn is_known(&self) -> bool {
matches!(self, ManufacturerIdentifier::Known(_))
}
pub fn known_manufacturer(&self) -> Option<Manufacturer> {
match self {
ManufacturerIdentifier::Known(manufacturer) => Some(*manufacturer),
ManufacturerIdentifier::Unknown(_) => None,
}
}
}
impl core::fmt::Display for ManufacturerIdentifier {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.name())
}
}
impl From<Manufacturer> for ManufacturerIdentifier {
fn from(manufacturer: Manufacturer) -> Self {
ManufacturerIdentifier::Known(manufacturer)
}
}
#[cfg(test)]
mod tests {
use std::string::ToString;
use super::*;
#[test]
fn test_full_names() {
assert_eq!(
Manufacturer::CranePaymentSolutions.full_name(),
"Crane Payment Solutions"
);
assert_eq!(
Manufacturer::InnovativeTechnology.full_name(),
"Innovative Technology Ltd"
);
}
#[test]
fn test_abbreviated_names() {
assert_eq!(
Manufacturer::CranePaymentSolutions.abbreviated_name(),
"CPS"
);
assert_eq!(Manufacturer::InnovativeTechnology.abbreviated_name(), "ITL");
}
#[test]
fn test_from_full_name() {
assert_eq!(
Manufacturer::from_full_name("Crane Payment Solutions"),
Some(Manufacturer::CranePaymentSolutions)
);
assert_eq!(Manufacturer::from_full_name("Unknown Company"), None);
}
#[test]
fn test_from_abbreviated_name() {
assert_eq!(
Manufacturer::from_abbreviated_name("CPS"),
Some(Manufacturer::CranePaymentSolutions)
);
assert_eq!(Manufacturer::from_abbreviated_name("UNK"), None);
}
#[test]
fn test_from_name() {
assert_eq!(
Manufacturer::from_name("CPS"),
Some(Manufacturer::CranePaymentSolutions)
);
assert_eq!(
Manufacturer::from_name("Crane Payment Solutions"),
Some(Manufacturer::CranePaymentSolutions)
);
assert_eq!(Manufacturer::from_name("Unknown"), None);
}
#[test]
fn test_manufacturer_identifier_known() {
let id = ManufacturerIdentifier::new("CPS");
assert!(id.is_known());
assert_eq!(
id.known_manufacturer(),
Some(Manufacturer::CranePaymentSolutions)
);
assert_eq!(id.name(), "Crane Payment Solutions");
}
#[test]
fn test_manufacturer_identifier_unknown() {
let id = ManufacturerIdentifier::new("Custom Manufacturer");
assert!(!id.is_known());
assert_eq!(id.known_manufacturer(), None);
assert_eq!(id.name(), "Custom Manufacturer");
}
#[test]
fn test_display() {
assert_eq!(
Manufacturer::CranePaymentSolutions.to_string(),
"Crane Payment Solutions"
);
let id = ManufacturerIdentifier::new("ITL");
assert_eq!(id.to_string(), "Innovative Technology Ltd");
}
#[test]
fn test_all_manufacturers_count() {
assert_eq!(Manufacturer::all().len(), 28);
}
}