Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ embedded-io = { version = "0.6.1" }
futures = { version = "0.3.31", default-features = false, features = [
"async-await",
] }
heapless = "0.8.0"
log = "0.4.27"
serde = { version = "1.0.219", features = ["derive"] }
snafu = { version = "0.8.5", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ critical-section = { version = "1.2.0", features = ["std"] }
embedded-io.workspace = true
futures.workspace = true
tokio = { version = "1.44.2", features = ["rt", "macros", "time", "sync"] }
rand = "0.9.2"

[dev-dependencies]
assertables = "9.8.1"
Expand Down
69 changes: 69 additions & 0 deletions integration_tests/device_configs/example1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,72 @@ array_size = 9
data_type = "uint8"
access_type = "rw"
pdo_mapping = "both"

[[objects]]
index = 0x300B
parameter_name = "Time Objects"
object_type = "record"
[[objects.subs]]
sub_index = 1
data_type = "TimeOfDay"
access_type = "rw"
pdo_mapping = "tpdo"
[[objects.subs]]
sub_index = 2
data_type = "TimeDifference"
access_type = "rw"

[[objects]]
index = 0x300C
parameter_name = "All The Numbers"
object_type = "record"
[[objects.subs]]
sub_index = 1
data_type = "uint8"
access_type = "rw"
pdo_mapping = "both"
[[objects.subs]]
sub_index = 2
data_type = "uint16"
access_type = "rw"
pdo_mapping = "both"
[[objects.subs]]
sub_index = 3
data_type = "uint32"
access_type = "rw"
pdo_mapping = "both"
[[objects.subs]]
sub_index = 4
data_type = "uint64"
access_type = "rw"
pdo_mapping = "both"
[[objects.subs]]
sub_index = 5
data_type = "int8"
access_type = "rw"
pdo_mapping = "both"
[[objects.subs]]
sub_index = 6
data_type = "int16"
access_type = "rw"
pdo_mapping = "both"
[[objects.subs]]
sub_index = 7
data_type = "int32"
access_type = "rw"
pdo_mapping = "both"
[[objects.subs]]
sub_index = 8
data_type = "int64"
access_type = "rw"
pdo_mapping = "both"
[[objects.subs]]
sub_index = 9
data_type = "real32"
access_type = "rw"
pdo_mapping = "both"
[[objects.subs]]
sub_index = 10
data_type = "real64"
access_type = "rw"
pdo_mapping = "both"
132 changes: 132 additions & 0 deletions integration_tests/tests/node_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use std::{
};

use integration_tests::{object_dict1, prelude::*};
use rand::Rng as _;
use serial_test::serial;
use zencan_client::nmt_master::NmtMaster;
use zencan_common::{TimeDifference, TimeOfDay};

#[serial]
#[tokio::test]
Expand Down Expand Up @@ -453,3 +455,133 @@ async fn test_node_state_callbacks() {
};
test_with_background_process(&mut [&mut node], &mut bus, test_task).await;
}

/// Access time fields
#[serial]
#[tokio::test]
async fn test_time_field_access() {
use object_dict1::*;

let _ = env_logger::try_init();

const NODE_ID: u8 = 1;
let mut bus = SimBus::new();
bus.add_node(&NODE_MBOX);
let callbacks = Callbacks::new();
let mut node = Node::new(
NodeId::new(NODE_ID).unwrap(),
callbacks,
&NODE_MBOX,
&NODE_STATE,
&OD_TABLE,
);
let mut client = get_sdo_client(&mut bus, NODE_ID);

let _logger = BusLogger::new(bus.new_receiver());

let test_task = move |_ctx| async move {
let time = TimeOfDay::from_ymd_hms_ms(2015, 8, 23, 10, 20, 5, 500).unwrap();
client.write_time_of_day(0x300B, 1, time).await.unwrap();
assert_eq!(time, OBJECT300B.get_sub1());
let read_time = client.read_time_of_day(0x300B, 1).await.unwrap();
assert_eq!(time, read_time);

let delta = TimeDifference::new(20, 50000);
client
.write_time_difference(0x300B, 2, delta)
.await
.unwrap();
assert_eq!(delta, OBJECT300B.get_sub2());
let read_delta = client.read_time_difference(0x300B, 2).await.unwrap();
assert_eq!(delta, read_delta);
};
test_with_background_process(&mut [&mut node], &mut bus, test_task).await;
}

/// Access fields for all numeric types
#[serial]
#[tokio::test]
async fn test_numeric_access() {
use object_dict1::*;

let _ = env_logger::try_init();

const NODE_ID: u8 = 1;
let mut bus = SimBus::new();
bus.add_node(&NODE_MBOX);
let callbacks = Callbacks::new();
let mut node = Node::new(
NodeId::new(NODE_ID).unwrap(),
callbacks,
&NODE_MBOX,
&NODE_STATE,
&OD_TABLE,
);
let mut client = get_sdo_client(&mut bus, NODE_ID);

let _logger = BusLogger::new(bus.new_receiver());

let mut rng = rand::rng();
let test_task = move |_ctx| async move {
let val: u8 = rng.random();
client.write_u8(0x300C, 1, val).await.unwrap();
let read_val = client.read_u8(0x300C, 1).await.unwrap();
assert_eq!(val, OBJECT300C.get_sub1());
assert_eq!(val, read_val);

let val: u16 = rng.random();
client.write_u16(0x300C, 2, val).await.unwrap();
let read_val = client.read_u16(0x300C, 2).await.unwrap();
assert_eq!(val, OBJECT300C.get_sub2());
assert_eq!(val, read_val);

let val: u32 = rng.random();
client.write_u32(0x300C, 3, val).await.unwrap();
let read_val = client.read_u32(0x300C, 3).await.unwrap();
assert_eq!(val, OBJECT300C.get_sub3());
assert_eq!(val, read_val);

let val: u64 = rng.random();
client.write_u64(0x300C, 4, val).await.unwrap();
let read_val = client.read_u64(0x300C, 4).await.unwrap();
assert_eq!(val, OBJECT300C.get_sub4());
assert_eq!(val, read_val);

let val: i8 = rng.random();
client.write_i8(0x300C, 5, val).await.unwrap();
let read_val = client.read_i8(0x300C, 5).await.unwrap();
assert_eq!(val, OBJECT300C.get_sub5());
assert_eq!(val, read_val);

let val: i16 = rng.random();
client.write_i16(0x300C, 6, val).await.unwrap();
let read_val = client.read_i16(0x300C, 6).await.unwrap();
assert_eq!(val, OBJECT300C.get_sub6());
assert_eq!(val, read_val);

let val: i32 = rng.random();
client.write_i32(0x300C, 7, val).await.unwrap();
let read_val = client.read_i32(0x300C, 7).await.unwrap();
assert_eq!(val, OBJECT300C.get_sub7());
assert_eq!(val, read_val);

let val: i64 = rng.random();
client.write_i64(0x300C, 8, val).await.unwrap();
let read_val = client.read_i64(0x300C, 8).await.unwrap();
assert_eq!(val, OBJECT300C.get_sub8());
assert_eq!(val, read_val);

let val: f32 = rng.random();
client.write_f32(0x300C, 9, val).await.unwrap();
let read_val = client.read_f32(0x300C, 9).await.unwrap();
assert_eq!(val, OBJECT300C.get_sub9());
assert_eq!(val, read_val);

let val: f64 = rng.random();
client.write_f64(0x300C, 10, val).await.unwrap();
let read_val = client.read_f64(0x300C, 10).await.unwrap();
assert_eq!(val, OBJECT300C.get_sub10());
assert_eq!(val, read_val);
};
test_with_background_process(&mut [&mut node], &mut bus, test_task).await;
}
Loading