### Define Command Database in Rust Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt Constructs a command database using the Database and Entry structures. Includes examples of standard commands and dangerous operations. ```rust use tlmcmddb::cmd::{Database, Entry, Command, Parameter, DataType, Comment}; // Create a command database let cmd_db = Database { entries: vec![ Entry::Comment(Comment { text: "Time management commands".to_string(), }), Entry::Command(Command { name: "Cmd_TMGR_SET_TIME".to_string(), target: "OBC".to_string(), code: 0x0001, parameters: vec![ Parameter { data_type: DataType::Uint32, description: "TI (Time Index)".to_string(), } ], is_danger: false, is_restricted: false, description: "Set MOBC time".to_string(), note: String::new(), }), Entry::Command(Command { name: "Cmd_TMGR_UPDATE_UNIXTIME".to_string(), target: "OBC".to_string(), code: 0x0002, parameters: vec![ Parameter { data_type: DataType::Double, description: "unixtime".to_string(), }, Parameter { data_type: DataType::Uint32, description: "total_cycle".to_string(), }, Parameter { data_type: DataType::Uint32, description: "step".to_string(), }, ], is_danger: false, is_restricted: false, description: "Update MOBC UNIXTIME".to_string(), note: String::new(), }), Entry::Command(Command { name: "Cmd_BCT_OVERWRITE_CMD".to_string(), target: "OBC".to_string(), code: 0x001E, parameters: vec![ Parameter { data_type: DataType::Uint16, description: "CMD_CODE".to_string() }, Parameter { data_type: DataType::Uint32, description: "TI".to_string() }, Parameter { data_type: DataType::Uint16, description: "pos.block".to_string() }, Parameter { data_type: DataType::Uint8, description: "pos.cmd".to_string() }, Parameter { data_type: DataType::Raw, description: "cmd_param (big endian)".to_string() }, ], is_danger: true, // Dangerous command flag is_restricted: false, description: "Overwrite BCT content".to_string(), note: String::new(), }), ], }; ``` -------------------------------- ### Telemetry Conversion Definitions Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt Shows examples of `ConversionInfo` for telemetry fields, including `Status` for integer-to-string mapping and `Polynomial` for engineering value calculations. These are used within `Field` definitions. ```rust // Status conversion example (integer to string mapping) let status_conversion = ConversionInfo::Status(Status { variants: vec![ Variant { key: 0, value: "SUCCESS".to_string() }, Variant { key: 1, value: "ERROR".to_string() }, ], default_value: Some("UNKNOWN".to_string()), }); // Polynomial conversion example (engineering value calculation) let polynomial_conversion = ConversionInfo::Polynomial(Polynomial { a0: 0.0, a1: 1.0, a2: 0.0, a3: 0.0, a4: 0.0, a5: 0.0, }); ``` -------------------------------- ### Create and Serialize Database with Components Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt Demonstrates creating a `Database` struct with components, including telemetry and command definitions, and serializing it to a pretty-printed JSON string. Requires the `tlmcmddb` and `serde_json` crates. ```rust use tlmcmddb::{Database, Component}; use tlmcmddb::tlm::{Telemetry, Metadata, Content, Entry, FieldGroup, Field}; use tlmcmddb::cmd::{Command, Parameter, DataType}; // Create a database with components let database = Database { components: vec![ Component { name: "MOBC".to_string(), tlm: tlmcmddb::tlm::Database { telemetries: vec![ Telemetry { name: "HK".to_string(), metadata: Metadata { target: "OBC".to_string(), packet_id: 240, is_enabled: true, is_restricted: false, local_variables: String::new(), }, content: Content::Struct(vec![]), } ], }, cmd: tlmcmddb::cmd::Database { entries: vec![ tlmcmddb::cmd::Entry::Command(Command { name: "Cmd_NOP".to_string(), target: "OBC".to_string(), code: 0x0000, parameters: vec![], is_danger: false, is_restricted: false, description: "Dummy command".to_string(), note: String::new(), }) ], }, } ], }; // Serialize to JSON let json = serde_json::to_string_pretty(&database).unwrap(); println!("{}", json); ``` -------------------------------- ### Bundle Databases with CLI Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt Combines telemetry and command CSV directories into a single JSON database file. ```bash # Bundle TLM_DB and CMD_DB directories into a JSON file tlmcmddb-cli bundle ./TLM_DB ./CMD_DB output.json # Bundle with pretty-printed JSON output tlmcmddb-cli bundle ./TLM_DB ./CMD_DB output.json --pretty # Bundle with explicit component name (overrides filename-derived names) tlmcmddb-cli bundle ./TLM_DB ./CMD_DB output.json --component-name MOBC --pretty ``` -------------------------------- ### Merge JSON Databases with tlmcmddb-cli Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt Use the tlmcmddb-cli tool to merge multiple JSON database files into a single output file. Supports pretty-printed output for readability. ```bash tlmcmddb-cli merge db1.json db2.json db3.json --output merged.json ``` ```bash tlmcmddb-cli merge db1.json db2.json --output merged.json --pretty ``` -------------------------------- ### Add tlmcmddb Crates to Cargo.toml Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt Specifies how to add the tlmcmddb crates as dependencies in a Rust project's `Cargo.toml` file. This enables the use of the library's functionality in your Rust code. ```toml [dependencies] tlmcmddb = "2.6" tlmcmddb-csv = "2.6" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" ``` -------------------------------- ### Rust Variable Type Utility Methods Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt Demonstrates the usage of the `VariableType` enum in Rust for handling telemetry fields and command parameters. Includes methods for checking octet/bit widths and type classification. ```rust use tlmcmddb::tlm::VariableType; let var_type = VariableType::Uint32; // Get octet (byte) width assert_eq!(var_type.octet_width(), 4); // Get bit width assert_eq!(var_type.bit_width(), 32); // Check if unsigned integer type assert!(var_type.is_unsigned_integer()); // Available types: // - Int8, Int16, Int32 (signed integers) // - Uint8, Uint16, Uint32 (unsigned integers) // - Float, Double (floating point) // Command parameters also support DataType::Raw for variable-length data ``` -------------------------------- ### Parse Telemetry Filenames Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt Extracts component and telemetry names from standardized CSV filenames. ```rust use tlmcmddb_csv::tlm::Filename; use std::str::FromStr; // Parse telemetry filename to extract component and telemetry names // Format: PREFIX_COMPONENT_TLM_DB_TELEMETRY.csv let filename = "SAMPLE_MOBC_TLM_DB_HK.csv"; let parsed: Filename = filename.parse().unwrap(); assert_eq!(parsed.component, Some("MOBC".to_string())); assert_eq!(parsed.telemetry, "HK".to_string()); // Filename without component name let filename2 = "SAMPLE_TLM_DB_SYSTEM.csv"; let parsed2: Filename = filename2.parse().unwrap(); assert_eq!(parsed2.component, None); assert_eq!(parsed2.telemetry, "SYSTEM".to_string()); ``` -------------------------------- ### Parse CSV Files with tlmcmddb-csv Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt Parses command and telemetry database CSV files into internal data structures. ```rust use std::fs::File; use tlmcmddb_csv::cmd::parse_csv as parse_cmd_csv; use tlmcmddb_csv::tlm::parse_csv as parse_tlm_csv; // Parse a command database CSV file let cmd_file = File::open("CMD_DB/SAMPLE_CMD_DB_CMD_DB.csv").unwrap(); let (component_name, cmd_database) = parse_cmd_csv(cmd_file).unwrap(); println!("Component: {}", component_name); println!("Commands: {}", cmd_database.entries.len()); // Parse a telemetry database CSV file let tlm_file = File::open("TLM_DB/SAMPLE_TLM_DB_HK.csv").unwrap(); let telemetry = parse_tlm_csv("HK".to_string(), tlm_file).unwrap(); println!("Telemetry: {}", telemetry.name); println!("Packet ID: {}", telemetry.metadata.packet_id); ``` -------------------------------- ### Define Telemetry Field Group with Bit Fields Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt Illustrates defining a `FieldGroup` for telemetry data, including `Field` definitions with `FieldExtractionInfo` for bit-level details. Requires imports from `tlmcmddb::tlm` and `tlmcmddb::tlm::conversion`. ```rust use tlmcmddb::tlm::{ Entry, FieldGroup, SubEntry, Field, FieldExtractionInfo, OnboardSoftwareInfo, VariableType, ConversionInfo, conversion::{Status, Variant, Polynomial}, }; // Define a telemetry field group with bit fields let field_group = FieldGroup { onboard_software_info: OnboardSoftwareInfo { variable_type: VariableType::Uint16, expression: "".to_string(), }, sub_entries: vec![ SubEntry::Field(Field { name: "PH.VER".to_string(), extraction_info: FieldExtractionInfo { extraction_type: "PACKET".to_string(), octet_position: 0, bit_position: 0, bit_length: 3, }, conversion_info: ConversionInfo::None, display_info: None, description: "Packet version".to_string(), note: String::new(), }), SubEntry::Field(Field { name: "PH.TYPE".to_string(), extraction_info: FieldExtractionInfo { extraction_type: "PACKET".to_string(), octet_position: 0, bit_position: 3, bit_length: 1, }, conversion_info: ConversionInfo::None, display_info: None, description: "Packet type flag".to_string(), note: String::new(), }), ], }; ``` -------------------------------- ### C2A TlmCmd DB JSON Output Structure Source: https://context7.com/arkedge/c2a-tlmcmddb/llms.txt The JSON output from CLI operations adheres to a specific data model schema, including components with telemetry and command definitions. This structure is used for integration with ground station software and telemetry viewers. ```json { "components": [ { "name": "MOBC", "tlm": { "telemetries": [ { "name": "HK", "metadata": { "target": "OBC", "packet_id": 240, "is_enabled": true, "is_restricted": false, "local_variables": "" }, "entries": [ { "type": "FIELD_GROUP", "onboard_software_info": { "variable_type": "uint16_t", "expression": "" }, "sub_entries": [ { "type": "FIELD", "name": "PH.VER", "extraction_info": { "extraction_type": "PACKET", "octet_position": 0, "bit_position": 0, "bit_length": 3 }, "conversion_info": "NONE", "description": "", "note": "" } ] } ] } ] }, "cmd": { "entries": [ { "type": "COMMAND", "name": "Cmd_NOP", "target": "OBC", "code": 0, "parameters": [], "is_danger": false, "is_restricted": false, "description": "Dummy command", "note": "" } ] } } ] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.