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
objectintoeventStatethat happened attimeStamp(AcknowledgeAlarm).override -
acknowledgeEvent(
EventNotificationEvent notification, {required String source, DateTime? time, Duration? timeout}) → Future< void> -
Acknowledges the transition
notificationreported.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< property, List<E> >E> elements, {Duration? timeout}) → Future<void> -
Adds
elementsto the listpropertyofobject.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 updeviceId: starts the backup, waits until the device is ready (Backup_And_Restore_State, at mostpreparationTimeout), reads the files of Configuration_Files and ends the backup (also when it fails).onProgressreports 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 oftypewhose instance the device chooses, orobject.override -
deleteObject(
int deviceId, BacnetObject object, {Duration? timeout}) → Future< void> -
Deletes
objectfromdeviceId(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 ofdeviceId: ReadPropertyMultiple with ALL forbatchSizeobjects at a time,concurrencybatches in parallel; objects the device cannot describe that way (no ReadPropertyMultiple, answers too large) are read property by property from their Property_List.onProgressreports the objects read. -
deviceCommunicationControl(
int deviceId, BacnetCommunicationState state, {Duration? duration, String? password, Duration? timeout}) → Future< void> -
Enables or disables the communication of
deviceId(DeviceCommunicationControl) forduration(whole minutes, null for indefinitely).override -
deviceMaxApdu(
int deviceId) → Future< int?> -
The maximum APDU
deviceIdaccepts, 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 fortimeout. -
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
deviceIdin alarm (GetAlarmSummary).override -
getEventInformation(
int deviceId, {Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future< List< BacnetEventSummary> > -
Returns the objects of
deviceIdthat 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
deviceIdis known.override -
localAddress(
) → Future< BacnetAddressRecipient> -
127.0.0.1and 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
serviceNumberofvendorIdindeviceId(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
propertyofobjectas 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 objectfileInstance(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
countrecords from recordstartof File objectfileInstance(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
countoctets from positionstartof File objectfileInstance(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
rangewith 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 atip(an IPv4 address or host name) andport: sends an Initialize-Routing-Table without entries, which routers answer with their table. -
receive(
BacnetEvent event) → void -
Delivers
eventto 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
deviceIdor 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< property, List<E> >E> elements, {Duration? timeout}) → Future<void> -
Removes
elementsfrom the listpropertyofobject; 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
RestoresbackuptodeviceId: 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 tocompletionTimeoutfor 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
objector for the object namedobjectName(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(andmacAddress) to the device withvendorId,modelNameandserialNumber(You-Are, the answer to a Who-Am-I). Sent todestination(e.g. WhoAmIEvent.source), else broadcast onnetwork(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 ClassnotificationClassofdeviceIdand 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).
maxNotificationDelaylets 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
deviceIdand 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
specificationsmade 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 withintimeout. -
whoIsRouterToNetwork(
{int? network}) → Future< void> -
Available on BacnetClient, provided by the BacnetNetworkDiscovery extension
Broadcasts a Who-Is-Router-To-Network: the routers tonetwork, 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
valuetopropertyofobject; 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
Writesdatato File objectfileInstancefrom position 0 (stream access), in chunks that fit into one APDU of the device. -
writeFileRecords(
int deviceId, int fileInstance, List< List< records, {int start = 0, Duration? timeout, bool background = false, BacnetCancelToken? cancelToken}) → Future<int> >int> -
Writes
recordsto File objectfileInstancefrom recordstart(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
datato File objectfileInstanceat positionstart(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
changesto the Channel objects of all devices whose Control_Groups containgroupNumber(WriteGroup, broadcast onnetwork) atwritePriority;inhibitDelaymakes 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