---
# ----------------------------------------------------------------------------
# Service Commissioning File
# ----------------------------------------------------------------------------
# Copyright: Cybus GmbH
# Contact: support@cybus.io
# ----------------------------------------------------------------------------
# Migrating from Ignition (Example)
# ----------------------------------------------------------------------------

description: >
  Service commissioning file migrated from the Ignition tag folder Line1
  with the devices S7-1500_Line1 and ModbusPLC (Example)

metadata:
  name: Ignition Migration Example
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  s7Host:
    description: IP address of the device S7-1500_Line1
    type: string
    default: 192.168.1.100

  modbusHost:
    description: IP address of the device ModbusPLC
    type: string
    default: 192.168.1.101

definitions:
  # Topics mirror the Ignition tag folder hierarchy
  MQTT_TOPIC_PREFIX: line1

resources:
  # Ignition device connection "S7-1500_Line1" (Siemens driver)
  # Connection-level polling: tag group Fast500ms (500 ms)
  s7Line1Connection:
    type: Cybus::Connection
    properties:
      protocol: S7
      targetState: connected
      connection:
        host: !ref s7Host
        port: 102
        rack: 0
        slot: 1
        pollInterval: 500

  # Ignition device connection "ModbusPLC" (Modbus driver)
  modbusPlcConnection:
    type: Cybus::Connection
    properties:
      protocol: Modbus
      targetState: connected
      connection:
        host: !ref modbusHost
        port: 502

  # Tag "MotorSpeed": [S7-1500_Line1]DB10,INT4, Int2, tag group Fast500ms
  motorSpeed:
    type: Cybus::Endpoint
    properties:
      protocol: S7
      connection: !ref s7Line1Connection
      subscribe:
        address: DB10,INT4

  # Tag "FillLevel": [ModbusPLC]HRF20, Float4, default tag group (1000 ms)
  fillLevel:
    type: Cybus::Endpoint
    properties:
      protocol: Modbus
      connection: !ref modbusPlcConnection
      subscribe:
        fc: 3
        address: 19
        length: 2
        dataType: floatBE
        interval: 1000

  # Tag "RunningFlag": [ModbusPLC]C5, Boolean, default tag group (1000 ms)
  runningFlag:
    type: Cybus::Endpoint
    properties:
      protocol: Modbus
      connection: !ref modbusPlcConnection
      subscribe:
        fc: 1
        address: 4
        length: 1
        dataType: boolean
        interval: 1000

  mapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            endpoint: !ref motorSpeed
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/motor-speed'
        - subscribe:
            endpoint: !ref fillLevel
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/fill-level'
        - subscribe:
            endpoint: !ref runningFlag
          publish:
            topic: !sub '${MQTT_TOPIC_PREFIX}/running-flag'
