FakeBacnetClient class

A BacnetClient backed by in-memory FakeBacnetDevices, for testing applications without a network or the native stack.

It discovers devices (Who-Is/I-Am), reads and writes properties with the errors real devices return, commands outputs through a priority array, sends COV notifications for subscribed properties and can simulate latency and offline devices. Every request is recorded in requests.

final ahu = FakeBacnetDevice(1234)
  ..addObject(BacnetObjectType.analogValue, 1,
      presentValue: const BacnetReal(21));
final client = FakeBacnetClient(devices: [ahu]);
await client.start();

final monitor = PropertyMonitor(client);
final updates = monitor.monitorPresentValue(
  1234,
  const BacnetObject(type: BacnetObjectType.analogValue, instance: 1),
);
ahu.object(BacnetObjectType.analogValue, 1)![BacnetPropertyId.presentValue] =
    const BacnetReal(22.5); // delivered as a COV notification
Implemented types
Available extensions

Constructors

FakeBacnetClient({Iterable<FakeBacnetDevice> devices = const [], Iterable<FakeBacnetRouter> routers = const [], int? networkNumber, Duration latency = Duration.zero, BacnetConfig config = const BacnetConfig()})
Creates a client serving devices.

Properties

config → BacnetConfig
Configuration of this client.
no setteroverride
covEvents → Stream<CovNotificationEvent>
Change-of-Value notifications.
no setteroverride
devices → Map<int, FakeBacnetDevice>
Devices served by this client.
no setter
eventNotifications → Stream<EventNotificationEvent>
Alarm and event notifications sent to this client (see addListElements to become a recipient).
no setteroverride
events → Stream<BacnetEvent>
Stream of all unsolicited events (I-Am, COV notifications, server writes, logs and errors).
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
iAmEvents → Stream<IAmEvent>
I-Am announcements.
no setteroverride
latency ↔ Duration
Response time of every request.
getter/setter pair
nativeVersion → String?
Version of the native engine and bacnet-stack, once started.
no setteroverride
networkMessages → Stream<NetworkMessageEvent>
Network layer messages received from routers and other devices (I-Am-Router-To-Network, Network-Number-Is, Reject-Message-To-Network, ...). BacnetNetworkDiscovery builds router discovery on them.
no setteroverride
networkNumber ↔ int?
Number of the local network: the first online router answers What-Is-Network-Number with it (null: nobody answers).
getter/setter pair
requests → List<FakeBacnetRequest>
Requests received, oldest first.
final
routers → List<FakeBacnetRouter>
Routers of the simulated network.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
whoAmIRequests → Stream<WhoAmIEvent>
Who-Am-I requests of devices without a configured device instance; a supervisor answers with sendYouAre.
no setteroverride

Methods

acknowledgeAlarm(int deviceId, BacnetObject object, BacnetEventState eventState, BacnetTimeStamp timeStamp, {required String source, int processId = 0, DateTime? time, Duration? timeout}) → Future<void>
Acknowledges the transition of object into eventState that happened at timeStamp (AcknowledgeAlarm).
override
acknowledgeEvent(EventNotificationEvent notification, {required String source, DateTime? time, Duration? timeout}) → Future<void>
Acknowledges the transition notification reported.
override
addDevice(FakeBacnetDevice device) → void
Adds a device; it answers Who-Is and requests.
addDeviceBinding(int deviceId, String ip, {int port = 47808, int network = 0, List<int> adr = const [], int maxApdu = 1476}) → Future<void>
Adds (or replaces) a static device address binding.
override
addListElement(int deviceId, BacnetObjectType objectType, int instance, BacnetPropertyId propertyId, BacnetValue elements, {int arrayIndex = -1, Duration? timeout}) → Future<void>
Adds elements (the elements one after another) to a list property with AddListElement; elements already in the list are not added twice.
override
addListElements<E>(int deviceId, BacnetObject object, BacnetWritableProperty<List<E>> property, List<E> elements, {Duration? timeout}) → Future<void>
Adds elements to the list property of object.
override
allocateProcessId() → int
Allocates a subscriber process identifier for COV subscriptions.
override
backupDevice(int deviceId, {String? password, Duration preparationTimeout = const Duration(minutes: 2), BacnetFileProgress? onProgress, Duration? timeout}) → Future<BacnetDeviceBackup>

Available on BacnetClient, provided by the BacnetDeviceBackups extension

