bacure.core

boot-up!

(boot-up!)(boot-up! configs)
Create a local-device, load its config file, initialize it, and
find the remote devices.

find-bacnet-port

(find-bacnet-port)(find-bacnet-port configs)
Scan ports to see if any BACnet device will respond. Use port
numbers as device-id.

Example use:
(find-bacnet-port) ;;will scan ports 47801 to 47820
(find-bacnet-port {:delay 100}) ;; scan the same ports, but faster
(find-bacnet-port {:port-min 47850 :port-max 47900}) ;;new port range

The argument is a map of configs for the BACnet devices that will be
created (like in `bacure.local-device/new-local-device!'), but it
will also accepts these additional fields :

- :port-min
- :port-max
- :delay

If the optionals port-min and port-max aren't
given, default to all ports between 47801 and 47820.

By default each port will wait 500 ms for an answer.

Even if we could simply send a WhoIs on another port, some BACnet
devices have bad behaviour and send data back to 'their' port,
regardless from which port the WhoIs came. In other to maximize our
chances of finding them, we reset the local device with a new port
each time.

find-objects

(find-objects device-id criteria-map)(find-objects device-id criteria-map object-identifiers)
Return a list of objects-maps (properties) matching the criteria-map.

Criteria-map example:
{:present-value #(> % 10) :object-name #"(?i)analog" :model-name "GNU"}

Each different* property is requested individually, which requires
a higher traffic on the network. However, it also enables us to
stop a query if one of the properties values isn't what we wished.
Useful if we want to find devices with particular properties.

If the criteria-map fails, any unfetched properties will just be
dropped, saving some traffic on the network. Can quickly become
advantageous if we query a large number of devices.

* In case of multiple objects, if segmentation is supported, the
  same property is retrieved in a single request. For example, the
  `description' property for 3 different objects would be merged
  into a single request.

find-objects-everywhere

(find-objects-everywhere criteria-map)(find-objects-everywhere criteria-map object-identifiers)
Same as `find-objects', but will search every known devices on the network.
Group the result in a map where the device object identifier is the
key. E.g. [:device 1234]

Thus, to retrieve the result for a given device, simply do:
(get <result> [:device 1234]).

One could also get the list of devices in which a result matched with:
(keys <result>).

Criteria-map example:
{:present-value #(> % 10) :object-name #"(?i)analog" :model-name "GNU"}

All remote devices are queried simultaneously (or as much as the
local-device can allow).

get-device-id

(get-device-id device-map)
Return the device-id from a device-map (bunch of properties).

This can be used to search the device-id amongst all the properties
returned by (remote-objects-all-properties <some-device-id>).

read-trend-log

(read-trend-log device-id object-identifier)(read-trend-log local-device-id device-id object-identifier)
A convenience function to retrieve all data from a trend-log (even the log-buffer).

Example:  (read-trend-log 4589 [:trend-log 1])
-> {:object-name "Trend Log 1",
    :start-time "2009-01-01T05:00:00.000Z",
    :log-buffer
    [["2009-03-01T07:15:00.000Z" 1009.0]
     ["2009-03-01T07:30:00.000Z" 1010.0]...]...}

remote-object-properties

(remote-object-properties device-id object-identifiers properties)(remote-object-properties local-device-id device-id object-identifiers properties)
Query a remote device and return the properties values
 Example: (remote-object-properties 1234 [:analog-input 0] :all)
 -> {:notification-class 4194303, :event-enable .....}

 Both `object-identifiers' and `properties' accept either a single
 item or a collection.

 Discards any properties with an error value 
(example: property not found in object).

remote-object-properties-with-error

(remote-object-properties-with-error device-id object-identifiers properties)(remote-object-properties-with-error local-device-id device-id object-identifiers properties)
Query a remote device and return the properties values
Example: (remote-object-properties-with-error 1234 [:analog-input 0] :all)
-> {:notification-class 4194303, :event-enable .....}

Both `object-identifiers' and `properties' accept either a single
item or a collection.

You probably want to use `remote-object-properties'.

remote-objects

(remote-objects device-id)(remote-objects local-device-id device-id)
Return a collection of every objects in the remote device.
-> [[:device 1234] [:analog-input 0]...]

remote-objects-all-properties

(remote-objects-all-properties device-id)(remote-objects-all-properties local-device-id device-id)
Return a list of maps of every objects and their properties.

where

(where criteria)
Will test with criteria map as a predicate. If the value of a
key-val pair is a function, use it as a predicate. If the tested map
value is not found, fail.

For example:
Criteria map:  {:a #(> % 10) :b "foo"}
Tested-maps  {:a 20 :b "foo"}  success
             {:b "foo"}        fail
             {:a nil :b "foo"} fail

where-or-not-found

(where-or-not-found criteria)
Will test with criteria map as a predicate. If the value of a
key-val pair is a function, use it as a predicate. If the tested map
value is not found, pass.

For example:
Criteria map:  {:a #(> % 10) :b "foo"}
Tested-maps  {:a 20 :b "foo"}  success
             {:b "foo"}        success
             {:a nil :b "foo"} fail