reportEvent method

EventNotificationEvent reportEvent(
  1. BacnetEventState toState, {
  2. BacnetEventValues? eventValues,
  3. BacnetEventType? eventType,
  4. String? messageText,
  5. DateTime? time,
})

Reports that the object entered toState, like an event algorithm of the device: updates Event_State, Event_Time_Stamps and Acked_Transitions, and sends an EventNotificationEvent to every recipient of the Notification Class that wants the transition. Returns the notification (with process identifier 0).

eventType defaults to the type of eventValues. Call enableEventReporting first.

Implementation

EventNotificationEvent reportEvent(
  BacnetEventState toState, {
  BacnetEventValues? eventValues,
  BacnetEventType? eventType,
  String? messageText,
  DateTime? time,
}) {
  final classNumber = properties[BacnetPropertyId.notificationClass]?.asInt;
  if (classNumber == null) {
    throw StateError('event reporting of $identifier is not enabled');
  }
  final transition = BacnetEventTransition.into(toState);
  final notificationClass = device.object(
    BacnetObjectType.notificationClass,
    classNumber,
  );
  final ackRequired = _transitionBit(
    _decodeOr(
      notificationClass?[BacnetPropertyId.ackRequired],
      BacnetEventTransitionBits.fromValue,
      const BacnetEventTransitionBits(),
    ),
    transition,
  );
  final priorities = _decodeOr(
    notificationClass?[BacnetPropertyId.priority],
    BacnetEventPriorities.fromValue,
    const BacnetEventPriorities(
      toOffNormal: 255,
      toFault: 255,
      toNormal: 255,
    ),
  );
  final enabled = _transitionBit(
    _decodeOr(
      properties[BacnetPropertyId.eventEnable],
      BacnetEventTransitionBits.fromValue,
      _allTransitions,
    ),
    transition,
  );
  final timeStamp = BacnetTimeStampDateTime(
    BacnetDateTime.fromDateTime(time ?? DateTime.now()),
  );
  final notification = EventNotificationEvent(
    processId: 0,
    deviceId: device.deviceId,
    object: identifier,
    timeStamp: timeStamp,
    notificationClass: classNumber,
    priority: priorities[transition],
    eventType:
        eventType ?? eventValues?.eventType ?? BacnetEventType.changeOfState,
    messageText: messageText,
    notifyType: BacnetNotifyType(
      properties[BacnetPropertyId.notifyType]?.asInt ??
          BacnetNotifyType.alarm,
    ),
    ackRequired: enabled && ackRequired,
    fromState: _eventState,
    toState: toState,
    eventValues: eventValues,
  );
  _eventState = toState;
  _stamps[transition.index] = timeStamp;
  _acked = _withTransition(_acked, transition, !(enabled && ackRequired));
  _publishEventState();
  if (enabled) device._notifyRecipients(notification, transition);
  return notification;
}