Backs up deviceId: starts the backup, waits until the device is ready (Backup_And_Restore_State, at most preparationTimeout), reads the files of Configuration_Files and ends the backup (also when it fails). onProgress reports the files read.
close() → Future<void>
Releases the stack (stopped when no client or server uses it).
override
createObject(int deviceId, {BacnetObjectType? type, BacnetObject? object, List<BacnetPropertyValue> initialValues = const [], Duration? timeout}) → Future<BacnetObject>
Creates an object in deviceId (CreateObject) and returns it: an object of type whose instance the device chooses, or object.
override
deleteObject(int deviceId, BacnetObject object, {Duration? timeout}) → Future<void>
Deletes object from deviceId (DeleteObject).
override
describeDevice(int deviceId, {int batchSize = 8, int concurrency = 2, void onProgress(int done, int total)?}) → Future<BacnetDeviceDescription>

Available on BacnetClient, provided by the BacnetDeviceDescriptions extension

Reads all properties of all objects of deviceId: ReadPropertyMultiple with ALL for batchSize objects at a time, concurrency batches in parallel; objects the device cannot describe that way (no ReadPropertyMultiple, answers too large) are read property by property from their Property_List. onProgress reports the objects read.
deviceCommunicationControl(int deviceId, BacnetCommunicationState state, {Duration? duration, String? password, Duration? timeout}) → Future<void>
Enables or disables the communication of deviceId (DeviceCommunicationControl) for duration (whole minutes, null for indefinitely).
override
deviceMaxApdu(int deviceId) → Future<int?>
The maximum APDU deviceId accepts, from its address binding (null when the device is not bound yet; any request binds it).
override
discoverRouters({int? network, Duration timeout = const Duration(seconds: 3)}) → Future<List<BacnetRouter>>

Available on BacnetClient, provided by the BacnetNetworkDiscovery extension

