ocpp-kit 0.4.0

Open Charge Point Protocol (OCPP 1.6J, 2.0.1, 2.1) toolkit for Rust: typed messages, OCPP-J framing, a sans-I/O protocol engine, and transports for charging stations, CSMS and local controllers.
Documentation
//! The catalogues OCPP 2.x defines outside the JSON schemas.
//!
//! Part 2 — Appendices lists things two implementations have to agree on that no schema
//! carries: which security events exist and which of them are critical, what the standardized
//! device-model components and variables are called, and the standardized `reasonCode`
//! values. These modules reproduce that vocabulary — names, data types and criticality — so
//! it can be used and checked in code rather than transcribed from a PDF each time.
//!
//! Generated by `cargo xtask appendix` from OCPP 2.1 Part 2 — Appendices v2.0. The prose
//! descriptions are not reproduced; read them in the appendix.

pub mod components;
pub mod reason_codes;
pub mod security_events;

pub use components::{ComponentKind, StandardComponent, StandardVariable};
pub use reason_codes::ReasonCode;
pub use security_events::SecurityEvent;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn the_security_event_list_matches_the_appendix() {
        // The appendix's table has 21 rows.
        assert_eq!(SecurityEvent::VARIANTS.len(), 21);

        // The ones the specification marks critical are pushed to the CSMS, not just logged.
        assert!(SecurityEvent::TamperDetectionActivated.is_critical());
        assert!(SecurityEvent::InvalidCsmsCertificate.is_critical());
        assert!(SecurityEvent::FirmwareUpdated.is_critical());
        // …and the ones it does not are only logged.
        assert!(!SecurityEvent::InvalidMessages.is_critical());
        assert!(!SecurityEvent::AttemptedReplayAttacks.is_critical());
        assert!(!SecurityEvent::FailedToAuthenticateAtCsms.is_critical());
        assert!(!SecurityEvent::ReconfigurationOfSecurityParameters.is_critical());

        // A vendor-specific event is reported rather than quietly dropped.
        let vendor = SecurityEvent::from_wire("AcmeCabinetOpened");
        assert!(!vendor.is_known());
        assert!(vendor.is_critical());

        assert_eq!(SecurityEvent::critical().len(), 16);
    }

    #[test]
    fn standardized_components_carry_their_variables_types_and_units() {
        assert_eq!(components::COMPONENTS.len(), 74);

        let comm = components::component("OCPPCommCtrlr").expect("a controller component");
        assert_eq!(comm.kind, ComponentKind::Controller);
        assert!(
            comm.variables
                .iter()
                .any(|v| v.name == "RetryBackOffWaitMinimum")
        );
        // A wrapped name in the PDF must come out whole.
        assert!(
            comm.variables
                .iter()
                .any(|v| v.name == "NetworkProfileConnectionAttempts")
        );

        let heartbeat = components::variable("OCPPCommCtrlr", "HeartbeatInterval").unwrap();
        assert_eq!(heartbeat.data_type, Some("integer"));
        assert_eq!(heartbeat.unit, Some("s"));

        let evse = components::component("EVSE").expect("a physical component");
        assert_eq!(evse.kind, ComponentKind::Physical);
        // `Count[ChargingProfiles]` is a variable *instance*, not a name.
        let count = evse
            .variables
            .iter()
            .find(|v| v.name == "Count")
            .expect("Count");
        assert_eq!(count.instance, Some("ChargingProfiles"));

        assert!(components::component("NotAComponent").is_none());
    }

    #[test]
    fn reason_codes_come_from_the_appendix_and_stay_open() {
        assert!(ReasonCode::VARIANTS.len() >= 50);
        assert_eq!(ReasonCode::InvalidProfile.as_str(), "InvalidProfile");
        assert!(!ReasonCode::from_wire("SomethingVendorSpecific").is_known());
    }
}