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