cfs-synapse-codegen-cfs 0.2.14

cFS C and Rust code generator for Synapse IDL files
Documentation
use std::collections::HashMap;

/// Deterministic banner included at the top of generated files.
pub const GENERATED_BANNER: &str = concat!(
    "Generated by Synapse ",
    env!("CARGO_PKG_VERSION"),
    ". Do not edit directly."
);

/// Preamble included at the top of generated cFS C headers.
pub const PREAMBLE: &str = concat!(
    "/* Generated by Synapse ",
    env!("CARGO_PKG_VERSION"),
    ". Do not edit directly. */\n\
#pragma once
#include \"cfe.h\"

"
);

/// Resolved integer constants visible to a file from imported namespaces.
pub type ResolvedConstants = HashMap<Vec<String>, u64>;

/// cFE message ID layout policy used for command/telemetry validation.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MsgIdLayout {
    /// Legacy CCSDS-style cFE `MISSION_MSG_V1` layout.
    ///
    /// Command MIDs are expected to have bit `0x1000` set and telemetry MIDs
    /// are expected to have that bit clear.
    CcsdsV1,
    /// Treat message IDs as opaque mission-owned values.
    ///
    /// Synapse still resolves MIDs and checks uniqueness, but it does not infer
    /// command or telemetry kind from raw MID bits.
    Opaque,
}

impl Default for MsgIdLayout {
    fn default() -> Self {
        Self::CcsdsV1
    }
}

/// Options for cFS validation and code generation.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct CfsOptions {
    /// Message ID layout policy for command/telemetry bit-pattern validation.
    pub msgid_layout: MsgIdLayout,
}

/// cFS packet category used by mission-wide validation.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CfsPacketKind {
    /// cFS Software Bus command packet.
    Command,
    /// cFS Software Bus telemetry packet.
    Telemetry,
}

/// Resolved cFS packet facts for registry-style validation.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CfsPacket {
    /// Namespace segments declared by the source file, if any.
    pub namespace: Vec<String>,
    /// Packet declaration name.
    pub name: String,
    /// Packet kind.
    pub kind: CfsPacketKind,
    /// Resolved numeric message ID.
    pub mid: u64,
    /// Resolved numeric command code for command packets.
    pub cc: Option<u64>,
}

/// Options for Rust cFS binding generation.
pub struct RustOptions<'a> {
    /// Module path prefix for the cFS header types.
    /// e.g. `"cfs"` -> `cfs::TelemetryHeader`, `"cfe_sys"` -> `cfe_sys::TelemetryHeader`.
    /// Set to `""` to use bare type names.
    pub cfs_module: &'a str,
    /// Rust type name for telemetry message headers. Default: `"TelemetryHeader"`.
    pub tlm_header: &'a str,
    /// Rust type name for command message headers. Default: `"CommandHeader"`.
    pub cmd_header: &'a str,
}

impl Default for RustOptions<'_> {
    fn default() -> Self {
        RustOptions {
            cfs_module: "cfs_sys",
            tlm_header: "CFE_MSG_TelemetryHeader_t",
            cmd_header: "CFE_MSG_CommandHeader_t",
        }
    }
}