bnr_xfs/
capabilities.rs

1use std::fmt;
2
3use crate::status::CdrPositionCapabilitiesList;
4use crate::xfs::{
5    method_response::XfsMethodResponse,
6    params::{XfsParam, XfsParams},
7};
8use crate::{create_xfs_bool, create_xfs_i4, impl_xfs_struct, Error, Result};
9
10mod anti_fishing_level;
11mod cdr_type;
12mod default_rollback_position;
13mod euro_art6_capability;
14mod recognition_sensor_type;
15mod reporting_mode;
16mod secured_comm_level;
17mod self_test_mode;
18
19pub use anti_fishing_level::*;
20pub use cdr_type::*;
21pub use default_rollback_position::*;
22pub use euro_art6_capability::*;
23pub use recognition_sensor_type::*;
24pub use reporting_mode::*;
25pub use secured_comm_level::*;
26pub use self_test_mode::*;
27
28create_xfs_bool!(
29    AutoPresent,
30    "autoPresent",
31    r#"This specifies whether cash will be automatically presented to the user on execution of a dispense (autoPresent set to TRUE), or whether the cash will only be transported to the Bundler.
32
33In the latter case, a [present](crate::cash::present) command will need to be issued following the [dispense](crate::cash::dispense) command.
34
35Default value is FALSE.
36"#
37);
38create_xfs_bool!(TrustedUser, "trustedUser", "Reserved for future use.");
39create_xfs_i4!(
40    MaxInBills,
41    "maxInBills",
42    "Maximum number of bills to be accepted by one command. Allways 1 for the BNR."
43);
44create_xfs_i4!(MaxOutBills, "maxOutBills", "Maximum number of bills to be dispensed by one command. Equals to 20 in BNA6 configuration, otherwise equals to 15.");
45create_xfs_bool!(
46    ShutterCmd,
47    "shutterCmd",
48    "The shutter be accessed by commands. Allways FALSE in the BNR."
49);
50create_xfs_bool!(Retract, "retract", "The cash dispenser can retract presented bills. Always TRUE in the BNR since FW v1.3.0, FALSE with previous versions.");
51create_xfs_bool!(
52    SafeDoorCmd,
53    "safeDoorCmd",
54    "This device supports a safe door command. Always FALSE in the BNR."
55);
56create_xfs_bool!(
57    CashBox,
58    "cashBox",
59    "The service can handle a cash box. Always TRUE in the BNR."
60);
61create_xfs_bool!(Refill, "refill", "Can the BNR be refilled by placing bills of the same size on the stack of the Loader. Always TRUE in the BNR.");
62create_xfs_bool!(Dispense, "dispense", "The device can dispense cash. Equals to FALSE in BNA6 configuration, otherwise equals to TRUE.");
63create_xfs_bool!(
64    Deposit,
65    "deposit",
66    "The device can deposit cash. Always TRUE in the BNR."
67);
68create_xfs_bool!(
69    IntermediateStacker,
70    "intermediateStacker",
71    "The device has a temporary storage before presenting bills. Always TRUE in the BNR."
72);
73create_xfs_bool!(
74    BillsTakenSensor,
75    "billsTakenSensor",
76    "The device has a bills taken sensor. Always TRUE in the BNR."
77);
78create_xfs_bool!(
79    Escrow,
80    "escrow",
81    "The device supports an escrow. Always TRUE in the BNR."
82);
83create_xfs_i4!(EscrowSize, "escrowSize", "Specifies the maximum number of bills on the escrow. Equals to 20 in BNA6 configuration, otherwise equals to 15.");
84create_xfs_bool!(
85    Detector,
86    "detector",
87    "The device supports a detector to verify accepted cash. Always TRUE in the BNR."
88);
89create_xfs_bool!(
90    AllowUsbFrontSwitch,
91    "allowUsbFrontSwitch",
92    "Allows to use USB Front interface to communicate with the BNR. Default value is TRUE."
93);
94create_xfs_bool!(ReportUsbConsumption, "reportUsbConsumption", "Specifies whether real max USB line consumption is reported on usb configuration descriptor instead of 0mA. Default value is FALSE.");
95create_xfs_bool!(AutoRetractAtInlet, "autoRetractAtInlet", "Specifies whether bill will be automatically retracted to positioner when jam occurred during bill presenting at inlet or outlet. Default value is FALSE.");
96create_xfs_bool!(RejectViaOutlet, "rejectViaOutlet", "Specifies whether measured but unknown or inhibited notes are rejected via the BNR’s Outlet instead of the Inlet. Default value is FALSE.");
97
98/// Describes the BNR capabilities.
99///
100/// By default, capabilities are read-only properties, the following are writable:
101///
102/// - `auto_present`
103/// - `self_test_mode`
104/// - `anti_fishing_level`
105/// - `allow_usb_front_switch`
106/// - `reporting_mode`
107/// - `report_usb_consumption`
108/// - `auto_retract`
109/// - `reject_via_outlet`
110#[repr(C)]
111#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
112pub struct Capabilities {
113    pub auto_present: AutoPresent,
114    ///  Type of device. Always [CdrType::ATM](CdrType) for the BNR.
115    pub cd_type: CdrType,
116    /// Reserved for future use.
117    pub euro_art6_capability: EuroArt6Capability,
118    pub trusted_user: TrustedUser,
119    pub max_in_bills: MaxInBills,
120    pub max_out_bills: MaxOutBills,
121    pub shutter_cmd: ShutterCmd,
122    pub retract: Retract,
123    pub safe_door_cmd: SafeDoorCmd,
124    pub cash_box: CashBox,
125    pub refill: Refill,
126    pub dispense: Dispense,
127    pub deposit: Deposit,
128    pub intermediate_stacker: IntermediateStacker,
129    pub bills_taken_sensor: BillsTakenSensor,
130    pub escrow: Escrow,
131    pub escrow_size: EscrowSize,
132    pub detector: Detector,
133    /// Specifies the default output position to rollback cash. Always [CdrPosition::Bottom](CdrPosition::Bottom) in the BNR.
134    pub default_rollback_position: DefaultRollbackPosition,
135    /// Specifies the capabilities of each position supported by the device. Please refer to [CdrPositionCapabilities] for default values.
136    pub position_capabilities_list: CdrPositionCapabilitiesList,
137    /// Allows to choose when the BNR can perform the self tests. Default value is [Auto](SelfTestMode::Auto) (recommended).
138    pub self_test_mode: SelfTestMode,
139    pub recognition_sensor_type: RecognitionSensorType,
140    /// Sensitivity level of string detection at Inlet.
141    /// Default value is [Normal](AntiFishingLevel::Normal).
142    pub anti_fishing_level: AntiFishingLevel,
143    pub allow_usb_front_switch: AllowUsbFrontSwitch,
144    /// Specifies the kind of report generated on failure detection with no bill transported. Default value is [Normal](ReportingMode::Normal).
145    pub reporting_mode: ReportingMode,
146    pub report_usb_consumption: ReportUsbConsumption,
147    pub auto_retract_at_inlet: AutoRetractAtInlet,
148    pub reject_via_outlet: RejectViaOutlet,
149    /// Indicates the security level in communication between Host and Bnr. Defaut value is [Level1](SecuredCommLevel::Level1).
150    pub secured_comm_level: SecuredCommLevel,
151}
152
153impl Capabilities {
154    /// Creates a new [Capabilities].
155    pub const fn new() -> Self {
156        Self {
157            auto_present: AutoPresent::new(),
158            cd_type: CdrType::Atm,
159            euro_art6_capability: EuroArt6Capability::new(),
160            trusted_user: TrustedUser::new(),
161            max_in_bills: MaxInBills::create(1),
162            max_out_bills: MaxOutBills::create(15),
163            shutter_cmd: ShutterCmd::new(),
164            retract: Retract::create(true),
165            safe_door_cmd: SafeDoorCmd::new(),
166            cash_box: CashBox::create(true),
167            refill: Refill::create(true),
168            dispense: Dispense::create(true),
169            deposit: Deposit::create(true),
170            intermediate_stacker: IntermediateStacker::create(true),
171            bills_taken_sensor: BillsTakenSensor::create(true),
172            escrow: Escrow::create(true),
173            escrow_size: EscrowSize::create(15),
174            detector: Detector::create(true),
175            default_rollback_position: DefaultRollbackPosition::Bottom,
176            position_capabilities_list: CdrPositionCapabilitiesList::new(),
177            self_test_mode: SelfTestMode::new(),
178            recognition_sensor_type: RecognitionSensorType::create(b'B'),
179            anti_fishing_level: AntiFishingLevel::new(),
180            allow_usb_front_switch: AllowUsbFrontSwitch::create(true),
181            reporting_mode: ReportingMode::new(),
182            report_usb_consumption: ReportUsbConsumption::new(),
183            auto_retract_at_inlet: AutoRetractAtInlet::new(),
184            reject_via_outlet: RejectViaOutlet::new(),
185            secured_comm_level: SecuredCommLevel::new(),
186        }
187    }
188}
189
190impl From<&Capabilities> for XfsParam {
191    fn from(val: &Capabilities) -> Self {
192        Self::create(val.into())
193    }
194}
195
196impl From<Capabilities> for XfsParam {
197    fn from(val: Capabilities) -> Self {
198        (&val).into()
199    }
200}
201
202impl TryFrom<&XfsParam> for Capabilities {
203    type Error = Error;
204
205    fn try_from(val: &XfsParam) -> Result<Self> {
206        val.value().try_into()
207    }
208}
209
210impl TryFrom<XfsParam> for Capabilities {
211    type Error = Error;
212
213    fn try_from(val: XfsParam) -> Result<Self> {
214        (&val).try_into()
215    }
216}
217
218impl TryFrom<&XfsParams> for Capabilities {
219    type Error = Error;
220
221    fn try_from(val: &XfsParams) -> Result<Self> {
222        val.params()
223            .first()
224            .ok_or(Error::Xfs(format!("Missing param: {val}")))?
225            .inner()
226            .value()
227            .try_into()
228    }
229}
230
231impl TryFrom<XfsParams> for Capabilities {
232    type Error = Error;
233
234    fn try_from(val: XfsParams) -> Result<Self> {
235        (&val).try_into()
236    }
237}
238
239impl TryFrom<&XfsMethodResponse> for Capabilities {
240    type Error = Error;
241
242    fn try_from(val: &XfsMethodResponse) -> Result<Self> {
243        val.as_params()?.try_into()
244    }
245}
246
247impl TryFrom<XfsMethodResponse> for Capabilities {
248    type Error = Error;
249
250    fn try_from(val: XfsMethodResponse) -> Result<Self> {
251        (&val).try_into()
252    }
253}
254
255impl fmt::Display for Capabilities {
256    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
257        write!(f, "{{")?;
258        write!(f, r#""auto_present":{},"#, self.auto_present)?;
259        write!(f, r#""cd_type":{},"#, self.cd_type)?;
260        write!(
261            f,
262            r#""euro_art6_capability":{},"#,
263            self.euro_art6_capability
264        )?;
265        write!(f, r#""trusted_user":{},"#, self.trusted_user)?;
266        write!(f, r#""max_in_bills":{},"#, self.max_in_bills)?;
267        write!(f, r#""max_out_bills":{},"#, self.max_out_bills)?;
268        write!(f, r#""shutter_cmd":{},"#, self.shutter_cmd)?;
269        write!(f, r#""retract":{},"#, self.retract)?;
270        write!(f, r#""safe_door_cmd":{},"#, self.safe_door_cmd)?;
271        write!(f, r#""cash_box":{},"#, self.cash_box)?;
272        write!(f, r#""refill":{},"#, self.refill)?;
273        write!(f, r#""dispense":{},"#, self.dispense)?;
274        write!(f, r#""deposit":{},"#, self.deposit)?;
275        write!(
276            f,
277            r#""intermediate_stacker":{},"#,
278            self.intermediate_stacker
279        )?;
280        write!(f, r#""bills_taken_sensor":{},"#, self.bills_taken_sensor)?;
281        write!(f, r#""escrow":{},"#, self.escrow)?;
282        write!(f, r#""escrow_size":{},"#, self.escrow_size)?;
283        write!(f, r#""detector":{},"#, self.detector)?;
284        write!(
285            f,
286            r#""default_rollback_position":{},"#,
287            self.default_rollback_position
288        )?;
289        write!(
290            f,
291            r#""position_capabilities_list":{},"#,
292            self.position_capabilities_list
293        )?;
294        write!(f, r#""self_test_mode":{},"#, self.self_test_mode)?;
295        write!(
296            f,
297            r#""recognition_sensor_type":{},"#,
298            self.recognition_sensor_type
299        )?;
300        write!(f, r#""anti_fishing_level":{},"#, self.anti_fishing_level)?;
301        write!(
302            f,
303            r#""allow_usb_front_switch":{},"#,
304            self.allow_usb_front_switch
305        )?;
306        write!(f, r#""reporting_mode":{},"#, self.reporting_mode)?;
307        write!(
308            f,
309            r#""report_usb_consumption":{},"#,
310            self.report_usb_consumption
311        )?;
312        write!(
313            f,
314            r#""auto_retract_at_inlet":{},"#,
315            self.auto_retract_at_inlet
316        )?;
317        write!(f, r#""reject_via_outlet":{},"#, self.reject_via_outlet)?;
318        write!(f, r#""secured_comm_level":{}"#, self.secured_comm_level)?;
319        write!(f, "}}")
320    }
321}
322
323impl_xfs_struct!(
324    Capabilities,
325    "capabilities",
326    [
327        auto_present: AutoPresent,
328        cd_type: CdrType,
329        euro_art6_capability: EuroArt6Capability,
330        trusted_user: TrustedUser,
331        max_in_bills: MaxInBills,
332        max_out_bills: MaxOutBills,
333        shutter_cmd: ShutterCmd,
334        retract: Retract,
335        safe_door_cmd: SafeDoorCmd,
336        cash_box: CashBox,
337        refill: Refill,
338        dispense: Dispense,
339        deposit: Deposit,
340        intermediate_stacker: IntermediateStacker,
341        bills_taken_sensor: BillsTakenSensor,
342        escrow: Escrow,
343        escrow_size: EscrowSize,
344        detector: Detector,
345        default_rollback_position: DefaultRollbackPosition,
346        position_capabilities_list: CdrPositionCapabilitiesList,
347        self_test_mode: SelfTestMode,
348        recognition_sensor_type: RecognitionSensorType,
349        anti_fishing_level: AntiFishingLevel,
350        allow_usb_front_switch: AllowUsbFrontSwitch,
351        reporting_mode: ReportingMode,
352        report_usb_consumption: ReportUsbConsumption,
353        auto_retract_at_inlet: AutoRetractAtInlet,
354        reject_via_outlet: RejectViaOutlet,
355        secured_comm_level: SecuredCommLevel
356    ]
357);