package com.mvc.netty.xmodem;

/**
 * X-Modem协议控制字符枚举
 */
public enum ControlChar {
    SOH("128字节头", (byte)0x01,"SOH","01"),
    STX("1024字节头", (byte)0x02,"STX","02"),
    EOT("发送结束标志", (byte)0x04,"EOT","04"),
    ACK("应答标志", (byte)0x06,"ACK","06"),
    NAK("非应答标志", (byte)0x15,"NAK","15"),
    CAN("取消发送标志", (byte)0x18,"CAN","18"),
    CTL_C("起始字符", (byte)0x43,"C","43")
    ;

    //指令描述
    private String desc;

    //指令byte值
    private byte value;

    //指令ASCII描述
    private String ascii;

    //指令byte十六进制字符串
    private String hex;

    ControlChar(String desc, byte value,String ascii,String hex) {
        this.desc = desc;
        this.value = value;
        this.ascii=ascii;
        this.hex=hex;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public byte getValue() {
        return value;
    }

    public void setValue(byte value) {
        this.value = value;
    }

    public String getAscii() {
        return ascii;
    }

    public void setAscii(String ascii) {
        this.ascii = ascii;
    }

    public String getHex() {
        return hex;
    }

    public void setHex(String hex) {
        this.hex = hex;
    }

    /**
     * 根据十六进制Value字符串获取枚举对象
     * @param value
     * @return
     */
    public static ControlChar getEnumByHexString(String value){
        for(ControlChar temp:ControlChar.values()){
            if(temp.getHex().equals(value)){
                return temp;
            }
        }
        return null;
    }

    /**
     * 根据Value获取枚举对象
     * @param value
     * @return
     */
    public static ControlChar getEnumByValue(byte value){
        for(ControlChar temp:ControlChar.values()){
            if(temp.getValue()==value){
                return temp;
            }
        }
        return null;
    }
}
