package org.nl.acs.device.device_driver.standard_inspect;

import lombok.extern.slf4j.Slf4j;

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

//RD3.RD3.225.to_command
@Slf4j
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_task = "task";
    public static String item_container_quantity = "container_quantity";
    public static String item_container_code = "container_code";
    public static String item_to_command = "to_command";
    public static String item_to_target = "to_target";
    public static String item_to_task = "to_task";
    public static String item_weight = "weight";

    private BaseDeviceDriver driver;

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

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

    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, "心跳", "DB100.B0"));
        list.add(new ItemDto(item_mode, "工作状态", "DB100.B2", Boolean.valueOf(true)));
        list.add(new ItemDto(item_move, "光电开关信号", "DB100.B3"));
        list.add(new ItemDto(item_action, "动作信号", "DB100.B4"));
        list.add(new ItemDto(item_error, "报警信号", "DB100.B5"));
        list.add(new ItemDto(item_task, "任务号", "DB100.D6"));
        return list;
    }

    public static List<ItemDto> getWriteableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(item_to_command, "作业命令", "DB200.W2", Boolean.valueOf(true)));
        list.add(new ItemDto(item_to_target, "目标站", "DB200.W4"));
        list.add(new ItemDto(item_to_task, "任务号", "DB200.D6"));
        return list;
    }

}

