motorcortex-rust 0.5.0

Motorcortex Rust: a Rust client for the Motorcortex Core real-time control system (async + blocking).
Documentation
//! Broad type-coverage helpers used by the async integration tests.
//!
//! Given a connected [`motorcortex_rust::core::Request`], `test_values`
//! and `test_vectors` run a dense matrix of set-then-get round-trips
//! across every dtype the server exposes. Each invocation pins one
//! (target_dtype × source_type) combination — e.g. writing a `u16` to
//! a `DummyInt32` slot, reading back as `i32`. A regression in any
//! converter surfaces here before the rest of the suite runs.

use motorcortex_rust::core::Request;
use motorcortex_rust::{GetParameterValue, SetParameterValue};

pub async fn test_parameter<V>(request: &Request, path: &str, value: V)
where
    V: SetParameterValue + GetParameterValue + Default + Clone + PartialEq + std::fmt::Debug,
{
    request
        .set_parameter(path, value.clone())
        .await
        .expect("set_parameter failed");

    let result: V = request
        .get_parameter(path)
        .await
        .expect("get_parameter failed");
    assert_eq!(result, value);
}

pub async fn test_values(request: &Request) {
    // String
    test_parameter(
        request,
        "root/Control/dummyString",
        "Hello, world!".to_string(),
    )
    .await;

    test_parameter(request, "root/Control/dummyUint8", u8::MAX).await;
    test_parameter(request, "root/Control/dummyUint8", i8::MAX).await;
    test_parameter(request, "root/Control/dummyUint8", u8::MAX as u16).await;
    test_parameter(request, "root/Control/dummyUint8", i8::MAX as i16).await;
    test_parameter(request, "root/Control/dummyUint8", u8::MAX as u32).await;
    test_parameter(request, "root/Control/dummyUint8", i8::MAX as i32).await;
    test_parameter(request, "root/Control/dummyUint8", u8::MAX as u64).await;
    test_parameter(request, "root/Control/dummyUint8", i8::MAX as i64).await;
    test_parameter(request, "root/Control/dummyUint8", u8::MAX as f32).await;
    test_parameter(request, "root/Control/dummyUint8", i8::MAX as f64).await;

    // Uint16 — the single-element Vec write is kept to exercise the
    // Vec<i32> → u16 conversion path.
    let dynamic_vector: Vec<i32> = vec![3];
    request
        .set_parameter("root/Control/dummyUint16", dynamic_vector)
        .await
        .unwrap();
    test_parameter(request, "root/Control/dummyUint16", u8::MAX).await;
    test_parameter(request, "root/Control/dummyUint16", i8::MAX).await;
    test_parameter(request, "root/Control/dummyUint16", u16::MAX).await;
    test_parameter(request, "root/Control/dummyUint16", i16::MAX).await;
    test_parameter(request, "root/Control/dummyUint16", u16::MAX as u32).await;
    test_parameter(request, "root/Control/dummyUint16", i16::MAX as i32).await;
    test_parameter(request, "root/Control/dummyUint16", u16::MAX as u64).await;
    test_parameter(request, "root/Control/dummyUint16", i16::MAX as i64).await;
    test_parameter(request, "root/Control/dummyUint16", u16::MAX as f32).await;
    test_parameter(request, "root/Control/dummyUint16", i16::MAX as f64).await;

    // Uint32
    test_parameter(request, "root/Control/dummyUint32", u8::MAX).await;
    test_parameter(request, "root/Control/dummyUint32", i8::MAX).await;
    test_parameter(request, "root/Control/dummyUint32", u16::MAX).await;
    test_parameter(request, "root/Control/dummyUint32", i16::MAX).await;
    test_parameter(request, "root/Control/dummyUint32", u32::MAX).await;
    test_parameter(request, "root/Control/dummyUint32", i32::MAX).await;
    test_parameter(request, "root/Control/dummyUint32", u32::MAX as u64).await;
    test_parameter(request, "root/Control/dummyUint32", i32::MAX as i64).await;
    test_parameter(request, "root/Control/dummyUint32", u32::MAX as f32).await;
    test_parameter(request, "root/Control/dummyUint32", i32::MAX as f64).await;

    // Uint64
    test_parameter(request, "root/Control/dummyUint64", u8::MAX).await;
    test_parameter(request, "root/Control/dummyUint64", i8::MAX).await;
    test_parameter(request, "root/Control/dummyUint64", u16::MAX).await;
    test_parameter(request, "root/Control/dummyUint64", i16::MAX).await;
    test_parameter(request, "root/Control/dummyUint64", u32::MAX).await;
    test_parameter(request, "root/Control/dummyUint64", i32::MAX).await;
    test_parameter(request, "root/Control/dummyUint64", u64::MAX).await;
    test_parameter(request, "root/Control/dummyUint64", i64::MAX).await;
    test_parameter(request, "root/Control/dummyUint64", u64::MAX as f32).await;
    test_parameter(request, "root/Control/dummyUint64", i64::MAX as f64).await;

    // Int8
    test_parameter(request, "root/Control/dummyInt8", i8::MAX as u8).await;
    test_parameter(request, "root/Control/dummyInt8", i8::MIN).await;
    test_parameter(request, "root/Control/dummyInt8", i8::MAX as u16).await;
    test_parameter(request, "root/Control/dummyInt8", i8::MIN as i16).await;
    test_parameter(request, "root/Control/dummyInt8", i8::MAX as u32).await;
    test_parameter(request, "root/Control/dummyInt8", i8::MIN as i32).await;
    test_parameter(request, "root/Control/dummyInt8", i8::MAX as u64).await;
    test_parameter(request, "root/Control/dummyInt8", i8::MIN as i64).await;
    test_parameter(request, "root/Control/dummyInt8", i8::MAX as f32).await;
    test_parameter(request, "root/Control/dummyInt8", i8::MIN as f64).await;

    // Int16
    test_parameter(request, "root/Control/dummyInt16", i8::MAX).await;
    test_parameter(request, "root/Control/dummyInt16", i8::MIN).await;
    test_parameter(request, "root/Control/dummyInt16", i16::MAX).await;
    test_parameter(request, "root/Control/dummyInt16", i16::MIN).await;
    test_parameter(request, "root/Control/dummyInt16", i16::MAX as u32).await;
    test_parameter(request, "root/Control/dummyInt16", i16::MIN as i32).await;
    test_parameter(request, "root/Control/dummyInt16", i16::MAX as u64).await;
    test_parameter(request, "root/Control/dummyInt16", i16::MIN as i64).await;
    test_parameter(request, "root/Control/dummyInt16", i16::MAX as f32).await;
    test_parameter(request, "root/Control/dummyInt16", i16::MIN as f64).await;

    // Int32
    test_parameter(request, "root/Control/dummyInt32", i8::MAX).await;
    test_parameter(request, "root/Control/dummyInt32", i8::MIN).await;
    test_parameter(request, "root/Control/dummyInt32", i16::MAX).await;
    test_parameter(request, "root/Control/dummyInt32", i16::MIN).await;
    test_parameter(request, "root/Control/dummyInt32", i32::MAX).await;
    test_parameter(request, "root/Control/dummyInt32", i32::MIN).await;
    test_parameter(request, "root/Control/dummyInt32", i32::MAX as u64).await;
    test_parameter(request, "root/Control/dummyInt32", i32::MIN as i64).await;
    test_parameter(request, "root/Control/dummyInt32", i32::MAX as f32).await;
    test_parameter(request, "root/Control/dummyInt32", i32::MIN as f64).await;

    // Int64
    test_parameter(request, "root/Control/dummyInt64", i8::MAX).await;
    test_parameter(request, "root/Control/dummyInt64", i8::MIN).await;
    test_parameter(request, "root/Control/dummyInt64", i16::MAX).await;
    test_parameter(request, "root/Control/dummyInt64", i16::MIN).await;
    test_parameter(request, "root/Control/dummyInt64", i32::MAX).await;
    test_parameter(request, "root/Control/dummyInt64", i32::MIN).await;
    test_parameter(request, "root/Control/dummyInt64", i64::MAX).await;
    test_parameter(request, "root/Control/dummyInt64", i64::MIN).await;
    test_parameter(request, "root/Control/dummyInt64", i64::MAX as f32).await;
    test_parameter(request, "root/Control/dummyInt64", i64::MIN as f64).await;
}

