| | |
| | | import com.zy.acs.gateway.AbstractInboundHandler; |
| | | import com.zy.acs.gateway.Executors; |
| | | import com.zy.acs.gateway.constant.ProtocolType; |
| | | import com.zy.acs.gateway.constant.RabbitmqConstant; |
| | | import com.zy.acs.gateway.domain.AgvPackage; |
| | | import com.zy.acs.gateway.process.AckMsgBuilder; |
| | | import io.netty.channel.ChannelHandler; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | @Autowired |
| | | private Executors executors; |
| | | |
| | | @Autowired |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | |
| | | |
| | | @Override |
| | | @SuppressWarnings("all") |
| | | protected boolean channelRead0(ChannelHandlerContext ctx, AgvPackage pac) throws Exception { |
| | |
| | | |
| | | AGV_01_UP agv_01_up = (AGV_01_UP) pac.getBody().getMessageBody(); |
| | | |
| | | redis.setObject(RedisConstant.AGV_CMD_UP_FLAG |
| | | redis.setObject(RedisConstant.AGV_PATH_UP_FLAG |
| | | , pac.getHeader().getUniqueNo() + "_" + agv_01_up.getSerialNo() |
| | | , agv_01_up); |
| | | |
| | | AgvPackage pathAckPac = AckMsgBuilder.ofSuccess(pac, ProtocolType.PATH_ACK_RESPONSE); |
| | | |
| | | AGV_B1_DOWN agv_b1_down = (AGV_B1_DOWN) pathAckPac.getBody().getMessageBody(); |
| | | agv_b1_down.setSerialNo(agv_01_up.getSerialNo()); |
| | | agv_b1_down.setPathLen(agv_01_up.getPathLen()); |
| | | ctx.writeAndFlush(pathAckPac); |
| | | |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.PATH_ACK.name()), agv_01_up); |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_DOWN.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.PATH_ACK_RESPONSE.name()), agv_b1_down); |
| | | |
| | | break label; |
| | | |
| | | case PICK_PLACE_REQUEST: // 取放货请求包 |
| | | |
| | | AGV_06_UP agv_06_up = (AGV_06_UP) pac.getBody().getMessageBody(); |
| | | redis.push(RedisConstant.AGV_COMPLETE_FLAG, AgvProtocol.build(uniqueNo).setMessageBody(agv_06_up)); |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.PICK_PLACE_REQUEST.name()), agv_06_up); |
| | | |
| | | break label; |
| | | |
| | |
| | | redis.setObject(RedisConstant.AGV_CMD_UP_FLAG |
| | | , pac.getHeader().getUniqueNo() + "_" + agv_02_up.getSerialNo() |
| | | , agv_02_up); |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.COMMAND_ACK.name()), agv_02_up); |
| | | |
| | | break label; |
| | | |
| | |
| | | AGV_11_UP agv_11_up = (AGV_11_UP) pac.getBody().getMessageBody(); |
| | | redis.push(RedisConstant.AGV_COMPLETE_FLAG, AgvProtocol.build(uniqueNo).setMessageBody(agv_11_up)); |
| | | |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.ACTION_COMPLETE.name()), agv_11_up); |
| | | |
| | | // 动作完成应答 |
| | | if (null != ackType) { |
| | | AgvPackage ackPac = AckMsgBuilder.ofSuccess(pac, ackType); |
| | |
| | | agv_a1_down.setAckSign((byte) agv_11_up.getCompleteCode()); |
| | | |
| | | ctx.writeAndFlush(ackPac); |
| | | } |
| | | |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_DOWN.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ackType.name()), agv_a1_down); |
| | | } |
| | | |
| | | break label; |
| | | |
| | |
| | | // } |
| | | // |
| | | // }); |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.DATA_CODE_REPORT.name()), agv_12_up); |
| | | |
| | | break label; |
| | | |
| | |
| | | // |
| | | // }); |
| | | |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.DATA_WITHOUT_CODE_REPORT.name()), agv_13_up); |
| | | |
| | | break label; |
| | | |
| | |
| | | // } |
| | | // |
| | | // }); |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.HEARTBEAT_REPORT.name()), agv_03_up); |
| | | |
| | | break label; |
| | | |
| | |
| | | // |
| | | // }); |
| | | |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.SILO_REPORT.name()), agv_70_up); |
| | | |
| | | break label; |
| | | |
| | |
| | | |
| | | AGV_F0_UP agv_f0_up = (AGV_F0_UP) pac.getBody().getMessageBody(); |
| | | redis.push(RedisConstant.AGV_DATA_FLAG, AgvProtocol.build(uniqueNo).setMessageBody(agv_f0_up)); |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.LOGIN_REPORT.name()), agv_f0_up); |
| | | |
| | | // 登录应答 |
| | | if (null != ackType) { |
| | | AgvPackage ackPac = AckMsgBuilder.ofSuccess(pac, ackType); |
| | | |
| | | ctx.writeAndFlush(ackPac); |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_DOWN.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ackType.name()), ackPac.getBody().getMessageBody()); |
| | | } |
| | | |
| | | // 30s redis |
| | |
| | | AGV_04_UP agv_04_up = (AGV_04_UP) pac.getBody().getMessageBody(); |
| | | redis.push(RedisConstant.AGV_DATA_FLAG, AgvProtocol.build(uniqueNo).setMessageBody(agv_04_up)); |
| | | |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.FAULT_REPORT.name()), agv_04_up); |
| | | |
| | | break label; |
| | | |