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

description: >
  Service commissioning file for reading machine status, job information, and
  cycle data from an injection molding machine that implements EUROMAP 77
  (OPC 40077) (Example)

metadata:
  name: EUROMAP 77 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 EUROMAP 77 instance nodes on your machine. Resolve
      it from the NamespaceArray (ns=0;i=2255) of your machine's OPC UA server.
    type: integer
    default: 4

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

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

  # --------------------------------------------------------------------------
  # Machine status (MachineStatusType, defined in OPC 40083)
  # --------------------------------------------------------------------------
  # All NodeId string identifiers below are machine-specific examples.
  # Replace them with the NodeIds that your OPC UA client shows for your
  # machine (Objects > DeviceSet > IMM_<Manufacturer>_<SerialNumber> > ...).

  machineMode:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/machine-status/machine-mode'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.MachineStatus.MachineMode'

  isPresent:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/machine-status/is-present'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.MachineStatus.IsPresent'

  # --------------------------------------------------------------------------
  # Job information (Jobs.ActiveJob and Jobs.ActiveJobValues)
  # --------------------------------------------------------------------------

  jobName:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/job/name'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.Jobs.ActiveJob.JobName'

  productionDatasetName:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/job/production-dataset-name'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.Jobs.ActiveJob.ProductionDatasetName'

  jobStatus:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/job/status'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.Jobs.ActiveJobValues.JobStatus'

  jobPartsCounter:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/job/parts-counter'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.Jobs.ActiveJobValues.JobPartsCounter'

  jobGoodPartsCounter:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/job/good-parts-counter'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.Jobs.ActiveJobValues.JobGoodPartsCounter'

  jobBadPartsCounter:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/job/bad-parts-counter'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.Jobs.ActiveJobValues.JobBadPartsCounter'

  # --------------------------------------------------------------------------
  # Cycle data (Jobs.ActiveJobValues)
  # --------------------------------------------------------------------------
  # These values update with every machine cycle, so they are grouped into a
  # faster subscription than the job information above.

  machineCycleCounter:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/cycle/machine-cycle-counter'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.Jobs.ActiveJobValues.MachineCycleCounter'
        publishInterval: 500
        samplingInterval: 500

  lastCycleTime:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/cycle/last-cycle-time'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.Jobs.ActiveJobValues.LastCycleTime'
        publishInterval: 500
        samplingInterval: 500

  averageCycleTime:
    type: Cybus::Endpoint
    properties:
      protocol: Opcua
      connection: !ref euromapConnection
      topic: !sub '${topicRoot}/cycle/average-cycle-time'
      subscribe:
        nodeId: !sub 'ns=${namespaceIndex};s=IMM_EXAMPLE_0123456.Jobs.ActiveJobValues.AverageCycleTime'
        publishInterval: 500
        samplingInterval: 500