pub async fn test_vectors(request: &Request) {
    test_parameter(
        request,
        "root/Control/dummyDoubleVec",
        [f64::MAX, f64::MIN, f64::MAX, f64::MIN, f64::MAX],
    )
    .await;
    test_parameter(
        request,
        "root/Control/dummyDoubleVec",
        vec![f64::MAX, f64::MIN, f64::MAX, f64::MIN, f64::MAX],
    )
    .await;

    test_parameter(
        request,
        "root/Control/dummyFloatVec",
        [1.56_f32, 2.34_f32, 3.567_f32, 4.234_f32, 5.3435_f32],
    )
    .await;
    test_parameter(
        request,
        "root/Control/dummyFloatVec",
        vec![1.56_f32, 2.34_f32, 3.567_f32, 4.234_f32, 5.3435_f32],
    )
    .await;
    test_parameter(
        request,
        "root/Control/dummyFloatVec",
        [1_i32, 2_i32, 3_i32, 4_i32, 5_i32],
    )
    .await;
    test_parameter(
        request,
        "root/Control/dummyFloatVec",
        vec![1_i32, 2_i32, 3_i32, 4_i32, 5_i32],
    )
    .await;

    test_parameter(
        request,
        "root/Control/dummyBoolVec",
        [true, false, true, false, true],
    )
    .await;

    test_parameter(request, "root/Control/dummyBoolVec", [1, 1, 0, 0, 0]).await;

    test_parameter(
        request,
        "root/Control/dummyBoolVec",
        vec![true, true, false, false, true],
    )
    .await;

    test_parameter(
        request,
        "root/Control/dummyBoolVec",
        vec![1.0, 0.0, 0.0, 1.0, 1.0],
    )
    .await;
}