package com.jwk.spring.boot.autoconfigure;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @author JWK
 * @version 1.0
 * @date 2022/12/2 15:40
 */
@Data
@ConfigurationProperties(prefix = ModbusProperties.DEMO_PREFIX)
public class ModbusProperties {

    public static final String DEMO_PREFIX = "modbus";

    private RtuMaster rtuMaster;
    private TcpMaster tcpMaster;

    @Data
    public static class RtuMaster {
        /**
         * 是否打开串口
         */
        private boolean open = false;
        /**
         * 串口
         */
        private String port = "COM1";

        /**
         * 波特率
         */
        private Integer baudRate = 9600;

        /**
         * 数据位的位数，RTU是8位，ASCII是7位
         */
        private Integer dataBits = 8;

        /**
         * 停止位的位数，如果无奇偶校验为2，有奇偶校验为1
         */
        private Integer stopBits = 1;

        /**
         * 奇偶校验位，无校验是0，奇校验是1，偶校验是2
         */
        private Integer parity = 0;

        /**
         * 硬件之间输入流应答控制
         */
        private Integer flowControlIn = 0;

        /**
         * 硬件之间输出流应答控制
         */
        private Integer flowControlOut = 0;

    }

    @Data
    public static class TcpMaster {
        /**
         * 是否打开Tcp连接
         */
        private boolean open = false;

        /**
         * ip
         */
        private String host = "localhost";

        /**
         * 端口
         */
        private Integer port;
    }
}
