|  |  | 
 |  |  | package com.zy.asrs.wcs.core.action; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSON; | 
 |  |  | import com.alibaba.fastjson.JSONObject; | 
 |  |  | import com.zy.asrs.wcs.core.entity.BasShuttle; | 
 |  |  | import com.zy.asrs.wcs.core.model.NavigateNode; | 
 |  |  | import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand; | 
 |  |  | import com.zy.asrs.wcs.core.model.command.ShuttleCommand; | 
 |  |  | import com.zy.asrs.wcs.core.model.command.ShuttleRedisCommand; | 
 |  |  | import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType; | 
 |  |  | import com.zy.asrs.wcs.core.service.BasShuttleService; | 
 |  |  | import com.zy.asrs.wcs.core.utils.NavigateMapUtils; | 
 |  |  | import com.zy.asrs.wcs.core.utils.RedisUtil; | 
 |  |  | import com.zy.asrs.wcs.core.utils.Utils; | 
 |  |  | 
 |  |  |     private RedisUtil redisUtil; | 
 |  |  |     @Autowired | 
 |  |  |     private NavigateMapUtils navigateMapUtils; | 
 |  |  |     @Autowired | 
 |  |  |     private BasShuttleService basShuttleService; | 
 |  |  |  | 
 |  |  |     public synchronized boolean assignWork(Device device, ShuttleAssignCommand assignCommand) { | 
 |  |  |         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); | 
 |  |  | 
 |  |  |         redisCommand.setAssignCommand(assignCommand);//命令 | 
 |  |  |         //任务数据保存到redis | 
 |  |  |         if (redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand))) { | 
 |  |  |             //下发行驶路径 | 
 |  |  |             boolean result = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getTaskNo().intValue()); | 
 |  |  |             if (!result) { | 
 |  |  |                 return false; | 
 |  |  |             } | 
 |  |  |             shuttleProtocol.setTaskNo(assignCommand.getTaskNo().intValue()); | 
 |  |  |             return true; | 
 |  |  |         } | 
 |  |  | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //四向穿梭车空闲、有任务、标记为true、存在任务指令,需要执行任务的下一条指令 | 
 |  |  |         if (!shuttleProtocol.getIdle() | 
 |  |  |                 || shuttleProtocol.getTaskNo() == 0 | 
 |  |  |                 || !shuttleProtocol.getPakMk()) { | 
 |  |  |         //判断设备是否空闲 | 
 |  |  |         if (!shuttleThread.isIdle()) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  | 
 |  |  |                 if (!shuttleProtocol.getHasLift()) { | 
 |  |  |                     command.setComplete(true); | 
 |  |  |                 } | 
 |  |  |             } else if (command.getMode() == ShuttleCommandModeType.CHARGE.id) { | 
 |  |  |                 // 充电开关 | 
 |  |  |             } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id) { | 
 |  |  |                 // 充电开 | 
 |  |  |                 //判断小车充电状态 | 
 |  |  |                 if (shuttleProtocol.getHasCharge()) { | 
 |  |  |                     command.setComplete(true); | 
 |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //取出命令 | 
 |  |  |         ShuttleCommand command = commands.get(commandStep); | 
 |  |  |  | 
 |  |  |         // 下发命令 | 
 |  |  |         if (!write(command, device)) { | 
 |  |  |             News.error("四向穿梭车命令下发失败,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return true; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private synchronized boolean write(ShuttleCommand command, Device device) { | 
 |  |  |         if (null == command) { | 
 |  |  |             News.error("四向穿梭车写入命令为空"); | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); | 
 |  |  |         boolean result = false; | 
 |  |  |         if (command.getMode() == ShuttleCommandModeType.MOVE.id | 
 |  |  |                 || command.getMode() == ShuttleCommandModeType.IN_LIFT.id | 
 |  |  |                 || command.getMode() == ShuttleCommandModeType.OUT_LIFT.id) {//移动 | 
 |  |  |             result = shuttleThread.move(command); | 
 |  |  |         } else if (command.getMode() == ShuttleCommandModeType.PALLET_LIFT.id | 
 |  |  |                 || command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {//顶升 | 
 |  |  |             result = shuttleThread.lift(command); | 
 |  |  |         } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id | 
 |  |  |                 || command.getMode() == ShuttleCommandModeType.CHARGE_CLOSE.id) {//充电 | 
 |  |  |             result = shuttleThread.charge(command); | 
 |  |  |         } else if (command.getMode() == ShuttleCommandModeType.RESET.id) {//复位 | 
 |  |  |             result = shuttleThread.reset(command); | 
 |  |  |         } | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |