package com.hdl.sdk.ttl.HDLDeviceManger.Bean; /** * Created by JLChen on 2019/7/24 */ public class MCUConfigurationBean { // 协议类型[1byte 0:Buspro,1:zigbee,2:KNX,3:Modbus, 5:自定义] // 波特率[1byte 0:1200,1:2400,2:4800:3:9600,4:19200,5:38400,6:57600,7:115200,8:250000] // 开始位[1byte 0: 固定1bit] // 数据位[1byte 0:8bit,1:9bit] // 校验位[1byte 0:无, 1:偶, 2:奇,] // 停止位[1byte 0:0.5bit, 1:bit, 2:2bit, 3:1.5bit] public static final int TYPE_BUSPRO = 0; public static final int TYPE_ZIGBEE = 1; public static final int TYPE_KNX = 2; public static final int TYPE_MODBUS = 3; public static final int TYPE_DIY = 5; // 波特率[1byte 0:1200,1:2400,2:4800:3:9600,4:19200,5:38400,6:57600,7:115200,8:250000] public static final int BAUDRATE_1200 = 0; public static final int BAUDRATE_2400 = 1; public static final int BAUDRATE_4800 = 2; public static final int BAUDRATE_9600 = 3; public static final int BAUDRATE_19200 = 4; public static final int BAUDRATE_38400 = 5; public static final int BAUDRATE_57600 = 6; public static final int BAUDRATE_115200 = 7; public static final int BAUDRATE_250000 = 8; //校验位[1byte 0:无, 1:偶, 2:奇,] public static final int CHECKBIT_NO = 0; public static final int CHECKBIT_EVEN = 1; public static final int CHECKBIT_ODD = 2; //停止位[1byte 0:0.5bit, 1:bit, 2:2bit, 3:1.5bit] public static final int STOPBIT_0_5 = 0; public static final int STOPBIT_1 = 1; public static final int STOPBIT_2 = 2; public static final int STOPBIT_1_5 = 3; //协议类型 private int mcuAgreementType; //波特率 private int mcuBaudrate; //开始位 private int mcuStartBit; //数据位 private int mcuDataBit; //检验位 private int mcuCheckBit; //停止位 private int mcuStopBit; /** * 魔镜MCU协议 * @return */ public byte[] getMCUConfigurationSendBytes() { //纠正异常数据 if(this.mcuAgreementType < 0 || this.mcuAgreementType > 5) this.mcuAgreementType = 0; if(this.mcuBaudrate < 0 || this.mcuBaudrate > 8) this.mcuBaudrate = 0; if(this.mcuDataBit < 0 || this.mcuDataBit > 1) this.mcuDataBit = 0; if(this.mcuCheckBit < 0 || this.mcuCheckBit > 2) this.mcuCheckBit = 0; if(this.mcuStopBit < 0 || this.mcuStopBit > 3) this.mcuStopBit = 0; byte[] sendBytes = new byte[6]; //Boot code sendBytes[0] = (byte) this.mcuAgreementType; sendBytes[1] = (byte) this.mcuBaudrate; //波特率 sendBytes[2] = (byte) 0; //开始位 sendBytes[3] = (byte) this.mcuDataBit; //数据位 sendBytes[4] = (byte) this.mcuCheckBit; //检验位 sendBytes[5] = (byte) this.mcuStopBit; //停止位 return sendBytes; } public int getMcuAgreementType() { return mcuAgreementType; } public void setMcuAgreementType(int mcuAgreementType) { this.mcuAgreementType = mcuAgreementType; } public int getMcuBaudrate() { return mcuBaudrate; } public void setMcuBaudrate(int mcuBaudrate) { this.mcuBaudrate = mcuBaudrate; } public int getMcuStartBit() { return mcuStartBit; } public void setMcuStartBit(int mcuStartBit) { this.mcuStartBit = mcuStartBit; } public int getMcuDataBit() { return mcuDataBit; } public void setMcuDataBit(int mcuDataBit) { this.mcuDataBit = mcuDataBit; } public int getMcuCheckBit() { return mcuCheckBit; } public void setMcuCheckBit(int mcuCheckBit) { this.mcuCheckBit = mcuCheckBit; } public int getMcuStopBit() { return mcuStopBit; } public void setMcuStopBit(int mcuStopBit) { this.mcuStopBit = mcuStopBit; } }