| package com.zy.core.model.protocol; | 
|   | 
| import com.zy.asrs.entity.BasRgv; | 
| import com.zy.asrs.entity.BasRgvErrorLog; | 
| import com.zy.core.enums.RgvModeType; | 
| import com.zy.core.enums.RgvStatusType; | 
| import lombok.Data; | 
|   | 
| import javax.swing.*; | 
| import java.util.HashMap; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * Created by vincent on 2020/8/7 | 
|  */ | 
| @Data | 
| public class RgvProtocol implements Cloneable{ | 
|   | 
|     private short RgvNo; | 
|   | 
|     /** | 
|      * 1 = 手动模式 | 
|      * 2 = 自动模式 | 
|      * 3 = 电脑模式 | 
|      */ | 
|     public Short mode; | 
|   | 
|     public RgvModeType modeType; | 
|   | 
|     private transient Long loadingStartTime; | 
|   | 
|     /** | 
|      * 执行优先级 | 
|      * 0:不判断 | 
|      * 1:工位1先执行 | 
|      * 2:工位2先执行 | 
|      */ | 
|     public Short wrkTaskPri; | 
|   | 
|     public Short wrkTaskMove1; | 
|   | 
|     public Short wrkTaskMove2; | 
|   | 
|   | 
|     /** | 
|      * RGV当前状态工位1 | 
|      * 0:空闲,无任务 | 
|      * 1:作业中 | 
|      * 2:报警 | 
|      */ | 
|     public Short status; | 
|   | 
|   | 
|     /** | 
|      * 状态枚举 | 
|      */ | 
|     public RgvStatusType statusType; | 
|   | 
|     /** | 
|      * 工位1任务号 | 
|      */ | 
|     public Integer taskNo1 = 0; | 
|     /** | 
|      * 工位1目标站 | 
|      */ | 
|     public Integer staNo1 = 0; | 
|   | 
|     /** | 
|      * RGV工位1当前状态 | 
|      * 0:空闲,无任务 | 
|      * 11:取货中 | 
|      * 12:放货中 | 
|      * 10:任务完成等待WCS确认 | 
|      */ | 
|     public Short status1; | 
|   | 
|     /** | 
|      * 状态枚举 | 
|      */ | 
|     public RgvStatusType statusType1; | 
|   | 
|     /** | 
|      * 工位1有物 | 
|      */ | 
|     public Boolean loaded1; | 
|   | 
|     /** | 
|      * RGV当前位置 | 
|      */ | 
|     public Integer RgvPos; | 
|   | 
|     /** | 
|      * RGV当前目的位置 | 
|      */ | 
|     public Integer RgvPosDestination; | 
|   | 
|   | 
|     /** | 
|      * 走行在定位 | 
|      * 0 = 在定位 | 
|      * 1 = 不在定位 | 
|      */ | 
|     public Short walkPos; | 
|   | 
|     /** | 
|      * 急停触发 | 
|      */ | 
|     public Boolean err1; | 
|   | 
|     /** | 
|      * | 
|      */ | 
|     public Boolean err2; | 
|   | 
|     /** | 
|      * 有资料无物 | 
|      */ | 
|     public Boolean err3; | 
|   | 
|     /** | 
|      * 命令错误走行联调冲突 | 
|      */ | 
|     public Boolean err4; | 
|   | 
|     /** | 
|      * 目标为超过行走极限 | 
|      */ | 
|     public Boolean err5; | 
|   | 
|     /** | 
|      *  变频器异常 | 
|      */ | 
|     public Boolean err6; | 
|   | 
|     /** | 
|      * 光电异常 | 
|      */ | 
|     public Boolean err7; | 
|   | 
|     public Boolean err8; | 
|     public Boolean err9; | 
|     public Boolean err10; | 
|     public Boolean err11; | 
|     public Boolean err12; | 
|   | 
|     //////////////////////     工位2定义   ////////////////////////////////////////////////// | 
|     /** | 
|      * 工位2任务号 | 
|      */ | 
|     public Integer taskNo2 = 0; | 
|     /** | 
|      * 工位1目标站 | 
|      */ | 
|     public Integer staNo2 = 0; | 
|   | 
|     /** | 
|      * RGV工位2当前状态 | 
|      * 0:空闲,无任务 | 
|      * 11:取货中 | 
|      * 12:放货中 | 
|      * 10:任务完成等待WCS确认 | 
|      */ | 
|     public Short status2; | 
|   | 
|     /** | 
|      * 状态枚举 | 
|      */ | 
|     public RgvStatusType statusType2; | 
|   | 
|     /** | 
|      * 工位2有物 | 
|      */ | 
|     public Boolean loaded2; | 
|   | 
| //    /** | 
| //     * 急停 | 
| //     */ | 
| //    public Boolean err21; | 
| // | 
| //    /** | 
| //     * 有物无资料 | 
| //     */ | 
| //    public Boolean err22; | 
| // | 
| //    /** | 
| //     * 有资料无物 | 
| //     */ | 
| //    public Boolean err23; | 
| // | 
| //    /** | 
| //     * 命令错误走行联调冲突 | 
| //     */ | 
| //    public Boolean err24; | 
| // | 
| //    /** | 
| //     * 目标为超过行走极限 | 
| //     */ | 
| //    public Boolean err25; | 
| // | 
| //    /** | 
| //     *  变频器异常 | 
| //     */ | 
| //    public Boolean err26; | 
| // | 
| //    /** | 
| //     * 光电异常 | 
| //     */ | 
| //    public Boolean err27; | 
|   | 
|   | 
|     /////////////////////////////////////////////////////////////////////////////////////// | 
|     //配置信号----------------------------------------------------------------------------- | 
|     // 故障读取锁定标记 | 
|     private boolean errorMk = false; | 
|     //写入标记 | 
|     private boolean writeMk = true; | 
|     private Boolean chainForward1 = false;       // 链条前进 1 | 
|     private Boolean chainReverse1 = false;       // 链条后退 1 | 
|     private Boolean inverterAlarm = false;       // 变频器报警 | 
|     private Boolean leftOverlimit2 = false;      // 左超限 2 | 
|     private Boolean rightOverlimit2 = false;     // 右超限 2 | 
|     private Boolean leftAtPosition2 = false;     // 左到位 2 | 
|     private Boolean rightAtPosition2 = false;    // 右到位 2 | 
|     private Boolean cargoSpeedReduction = false; // 货物减速 | 
|     private Boolean conveyorInverterAlarm2 = false; // 输送变频器报警 2 | 
|   | 
|     private Boolean emergencyStop = false;       // 急停触发 | 
|     private Boolean slot1EmptyNoData = false;    // 1号位有物无资料 | 
|     private Boolean slot2EmptyNoData = false;    // 2号位有物无资料 | 
|     private Boolean commandErrorChainConflict = false; // 命令错误走链条冲突 | 
|     private Boolean targetPositionIssue = false; // 目标位下发错误 | 
|     private Boolean travelInverterError = false; // 走行变频器异常 | 
|     private Boolean photoelectric1Error = false; // 1号光电异常 | 
|     private Boolean photoelectric2Error = false; // 2号光电异常 | 
|     private Boolean timeoutConnectionWithLine = false; // 与输线时接超时 | 
|     private Boolean leftRollerTimeout = false;    // 左侧滚筒运行超时 | 
|     private Boolean rightRollerTimeout = false;   // 右侧滚筒运行超时 | 
|     private Boolean rgvRunTimeout = false;        // rgv运行超时 | 
|     private Boolean position1ChainInverterError = false; // 1号工位链条变频器异常 | 
|     private Boolean position2ChainInverterError = false; // 2号工位链条变频器异常 | 
|     private Boolean frontRearLimit = false;      // 前后极限位 | 
|     private Boolean emergencyButton = false;     // 急停按钮 | 
|     private Boolean forwardButton = false;       // 前进按钮 | 
|     private Boolean reverseButton = false;       // 后退按钮 | 
|     private Boolean localRemote = false;         // 本地/远程 | 
|     private Boolean reset = false;               // 复位 | 
|     private Boolean travelBrakeSwitch = false;   // 走行抱闸开关钮 | 
|     private Boolean travelSpeedLimitPhotoelectric = false; // 走行强制减速光电 | 
|     private Boolean leftOverlimit1 = false;      // 左超限 1 | 
|     private Boolean rightOverlimit1 = false;     // 右超限 1 | 
|     private Boolean leftAtPosition1 = false;     // 左到位 1 | 
|     private Boolean rightAtPosition1 = false;    // 右到位 1 | 
|   | 
|     private Boolean rightConveyor2 = false;      // 右输送 2 | 
|     private Boolean leftConveyor2 = false;       // 左输送 2 | 
|     //--------------------------------------------------------------------- | 
|     /** | 
|      * 异常码 | 
|      */ | 
|     public Short alarm; | 
|   | 
|     /** | 
|      * 心跳指令 1-2每秒切换一次 | 
|      */ | 
|     public Short heart; | 
|   | 
|     private Short temp1; | 
|   | 
|     private Short temp2; | 
|   | 
|     private Short temp3; | 
|   | 
|     private Short temp4; | 
|   | 
|     private Short temp5; | 
|   | 
|     /** | 
|      * X行走行速度m/min | 
|      */ | 
|     private Float xSpeed; | 
|   | 
|     /** | 
|      * 堆垛机累计走行距离km | 
|      */ | 
|     public Float xDistance; | 
|   | 
|     /** | 
|      * 堆垛机累计走行时长h | 
|      */ | 
|     public Float xDuration; | 
|   | 
|   | 
|     public BasRgvErrorLog toSqlModelError(){ | 
|         BasRgvErrorLog basRgvErrorLog = new BasRgvErrorLog(); | 
|         basRgvErrorLog.setRgvNo((int) RgvNo);// 设备号(假设有定义 siteId) | 
|         basRgvErrorLog.setChainForward1(chainForward1 ? "Y" : "N");       // 链条前进 1 | 
|         basRgvErrorLog.setChainReverse1(chainReverse1 ? "Y" : "N");       // 链条后退 1 | 
|         basRgvErrorLog.setInverterAlarm(inverterAlarm ? "Y" : "N");       // 变频器报警 | 
|         basRgvErrorLog.setLeftOverlimit2(leftOverlimit2 ? "Y" : "N");      // 左超限 2 | 
|         basRgvErrorLog.setRightOverlimit2(rightOverlimit2 ? "Y" : "N");     // 右超限 2 | 
|         basRgvErrorLog.setLeftAtPosition2(leftAtPosition2 ? "Y" : "N");     // 左到位 2 | 
|         basRgvErrorLog.setRightAtPosition2(rightAtPosition2 ? "Y" : "N");    // 右到位 2 | 
|         basRgvErrorLog.setCargoSpeedReduction(cargoSpeedReduction ? "Y" : "N"); // 货物减速 | 
|         basRgvErrorLog.setConveyorInverterAlarm2(conveyorInverterAlarm2 ? "Y" : "N"); // 输送变频器报警 2 | 
|         basRgvErrorLog.setEmergencyStop(emergencyStop ? "Y" : "N");       // 急停触发 | 
|         basRgvErrorLog.setSlot1EmptyNoData(slot1EmptyNoData ? "Y" : "N");    // 1号位有物无资料 | 
|         basRgvErrorLog.setSlot2EmptyNoData(slot2EmptyNoData ? "Y" : "N");    // 2号位有物无资料 | 
|         basRgvErrorLog.setCommandErrorChainConflict(commandErrorChainConflict ? "Y" : "N"); // 命令错误走链条冲突 | 
|         basRgvErrorLog.setTargetPositionIssue(targetPositionIssue ? "Y" : "N"); // 目标位下发错误 | 
|         basRgvErrorLog.setTravelInverterError(travelInverterError ? "Y" : "N"); // 走行变频器异常 | 
|         basRgvErrorLog.setPhotoelectric1Error(photoelectric1Error ? "Y" : "N"); // 1号光电异常 | 
|         basRgvErrorLog.setPhotoelectric2Error(photoelectric2Error ? "Y" : "N"); // 2号光电异常 | 
|         basRgvErrorLog.setTimeoutConnectionWithLine(timeoutConnectionWithLine ? "Y" : "N"); // 与输线时接超时 | 
|         basRgvErrorLog.setLeftRollerTimeout(leftRollerTimeout ? "Y" : "N");    // 左侧滚筒运行超时 | 
|         basRgvErrorLog.setRightRollerTimeout(rightRollerTimeout ? "Y" : "N");   // 右侧滚筒运行超时 | 
|         basRgvErrorLog.setRgvRunTimeout(rgvRunTimeout ? "Y" : "N");        // rgv运行超时 | 
|         basRgvErrorLog.setPosition1ChainInverterError(position1ChainInverterError ? "Y" : "N"); // 1号工位链条变频器异常 | 
|         basRgvErrorLog.setPosition2ChainInverterError(position2ChainInverterError ? "Y" : "N"); // 2号工位链条变频器异常 | 
|         basRgvErrorLog.setFrontRearLimit(frontRearLimit ? "Y" : "N");      // 前后极限位 | 
|         basRgvErrorLog.setEmergencyButton(emergencyButton ? "Y" : "N");     // 急停按钮 | 
|         basRgvErrorLog.setForwardButton(forwardButton ? "Y" : "N");       // 前进按钮 | 
|         basRgvErrorLog.setReverseButton(reverseButton ? "Y" : "N");       // 后退按钮 | 
|         basRgvErrorLog.setLocalRemote(localRemote ? "Y" : "N");         // 本地/远程 | 
|         basRgvErrorLog.setReset(reset ? "Y" : "N");               // 复位 | 
|         basRgvErrorLog.setTravelBrakeSwitch(travelBrakeSwitch ? "Y" : "N");   // 走行抱闸开关钮 | 
|         basRgvErrorLog.setTravelSpeedLimitPhotoelectric(travelSpeedLimitPhotoelectric ? "Y" : "N"); // 走行强制减速光电 | 
|         basRgvErrorLog.setLeftOverlimit1(leftOverlimit1 ? "Y" : "N");      // 左超限 1 | 
|         basRgvErrorLog.setRightOverlimit1(rightOverlimit1 ? "Y" : "N");     // 右超限 1 | 
|         basRgvErrorLog.setLeftAtPosition1(leftAtPosition1 ? "Y" : "N");     // 左到位 1 | 
|         basRgvErrorLog.setRightAtPosition1(rightAtPosition1 ? "Y" : "N");    // 右到位 1 | 
|         basRgvErrorLog.setRightConveyor2(rightConveyor2 ? "Y" : "N");      // 右输送 2 | 
|         basRgvErrorLog.setLeftConveyor2(leftConveyor2 ? "Y" : "N");       // 左输送 2 | 
|   | 
|         return basRgvErrorLog; | 
|     } | 
|   | 
|     public void setMode(Short mode) { | 
|         this.mode = mode; | 
|         this.modeType = RgvModeType.get(mode); | 
|     } | 
|   | 
|     public void setMode(RgvModeType type) { | 
|         this.modeType = type; | 
|         this.mode = RgvModeType.get(type).id.shortValue(); | 
|     } | 
|   | 
|     public void setStatus(Short status){ | 
|         this.status = status; | 
|         this.statusType = RgvStatusType.get(status); | 
|     } | 
|   | 
|     public void setStatus(RgvStatusType type){ | 
|         this.statusType = type; | 
|         this.status = RgvStatusType.get(type).id.shortValue(); | 
|     } | 
|   | 
|     public void setStatus1(Short status1){ | 
|         this.status1 = status1; | 
|         this.statusType1 = RgvStatusType.get(status1); | 
|     } | 
|   | 
|     public void setStatus1(RgvStatusType type1){ | 
|         this.statusType1 = type1; | 
|         this.status1 = RgvStatusType.get(type1).id.shortValue(); | 
|     } | 
|   | 
|     public void setStatus2(Short status2){ | 
|         this.status2 = status2; | 
|         this.statusType2 = RgvStatusType.get(status2); | 
|     } | 
|   | 
|     public void setStatus2(RgvStatusType type2){ | 
|         this.statusType2 = type2; | 
|         this.status2 = RgvStatusType.get(type2).id.shortValue(); | 
|     } | 
|   | 
|     public boolean isLoaded1ing() { | 
|         return Boolean.TRUE.equals(this.loaded1); | 
|     } | 
|   | 
|     public boolean isLoaded2ing() { | 
|         return Boolean.TRUE.equals(this.loaded2); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 最近一次入出库类型 | 
|      *       I:入库 | 
|      *       O:出库 | 
|      */ | 
|     private String lastIo = "I"; | 
|   | 
|   | 
|     public BasRgv toSqlModel(BasRgv basRgv){ | 
|         if (alarm!=null) { | 
|             basRgv.setRgvErr(alarm.longValue()); | 
|         } | 
|         basRgv.setWrkNo1(taskNo1.intValue()); | 
|         basRgv.setWrkNo2(taskNo2.intValue()); | 
|         return basRgv; | 
|     } | 
|   | 
|     public void setxSpeed(Short xSpeed) { | 
|         this.xSpeed = Float.valueOf(xSpeed); | 
|     } | 
|   | 
|     public void setxDistance(Short xDistance) { | 
|         this.xDistance = Float.valueOf(xDistance); | 
|     } | 
|   | 
|     public void setxDuration(Short xDuration) { | 
|         this.xDuration = Float.valueOf(xDuration); | 
|     } | 
|   | 
|     public Integer getRgvPosI(){ | 
|         //需要根据现场改造  根据读到的值获取对应站点位置 | 
|         Map<Short,Integer> map = new HashMap<>(); | 
|         map.put((short) 1,1004);map.put((short) 2,1007); | 
|         map.put((short) 3,1010);map.put((short) 4,1014); | 
|         map.put((short) 5,1018);map.put((short) 6,1021); | 
|        map.put((short) 7,1024); map.put((short) 8,1028); | 
|         map.put((short) 9,1031);map.put((short) 10,1035); | 
|         map.put((short) 11,2003);map.put((short) 12,2006); | 
|         map.put((short) 13,2009);map.put((short) 14,2012); | 
|         map.put((short) 15,2015);map.put((short) 16,2018); | 
|         map.put((short) 17,2021);map.put((short) 18,2024); | 
|         map.put((short) 19,2027);map.put((short) 20,2030); | 
|         if (RgvPos==null) return 0; | 
|   | 
|         return map.get(RgvPos); | 
|     } | 
|   | 
|     public Integer getRgvPosI2() { | 
|         // key: 站点号  value: 基准物理位置 | 
|         Map<Integer, Integer> posMap = new HashMap<>(); | 
|         posMap.put(1004, 6534); | 
|         posMap.put(1007, 33634); | 
|         posMap.put(1010, 75174); | 
|         posMap.put(1014, 102124); | 
|         posMap.put(1018, 138224); | 
|         posMap.put(1021, 178034); | 
|         posMap.put(1024, 219684); | 
|         posMap.put(1028, 246724); | 
|         posMap.put(1031, 288194); | 
|         posMap.put(2003, 314954); | 
|         posMap.put(2006, 288094); | 
|         posMap.put(2009, 246574); | 
|         posMap.put(2012, 219584); | 
|         posMap.put(2015, 177934); | 
|         posMap.put(2018, 138126); | 
|         posMap.put(2021, 102124); | 
|         posMap.put(2024, 75174); | 
|         posMap.put(2027, 33748); | 
|         posMap.put(2030, 6449); | 
|   | 
|   | 
|         int tolerance = 200; // 允许误差范围 | 
|   | 
|         for (Map.Entry<Integer, Integer> entry : posMap.entrySet()) { | 
|             int site = entry.getKey(); | 
|             int basePos = entry.getValue(); | 
|             if (Math.abs(RgvPos - basePos) <= tolerance) { | 
|                 return site; | 
|             } | 
|         } | 
|   | 
|         return 0; // 没匹配到站点 | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public RgvProtocol clone() { | 
|         try { | 
|             return (RgvProtocol) super.clone(); | 
|         } catch (CloneNotSupportedException e) { | 
|             e.printStackTrace(); | 
|         } | 
|         return null; | 
|     } | 
|   | 
| } |