Skip to main content

autocore_main

Macro autocore_main 

Source
macro_rules! autocore_main {
    ($prog_type:ty, $shm_name:expr, $tick_signal:expr) => { ... };
}
Expand description

Generates the standard main function for a control program.

This macro reduces boilerplate by creating a properly configured main function that initializes and runs your control program.

§Arguments

  • $prog_type - The type of your control program (must implement ControlProgram)
  • $shm_name - The shared memory segment name (string literal)
  • $tick_signal - The tick signal name in shared memory (string literal)

§Example

mod gm;
use gm::GlobalMemory;

pub struct MyProgram;

impl MyProgram {
    pub fn new() -> Self { Self }
}

impl autocore_std::ControlProgram for MyProgram {
    type Memory = GlobalMemory;

    fn process_tick(&mut self, mem: &mut GlobalMemory, _cycle: u64) {
        // Your logic here
    }
}

// This generates the main function
autocore_std::autocore_main!(MyProgram, "my_project_shm", "tick");

§Generated Code

The macro expands to:

fn main() -> anyhow::Result<()> {
    let config = autocore_std::RunnerConfig {
        ipc_address: "127.0.0.1:9100".to_string(),
        module_name: "control".to_string(),
        shm_name: "my_project_shm".to_string(),
        tick_signal_name: "tick".to_string(),
        busy_signal_name: None,
        log_level: log::LevelFilter::Info,
        log_udp_port: autocore_std::logger::DEFAULT_LOG_UDP_PORT,
    };

    autocore_std::ControlRunner::new(MyProgram::new())
        .config(config)
        .run()
}