Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/learn_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async fn main() -> Result<(), BacnetError<MySocket>> {
| ObjectType::ObjectAnalogValue
| ObjectType::ObjectSchedule
| ObjectType::ObjectTrendlog => {
let list = map.entry(item.object_type.clone() as u32).or_insert(vec![]);
let list = map.entry(item.object_type.as_u32()).or_insert(vec![]);
list.push(item);
}
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion src/application_protocol/primitives/data_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Enumerated {
let value = match self {
Self::Units(x) => x.clone() as u32,
Self::Binary(x) => x.clone() as u32,
Self::ObjectType(x) => *x as u32,
Self::ObjectType(x) => x.as_u32(),
Self::EventState(x) => x.clone() as u32,
Self::NotifyType(x) => x.clone() as u32,
Self::LoggingType(x) => x.clone() as u32,
Expand Down
4 changes: 2 additions & 2 deletions src/application_protocol/services/read_property_multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<'a> PropertyResultList<'a> {
pub fn new(property_results: &'a [PropertyResult<'a>]) -> Self {
Self {
property_results,
object_id: ObjectId::new(ObjectType::Invalid, 0),
object_id: ObjectId::new(ObjectType::ObjectVendorSpecific(0), 0),
buf: &[],
}
}
Expand All @@ -256,7 +256,7 @@ impl<'a> PropertyResult<'a> {
const PROPERTY_VALUE_ERROR_TAG: u8 = 5;

pub fn encode(&self, writer: &mut Writer) {
encode_context_unsigned(writer, Self::PROPERTY_ID_TAG, self.id as u32);
encode_context_unsigned(writer, Self::PROPERTY_ID_TAG, self.id.as_u32());
match &self.value {
PropertyValue::PropValue(val) => {
encode_opening_tag(writer, Self::PROPERTY_VALUE_TAG);
Expand Down
2 changes: 1 addition & 1 deletion src/common/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub fn decode_context_property_id(
}

pub fn encode_context_enumerated(writer: &mut Writer, tag_number: u8, property_id: &PropertyId) {
let value = *property_id as u32;
let value = property_id.as_u32();
let len = get_len_u64(value as u64);

let tag = Tag::new(TagNumber::ContextSpecific(tag_number), len);
Expand Down
197 changes: 127 additions & 70 deletions src/common/object_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl ObjectId {
}

pub fn encode(&self, writer: &mut Writer) {
let value = ((self.object_type as u32 & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS)
let value = ((self.object_type.as_u32() & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS)
| (self.id & BACNET_MAX_INSTANCE);
writer.extend_from_slice(&value.to_be_bytes());
}
Expand All @@ -42,80 +42,137 @@ impl ObjectId {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum ObjectType {
ObjectAnalogInput = 0,
ObjectAnalogOutput = 1,
ObjectAnalogValue = 2,
ObjectBinaryInput = 3,
ObjectBinaryOutput = 4,
ObjectBinaryValue = 5,
ObjectCalendar = 6,
ObjectCommand = 7,
ObjectDevice = 8,
ObjectEventEnrollment = 9,
ObjectFile = 10,
ObjectGroup = 11,
ObjectLoop = 12,
ObjectMultiStateInput = 13,
ObjectMultiStateOutput = 14,
ObjectNotificationClass = 15,
ObjectProgram = 16,
ObjectSchedule = 17,
ObjectAveraging = 18,
ObjectMultiStateValue = 19,
ObjectTrendlog = 20,
ObjectLifeSafetyPoint = 21,
ObjectLifeSafetyZone = 22,
ObjectAccumulator = 23,
ObjectPulseConverter = 24,
ObjectEventLog = 25,
ObjectGlobalGroup = 26,
ObjectTrendLogMultiple = 27,
ObjectLoadControl = 28,
ObjectStructuredView = 29,
ObjectAccessDoor = 30,
ObjectTimer = 31,
ObjectAccessCredential = 32, // addendum 2008-j
ObjectAccessPoint = 33,
ObjectAccessRights = 34,
ObjectAccessUser = 35,
ObjectAccessZone = 36,
ObjectCredentialDataInput = 37, // authentication-factor-input
ObjectNetworkSecurity = 38, // Addendum 2008-g
ObjectBitstringValue = 39, // Addendum 2008-w
ObjectCharacterstringValue = 40, // Addendum 2008-w
ObjectDatePatternValue = 41, // Addendum 2008-w
ObjectDateValue = 42, // Addendum 2008-w
ObjectDatetimePatternValue = 43, // Addendum 2008-w
ObjectDatetimeValue = 44, // Addendum 2008-w
ObjectIntegerValue = 45, // Addendum 2008-w
ObjectLargeAnalogValue = 46, // Addendum 2008-w
ObjectOctetstringValue = 47, // Addendum 2008-w
ObjectPositiveIntegerValue = 48, // Addendum 2008-w
ObjectTimePatternValue = 49, // Addendum 2008-w
ObjectTimeValue = 50, // Addendum 2008-w
ObjectNotificationForwarder = 51, // Addendum 2010-af
ObjectAlertEnrollment = 52, // Addendum 2010-af
ObjectChannel = 53, // Addendum 2010-aa
ObjectLightingOutput = 54, // Addendum 2010-i
ObjectBinaryLightingOutput = 55, // Addendum 135-2012az
ObjectNetworkPort = 56, // Addendum 135-2012az
ObjectAnalogInput,
ObjectAnalogOutput,
ObjectAnalogValue,
ObjectBinaryInput,
ObjectBinaryOutput,
ObjectBinaryValue,
ObjectCalendar,
ObjectCommand,
ObjectDevice,
ObjectEventEnrollment,
ObjectFile,
ObjectGroup,
ObjectLoop,
ObjectMultiStateInput,
ObjectMultiStateOutput,
ObjectNotificationClass,
ObjectProgram,
ObjectSchedule,
ObjectAveraging,
ObjectMultiStateValue,
ObjectTrendlog,
ObjectLifeSafetyPoint,
ObjectLifeSafetyZone,
ObjectAccumulator,
ObjectPulseConverter,
ObjectEventLog,
ObjectGlobalGroup,
ObjectTrendLogMultiple,
ObjectLoadControl,
ObjectStructuredView,
ObjectAccessDoor,
ObjectTimer,
ObjectAccessCredential, // addendum 2008-j
ObjectAccessPoint,
ObjectAccessRights,
ObjectAccessUser,
ObjectAccessZone,
ObjectCredentialDataInput, // authentication-factor-input
ObjectNetworkSecurity, // Addendum 2008-g
ObjectBitstringValue, // Addendum 2008-w
ObjectCharacterstringValue, // Addendum 2008-w
ObjectDatePatternValue, // Addendum 2008-w
ObjectDateValue, // Addendum 2008-w
ObjectDatetimePatternValue, // Addendum 2008-w
ObjectDatetimeValue, // Addendum 2008-w
ObjectIntegerValue, // Addendum 2008-w
ObjectLargeAnalogValue, // Addendum 2008-w
ObjectOctetstringValue, // Addendum 2008-w
ObjectPositiveIntegerValue, // Addendum 2008-w
ObjectTimePatternValue, // Addendum 2008-w
ObjectTimeValue, // Addendum 2008-w
ObjectNotificationForwarder, // Addendum 2010-af
ObjectAlertEnrollment, // Addendum 2010-af
ObjectChannel, // Addendum 2010-aa
ObjectLightingOutput, // Addendum 2010-i
ObjectBinaryLightingOutput, // Addendum 135-2012az
ObjectNetworkPort, // Addendum 135-2012az
// Enumerated values 0-127 are reserved for definition by ASHRAE.
// Enumerated values 128-1023 may be used by others subject to
// the procedures and constraints described in Clause 23.
// do the max range inside of enum so that
// compilers will allocate adequate sized datatype for enum
// which is used to store decoding
Reserved = 57,
Proprietary = 128,
Invalid = 1024,
ObjectReserved(u32), // 57..=127
ObjectVendorSpecific(u32), // 128..=1023
}

impl TryFrom<u32> for ObjectType {
type Error = u32;
impl ObjectType {
pub fn as_u32(&self) -> u32 {
match self {
Self::ObjectAnalogInput => 0,
Self::ObjectAnalogOutput => 1,
Self::ObjectAnalogValue => 2,
Self::ObjectBinaryInput => 3,
Self::ObjectBinaryOutput => 4,
Self::ObjectBinaryValue => 5,
Self::ObjectCalendar => 6,
Self::ObjectCommand => 7,
Self::ObjectDevice => 8,
Self::ObjectEventEnrollment => 9,
Self::ObjectFile => 10,
Self::ObjectGroup => 11,
Self::ObjectLoop => 12,
Self::ObjectMultiStateInput => 13,
Self::ObjectMultiStateOutput => 14,
Self::ObjectNotificationClass => 15,
Self::ObjectProgram => 16,
Self::ObjectSchedule => 17,
Self::ObjectAveraging => 18,
Self::ObjectMultiStateValue => 19,
Self::ObjectTrendlog => 20,
Self::ObjectLifeSafetyPoint => 21,
Self::ObjectLifeSafetyZone => 22,
Self::ObjectAccumulator => 23,
Self::ObjectPulseConverter => 24,
Self::ObjectEventLog => 25,
Self::ObjectGlobalGroup => 26,
Self::ObjectTrendLogMultiple => 27,
Self::ObjectLoadControl => 28,
Self::ObjectStructuredView => 29,
Self::ObjectAccessDoor => 30,
Self::ObjectTimer => 31,
Self::ObjectAccessCredential => 32,
Self::ObjectAccessPoint => 33,
Self::ObjectAccessRights => 34,
Self::ObjectAccessUser => 35,
Self::ObjectAccessZone => 36,
Self::ObjectCredentialDataInput => 37,
Self::ObjectNetworkSecurity => 38,
Self::ObjectBitstringValue => 39,
Self::ObjectCharacterstringValue => 40,
Self::ObjectDatePatternValue => 41,
Self::ObjectDateValue => 42,
Self::ObjectDatetimePatternValue => 43,
Self::ObjectDatetimeValue => 44,
Self::ObjectIntegerValue => 45,
Self::ObjectLargeAnalogValue => 46,
Self::ObjectOctetstringValue => 47,
Self::ObjectPositiveIntegerValue => 48,
Self::ObjectTimePatternValue => 49,
Self::ObjectTimeValue => 50,
Self::ObjectNotificationForwarder => 51,
Self::ObjectAlertEnrollment => 52,
Self::ObjectChannel => 53,
Self::ObjectLightingOutput => 54,
Self::ObjectBinaryLightingOutput => 55,
Self::ObjectNetworkPort => 56,
Self::ObjectReserved(v) => *v,
Self::ObjectVendorSpecific(v) => *v,
}
}

fn try_from(value: u32) -> Result<Self, u32> {
pub fn try_from(value: u32) -> Result<Self, u32> {
match value {
0 => Ok(Self::ObjectAnalogInput),
1 => Ok(Self::ObjectAnalogOutput),
Expand Down Expand Up @@ -174,8 +231,8 @@ impl TryFrom<u32> for ObjectType {
54 => Ok(Self::ObjectLightingOutput),
55 => Ok(Self::ObjectBinaryLightingOutput),
56 => Ok(Self::ObjectNetworkPort),
57..=127 => Ok(Self::Reserved),
128..=1023 => Ok(Self::Proprietary),
57..=127 => Ok(Self::ObjectReserved(value)),
128..=1023 => Ok(Self::ObjectVendorSpecific(value)),
x => Err(x),
}
}
Expand Down
Loading