---
# ----------------------------------------------------------------------------
# Service Commissioning File
# ----------------------------------------------------------------------------
# Copyright: Cybus GmbH
# Contact: support@cybus.io
# ----------------------------------------------------------------------------
# umati Integration (Example)
# ----------------------------------------------------------------------------

description: >
  Service commissioning file for reading operation mode, active program
  information, and stacklight signals from a machine tool that implements
  umati (OPC UA for Machine Tools, OPC 40501-1) (Example)

metadata:
  name: umati Integration
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  machineHost:
    description: Hostname or IP address of the machine's OPC UA server
    type: string
    default: 192.168.1.100

  machinePort:
    description: Port of the machine's OPC UA server
    type: integer
    default: 4840

  opcuaUser:
    description: Username for the machine's OPC UA server (empty for anonymous access)
    type: string
    default: ''

  opcuaPass:
    description: Password for the machine's OPC UA server
    type: string
    default: ''

  namespaceIndex:
    description: >-
      Namespace index of the machine tool instance nodes on your machine.
      Resolve it from the NamespaceArray (ns=0;i=2255) of your machine's
      OPC UA server.
    type: integer
    default: 5

  topicRoot:
    description: Root of the ISA-95-style MQTT topic hierarchy for this machine
    type: string
    default: enterprise/hamburg/machining/line-1/machine-tool-01

resources:
  # Connection to the machine's OPC UA server. For security policies and
  # certificate exchange, see the OPC UA client documentation.
  umatiConnection:
    type: Cybus::Connection
    properties:
      protocol: Opcua
      connection:
        host: !ref machineHost
        port: !ref machinePort
        username: !ref opcuaUser
        password: !ref opcuaPass

  # --------------------------------------------------------------------------
  # Monitoring (Monitoring.MachineTool and Monitoring.Stacklight)
  # --------------------------------------------------------------------------
  # All NodeId string identifiers below are machine-specific examples.
  # Replace them with the NodeIds that your OPC UA client shows for your
  # machine (Objects > Machines > <machine tool instance> > ...).

  operationMode:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref umatiConnection
      topic: !sub '${topicRoot}/monitoring/operation-mode'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=ExampleMachineTool.Monitoring.MachineTool.OperationMode'

  powerOnDuration:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref umatiConnection
      topic: !sub '${topicRoot}/monitoring/power-on-duration'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=ExampleMachineTool.Monitoring.MachineTool.PowerOnDuration'

  # The stacklight element names (for example, Light0) are server-specific.
  # Browse Monitoring > Stacklight on your machine for the actual elements.

  stacklightSignalOn:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref umatiConnection
      topic: !sub '${topicRoot}/monitoring/stacklight/light-0/signal-on'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=ExampleMachineTool.Monitoring.Stacklight.Light0.SignalOn'

  stacklightSignalColor:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref umatiConnection
      topic: !sub '${topicRoot}/monitoring/stacklight/light-0/signal-color'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=ExampleMachineTool.Monitoring.Stacklight.Light0.SignalColor'

  # --------------------------------------------------------------------------
  # Active program (Production.ActiveProgram)
  # --------------------------------------------------------------------------

  programName:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref umatiConnection
      topic: !sub '${topicRoot}/production/active-program/name'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=ExampleMachineTool.Production.ActiveProgram.Name'

  programNumberInList:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref umatiConnection
      topic: !sub '${topicRoot}/production/active-program/number-in-list'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=ExampleMachineTool.Production.ActiveProgram.NumberInList'

  programState:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref umatiConnection
      topic: !sub '${topicRoot}/production/active-program/state'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=ExampleMachineTool.Production.ActiveProgram.State.CurrentState'
