# yaml-language-server: $schema=http://json-schema.org/draft-07/schema
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
# SPDX-License-Identifier: Apache-2.0
---
allOf:
- type: object
  anyOf:
  - required: [transport, remote]
    properties:

      transport:
        type: string
        enum:
        - tcp

      remote:
        type: string
        description: The hostname or IP of the modbus TCP device.
        example: example.com

      port:
        type: integer
        description: The port number of the modbus TCP device.
        default: 1883

      unit:
        type: integer
        description: The addressed unit used for serial communication. This is optional for TCP.
        minimum: 0
        maximum: 65535
        example: 1

  - required: [transport, device, baudrate, parity, data_bits, stop_bits, unit]
    properties:

      transport:
        type: string
        enum:
        - rtu

      device:
        type: string
        description: Path to the serial device file.
        example: /dev/ttyS0

      baudrate:
        type: integer
        description: The baudrate used for serial communication.
        example: 9600

      parity:
        type: string
        enum:
        - none
        - even
        - odd
        description: The parity used for serial communication.
        example: none

      data_bits:
        type: integer
        description: The data bits used for serial communication.
        minimum: 5
        maximum: 8
        example: 5

      stop_bits:
        type: integer
        description: The stop bits used for serial communication.
        minimum: 1
        maximum: 2
        example: 5

      unit:
        type: integer
        description: The addressed unit used for serial communication. This is optional for TCP.
        minimum: 0
        maximum: 65535
        example: 1

  properties:

    response_timeout:
      type: number
      description: The timeout in seconds when waiting for responses from a modbus server.
      example: 1.0

    rate:
      type: number
      description: The rate at which modbus device registers are queried for changes.
      example: 1.0

    in:
      type: object
      properties:
        signals:
          type: array
          items:
            $ref: ./signals/modbus_signal.yaml

    out:
      type: object
      properties:
        signals:
          type: array
          items:
            $ref: ./signals/modbus_signal.yaml

- $ref: ../node.yaml