spodes-rs 0.7.1

A pure-Rust DLMS/COSEM stack: interface classes, transport, xDLMS services and security (IEC 62056 and the СТО 34.01-5.1-006-2023 / Р 1323565.1 GOST profiles).
Documentation
//! OBIS codes of the СПОДУС / ИВКЭ information model (СТО 34.01-5.1-013-2023).
//!
//! Each function returns the [`ObisCode`] of a mandated object. Codes with a
//! channel component (`0.b.…`) take the channel as an argument.

use crate::obis::ObisCode;

/// SAP assignment object of the management logical device (§10.1.8,
/// `0.0.41.0.0.255`, IC 17). The management logical device itself has address 1.
pub fn sap_assignment() -> ObisCode {
    ObisCode::new(0, 0, 41, 0, 0, 255)
}

// --- Notifications (§8.5) --------------------------------------------------

/// Push setup object (`0.0.25.9.0.255`, IC 40 v2).
pub fn push_setup() -> ObisCode {
    ObisCode::new(0, 0, 25, 9, 0, 255)
}

/// Event push-message object (§8.5.11, `0.0.96.50.0.255`, class Data).
pub fn event_message() -> ObisCode {
    ObisCode::new(0, 0, 96, 50, 0, 255)
}

/// Push-message filter mask (`0.0.97.98.10.255`, class Data).
pub fn push_mask() -> ObisCode {
    ObisCode::new(0, 0, 97, 98, 10, 255)
}

/// ИВКЭ logical name (`0.0.42.0.0.255`).
pub fn ivke_logical_name() -> ObisCode {
    ObisCode::new(0, 0, 42, 0, 0, 255)
}

// --- Nameplate / passport data (§10.14, class Data) ------------------------

/// Passport-data reference profile (§10.14, `0.0.94.7.0.255`, Profile generic).
pub fn nameplate_profile() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 0, 255)
}

/// Time-difference-with-meters delta (`0.0.94.7.141.255`, class Data, unsigned).
pub fn time_delta() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 141, 255)
}

/// Discrete-inputs state bitmask (`0.0.96.3.1.255`, class Data, long-unsigned).
pub fn discrete_inputs() -> ObisCode {
    ObisCode::new(0, 0, 96, 3, 1, 255)
}

/// ИВКЭ serial number (`0.0.96.1.0.255`).
pub fn serial_number() -> ObisCode {
    ObisCode::new(0, 0, 96, 1, 0, 255)
}

/// ИВКЭ model (`0.0.96.1.1.255`).
pub fn model() -> ObisCode {
    ObisCode::new(0, 0, 96, 1, 1, 255)
}

/// Firmware version (`0.0.96.1.2.255`).
pub fn firmware_version() -> ObisCode {
    ObisCode::new(0, 0, 96, 1, 2, 255)
}

/// Manufacturer name (`0.0.96.1.3.255`).
pub fn manufacturer() -> ObisCode {
    ObisCode::new(0, 0, 96, 1, 3, 255)
}

/// Production year (`0.0.96.1.4.255`).
pub fn production_year() -> ObisCode {
    ObisCode::new(0, 0, 96, 1, 4, 255)
}

/// Hardware version (`0.0.0.2.1.255`).
pub fn hardware_version() -> ObisCode {
    ObisCode::new(0, 0, 0, 2, 1, 255)
}

/// СПОДУС specification version (`0.0.96.1.6.255`).
pub fn spodus_version() -> ObisCode {
    ObisCode::new(0, 0, 96, 1, 6, 255)
}

/// Last firmware-update date (`0.0.96.1.7.255`).
pub fn last_update_date() -> ObisCode {
    ObisCode::new(0, 0, 96, 1, 7, 255)
}

/// Non-metrological firmware identifier (`0.0.96.1.8.255`).
pub fn nonmetrological_firmware_id() -> ObisCode {
    ObisCode::new(0, 0, 96, 1, 8, 255)
}

/// Metrological firmware checksum (`0.0.96.1.10.255`).
pub fn metrological_firmware_checksum() -> ObisCode {
    ObisCode::new(0, 0, 96, 1, 10, 255)
}

// --- Meter management lists ------------------------------------------------

/// Configured meter list (§10.2, `0.0.94.7.128.255`, class Data).
pub fn meter_list() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 128, 255)
}

