---
# ----------------------------------------------------------------------------#
# Commissioning File
# ----------------------------------------------------------------------------#
# Copyright: Cybus GmbH (2020)
# Contact: support@cybus.io
# ----------------------------------------------------------------------------#
# Source Interface Definition - Sopas - RFU620, SICK AG
# ----------------------------------------------------------------------------#

description: >
  Sample commissioning file for SICK Sopas protocol connectivity and data mapping

metadata:
  name: Sopas Protocol Connectivity
  icon: https://www.cybus.io/wp-content/uploads/2017/10/for-whom1.svg
  provider: cybus
  homepage: https://www.cybus.io
  version: 0.0.1

parameters:

  IP_Address:
    description: IP address of the SICK device
    type: string
    default: 192.168.10.10

  Port_Number:
    description: Port on the SICK device. Usually 2111 (sometimes 2112).
    type: number
    default: 2112

  initialReconnectDelay:
    type: integer
    default: 1000

  maxReconnectDelay:
    type: integer
    default: 30000

  factorReconnectDelay:
    type: integer
    default: 2

resources:
  sopasConnection:
    type: Cybus::Connection
    properties:
      protocol: Sopas
      connection:
        host: !ref IP_Address
        port: !ref Port_Number
        connectionStrategy:
          initialDelay: !ref initialReconnectDelay
          maxDelay: !ref maxReconnectDelay
          incrementFactor: !ref factorReconnectDelay

  inventory:
    type: Cybus::Endpoint
    properties:
      protocol: Sopas
      connection: !ref sopasConnection
      subscribe:
        name: QSinv
        type: event

  inventoryStart:
    type: Cybus::Endpoint
    properties:
      protocol: Sopas
      connection: !ref sopasConnection
      write:
        name: MIStartIn
        type: method

  inventoryStop:
    type: Cybus::Endpoint
    properties:
      protocol: Sopas
      connection: !ref sopasConnection
      write:
        name: MIStopIn
        type: method

  inventoryCheck:
    type: Cybus::Endpoint
    properties:
      protocol: Sopas
      connection: !ref sopasConnection
      read:
        name: QSIsRn
        type: variable

  inventoryRunning:
    type: Cybus::Endpoint
    properties:
      protocol: Sopas
      connection: !ref sopasConnection
      subscribe:
        name: QSIsRn
        type: variable

  feedbackLight:
    type: Cybus::Endpoint
    properties:
      protocol: Sopas
      connection: !ref sopasConnection
      write:
        name: HMISetFbLight
        type: method

  mapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            endpoint: !ref inventory
          publish:
            topic: !sub '${Cybus::MqttRoot}/inventory'
        - subscribe:
            topic: !sub '${Cybus::MqttRoot}/inventory/start'
          publish:
            endpoint: !ref inventoryStart
        - subscribe:
            topic: !sub '${Cybus::MqttRoot}/inventory/stop'
          publish:
            endpoint: !ref inventoryStop
        - subscribe:
            topic: !sub '${Cybus::MqttRoot}/inventory/check'
          publish:
            endpoint: !ref inventoryCheck
        - subscribe:
            endpoint: !ref inventoryRunning
          publish:
            topic: !sub '${Cybus::MqttRoot}/inventory/running'
        - subscribe:
            topic: !sub '${Cybus::MqttRoot}/light'
          publish:
            endpoint: !ref feedbackLight
