package com.xixun.communicate.Protocol;

/**
 * Created by Administrator on 2018/01/18.
 */

public enum NET_COMMU_TYPE {
    NONE(0x00),
    TICK(1),
    FPGA_MOONCELL(2),

    UART_SENSOR(3),
    UART_FPGA(4),
    UART_EXTENSION(5),

    MOONCELL_FPAG(7),
    FGPA_UPDATE_ACK(0x09),
    FGPA_VERSION_ACK(0x3C),

    FGPA_UPDATE(0x09+0x40),
    FGPA_VERSION(0x3C+0x40),
    NUM(0xFF);

    // 定义私有变量
    private int ucCommandType=0;

    // 构造函数，枚举类型只能为私有
    NET_COMMU_TYPE(int ucCommandType) {
        this.ucCommandType = ucCommandType;
    }

    public static NET_COMMU_TYPE GetEnumValue(byte ucCommandType){   //   手写的从int到enum的转换函数
        switch(ucCommandType) {
            case 0:         return NONE;
            case 1:         return TICK;
            case 2:         return FPGA_MOONCELL;

            case 3:         return UART_SENSOR;
            case 4:         return UART_FPGA;
            case 5:         return UART_EXTENSION;

            case 7:         return MOONCELL_FPAG;
            case 0x09:      return FGPA_UPDATE_ACK;
            case 0x3C:      return FGPA_VERSION_ACK;

            case (0x09+0x40):      return FGPA_UPDATE;
            case (0x3C+0x40):      return FGPA_VERSION;


            default:        return NONE;
        }
    }
    public byte getValue()
    {   return (byte)ucCommandType;
    }
    @Override
    public String toString() {
        return String.valueOf(ucCommandType);
    }

}