/// Direct-channel table (§10.3, `0.0.94.7.129.255`, class Data).
pub fn direct_channel_table() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 129, 255)
}

/// ИВКЭ channel list (§10.4, `0.0.94.7.130.255`, Profile generic).
pub fn channel_list() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 130, 255)
}

/// Discovered-meters list (§10.5, `0.0.94.7.131.255`, Profile generic).
pub fn discovered_meters() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 131, 255)
}

/// Meter access policies (§10.6, `0.0.94.7.132.255`, array of Data structs).
pub fn access_policies() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 132, 255)
}

/// Meter data-exchange task list (§10.7, `0.0.94.7.133.255`, class Data).
pub fn data_exchange_tasks() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 133, 255)
}

// --- Journals (§10.9, §10.13) ----------------------------------------------

/// Meter status table (§10.8, `0.0.94.7.134.255`, Profile generic).
pub fn meter_status_table() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 134, 255)
}

/// Meter data-exchange-status journal (§10.9, `0.0.94.7.135.255`, Profile generic).
pub fn exchange_status_journal() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 135, 255)
}

/// Object-correction journal (§10.10, `0.0.94.7.136.255`, Profile generic).
pub fn object_correction_journal() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 136, 255)
}

/// Numeric meter journal (§10.11, `0.0.94.7.137.255`, Profile generic).
pub fn numeric_meter_journal() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 137, 255)
}

/// Incoming-events table (§8.5.10, `0.0.94.7.140.255`, Profile generic).
pub fn incoming_events_table() -> ObisCode {
    ObisCode::new(0, 0, 94, 7, 140, 255)
}

/// Parameter-programming event log (§10.13, `0.0.96.11.3.255`).
pub fn parameter_programming_log() -> ObisCode {
    ObisCode::new(0, 0, 96, 11, 3, 255)
}

/// Access-control event log (§10.13, `0.0.96.11.6.255`).
pub fn access_control_log() -> ObisCode {
    ObisCode::new(0, 0, 96, 11, 6, 255)
}

/// Self-diagnostics event log (§10.13, `0.0.96.11.7.255`).
pub fn self_diagnostics_log() -> ObisCode {
    ObisCode::new(0, 0, 96, 11, 7, 255)
}

/// Switching event log for channel `b` (§10.13, `0.b.96.11.5.255`).
pub fn switching_log(channel: u8) -> ObisCode {
    ObisCode::new(0, channel, 96, 11, 5, 255)
}

/// Discrete-I/O event log for channel `b` (§10.13, `0.b.99.98.10.255`).
pub fn discrete_io_log(channel: u8) -> ObisCode {
    ObisCode::new(0, channel, 99, 98, 10, 255)
}

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

    #[test]
    fn nameplate_codes() {
        assert_eq!(serial_number().to_bytes(), vec![0, 0, 96, 1, 0, 255]);
        assert_eq!(hardware_version().to_bytes(), vec![0, 0, 0, 2, 1, 255]);
        assert_eq!(spodus_version().to_bytes(), vec![0, 0, 96, 1, 6, 255]);
        assert_eq!(metrological_firmware_checksum().to_bytes(), vec![0, 0, 96, 1, 10, 255]);
    }

    #[test]
    fn meter_lists_and_management() {
        assert_eq!(sap_assignment().to_bytes(), vec![0, 0, 41, 0, 0, 255]);
        assert_eq!(ivke_logical_name().to_bytes(), vec![0, 0, 42, 0, 0, 255]);
        assert_eq!(discovered_meters().to_bytes(), vec![0, 0, 94, 7, 131, 255]);
        assert_eq!(access_policies().to_bytes(), vec![0, 0, 94, 7, 132, 255]);
    }

    #[test]
    fn journal_codes() {
        assert_eq!(parameter_programming_log().to_bytes(), vec![0, 0, 96, 11, 3, 255]);
        assert_eq!(access_control_log().to_bytes(), vec![0, 0, 96, 11, 6, 255]);
        assert_eq!(self_diagnostics_log().to_bytes(), vec![0, 0, 96, 11, 7, 255]);
        // Channel-scoped journals.
        assert_eq!(switching_log(1).to_bytes(), vec![0, 1, 96, 11, 5, 255]);
        assert_eq!(discrete_io_log(2).to_bytes(), vec![0, 2, 99, 98, 10, 255]);
    }
}