| | |
| | | package com.zy.acs.gateway.handler; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.zy.acs.common.constant.RedisConstant; |
| | | import com.zy.acs.common.domain.AgvProtocol; |
| | | import com.zy.acs.common.domain.mq.DeviceMessage; |
| | |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | |
| | | |
| | | @Override |
| | | @SuppressWarnings("all") |
| | | protected boolean channelRead0(ChannelHandlerContext ctx, AgvPackage pac) throws Exception { |
| | |
| | | |
| | | final String uniqueNo = pac.getHeader().getUniqueNo(); |
| | | |
| | | label : switch (pac.getHeader().getProtocolType()){ |
| | | label: |
| | | switch (pac.getHeader().getProtocolType()) { |
| | | case PATH_ACK: // 路径包 ack |
| | | |
| | | AGV_01_UP agv_01_up = (AGV_01_UP) pac.getBody().getMessageBody(); |
| | |
| | | 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()), new DeviceMessage(pac.getSourceHexStr())); |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_DOWN.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.PATH_ACK_RESPONSE.name()), new DeviceMessage(pathAckPac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.PATH_ACK.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_DOWN.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.PATH_ACK_RESPONSE.name()), new DeviceMessage(pathAckPac.getSourceHexStr())); |
| | | |
| | | |
| | | break label; |
| | | |
| | |
| | | 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()), new DeviceMessage(pac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.PICK_PLACE_REQUEST.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | |
| | | |
| | | break label; |
| | | |
| | |
| | | , 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()), new DeviceMessage(pac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.COMMAND_ACK.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | |
| | | |
| | | break label; |
| | | |
| | |
| | | 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()), new DeviceMessage(pac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.ACTION_COMPLETE.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | |
| | | |
| | | // 动作完成应答 |
| | | if (null != ackType) { |
| | |
| | | agv_a1_down.setAckSign((byte) agv_11_up.getCompleteCode()); |
| | | |
| | | ctx.writeAndFlush(ackPac); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_DOWN.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ackType.name()), new DeviceMessage(ackPac.getSourceHexStr())); |
| | | |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_DOWN.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ackType.name()), new DeviceMessage(ackPac.getSourceHexStr())); |
| | | } |
| | | |
| | | 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()), new DeviceMessage(pac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.DATA_CODE_REPORT.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | |
| | | |
| | | 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()), new DeviceMessage(pac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.DATA_WITHOUT_CODE_REPORT.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | |
| | | |
| | | break label; |
| | | |
| | |
| | | // |
| | | // }); |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.HEARTBEAT_REPORT.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.HEARTBEAT_REPORT.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | |
| | | |
| | | break label; |
| | | |
| | | |
| | | case SILO_REPORT: // 料仓信息包 |
| | | |
| | | AGV_70_UP agv_70_up = (AGV_70_UP) pac.getBody().getMessageBody(); |
| | |
| | | // } |
| | | // |
| | | // }); |
| | | |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.SILO_REPORT.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.SILO_REPORT.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | |
| | | 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()), new DeviceMessage(pac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.LOGIN_REPORT.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | |
| | | // 登录应答 |
| | | 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()), new DeviceMessage(ackPac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_DOWN.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ackType.name()), new DeviceMessage(ackPac.getSourceHexStr())); |
| | | } |
| | | |
| | | // 30s redis |
| | |
| | | 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()), new DeviceMessage(pac.getSourceHexStr())); |
| | | saveLogToMq(RabbitmqConstant.TOPIC_EXCHANGE, RabbitmqConstant.ROUTING_KEY_UP.replaceFirst(RabbitmqConstant.SPILT_REGEX, uniqueNo).replaceFirst(RabbitmqConstant.SPILT_REGEX, ProtocolType.FAULT_REPORT.name()), new DeviceMessage(pac.getSourceHexStr())); |
| | | |
| | | break label; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | public void saveLogToMq(String topic_exchange, String routingKey, DeviceMessage message) { |
| | | if (rabbitTemplate.isRunning()) { |
| | | // 写入队列 |
| | | rabbitTemplate.convertAndSend(topic_exchange, routingKey, message); |
| | | } else { |
| | | log.warn("RabbitTemplate is not running, message not sent"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |