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
4 changes: 4 additions & 0 deletions zencan-cli/src/bin/zencan-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ async fn run_command<S: AsyncCanSender + Sync + Send>(cmd: Commands, manager: &m
Err(e) => println!("Error reading PDO config: {e}"),
}
}
Commands::Sync(args) => {
manager.sync(args.count).await;
println!("SYNC sent");
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions zencan-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum Commands {
/// LSS commands
#[command(subcommand)]
Lss(LssCommands),
/// Send a SYNC packet
Sync(SyncArgs),
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -94,6 +96,12 @@ pub struct SaveObjectsArgs {
pub node_id: u8,
}

#[derive(Debug, Args)]
pub struct SyncArgs {
/// The optional count value (0-255). When omitted, sends a SYNC with zero data length.
pub count: Option<u8>,
}

/// Specifies a node to apply an NMT command
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum NmtNodeArg {
Expand Down
8 changes: 7 additions & 1 deletion zencan-client/src/bus_manager/bus_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use zencan_common::constants::object_ids::{
RPDO_COMM_BASE, RPDO_MAP_BASE, TPDO_COMM_BASE, TPDO_MAP_BASE,
};
use zencan_common::lss::{LssIdentity, LssState};
use zencan_common::messages::{NmtCommand, NmtCommandSpecifier, ZencanMessage};
use zencan_common::messages::{NmtCommand, NmtCommandSpecifier, SyncObject, ZencanMessage};
use zencan_common::nmt::NmtState;
use zencan_common::node_id::ConfiguredNodeId;
use zencan_common::sdo::AbortCode;
Expand Down Expand Up @@ -549,6 +549,12 @@ impl<S: AsyncCanSender + Sync + Send> BusManager<S> {
self.send_nmt_cmd(NmtCommandSpecifier::Stop, node).await
}

/// Send a SYNC packet on the bus
pub async fn sync(&mut self, count: Option<u8>) {
let sync_obj = SyncObject::new(count);
self.sender.send(sync_obj.into()).await.ok();
}

async fn send_nmt_cmd(&mut self, cmd: NmtCommandSpecifier, node: u8) {
let message = NmtCommand { cs: cmd, node };
self.sender.send(message.into()).await.ok();
Expand Down
Loading