# ----------------------------------------------------------------------------#
# BACnet Service Commissioning File Example
# ----------------------------------------------------------------------------#
# Copyright: Cybus GmbH
# Contact: support@cybus.io
# ----------------------------------------------------------------------------#
# Source Interface Definition - BACnet
# ----------------------------------------------------------------------------#

description: |
  Sample commissioning file for BACnet protocol connectivity and data mapping

metadata:
  name: BACnet Protocol Connectivity
  icon: https://www.cybus.io/wp-content/uploads/2019/03/Cybus-logo-Claim-lang.svg
  provider: cybus
  homepage: https://www.cybus.io
  version: 0.0.1

parameters:
  IP_Address:
    type: string
    default: 192.168.1.100

  Port_Number:
    type: number
    default: 47808

  Device_Instance:
    type: number
    default: 2000

  initialReconnectDelay:
    type: integer
    default: 1000

  maxReconnectDelay:
    type: integer
    default: 30000

  factorReconnectDelay:
    type: integer
    default: 2

resources:
  # Define the connection to the device.
  bacnetConnection:
    type: Cybus::Connection
    properties:
      protocol: Bacnet
      targetState: connected
      connection:
        deviceInstance: !ref Device_Instance
        deviceAddress: !sub '${IP_Address}:${Port_Number}'
        connectionStrategy:
          initialDelay: !ref initialReconnectDelay
          maxDelay: !ref maxReconnectDelay
          incrementFactor: !ref factorReconnectDelay

  # The BACnet protocol supports endpoints of type read, write, and subscribe.
  # Below are examples of how to configure such operations.
  # Read endpoint
  bacnetReadBinaryOutput:
    type: Cybus::Endpoint
    properties:
      protocol: Bacnet
      connection: !ref bacnetConnection
      read:
        objectType: binary-output
        objectInstance: 303
        property: present-value

  # Write endpoint
  bacnetWriteBinaryOutput:
    type: Cybus::Endpoint
    properties:
      protocol: Bacnet
      connection: !ref bacnetConnection
      write:
        objectType: binary-output
        objectInstance: 303
        property: present-value
        priority: 8
        propertyTag: 7

  # Subscription endpoint
  bacnetSubscribeBinaryOutput:
    type: Cybus::Endpoint
    properties:
      protocol: Bacnet
      connection: !ref bacnetConnection
      subscribe:
        objectType: binary-output
        objectInstance: 303
        property: present-value
        interval: 1000
