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

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

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

@Slf4j
public class ItemProtocol {
    public static String item_heartbeat = "heartbeat";
    public static String item_mode = "mode";
    public static String item_state = "state";
    public static String item_action = "action";
    public static String item_error = "error";
    public static String item_to_command = "to_command";
    public static String item_to_state ="to_state";


    private StandardAutodoorDeviceDriver driver;

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

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

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

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

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

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

    public int getToState() {
        return this.getOpcIntegerValue(item_to_state);
    }


    public int getOpcIntegerValue(String protocol) {
        Integer value = this.driver.getIntegeregerValue(protocol);
        if (value == null) {
            log.error("读取错误!");
        } else {
            return value;
        }
        return 0;

    }

    public static List<ItemDto> getReadableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0"));
        list.add(new ItemDto(item_mode, "工作模式", "DB600.B1", Boolean.valueOf(true)));
        list.add(new ItemDto(item_state, "工作状态", "DB600.B2"));
        list.add(new ItemDto(item_action, "动作信号", "DB600.B3"));
        list.add(new ItemDto(item_error, "报警信号", "DB600.B4"));
        return list;
    }

    public static List<ItemDto> getWriteableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_to_command, "作业命令", "DB601.W2", Boolean.valueOf(true)));
        list.add(new ItemDto(item_to_state, "下发状态", "DB601.W3", Boolean.valueOf(true)));
        return list;
    }

}

