package com.imdroid.vermgr.entity;

import lombok.Data;

import java.sql.Timestamp;

//member name must be same as the field name in mysql
@Data
public class DeviceApp {
    //0:未连接；1：连接；2：升级中；3：传输完成；4：升级失败
    public static final short STATE_DISCONNECTED = 0;
    public static final short STATE_CONNECTED = 1;
    public static final short STATE_UPGRADING = 2;
    public static final short STATE_TX_COMPLETED = 3;
    public static final short STATE_TX_FAILED = 4;
    public static final String[] state_description = {
            "未连接","连接","升级中","发送完成","发送失败"
    };
    public static final String[] result_description = {
            "成功","其他错误","传输中断","超时","数据错误","超时","保存失败","文件错误"
    };

    long device_sn = 0;
    String version;
    String firmware;
    short upgrade_state = STATE_DISCONNECTED;
    short upgrade_result;   //失败原因
    Timestamp upgrade_time;
    String strState;
    String strResult;

    public void translateCode() {
        if(upgrade_state>STATE_TX_FAILED) upgrade_state=STATE_DISCONNECTED;
        strState = state_description[upgrade_state];
        if(upgrade_result>7) upgrade_result=7;
        strResult = result_description[upgrade_result];
    }

}
