| | |
| | | import com.ard.tianyu.model.dto.BoxSettingsDTO; |
| | | import com.ard.tianyu.model.receiver.*; |
| | | import com.ard.tianyu.netty.command.BaseCommand; |
| | | import com.ard.tianyu.netty.command.ControlAngleCommand; |
| | | import com.ard.tianyu.netty.command.HeartbeatCommand; |
| | | import com.ard.tianyu.netty.command.RegisterCommand; |
| | | import com.ard.tianyu.netty.TyNettyTcpClient; |
| | | import com.ard.tianyu.service.ITyService; |
| | | import com.ard.vtdu.util.ArdTool; |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.buffer.Unpooled; |
| | | import io.netty.channel.Channel; |
| | |
| | | return result.getState() == 1; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 注册天宇平台 |
| | | */ |
| | | @Override |
| | | public void registerMessage() { |
| | | AccessTokenReceiver tyToken = tyConfiguration.getAccessToken(); |
| | | RegisterCommand registerMessage = new RegisterCommand(tyToken.getCompanyId(), tyToken.getAccessToken().getBytes()); |
| | | this.sendMessage(tyConfiguration.getIpPort(), registerMessage); |
| | | } |
| | | |
| | | /** |
| | | * 发送消息 |
| | | */ |
| | | public boolean sendMessage(String key, BaseCommand msg) { |
| | | //将从用户接收的信息发送到天宇 commandCache |
| | | boolean cmdResult = false; |
| | |
| | | |
| | | channel.writeAndFlush(buffer); // 发送编码后的数据 |
| | | cmdResult = true; |
| | | log.info("向天宇服务器" + host + ":" + port + "发送数据" + ",命令码:" + msg.getCmdCode()); |
| | | log.info("向天宇服务器" + host + ":" + port + "发送数据" + ",命令码:" + String.format("0x%02X", msg.getCmdCode() & 0xFF)); |
| | | } else { |
| | | log.error("与天宇服务器链接断开,无法发送数据!"); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void controlAngle(String boxSn) { |
| | | ControlAngleCommand controlAngleCommand = new ControlAngleCommand(boxSn.getBytes(),(byte)0x00,(byte)0x00,(byte)0x05); |
| | | this.sendMessage(tyConfiguration.getIpPort(), controlAngleCommand); |
| | | } |
| | | |
| | | @Scheduled(fixedRate = 5000) |
| | | public void sendHeartBeat() { |
| | | long timestamp = System.currentTimeMillis(); |
| | | log.debug("定时向天宇发送⼼跳,时间戳{}", timestamp); |
| | | log.info("定时向天宇发送⼼跳,时间戳{}", timestamp); |
| | | HeartbeatCommand heartbeatMessage = new HeartbeatCommand(timestamp); |
| | | this.sendMessage(tyConfiguration.getIpPort(), heartbeatMessage); |
| | | } |