| | |
| | | private JarSlave slave; |
| | | private JarProtocol jarProtocol; |
| | | private short heartBeatVal = 1; |
| | | private boolean connectJar = false; |
| | | |
| | | |
| | | public JarThread(JarSlave slave) { |
| | | this.slave = slave; |
| | |
| | | @Override |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | | public void run() { |
| | | this.connect(); |
| | | |
| | | connectJar = this.connect(); |
| | | while(!connectJar){ |
| | | try { |
| | | connectJar = this.connect(); |
| | | Thread.sleep(100); |
| | | } catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | |
| | | // 启动线程自动重连 |
| | | new Thread(this::jarConnect).start(); |
| | | |
| | | // 启动读数据线程 |
| | | new Thread(this::readStatusJar).start(); |
| | | |
| | | // 启动任务下发线程 |
| | | new Thread(this::taskIssued).start(); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 任务下发 |
| | | */ |
| | | private void taskIssued() { |
| | | while (true) { |
| | | try { |
| | | int step = 1; |
| | |
| | | switch (step) { |
| | | // 读数据 |
| | | case 1: |
| | | readStatus(); |
| | | // readStatus(); |
| | | break; |
| | | // 写数据 ID+目标站 |
| | | case 2: |
| | |
| | | } |
| | | // 心跳 |
| | | // heartbeat(); |
| | | Thread.sleep(500); |
| | | Thread.sleep(200); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("JAR写线程异常"+e.getMessage()); |
| | | |
| | | // e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | private void jarConnect() { |
| | | while (true) { |
| | | try { |
| | | Thread.sleep(1000); |
| | | if(!connectJar){ |
| | | try { |
| | | connectJar = this.connect(); |
| | | Thread.sleep(100); |
| | | } catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("rgv连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | initSte(); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void readStatusJar() { |
| | | while (true) { |
| | | try { |
| | | Thread.sleep(50); |
| | | // System.out.println("读线程"+ slave.getId()); |
| | | |
| | | readStatus(); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("RGV数据读取线程异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | |
| | | initSte(); |
| | | // e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | // } else |
| | | if (jarProtocol.statusType .equals(JarStatusType.SOS2)){ |
| | | jarProtocol.setHoldingSign(!jarProtocol.getStatus().equals(jarProtocol.getUpStatus())); |
| | | if (!jarProtocol.rightDoorClose.equals(jarProtocol.leftDoorClose)) { |
| | | if (jarProtocol.rightDoorClose == 0 || jarProtocol.leftDoorClose == 0){ |
| | | if (jarProtocol.rightDoorClose == 2 || jarProtocol.leftDoorClose == 2){ |
| | | jarProtocol.setLeftDoorClose(0);//close the left door //进料门 |
| | | jarProtocol.setRightDoorClose(0);//close the right door //出料门 |
| | | } |
| | | } |
| | | if (jarProtocol.rightDoorOpen == 0 || jarProtocol.leftDoorOpen == 0){ |
| | | if (jarProtocol.rightDoorOpen == 2 || jarProtocol.leftDoorOpen == 2){ |
| | | jarProtocol.setLeftDoorOpen(0);//open the left door //进料门 |
| | | jarProtocol.setRightDoorOpen(0);//open the right door //出料门 |
| | | } |
| | | } |
| | | } |
| | | } else if (jarProtocol.statusType .equals(JarStatusType.WAITING3) || jarProtocol.statusType .equals(JarStatusType.WAITING4)){ |
| | | jarProtocol.setOpenDoorSign(!jarProtocol.getStatus().equals(jarProtocol.getUpStatus())); |
| | | } else if (jarProtocol.statusType .equals(JarStatusType.WAITING5) || jarProtocol.statusType .equals(JarStatusType.OFF_LINE)){ |
| | | jarProtocol.setCloseDoorSign(!jarProtocol.getStatus().equals(jarProtocol.getUpStatus())); |
| | | } else if (jarProtocol.leftDoorOpen==1 || jarProtocol.leftDoorClose==1 || |
| | | jarProtocol.rightDoorOpen==1 || jarProtocol.rightDoorClose==1){ |
| | | |
| | | } else { |
| | | if (jarProtocol.statusType .equals(JarStatusType.WAITING2)){ |
| | | |
| | | if (jarProtocol.rightDoorOpen == 2 || jarProtocol.leftDoorOpen == 2){ |
| | | jarProtocol.setLeftDoorOpen(0);//open the left door //进料门 |
| | | jarProtocol.setRightDoorOpen(0);//open the right door //出料门 |
| | | } |
| | | if (jarProtocol.rightDoorClose == 2 || jarProtocol.leftDoorClose == 2){ |
| | | jarProtocol.setLeftDoorClose(0);//close the left door //进料门 |
| | | jarProtocol.setRightDoorClose(0);//close the right door //出料门 |
| | | } |
| | | } else if (jarProtocol.statusType .equals(JarStatusType.WAITING1) || jarProtocol.statusType .equals(JarStatusType.MOVING)){ |
| | | if (!jarProtocol.rightDoorOpen.equals(jarProtocol.leftDoorOpen)) { |
| | | if (jarProtocol.rightDoorOpen == 0 || jarProtocol.leftDoorOpen == 0){ |
| | | if (jarProtocol.rightDoorOpen == 2 || jarProtocol.leftDoorOpen == 2){ |
| | | jarProtocol.setLeftDoorOpen(0);//open the left door //进料门 |
| | | jarProtocol.setRightDoorOpen(0);//open the right door //出料门 |
| | | } |
| | | } |
| | | } |
| | | if (jarProtocol.rightDoorClose == 0 || jarProtocol.leftDoorClose == 0){ |
| | | if (jarProtocol.rightDoorClose == 2 || jarProtocol.leftDoorClose == 2){ |
| | | jarProtocol.setLeftDoorClose(0);//close the left door //进料门 |
| | | jarProtocol.setRightDoorClose(0);//close the right door //出料门 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | jarProtocol.setUpStatus(jarProtocol.getStatus()); |