---
# ----------------------------------------------------------------------------#
# Cybus Connectware Device Commissioning File
# Device: Sinumerik OPC UA Reference Device
# ----------------------------------------------------------------------------#
# Copyright: Cybus GmbH (2020)
# Contact: support@cybus.io
# ----------------------------------------------------------------------------#
description: >
  Sinumerik OPC UA Reference Device

metadata:
  name: Sinumerik 840D
  icon: https://www.cybus.io/wp-content/uploads/2017/10/for-whom1.svg
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.0.0

parameters:
  host:
    type: string
    default: 192.168.0.1

  port:
    type: integer
    default: 4840

  username:
    type: string
    default: ''

  password:
    type: string
    default: ''

resources:
  sinumerikConnection:
    type: Cybus::Connection
    properties:
      protocol: Sinumerik
      connection:
        host: !ref host
        port: !ref port
        username: !ref username
        password: !ref password

  # Machine information

  # Machine info
  getMachineInfoSubscription:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        pollInterval: 5000
        method: getMachineInfo

  getMachineInfo:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getMachineInfo

  # Machine state
  # { anPoweronState,
  #   poweronTime,
  #   licenseStatus,
  #   nckMode,
  #   sysTimeSinceStartup,
  #   progStatus,
  #   progName } = getMachineState()
  getMachineStateSubscription:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        pollInterval: 5000
        method: getMachineState

  getMachineState:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getMachineState

  # On NC-Program change
  # { progStatus, progName } = onNcProgramChanged()
  onNcProgramChangedSubscription:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        method: onNcProgramChanged

  # Spindle Speed
  # { actSpeed, cmdSpeed } = getSpindleSpeed()
  getSpindleSpeed:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getSpindleSpeed

  # Spindle Feed
  # { acConstCutS, cmdConstCutSpeed } = getSpindleFeed
  getSpindleFeed:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getSpindleFeed

  # TOOLS

  # Get tool
  # tool = getTool(toolNo)
  getTool:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getTool

  # Get complete tool
  # tool = getToolComplete(toolNo)
  getToolComplete:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getToolComplete

  # Read tools
  # tools = getTools()
  getTools:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getTools

  # Read complete tools
  # tools = getToolsComplete()
  getToolsComplete:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getToolsComplete

  # Get tools in magazine
  # toolsInMagazine = getToolsInMagazine(toolNo)
  getToolsInMagazine:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getToolsInMagazine

  # Get tools in magazines
  # toolsInMagazine = getToolsInMagazines()
  getToolsInMagazines:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getToolsInMagazines

  # Create tool
  # createTool(toolNo, fields)
  createTool:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: createTool

  # Set tool fields
  # setToolFields(toolNo, fields)
  setToolFields:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: setToolFields

  # Set tool
  # toolNo = setTool(toolNo, toolInMag, toolinPlace, fields)
  setTool:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: setTool

  # Delete tool
  # deleteTool(toolNo)
  deleteTool:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: deleteTool

  # Delete Tool And Unload
  # deleteToolAndUnload(toolNo)
  deleteToolAndUnload:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: deleteToolAndUnload

  # Load tool into magazine
  # loadTool(toolInMag, toolInPlace, toolNo)
  loadTool:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: loadTool

  # Unload tool from magazine
  # unloadTool(toolInMag, toolInPlace)
  unloadTool:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: unloadTool

  # On active tool change
  # { active: {...}, previous: {...} } = onActiveToolChanged()
  onActiveToolChangedSubscription:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        method: onActiveToolChanged

  # On tool change
  # { toolNo, fields, previousFields } = onToolChanged()
  onToolChangedSubscription:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        method: onToolChanged

  # On magazine tool change
  # { magNo, magPlace, toolNo } = onMagazineToolChanged()
  onMagazineToolChangedSubscription:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      subscribe:
        type: poll
        method: onMagazineToolChanged

  # MAGAZINES

  # Get magazine
  # magazine = getMagazine(magNo)
  getMagazine:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getMagazine

  # Get magazines
  # magazines = getMagazines()
  getMagazines:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: getMagazines

  # FILES

  # Read file
  # { path, data } = readFile(path)
  readFile:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: readFile

  # Write file
  # path = writeFile(path, data, overwrite)
  writeFile:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: writeFile

  # Read directory
  # { path, entries } = readDirectory(path)
  readDirectory:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: readDirectory

  # Delete directory
  # path = deleteDirectory(path)
  deleteDirectory:
    type: Cybus::Endpoint
    properties:
      protocol: Sinumerik
      connection: !ref sinumerikConnection
      read:
        method: deleteDirectory
