use bacnet_types::enums::{ObjectType, PropertyIdentifier};
use bacnet_types::error::Error;
use bacnet_types::primitives::{ObjectIdentifier, PropertyValue};
use crate::common;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) struct GroupMembership {
pub(super) elevator_group: ObjectIdentifier,
pub(super) group_id: u8,
pub(super) installation_id: u8,
}
impl GroupMembership {
pub(super) fn new() -> Result<Self, Error> {
Ok(Self {
elevator_group: ObjectIdentifier::new(
ObjectType::ELEVATOR_GROUP,
ObjectIdentifier::MAX_INSTANCE,
)?,
group_id: 0,
installation_id: 0,
})
}
pub(super) fn read(&self, property: PropertyIdentifier) -> Option<PropertyValue> {
match property {
PropertyIdentifier::ELEVATOR_GROUP => {
Some(PropertyValue::ObjectIdentifier(self.elevator_group))
}
PropertyIdentifier::GROUP_ID => Some(PropertyValue::Unsigned(self.group_id.into())),
PropertyIdentifier::INSTALLATION_ID => {
Some(PropertyValue::Unsigned(self.installation_id.into()))
}
_ => None,
}
}
pub(super) fn set_elevator_group(&mut self, oid: ObjectIdentifier) -> Result<(), Error> {
if oid.object_type() != ObjectType::ELEVATOR_GROUP {
return Err(common::value_out_of_range_error());
}
self.elevator_group = oid;
Ok(())
}
}
macro_rules! group_membership_accessors {
($object:literal) => {
#[doc = concat!("Clauses 12.59 and 12.60 use when no Elevator Group lists this ", $object, ".")]
pub fn elevator_group(&self) -> ObjectIdentifier {
self.membership.elevator_group
}
#[doc = concat!($object, " among its Group_Members.")]
pub fn set_elevator_group(&mut self, oid: ObjectIdentifier) -> Result<(), Error> {
self.membership.set_elevator_group(oid)
}
pub fn group_id(&self) -> u8 {
self.membership.group_id
}
#[doc = concat!("Set the identification number of the group of the ", $object, ".")]
pub fn set_group_id(&mut self, group_id: u8) {
self.membership.group_id = group_id;
}
#[doc = concat!("The identification number of the ", $object, ", served as Installation_ID.")]
pub fn installation_id(&self) -> u8 {
self.membership.installation_id
}
#[doc = concat!("Set the identification number of the ", $object, " within its group.")]
pub fn set_installation_id(&mut self, installation_id: u8) {
self.membership.installation_id = installation_id;
}
};
}
pub(super) use group_membership_accessors;