bnr-xfs

Crates.iobnr-xfs
lib.rsbnr-xfs
version0.1.3
sourcesrc
created_at2024-01-24 23:32:32.398658
updated_at2024-03-13 20:26:49.134858
descriptionPure Rust implementation of the BNR XFS USB
homepage
repositoryhttps://github.com/bnr-rs/bnr
max_upload_size
id1113087
size749,511
BNR Rust Developers (bnr-rs)

documentation

README

BNR XFS

This library is used to communicate with MEI/CPI BNR cash recycler devices.

The XFS protocol is an XML-encoded messaging format over a USB connection.

Communication happens over four endpoints:

  • XFS response (device-to-host)
  • XFS call (host-to-device)
  • XFS callback call (device-to-host)
  • XFS callback response (host-to-device)

Usage

The main interface for device interaction is the DeviceHandle:

use bnr_xfs::{CallbackArg, DeviceHandle};

// Callback handler for when an async call completes
//
// See OperationCompletedFn for details.
fn op_com(_call_id: i32, _op_id: i32, _res: i32, _ext_res: i32, _cb_arg: &mut dyn CallbackArg) {
    // process the completion event...
}

// Callback handler for when an intermediate event occurs
//
// See IntermediateOccurredFn for details.
fn int_oc(_call_id: i32, _op_id: i32, _reason: i32, _cb_arg: &mut dyn CallbackArg) {
    // process the intermediate event...
}

// Callback handler for when a status event occurs
//
// See StatusOccurredFn for details.
fn st_oc(_call_id: i32, _op_id: i32, _reason: i32, _cb_arg: &mut dyn CallbackArg) {
    // process the status event...
}

let device_handle = DeviceHandle::open(Some(op_com), Some(int_oc), Some(st_oc)).unwrap();

let _status = device_handle.get_status().unwrap();

Testing

End-to-end device tests live in the tests/e2e_tests directory.

These tests currently require a BNR device to be connected to the computer running the tests.

To run the tests:

$ cargo test --all --features e2e_tests

WIP

There is still a reasonable amount of the BNR XFS API surface from the C library that needs to be implemented in Rust.

Implementations should follow the pattern of existing functions, and any additional types need to implement conversion to-and-from XFS XML.

Helper macros exist for implementing conversions of most of the basic XFS types.

If you notice an unimplemented type, please submit a merge request!

Commit count: 0

cargo fmt