dbc_rs/
lib.rs

1//! # dbc-rs
2//!
3//! A `no_std` compatible Rust library for parsing and working with DBC (CAN database) files.
4//!
5//! ## Features
6//!
7//! - **`no_std` compatible**: Works in embedded environments without the standard library
8//! - **Zero dependencies**: Pure Rust implementation
9//! - **Memory efficient**: Uses fixed-size arrays for `no_std` builds
10//! - **Type-safe**: Strong typing for all DBC elements
11//! - **Internationalized errors**: Support for multiple languages
12//!
13//! ## Usage
14//!
15//! ```rust,no_run
16//! use dbc_rs::Dbc;
17//!
18//! let dbc_content = r#"VERSION "1.0"
19//!
20//! BU_: ECM TCM
21//!
22//! BO_ 256 EngineData : 8 ECM
23//!  SG_ RPM : 0|16@0+ (0.25,0) [0|8000] "rpm" TCM
24//! "#;
25//!
26//! let dbc = Dbc::parse(dbc_content)?;
27//! # Ok::<(), dbc_rs::Error>(())
28//! ```
29
30#![cfg_attr(not(feature = "alloc"), no_std)]
31
32extern crate alloc;
33
34mod byte_order;
35mod dbc;
36mod error;
37mod message;
38mod nodes;
39mod parse_options;
40mod parser;
41mod receivers;
42mod signal;
43mod version;
44
45pub use byte_order::ByteOrder;
46pub use dbc::{Dbc, Messages};
47pub use error::{Error, Result};
48pub use message::{Message, Signals};
49pub use nodes::Nodes;
50pub use parse_options::ParseOptions;
51pub use receivers::Receivers;
52pub use signal::Signal;
53pub use version::Version;
54
55#[cfg(feature = "alloc")]
56pub use dbc::DbcBuilder;
57#[cfg(feature = "alloc")]
58pub use message::MessageBuilder;
59#[cfg(feature = "alloc")]
60pub use nodes::NodesBuilder;
61#[cfg(feature = "alloc")]
62pub use receivers::ReceiversBuilder;
63#[cfg(feature = "alloc")]
64pub use signal::SignalBuilder;
65#[cfg(feature = "alloc")]
66pub use version::VersionBuilder;
67
68pub(crate) use parser::Parser;
69
70/// The version of this crate as specified in `Cargo.toml`.
71///
72/// This constant is only available when the `std` feature is enabled.
73#[cfg(feature = "std")]
74pub const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
75
76// Maximum limits for two-pass parsing (no alloc)
77// Note: MAX_MESSAGES and MAX_SIGNALS_PER_MESSAGE are now defined in limits.rs
78// (generated by build.rs) and can be overridden at build time.
79// Access them via Signals::max_capacity() and Messages::max_capacity().
80pub(crate) const MAX_NODES: usize = 256;
81
82// DBC file format keywords
83pub(crate) const VERSION: &str = "VERSION";
84pub(crate) const CM_: &str = "CM_";
85pub(crate) const NS_: &str = "NS_";
86pub(crate) const BS_: &str = "BS_";
87pub(crate) const BU_: &str = "BU_";
88pub(crate) const BO_: &str = "BO_";
89pub(crate) const SG_: &str = "SG_";
90pub(crate) const VAL_TABLE_: &str = "VAL_TABLE_";
91pub(crate) const BA_DEF_: &str = "BA_DEF_";
92pub(crate) const BA_DEF_DEF_: &str = "BA_DEF_DEF_";
93pub(crate) const BA_: &str = "BA_";
94pub(crate) const VAL_: &str = "VAL_";
95pub(crate) const SIG_GROUP_: &str = "SIG_GROUP_";
96pub(crate) const SIG_VALTYPE_: &str = "SIG_VALTYPE_";
97pub(crate) const EV_: &str = "EV_";
98pub(crate) const BO_TX_BU_: &str = "BO_TX_BU_";
99
100// Additional DBC keywords
101pub(crate) const VECTOR__INDEPENDENT_SIG_MSG: &str = "VECTOR__INDEPENDENT_SIG_MSG";
102pub(crate) const VECTOR__XXX: &str = "VECTOR__XXX";
103pub(crate) const BA_DEF_DEF_REL_: &str = "BA_DEF_DEF_REL_";
104pub(crate) const BA_DEF_SGTYPE_: &str = "BA_DEF_SGTYPE_";
105pub(crate) const SIGTYPE_VALTYPE_: &str = "SIGTYPE_VALTYPE_";
106pub(crate) const ENVVAR_DATA_: &str = "ENVVAR_DATA_";
107pub(crate) const SIG_TYPE_REF_: &str = "SIG_TYPE_REF_";
108pub(crate) const NS_DESC_: &str = "NS_DESC_";
109pub(crate) const BA_DEF_REL_: &str = "BA_DEF_REL_";
110pub(crate) const BA_SGTYPE_: &str = "BA_SGTYPE_";
111pub(crate) const SGTYPE_VAL_: &str = "SGTYPE_VAL_";
112pub(crate) const BU_SG_REL_: &str = "BU_SG_REL_";
113pub(crate) const BU_EV_REL_: &str = "BU_EV_REL_";
114pub(crate) const BU_BO_REL_: &str = "BU_BO_REL_";
115pub(crate) const SG_MUL_VAL_: &str = "SG_MUL_VAL_";
116pub(crate) const BA_REL_: &str = "BA_REL_";
117pub(crate) const CAT_DEF_: &str = "CAT_DEF_";
118pub(crate) const EV_DATA_: &str = "EV_DATA_";
119pub(crate) const CAT_: &str = "CAT_";
120pub(crate) const FILTER: &str = "FILTER";
121
122#[cfg_attr(not(feature = "std"), allow(dead_code))]
123const DBC_KEYWORDS: &[&str] = &[
124    VECTOR__INDEPENDENT_SIG_MSG,
125    VECTOR__XXX,
126    BA_DEF_DEF_REL_,
127    BA_DEF_SGTYPE_,
128    SIGTYPE_VALTYPE_,
129    ENVVAR_DATA_,
130    SIG_TYPE_REF_,
131    NS_DESC_,
132    BA_DEF_REL_,
133    BA_SGTYPE_,
134    SGTYPE_VAL_,
135    VAL_TABLE_,
136    SIG_GROUP_,
137    SIG_VALTYPE_,
138    BO_TX_BU_,
139    BU_SG_REL_,
140    BU_EV_REL_,
141    BU_BO_REL_,
142    SG_MUL_VAL_,
143    BA_DEF_DEF_,
144    BA_DEF_,
145    BA_REL_,
146    CAT_DEF_,
147    EV_DATA_,
148    BA_,
149    VAL_,
150    CM_,
151    CAT_,
152    NS_,
153    BS_,
154    BU_,
155    BO_,
156    SG_,
157    EV_,
158    VERSION,
159    FILTER,
160];