package org.nl.acs.device_driver.basedriver.agv.xg_agv;

import cn.hutool.core.util.ObjectUtil;
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 is_charging = "is_charging";
    public static String stop = "stop";
    public static String DI0 = "DI0";
    public static String DI1 = "DI1";
    public static String DI2 = "DI2";
    public static String DI3 = "DI3";
    public static String DI4 = "DI4";
    public static String DI11 = "DI12";
    public static String DI12 = "DI12";
    public static String DO0 = "DO0";
    public static String DO1 = "DO1";
    public static String DO2 = "DO2";
    public static String x = "x";
    public static String y = "y";
    public static String angle = "angle";
    //站点的 id 号, 0 表示无导航站点
    public static String navigation_address = "navigation_address";
    //0 = 定位失败, 1 = 定位正确, 2 = 正在重定位, 3 = 定位完成；机器人刚启动后，定位状态为 2，
    // 当定位状态变为 3 时，可以用 [0x]00003 地址位确认定位正确，确认后定位状态将变为 1
    public static String positioning_status = "positioning_status";
    //0 = 无, 1 = 等待执行导航, 2 = 正在执行导航, 3 = 导航暂停, 4 = 到达, 5 = 失败, 6 = 取消, 7 = 超时
    public static String navigation_status = "navigation_status";
    //0 = 没有导航, 1 = 自由导航到任意点, 2 = 自由导航到站点, 3 = 路径导航到站点, 7 = 平动转动, 100 = 其他
    public static String navigation_type = "navigation_type";
    //范围为 0 ~ 1
    public static String electricity = "electricity";
    public static String address = "address";
    public static String next_address = "next_address";
    public static String home_relocation = "home_relocation";
    //确认定位正确
    public static String locate_correct = "locate_correct";
    public static String pause_navigation = "pause_navigation";
    public static String continue_navigation = "continue_navigation";
    public static String cancle_navigation = "cancle_navigation";
    //滚筒运行状态
    public static String drum_run_status = "drum_run_status";


    public static String to_home_relocation = "to_home_relocation";
    //确认定位正确
    public static String to_locate_correct = "to_locate_correct";
    public static String to_pause_navigation = "to_pause_navigation";
    public static String to_continue_navigation = "to_continue_navigation";
    public static String to_cancle_navigation = "to_cancle_navigation";
    public static String to_DO0_height = "to_DO0_height";
    public static String to_DO0_low = "to_DO0_low";
    public static String to_DO1_height = "to_DO1_height";
    public static String to_DO1_low = "to_DO1_low";
    public static String to_DO2_low = "to_DO2_low";
    public static String to_DO8_low = "to_DO8_low";
    public static String to_DO9_low = "to_DO9_low";

    public static String to_address = "to_address";
    public static String to_clear_error = "to_clear_error";
    //虚拟高电平写
    public static String to_di_height = "to_di_height";
    //虚拟低电平写
    public static String to_di_low = "to_di_low";
    //下发任务链
    public static String to_line = "to_line";


    public int getIs_charging() {
        return this.getOpcIntegerValue(is_charging);
    }

    public int getStop() {
        return this.getOpcIntegerValue(stop);
    }

    public int getDI0() {
        return this.getOpcIntegerValue(DI0);
    }

    public int getDI1() {
        return this.getOpcIntegerValue(DI1);
    }

    public int getDI2() {
        return this.getOpcIntegerValue(DI2);
    }

    public  int getDI3() {
        return this.getOpcIntegerValue(DI3);
    }

    public  int getDI4() {
        return this.getOpcIntegerValue(DI4);

    }

    public  int getDI11() {
        return this.getOpcIntegerValue(DI11);

    }

    public  int getDI12() {
        return this.getOpcIntegerValue(DI12);

    }

    public  int getDO0() {
        return this.getOpcIntegerValue(DO0);

    }

    public  int getDO1() {
        return this.getOpcIntegerValue(DO1);

    }
    public  int getDO2() {
        return this.getOpcIntegerValue(DO2);

    }

    public  Float getX() {
        return this.getOpcFloatValue(x);

    }

    public  Float getY() {
        return this.getOpcFloatValue(y);

    }

    public  Float getAngle() {
        return this.getOpcFloatValue(angle);

    }

    public  short getNavigation_address() {
        return this.getOpcShortValue(navigation_address);

    }

    public  short getPositioning_status() {
        return this.getOpcShortValue(positioning_status);
    }

    public  short getNavigation_status() {
        return this.getOpcShortValue(navigation_status);
    }

    public  short getNavigation_type() {
        return this.getOpcShortValue(navigation_type);

    }

    public  int getElectricity() {
        return this.getOpcIntegerValue(electricity);

    }

    public  int getAddress() {
        return this.getOpcIntegerValue(address);

    }

    public  short getNext_address() {
        return this.getOpcShortValue(next_address);
    }

    public  int getHome_relocation() {
        return this.getOpcIntegerValue(home_relocation);

    }

    public  int getLocate_correct() {
        return this.getOpcIntegerValue(locate_correct);

    }

    public  int getPause_navigation() {
        return this.getOpcIntegerValue(pause_navigation);

    }

    public  int getContinue_navigation() {
        return this.getOpcIntegerValue(continue_navigation);

    }

    public  int getCancle_navigation() {
        return this.getOpcIntegerValue(cancle_navigation);
    }

    public  short getDrum_run_status() {
        return this.getOpcShortValue(drum_run_status);
    }

    public static void setTo_home_relocation(String to_home_relocation) {
        ItemProtocol.to_home_relocation = to_home_relocation;
    }

    public static void setTo_locate_correct(String to_locate_correct) {
        ItemProtocol.to_locate_correct = to_locate_correct;
    }

    public static void setTo_pause_navigation(String to_pause_navigation) {
        ItemProtocol.to_pause_navigation = to_pause_navigation;
    }

    public static void setTo_continue_navigation(String to_continue_navigation) {
        ItemProtocol.to_continue_navigation = to_continue_navigation;
    }

    public static void setTo_cancle_navigation(String to_cancle_navigation) {
        ItemProtocol.to_cancle_navigation = to_cancle_navigation;
    }

    public static void setTo_DO0_height(String to_DO0_height) {
        ItemProtocol.to_DO0_height = to_DO0_height;
    }

    public static void setTo_DO0_low(String to_DO0_low) {
        ItemProtocol.to_DO0_low = to_DO0_low;
    }

    public static void setTo_DO1_height(String to_DO1_height) {
        ItemProtocol.to_DO1_height = to_DO1_height;
    }

    public static void setTo_DO1_low(String to_DO1_low) {
        ItemProtocol.to_DO1_low = to_DO1_low;
    }

    public static void setTo_DO8_low(String to_DO8_low) {
        ItemProtocol.to_DO8_low = to_DO8_low;
    }

    public static void setTo_DO9_low(String to_DO9_low) {
        ItemProtocol.to_DO9_low = to_DO9_low;
    }


    public static void setTo_address(String to_address) {
        ItemProtocol.to_address = to_address;
    }

    public static void setTo_clear_error(String to_clear_error) {
        ItemProtocol.to_clear_error = to_clear_error;
    }

    public static void setTo_di_height(String to_di_height) {
        ItemProtocol.to_di_height = to_di_height;
    }

    public static void setTo_di_low(String to_di_low) {
        ItemProtocol.to_di_low = to_di_low;
    }

    private XgagvDeviceDriver driver;

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

    public ItemProtocol() {

    }


    public Float getOpcFloatValue(String protocol) {
        Float value = this.driver.getFloatValue(protocol);
        if (ObjectUtil.isEmpty(value)) {

        } else {
            return value;
        }
        return 0.0f;
    }

    public int getOpcIntegerValue(String protocol) {
        Integer value = this.driver.getIntegerValue(protocol);
        if (value == null) {

        } else {
            return value;
        }
        return 0;

    }

    public short getOpcShortValue(String protocol) {
        Short value = this.driver.getShortValue(protocol);
        if (value == null) {

        } else {
            return value;
        }
        return 0;

    }

    public static List<ItemDto> getReadableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(is_charging, "是否充电", "10003"));
        list.add(new ItemDto(DI0, "DI0", "10020"));
        list.add(new ItemDto(DI1, "DI1", "10021"));
        list.add(new ItemDto(DI2, "DI2", "10022"));
        list.add(new ItemDto(DI3, "DI3", "10023"));
        list.add(new ItemDto(DI4, "DI4", "10024"));
        list.add(new ItemDto(DO1, "DO1", "10061"));
        list.add(new ItemDto(DO2, "DO2", "10062"));
        list.add(new ItemDto(DI11, "DI11", "10031"));
        list.add(new ItemDto(DI12, "DI12", "10032"));
        list.add(new ItemDto(x, "x", "30001"));
        list.add(new ItemDto(y, "y", "30003"));
        list.add(new ItemDto(angle, "angle", "30005"));
        list.add(new ItemDto(navigation_address, "当前导航站点", "30007"));
        list.add(new ItemDto(positioning_status, "定位状态", "30008"));
        list.add(new ItemDto(navigation_status, "当前导航状态", "30009"));
        list.add(new ItemDto(navigation_type, "当前导航类型", "30010"));
        list.add(new ItemDto(electricity, "电量", "30013"));
        list.add(new ItemDto(address, "当前所在站点", "30034"));
        list.add(new ItemDto(next_address, "下一个要经过的站点", "30036"));
        list.add(new ItemDto(home_relocation, "在Home点重定位", "00002"));
        list.add(new ItemDto(locate_correct, "确认定位正确", "00003"));
        list.add(new ItemDto(pause_navigation, "暂停导航", "00004"));
        list.add(new ItemDto(continue_navigation, "继续导航", "00005"));
        list.add(new ItemDto(cancle_navigation, "取消导航", "00006"));
        list.add(new ItemDto(drum_run_status, "滚筒运行状态", "30062"));
        list.add(new ItemDto(stop, "车子停止", "10019"));


        return list;
    }

    public static List<ItemDto> getWriteableItemDtos() {
        ArrayList list = new ArrayList();
        list.add(new ItemDto(to_home_relocation, "to_在Home点重定位", "00002"));
        list.add(new ItemDto(to_locate_correct, "to_确认定位正确", "00003"));
        list.add(new ItemDto(to_pause_navigation, "to_暂停导航", "00004"));
        list.add(new ItemDto(to_continue_navigation, "to_继续导航", "00005"));
        list.add(new ItemDto(to_cancle_navigation, "to_取消导航", "00006"));
        list.add(new ItemDto(to_DO0_height, "to_DO0置为高电平", "00061"));
        list.add(new ItemDto(to_DO0_low, "to_DO0置为低电平", "00020"));
        list.add(new ItemDto(to_DO1_height, "to_DO1置为高电平", "00062"));
        list.add(new ItemDto(to_DO1_low, "to_DO1置为低电平", "00021"));
        list.add(new ItemDto(to_DO2_low, "to_DO2置为低电平", "00022"));
        list.add(new ItemDto(to_DO8_low, "to_DO8置为低电平", "00028"));
        list.add(new ItemDto(to_DO9_low, "to_DO9置为低电平", "00029"));
        list.add(new ItemDto(to_address, "to_address", "40001"));
        list.add(new ItemDto(to_clear_error, "to_clear_error", "40090"));
        list.add(new ItemDto(to_di_height, "虚拟高电平写", "40063"));
        list.add(new ItemDto(to_di_low, "虚拟低电平写", "40064"));
        list.add(new ItemDto(to_line, "to_line", "40043"));

        return list;
    }

}

