Skip to main content

synapse_codegen_cfs/
types.rs

1use std::collections::HashMap;
2
3/// Deterministic banner included at the top of generated files.
4pub const GENERATED_BANNER: &str = concat!(
5    "Generated by Synapse ",
6    env!("CARGO_PKG_VERSION"),
7    ". Do not edit directly."
8);
9
10/// Preamble included at the top of generated cFS C headers.
11pub const PREAMBLE: &str = concat!(
12    "/* Generated by Synapse ",
13    env!("CARGO_PKG_VERSION"),
14    ". Do not edit directly. */\n\
15#pragma once
16#include \"cfe.h\"
17
18"
19);
20
21/// Resolved integer constants visible to a file from imported namespaces.
22pub type ResolvedConstants = HashMap<Vec<String>, u64>;
23
24/// cFE message ID layout policy used for command/telemetry validation.
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum MsgIdLayout {
27    /// Legacy CCSDS-style cFE `MISSION_MSG_V1` layout.
28    ///
29    /// Command MIDs are expected to have bit `0x1000` set and telemetry MIDs
30    /// are expected to have that bit clear.
31    CcsdsV1,
32    /// Treat message IDs as opaque mission-owned values.
33    ///
34    /// Synapse still resolves MIDs and checks uniqueness, but it does not infer
35    /// command or telemetry kind from raw MID bits.
36    Opaque,
37}
38
39impl Default for MsgIdLayout {
40    fn default() -> Self {
41        Self::CcsdsV1
42    }
43}
44
45/// Options for cFS validation and code generation.
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
47pub struct CfsOptions {
48    /// Message ID layout policy for command/telemetry bit-pattern validation.
49    pub msgid_layout: MsgIdLayout,
50}
51
52/// cFS packet category used by mission-wide validation.
53#[derive(Debug, Clone, Copy, PartialEq, Eq)]
54pub enum CfsPacketKind {
55    /// cFS Software Bus command packet.
56    Command,
57    /// cFS Software Bus telemetry packet.
58    Telemetry,
59}
60
61/// Resolved cFS packet facts for registry-style validation.
62#[derive(Debug, Clone, PartialEq, Eq)]
63pub struct CfsPacket {
64    /// Namespace segments declared by the source file, if any.
65    pub namespace: Vec<String>,
66    /// Packet declaration name.
67    pub name: String,
68    /// Packet kind.
69    pub kind: CfsPacketKind,
70    /// Resolved numeric message ID.
71    pub mid: u64,
72    /// Resolved numeric command code for command packets.
73    pub cc: Option<u64>,
74}
75
76/// Options for Rust cFS binding generation.
77pub struct RustOptions<'a> {
78    /// Module path prefix for the cFS header types.
79    /// e.g. `"cfs"` -> `cfs::TelemetryHeader`, `"cfe_sys"` -> `cfe_sys::TelemetryHeader`.
80    /// Set to `""` to use bare type names.
81    pub cfs_module: &'a str,
82    /// Rust type name for telemetry message headers. Default: `"TelemetryHeader"`.
83    pub tlm_header: &'a str,
84    /// Rust type name for command message headers. Default: `"CommandHeader"`.
85    pub cmd_header: &'a str,
86}
87
88impl Default for RustOptions<'_> {
89    fn default() -> Self {
90        RustOptions {
91            cfs_module: "cfs_sys",
92            tlm_header: "CFE_MSG_TelemetryHeader_t",
93            cmd_header: "CFE_MSG_CommandHeader_t",
94        }
95    }
96}