package org.nl.acs.device_driver.tianneng.site;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Data
public class ItemProtocol {

    public static String item_heartbeat = "heartbeat";
    public static String item_mode = "mode";
    public static String item_move = "move";
    public static String item_action = "action";
    public static String item_error = "error";
    public static String item_pallet_type = "pallet_type";
    public static String item_to_command = "to_command";

//    public static String open_time = "open_time";
//    public static String off_time = "off_time";
//    public static String standby_time1 = "standby_time1";
//    public static String production_time1 = "production_time1";
//    public static String error_time1 = "error_time1";
//    public static String standby_time2 = "standby_time2";
//    public static String production_time2 = "production_time2";
//    public static String error_time2 = "error_time2";



    private SiteDeviceDriver driver;

    public ItemProtocol(SiteDeviceDriver driver) {
        this.driver = driver;
    }

    public int getHeartbeat() {
        return this.getOpcIntegerValue(item_heartbeat);
    }

    public int getMode() {
        return this.getOpcIntegerValue(item_mode);
    }

    public int getMove() {
        return this.getOpcIntegerValue(item_move);
    }

    public int getAction() {
        return this.getOpcIntegerValue(item_action);
    }

    public int getError() {
        return this.getOpcIntegerValue(item_error);
    }

    public int getPalletType() {
        return this.getOpcIntegerValue(item_pallet_type);
    }

    public int getToCommand() {
        return this.getOpcIntegerValue(item_to_command);
    }

    //是否有货
    public int hasGoods(int move) {
        return move;
    }

    Boolean isonline;

    public int getOpcIntegerValue(String protocol) {
        Integer value = this.driver.getIntegeregerValue(protocol);
        if (value == null) {
//             log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
            setIsonline(false);
        } else {
            setIsonline(true);
            return value;
        }
        return 0;

    }

    public static List<ItemDto> getReadableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_heartbeat, "心跳", "DB6.DBB0"));
        list.add(new ItemDto(item_mode, "工作状态", "DB6.DBB2", Boolean.valueOf(true)));
        list.add(new ItemDto(item_move, "光电信号", "DB6.DBB3"));
        list.add(new ItemDto(item_action, "取放信号", "DB6.DBB4"));
        list.add(new ItemDto(item_error, "error", "DB6.DBB7"));
        list.add(new ItemDto(item_pallet_type, "托盘类型", "DB6.DBB6"));
        return list;
    }

    public static List<ItemDto> getReadableItemDtos1() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_heartbeat, "心跳", "DB6.DBB0"));
        list.add(new ItemDto(item_mode, "工作状态", "DB6.DBB52", Boolean.valueOf(true)));
        list.add(new ItemDto(item_move, "光电信号", "DB6.DBB53"));
        list.add(new ItemDto(item_action, "取放信号", "DB6.DBB54"));
        list.add(new ItemDto(item_error, "error", "DB6.DBB57"));
        list.add(new ItemDto(item_pallet_type, "托盘类型", "DB6.DBB56"));
        return list;
    }

    public static List<ItemDto> getReadableItemDtos2() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_heartbeat, "心跳", "DB6.DBB0"));
        list.add(new ItemDto(item_mode, "工作状态", "DB6.DBB102", Boolean.valueOf(true)));
        list.add(new ItemDto(item_move, "光电信号", "DB6.DBB103"));
        list.add(new ItemDto(item_action, "取放信号", "DB6.DBB104"));
        list.add(new ItemDto(item_error, "error", "DB6.DBB107"));
        list.add(new ItemDto(item_pallet_type, "托盘类型", "DB6.DBB106"));
        return list;
    }

    public static List<ItemDto> getReadableItemDtos3() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_heartbeat, "心跳", "DB6.DBB0"));
        list.add(new ItemDto(item_mode, "工作状态", "DB6.DBB152", Boolean.valueOf(true)));
        list.add(new ItemDto(item_move, "光电信号", "DB6.DBB153"));
        list.add(new ItemDto(item_action, "取放信号", "DB6.DBB154"));
        list.add(new ItemDto(item_error, "error", "DB6.DBB157"));
        list.add(new ItemDto(item_pallet_type, "托盘类型", "DB6.DBB156"));
        return list;
    }

    public static List<ItemDto> getReadableItemDtos4() {
        ArrayList list = new ArrayList();
        //        list.add(new ItemDto(open_time, "开机上报 ", "DB6.DTL770"));
        //        list.add(new ItemDto(off_time, "关机上报", "DB6.DTL782"));
        //        list.add(new ItemDto(standby_time1, "当前待机时间1", "DB6.DBD794"));
        //        list.add(new ItemDto(production_time1, "当前生产时间1", "DB6.DBD798"));
        //        list.add(new ItemDto(error_time1, "当前故障时间1", "DB6.DBD802"));
        //        list.add(new ItemDto(standby_time2, "当前待机时间2", "DB6.DBD806"));
        //        list.add(new ItemDto(production_time2, "当前生产时间2", "DB6.DBD810"));
        //        list.add(new ItemDto(error_time2, "当前故障时间2", "DB6.DBD814"));
        return list;
    }




    public static List<ItemDto> getWriteableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_to_command, "作业命令", "DB7.DBW2", Boolean.valueOf(true)));
        return list;
    }

    public static List<ItemDto> getWriteableItemDtos1() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_to_command, "作业命令", "DB7.DBW52", Boolean.valueOf(true)));
        return list;
    }

    public static List<ItemDto> getWriteableItemDtos2() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_to_command, "作业命令", "DB7.DBW102", Boolean.valueOf(true)));
        return list;
    }
    public static List<ItemDto> getWriteableItemDtos3() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_to_command, "作业命令", "DB7.DBW152", Boolean.valueOf(true)));
        return list;
    }


}