Finds the routers of the local network (and of the networks a BBMD connects): broadcasts Who-Is-Router-To-Network and collects the I-Am-Router-To-Network answers for timeout.
dispose() → void
Disposes of the client and releases resources.
override
getAlarmSummary(int deviceId, {Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<List<BacnetAlarmSummary>>
Returns the objects of deviceId in alarm (GetAlarmSummary).
override
getEventInformation(int deviceId, {Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<List<BacnetEventSummary>>
Returns the objects of deviceId that are in an event state other than normal or have unacknowledged transitions (GetEventInformation, repeated while the device reports more).
override
getTrendLog(int deviceId, int instance, {BacnetPropertyId logBufferPropId = BacnetPropertyId.logBuffer, int count = 100, int? fromSequenceNumber, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<TrendLogData>
Reads records of a Trend Log object.
override
isDeviceBound(int deviceId) → Future<bool>
Returns true when the address of deviceId is known.
override
localAddress() → Future<BacnetAddressRecipient>
127.0.0.1 and the port of config.
override
log(BacnetLogLevel level, String message, [Object? error, StackTrace? stackTrace]) → void
Logs a message using the configured logger.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
privateTransfer(int deviceId, int vendorId, int serviceNumber, {BacnetValue? parameters, Duration? timeout}) → Future<BacnetValue?>
Calls the vendor specific service serviceNumber of vendorId in deviceId (ConfirmedPrivateTransfer) and returns its result block.
override
read<T>(int deviceId, BacnetObject object, BacnetProperty<T> property, {Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<T>
Reads property of object as its Dart type.
override
readFile(int deviceId, int fileInstance, {int? chunkSize, BacnetFileProgress? onProgress, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<Uint8List>

Available on BacnetClient, provided by the BacnetFileTransfer extension

Reads the whole content of File object fileInstance (stream access), in chunks that fit into one APDU of the device.
readFileRecords(int deviceId, int fileInstance, {required int start, required int count, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<BacnetFileRecords>
Reads up to count records from record start of File object fileInstance (AtomicReadFile, record access).
override
readFileStream(int deviceId, int fileInstance, {required int start, required int count, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<BacnetFileChunk>
Reads up to count octets from position start of File object fileInstance (AtomicReadFile, stream access).
override
readMultiple(int deviceId, List<BacnetReadAccessSpecification> specs, {Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<Map<BacnetObject, Map<BacnetPropertyId, BacnetPropertyResult>>>
Reads multiple properties of multiple objects with ReadPropertyMultiple.
override
readProperty(int deviceId, BacnetObjectType objectType, int instance, BacnetPropertyId propertyId, {int arrayIndex = -1, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<BacnetValue>
Reads a property of an object.
override
readRange(int deviceId, BacnetObjectType objectType, int instance, BacnetPropertyId propertyId, {BacnetRange range = const BacnetRange.all(), int arrayIndex = -1, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<ReadRangeResult>
Reads the items of a list property selected by range with ReadRange (the whole list by default).
override
readRoutingTable(String ip, {int port = 47808, Duration timeout = const Duration(seconds: 3)}) → Future<List<BacnetRoutingTableEntry>>

Available on BacnetClient, provided by the BacnetNetworkDiscovery extension

Reads the routing table of the router at ip (an IPv4 address or host name) and port: sends an Initialize-Routing-Table without entries, which routers answer with their table.
receive(BacnetEvent event) → void
Delivers event to the listeners as if the network produced it, e.g. a WhoAmIEvent of a new device.
registerForeignDevice(String ip, {int port = 47808, int ttl = 120}) → Future<void>
Registers this client as a Foreign Device with a BBMD.
override
reinitializeDevice(int deviceId, BacnetReinitializedState state, {String? password, Duration? timeout}) → Future<void>
Restarts deviceId or controls its backup and restore procedure (ReinitializeDevice).
override
removeDeviceBinding(int deviceId) → Future<void>
Removes the address binding of a device.
override
removeListElement(int deviceId, BacnetObjectType objectType, int instance, BacnetPropertyId propertyId, BacnetValue elements, {int arrayIndex = -1, Duration? timeout}) → Future<void>
Removes elements (the elements one after another) from a list property with RemoveListElement.
override
removeListElements<E>(int deviceId, BacnetObject object, BacnetWritableProperty<List<E>> property, List<E> elements, {Duration? timeout}) → Future<void>
Removes elements from the list property of object; an element must match an entry of the list exactly.
override
restoreDevice(int deviceId, BacnetDeviceBackup backup, {String? password, Duration preparationTimeout = const Duration(minutes: 2), Duration completionTimeout = const Duration(minutes: 2), BacnetFileProgress? onProgress, Duration? timeout}) → Future<void>

Available on BacnetClient, provided by the BacnetDeviceBackups extension

Restores backup to deviceId: starts the restore, waits until the device is ready, writes the files (and their size where the device allows it) and ends the restore; aborts it when a step fails. Waits up to completionTimeout for the device to apply the files and throws a BacnetException when it reports a restore failure.
scanDevice(int deviceId, {bool background = false, BacnetCancelToken? cancelToken}) → Future<List<BacnetObject>>
Reads the object list of a device.
override
sendConfirmedRaw(int deviceId, BacnetConfirmedService service, Uint8List serviceData, {Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<Uint8List>
Sends any confirmed service with pre-encoded service data and returns the raw service ACK data (empty for a Simple-ACK).
override
sendNetworkMessage(BacnetNetworkMessage message, {String? ip, int port = 47808, int network = 0, List<int> adr = const []}) → Future<void>
Simulates the routers: they answer Who-Is-Router-To-Network, What-Is-Network-Number (with networkNumber) and routing table queries (an Initialize-Routing-Table without entries sent to them).
override
sendPrivateTransfer(int vendorId, int serviceNumber, {BacnetValue? parameters, int? deviceId, int network = 0xFFFF}) → Future<void>
Sends an UnconfirmedPrivateTransfer to deviceId, or as broadcast.
override
sendTextMessage(String message, {int? deviceId, int network = 0xFFFF, bool urgent = false, int? classNumber, String? classText}) → Future<void>
Sends an UnconfirmedTextMessage to deviceId, or as broadcast.
override
sendWhoHas({BacnetObject? object, String? objectName, int lowLimit = -1, int highLimit = -1, int network = 0xFFFF}) → Future<void>
Sends a Who-Has for object or for the object named objectName (exactly one of them). Devices hosting it answer with an IHaveEvent (see events).
override
sendWhoIs({int lowLimit = -1, int highLimit = -1, int network = 0xFFFF}) → Future<void>
Sends a Who-Is to discover devices.
override
sendYouAre({required int vendorId, required String modelName, required String serialNumber, int? deviceId, List<int>? macAddress, BacnetAddressRecipient? destination, int network = 0xFFFF}) → Future<void>
Assigns deviceId (and macAddress) to the device with vendorId, modelName and serialNumber (You-Are, the answer to a Who-Am-I). Sent to destination (e.g. WhoAmIEvent.source), else broadcast on network (0xFFFF: all networks, 0: the local one).
override
start({String? interface, int? port}) → Future<void>
Starts the BACnet stack (shared with BacnetServer instances).
override
stats() → Future<BacnetStats>
Returns runtime statistics of the engine.
override
subscribeAlarms(int deviceId, {required int notificationClass, BacnetRecipient? recipient, int? processId, bool confirmed = false, BacnetEventTransitionBits transitions = const BacnetEventTransitionBits(toOffNormal: true, toFault: true, toNormal: true), Duration? timeout}) → Future<AlarmSubscription>

Available on BacnetClient, provided by the BacnetAlarmSubscriptions extension

Adds this client to the recipients of Notification Class notificationClass of deviceId and returns the subscription, whose AlarmSubscription.notifications are the alarms and events of the objects that report to that class.
subscribeCOV(int deviceId, BacnetObjectType objectType, int instance, {BacnetPropertyId propId = BacnetPropertyId.presentValue, int processId = 1, Duration lifetime = const Duration(minutes: 5), bool confirmed = false, double? covIncrement, Duration? timeout}) → Future<void>
Subscribes to Change-of-Value notifications of an object.
override
subscribeCOVPropertyMultiple(int deviceId, List<BacnetCovSubscriptionSpecification> specifications, {int processId = 1, Duration lifetime = const Duration(minutes: 5), bool confirmed = false, Duration? maxNotificationDelay, Duration? timeout}) → Future<void>
Subscribes to changes of several properties of several objects with one request (SubscribeCOVPropertyMultiple), e.g. to watch a whole plant room. The device sends COVNotificationMultiple, which arrive as one CovNotificationEvent per object on covEvents (with CovNotificationEvent.changeTimes for timestamped references). maxNotificationDelay lets the device collect changes before it notifies.
override
textMessage(int deviceId, String message, {bool urgent = false, int? classNumber, String? classText, Duration? timeout}) → Future<void>
Sends a text to deviceId and waits for the acknowledgement (ConfirmedTextMessage). The message names the device instance of BacnetConfig.deviceInstance as its source.
override
timeSynchronization(DateTime time, {bool utc = false, int? deviceId}) → Future<void>
Sends a (UTC)TimeSynchronization to a device or as broadcast.
override
toString() → String
A string representation of this object.
inherited
unsubscribeCOV(int deviceId, BacnetObjectType objectType, int instance, {BacnetPropertyId propId = BacnetPropertyId.presentValue, int processId = 1, Duration? timeout}) → Future<void>
Cancels a COV subscription created with subscribeCOV.
override
unsubscribeCOVPropertyMultiple(int deviceId, List<BacnetCovSubscriptionSpecification> specifications, {int processId = 1, Duration? timeout}) → Future<void>
Cancels the subscriptions of specifications made with subscribeCOVPropertyMultiple.
override
whatIsNetworkNumber({Duration timeout = const Duration(seconds: 3)}) → Future<BacnetNetworkNumberIs?>

Available on BacnetClient, provided by the BacnetNetworkDiscovery extension

Asks for the number of the local network (What-Is-Network-Number): the first Network-Number-Is answer, or null when no device knows the number within timeout.
whoIsRouterToNetwork({int? network}) → Future<void>

Available on BacnetClient, provided by the BacnetNetworkDiscovery extension

Broadcasts a Who-Is-Router-To-Network: the routers to network, or all routers when it is null, answer with I-Am-Router-To-Network (BacnetClient.networkMessages).
write<T>(int deviceId, BacnetObject object, BacnetWritableProperty<T> property, T value, {int priority = 16, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<void>
Writes value to property of object; only writable properties are accepted.
override
writeFile(int deviceId, int fileInstance, List<int> data, {bool truncate = false, int? chunkSize, BacnetFileProgress? onProgress, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<void>

Available on BacnetClient, provided by the BacnetFileTransfer extension

Writes data to File object fileInstance from position 0 (stream access), in chunks that fit into one APDU of the device.
writeFileRecords(int deviceId, int fileInstance, List<List<int>> records, {int start = 0, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<int>
Writes records to File object fileInstance from record start (AtomicWriteFile, record access; -1 appends) and returns the first record the device wrote.
override
writeFileStream(int deviceId, int fileInstance, List<int> data, {int start = 0, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<int>
Writes data to File object fileInstance at position start (AtomicWriteFile, stream access; -1 appends) and returns the position the device wrote to.
override
writeGroup(int groupNumber, List<BacnetGroupChannelValue> changes, {int writePriority = 16, bool? inhibitDelay, int? deviceId, int network = 0xFFFF}) → Future<void>
Writes changes to the Channel objects of all devices whose Control_Groups contain groupNumber (WriteGroup, broadcast on network) at writePriority; inhibitDelay makes the channels skip their write delay.
override
writeMultiple(int deviceId, List<BacnetWriteAccessSpecification> specs, {Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<void>
Writes multiple properties of multiple objects with WritePropertyMultiple.
override
writeProperty(int deviceId, BacnetObjectType objectType, int instance, BacnetPropertyId propertyId, BacnetValue value, {int priority = 16, int arrayIndex = -1, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<void>
Writes a property value.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited