pnio/lib.rs
1//! `pnio` — pure-Rust PROFINET RT IO-Device stack.
2//!
3//! Community project, NOT affiliated with or endorsed by PROFIBUS & PROFINET
4//! International. "PROFINET" is a registered trademark of PNO.
5//!
6//! # Example: answer a DCP Identify on the device side
7//!
8//! ```
9//! use pnio::dcp::{handle_dcp_frame, DcpConfig, DeviceProperties};
10//! use pnio::eth::MacAddr;
11//!
12//! let cfg = DcpConfig {
13//! mac: MacAddr([0x02, 0xc0, 0xa8, 0x01, 0x0f, 0x02]),
14//! properties: DeviceProperties {
15//! name_of_station: "i-device".to_string(),
16//! type_of_station: "demo".to_string(),
17//! vendor_id: 0x002a,
18//! device_id: 0x010e,
19//! device_role: 0,
20//! device_instance: 0x1064,
21//! device_options: vec![0x02, 0x07],
22//! ip: [192, 168, 1, 61],
23//! subnet: [255, 255, 255, 0],
24//! gateway: [192, 168, 1, 61],
25//! ip_block_info: 1,
26//! },
27//! };
28//!
29//! // A DCP Identify request for "i-device" produces an Identify response.
30//! let req = [
31//! 0x01, 0x0e, 0xcf, 0x00, 0x00, 0x00, 0xec, 0x1c, 0x5d, 0x61, 0xe7, 0x3f, 0x88, 0x92,
32//! 0xfe, 0xfe, 0x05, 0x00, 0x03, 0x00, 0x01, 0x52, 0x00, 0x01, 0x00, 0x0c, 0x02, 0x02,
33//! 0x00, 0x08, 0x69, 0x2d, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65,
34//! ];
35//! let resp = handle_dcp_frame(&req, &cfg).unwrap();
36//! assert!(resp.is_some());
37//! ```
38
39// `unsafe` is confined to the raw-socket / scheduler layer: `eth::afpacket`, `eth::poll`,
40// `rt::sched`, `rt::runner`. Every other module is checked by the compiler to contain none.
41#![deny(unsafe_code)]
42#![warn(missing_docs)]
43
44pub mod alarm;
45#[cfg(target_os = "linux")]
46pub mod api;
47#[cfg(feature = "capture")]
48pub mod capture;
49pub mod cm;
50pub mod config;
51pub mod data;
52pub mod dcp;
53pub mod device;
54pub mod diag;
55pub mod eth;
56pub mod gsdml;
57pub mod im;
58pub mod rpc;
59pub mod rt;
60#[cfg(test)]
61pub(crate) mod testutil;
62
63/// Crate version (foundations smoke test).
64pub fn version() -> &'static str {
65 env!("CARGO_PKG_VERSION")
66}
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
73 fn version_is_not_empty() {
74 assert!(!version().is_empty());
75 }
76}