use super::*;
use bacnet_services::alarm_event::{GetEventInformationAck, GetEventInformationRequest};
use bacnet_services::alarm_summary::GetAlarmSummaryAck;
use bacnet_services::enrollment_summary::{GetEnrollmentSummaryAck, GetEnrollmentSummaryRequest};
use bacnet_types::primitives::ObjectIdentifier;
impl<T: TransportPort + 'static> BACnetClient<T> {
pub async fn get_event_information(
&self,
destination_mac: &[u8],
last_received_object_identifier: Option<ObjectIdentifier>,
) -> Result<GetEventInformationAck, Error> {
let buf = event_information_request(last_received_object_identifier);
let ack = self
.confirmed_request(
destination_mac,
ConfirmedServiceChoice::GET_EVENT_INFORMATION,
&buf,
)
.await?;
GetEventInformationAck::decode(&ack)
}
pub async fn get_event_information_from_device(
&self,
device_instance: u32,
last_received_object_identifier: Option<ObjectIdentifier>,
) -> Result<GetEventInformationAck, Error> {
let buf = event_information_request(last_received_object_identifier);
let ack = self
.confirmed_request_to_device(
device_instance,
ConfirmedServiceChoice::GET_EVENT_INFORMATION,
&buf,
)
.await?;
GetEventInformationAck::decode(&ack)
}
pub async fn get_alarm_summary(
&self,
destination_mac: &[u8],
) -> Result<GetAlarmSummaryAck, Error> {
let ack = self
.confirmed_request(
destination_mac,
ConfirmedServiceChoice::GET_ALARM_SUMMARY,
&[],
)
.await?;
GetAlarmSummaryAck::decode(&ack)
}
pub async fn get_alarm_summary_from_device(
&self,
device_instance: u32,
) -> Result<GetAlarmSummaryAck, Error> {
let ack = self
.confirmed_request_to_device(
device_instance,
ConfirmedServiceChoice::GET_ALARM_SUMMARY,
&[],
)
.await?;
GetAlarmSummaryAck::decode(&ack)
}
pub async fn get_enrollment_summary(
&self,
destination_mac: &[u8],
request: &GetEnrollmentSummaryRequest,
) -> Result<GetEnrollmentSummaryAck, Error> {
let mut buf = BytesMut::new();
request.try_encode(&mut buf)?;
let ack = self
.confirmed_request(
destination_mac,
ConfirmedServiceChoice::GET_ENROLLMENT_SUMMARY,
&buf,
)
.await?;
GetEnrollmentSummaryAck::decode(&ack)
}
pub async fn get_enrollment_summary_from_device(
&self,
device_instance: u32,
request: &GetEnrollmentSummaryRequest,
) -> Result<GetEnrollmentSummaryAck, Error> {
let mut buf = BytesMut::new();
request.try_encode(&mut buf)?;
let ack = self
.confirmed_request_to_device(
device_instance,
ConfirmedServiceChoice::GET_ENROLLMENT_SUMMARY,
&buf,
)
.await?;
GetEnrollmentSummaryAck::decode(&ack)
}
async fn confirmed_request_to_device(
&self,
device_instance: u32,
service_choice: ConfirmedServiceChoice,
service_data: &[u8],
) -> Result<Bytes, Error> {
let (mac, routing) = self.resolve_device(device_instance).await?;
match routing {
Some((network, address)) => {
self.confirmed_request_routed(&mac, network, &address, service_choice, service_data)
.await
}
None => {
self.confirmed_request(&mac, service_choice, service_data)
.await
}
}
}
}
fn event_information_request(
last_received_object_identifier: Option<ObjectIdentifier>,
) -> BytesMut {
let mut buf = BytesMut::new();
GetEventInformationRequest {
last_received_object_identifier,
}
.encode(&mut buf);
buf
}