package org.nl.acs.device_driver.basedriver.hongxiang_device;

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_door = "door";
    public static String item_temperature = "temperature";
    //恒温倒计时
    public static String item_countdown_house = "countdown_house";
    public static String item_countdown_min = "countdown_min";
    public static String item_countdown_sec = "countdown_sec";

    public static String item_finish = "finish";
    public static String item_task = "task";
    public static String item_error1 = "error1";
    public static String item_material = "material";
    public static String item_consumption = "consumption";
    public static String item_voltageA = "voltageA";
    public static String item_voltageB = "voltageB";
    public static String item_voltageC = "voltageC";
    public static String item_currentA = "currentA";
    public static String item_currentB = "currentB";
    public static String item_currentC = "currentC";


    public static String item_to_command = "to_command";
    public static String item_to_open_door = "to_open_door";
    public static String item_to_close_door = "to_close_door";
    public static String item_to_temperature = "to_temperature";
    public static String item_to_material = "to_material";
    public static String item_to_time_house = "to_time_house";
    public static String item_to_time_min = "to_time_min";
    public static String item_to_time_sec = "to_time_sec";

    public static String item_to_task = "to_task";


    private HongXiangConveyorDeviceDriver driver;

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

    public int getItem_heartbeat(){
        return this.getOpcIntegerValue(item_heartbeat);
    } ;
    public int getItem_mode(){
        return this.getOpcIntegerValue(item_mode);
    } ;
    public int getItem_move(){
        return this.getOpcIntegerValue(item_move);
    } ;
    public int getItem_action(){
        return this.getOpcIntegerValue(item_action);
    };
    public int getItem_error(){
        return this.getOpcIntegerValue(item_error);
    } ;
    public int getItem_door(){
        return this.getOpcIntegerValue(item_door);
    } ;
    public int getItem_temperature(){
        return this.getOpcIntegerValue(item_temperature);
    } ;
    public int getItem_countdown_house(){
        return this.getOpcIntegerValue(item_countdown_house);
    } ;
    public int getItem_countdown_min(){
        return this.getOpcIntegerValue(item_countdown_min);
    } ;
    public int getItem_countdown_sec(){
        return this.getOpcIntegerValue(item_countdown_sec);
    } ;
    public int getItem_finish(){
        return this.getOpcIntegerValue(item_finish);
    } ;
    public int getItem_task(){
        return this.getOpcIntegerValue(item_task);
    } ;
    public int getItem_error1(){
        return this.getOpcIntegerValue(item_error1);
    } ;
    public int getItem_material(){
        return this.getOpcIntegerValue(item_material);
    } ;
    public int getItem_consumption(){
        return this.getOpcIntegerValue(item_consumption);
    } ;
    public float getItem_voltageA(){
        return this.getOpcFloatValue(item_voltageA);
    } ;
    public float getItem_voltageB(){
        return this.getOpcFloatValue(item_voltageB);
    } ;
    public float getItem_voltageC(){
        return this.getOpcFloatValue(item_voltageC);
    } ;
    public float getItem_currentA(){
        return this.getOpcFloatValue(item_currentA);
    } ;
    public float getItem_currentB(){
        return this.getOpcFloatValue(item_currentB);
    } ;
    public float getItem_currentC(){
        return this.getOpcFloatValue(item_currentC);
    } ;

    Boolean isonline;

    public int getOpcIntegerValue(String protocol) {
        Integer value = this.driver.getIntegeregerValue(protocol);
        if (value == null) {
            setIsonline(false);
        } else {
            setIsonline(true);
            return value;
        }
        return 0;

    }

    public float getOpcFloatValue(String protocol) {
        Float value = this.driver.getDoubleValue(protocol);
        if (value == null) {
            setIsonline(false);
        } else {
            setIsonline(true);
            return value;
        }
        return 0L;

    }

    public static List<ItemDto> getReadableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_heartbeat, "心跳", "251"));
        list.add(new ItemDto(item_mode, "工作模式", "7990"));
        list.add(new ItemDto(item_move, "光电信号", "550"));
        list.add(new ItemDto(item_door, "门状态", "450"));
        list.add(new ItemDto(item_temperature, "工位温度", "7991"));
        list.add(new ItemDto(item_countdown_house, "恒温倒计时(时)", "80500"));
        list.add(new ItemDto(item_countdown_min, "恒温倒计时(分)", "80502"));
        list.add(new ItemDto(item_countdown_sec, "恒温倒计时(秒)", "80504"));
        list.add(new ItemDto(item_finish, "烘干完成", "8025"));
        list.add(new ItemDto(item_action, "取放信号", "450"));
        list.add(new ItemDto(item_task, "任务号", "220"));
        list.add(new ItemDto(item_error, "故障", "8055"));
        list.add(new ItemDto(item_error1, "故障1", "216"));
        list.add(new ItemDto(item_material, "物料", "223"));
        list.add(new ItemDto(item_consumption, "电能耗", "8092"));
        list.add(new ItemDto(item_voltageA, "A相电压", "8080"));
        list.add(new ItemDto(item_voltageB, "B相电压", "8082"));
        list.add(new ItemDto(item_voltageC, "C相电压", "8084"));
        list.add(new ItemDto(item_currentA, "A相电流", "8086"));
        list.add(new ItemDto(item_currentB, "B相电流", "8088"));
        list.add(new ItemDto(item_currentC, "C相电流", "8090"));
        return list;
    }

    public static List<ItemDto> getWriteableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_to_command, "下发命令", "40226"));
        list.add(new ItemDto(item_to_open_door, "开门", "00111"));
        list.add(new ItemDto(item_to_close_door, "关门", "00112"));
        list.add(new ItemDto(item_to_temperature, "生产温度", "48100"));
        list.add(new ItemDto(item_to_material, "生产物料", "40229"));
        list.add(new ItemDto(item_to_time_house, "生产时间(时)", "48771"));
        list.add(new ItemDto(item_to_time_min, "生产时间(分)", "48770"));
        list.add(new ItemDto(item_to_task, "任务号", "40232"));
        return list;
    }

    @Override
    public String toString() {
        return "";
    }

}

