| | |
| | | import com.ard.common.utils.ByteUtils; |
| | | import com.ard.work.aspect.annotation.CheckTakeoffAltitude; |
| | | import com.ard.work.aspect.annotation.CheckControlRight; |
| | | import com.ard.work.component.netty.TcpClientSession; |
| | | import com.ard.work.component.netty.TyTcpClientManager; |
| | | import com.ard.work.component.netty.command.BaseCmd; |
| | | import com.ard.work.component.netty.command.camera.*; |
| | | import com.ard.work.component.netty.command.manual.*; |
| | |
| | | import com.ard.work.component.netty.command.real.UavTelemetryDataCmd; |
| | | import com.ard.work.component.netty.handler.ErrorCodeEnum; |
| | | import com.ard.work.component.netty.protobuf.TelemetryDataPB; |
| | | import com.ard.work.service.IArdDroneService; |
| | | import com.ard.work.service.IArdServerService; |
| | | import com.ard.work.service.IArdDroneInfoService; |
| | | import com.ard.work.service.IArdServerInfoService; |
| | | import com.ard.work.service.ITyService; |
| | | import com.ard.work.domain.message.UavControlType; |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelFuture; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Service |
| | | public class TyServiceImpl implements ITyService { |
| | | @Resource |
| | | private IArdServerService ardServerService; |
| | | private IArdServerInfoService ardServerService; |
| | | @Resource |
| | | private IArdDroneService ardDroneService; |
| | | private IArdDroneInfoService ardDroneService; |
| | | @Resource |
| | | private TyClient tyClient; |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 定时向所有已连接的六合服务器发送心跳 |
| | | */ |
| | | @Scheduled(fixedRate = 5000) // 每5秒执行一次 |
| | | public void sendHeartBeat() { |
| | | long timestamp = System.currentTimeMillis(); |
| | | |
| | | for (TcpClientSession session : channels.values()) { |
| | | ChannelFuture future = session.getChannelFuture(); |
| | | if (future == null || !future.channel().isActive()) { |
| | | log.warn("边缘服务器 [{}] 连接未激活,跳过心跳发送", session.getServerId()); |
| | | continue; |
| | | } |
| | | |
| | | HeartbeatCmd heartbeat = new HeartbeatCmd(timestamp); |
| | | future.channel().writeAndFlush(heartbeat); |
| | | |
| | | log.info("→ 向边缘服务器 [{}] ({}:{}) 发送心跳,时间戳={}", |
| | | session.getServerId(), session.getHost(), session.getPort(), timestamp); |
| | | } |
| | | } |
| | | /** |
| | | * 发送消息 |
| | | */ |