pub struct CommandInterface { /* private fields */ }Expand description
Command Interface function block.
Manages the handshake protocol between an external command source and the
control program. Call call once per scan cycle. When a new
command arrives, call returns Some(command_code). The control program
then processes the command and calls set_done or
set_error when finished.
§Usage Pattern
// In your control program struct:
cmd: CommandInterface,
// In process_tick:
let mut cmd_view = my_cmd_view(gm);
if let Some(code) = self.cmd.call(&mut cmd_view) {
match code {
1 => { /* start something */ }
2 => { /* do something else */ }
_ => { self.cmd.set_error(&mut cmd_view, -1.0); }
}
}
// When async work completes later:
if self.cmd.is_executing() && work_is_done {
self.cmd.set_done(&mut cmd_view, result_value);
}Implementations§
Source§impl CommandInterface
impl CommandInterface
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new command interface. Status will be set to CommandStatus::Idle
on the first call to call.
Sourcepub fn call(&mut self, view: &mut CommandInterfaceView<'_>) -> Option<u32>
pub fn call(&mut self, view: &mut CommandInterfaceView<'_>) -> Option<u32>
Call once per scan cycle.
Returns Some(command_code) on the scan where a new Execute request is
detected while the interface is Idle. Returns None on all other scans.
This method handles the full handshake lifecycle:
- Idle + Execute → transition to
Executing, return the command code - Done + AckDone → transition back to
Idle - Error + AckDone → transition back to
Idle
Sourcepub fn is_executing(&self) -> bool
pub fn is_executing(&self) -> bool
Returns true if a command is currently being executed.
Sourcepub fn active_command(&self) -> Option<u32>
pub fn active_command(&self) -> Option<u32>
Returns the command code currently being executed, or None if idle.
Sourcepub fn set_done(&mut self, view: &mut CommandInterfaceView<'_>, result: f64)
pub fn set_done(&mut self, view: &mut CommandInterfaceView<'_>, result: f64)
Mark the current command as completed successfully.
Sets command_status to CommandStatus::Done and writes result to
command_result. The interface will wait for the external source to send
CommandRequest::AckDone before returning to idle.
Sourcepub fn set_error(
&mut self,
view: &mut CommandInterfaceView<'_>,
error_result: f64,
)
pub fn set_error( &mut self, view: &mut CommandInterfaceView<'_>, error_result: f64, )
Mark the current command as failed.
Sets command_status to CommandStatus::Error. Optionally write an
error code or description to command_result before calling this.
The interface will wait for CommandRequest::AckDone before returning
to idle.
Trait Implementations§
Source§impl Clone for CommandInterface
impl Clone for CommandInterface
Source§fn clone(&self) -> CommandInterface
fn clone(&self) -> CommandInterface
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more