liusuyi
2025-12-24 49c807f8c2e80cc012ed755acbe1308c5de0c65c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
package com.ard.work.service.impl;
 
import com.ard.common.exception.ControlException;
import com.ard.work.aspect.annotation.CheckControlRight;
import com.ard.work.aspect.annotation.CheckDroneStatus;
import com.ard.work.aspect.annotation.CheckNoFlyZone;
import com.ard.work.aspect.annotation.CheckTakeoffAltitude;
import com.ard.work.component.forest.TyClient;
import com.ard.work.component.netty.TcpClientUtil;
import com.ard.work.component.netty.command.BaseCmd;
import com.ard.work.component.netty.command.camera.*;
import com.ard.work.component.netty.command.control.AbsAngleControlCmd;
import com.ard.work.component.netty.command.control.AngleControlCmd;
import com.ard.work.component.netty.command.control.SpeedControlCmd;
import com.ard.work.component.netty.command.manual.*;
import com.ard.work.component.netty.command.notice.BoxPowerStatusReplyCmd;
import com.ard.work.component.netty.command.notice.WayLineFinishedReplyCmd;
import com.ard.work.component.netty.command.notice.UavReadyReplyCmd;
import com.ard.work.component.netty.command.real.SignalInfoCmd;
import com.ard.work.component.netty.command.real.UavStateCmd;
import com.ard.work.component.netty.command.real.UavTelemetryDataCmd;
import com.ard.work.component.netty.command.register.*;
import com.ard.work.component.netty.command.settings.*;
import com.ard.work.component.netty.command.speaker.*;
import com.ard.work.component.netty.command.wayline.*;
import com.ard.work.component.netty.handler.ErrorCodeEnum;
import com.ard.work.component.netty.protobuf.TelemetryDataPB;
import com.ard.work.component.websocket.utils.WebSocketUtil;
import com.ard.work.config.RouteStateMachineService;
import com.ard.work.domain.cache.UavSignalInfoCache;
import com.ard.work.domain.cache.UavStateCache;
import com.ard.work.domain.cache.UavTelemetryDataCache;
import com.ard.work.domain.dto.BoxHistoryDTO;
import com.ard.work.domain.dto.BoxPhotosDTO;
import com.ard.work.domain.dto.BoxSettingsDTO;
import com.ard.work.domain.dto.BoxVideosDTO;
import com.ard.work.domain.dto.camera.*;
import com.ard.work.domain.dto.control.AbsAngleControlDTO;
import com.ard.work.domain.dto.control.AngleControlDTO;
import com.ard.work.domain.dto.control.SpeedControlDTO;
import com.ard.work.domain.dto.converter.wayline.PlanLineDataConverter;
import com.ard.work.domain.dto.manual.*;
import com.ard.work.domain.dto.settings.ReturnHeightSettingDTO;
import com.ard.work.domain.dto.settings.ReturnPointSettingDTO;
import com.ard.work.domain.dto.settings.VideoStreamSettingDTO;
import com.ard.work.domain.dto.signal.SignalInfo;
import com.ard.work.domain.dto.speaker.*;
import com.ard.work.domain.dto.state.UavState;
import com.ard.work.domain.dto.telemetry.TelemetryData;
import com.ard.work.domain.dto.wayline.*;
import com.ard.work.domain.entity.ArdDroneInfo;
import com.ard.work.domain.entity.ArdServerInfo;
import com.ard.work.domain.enums.RouteEvent;
import com.ard.work.domain.message.ServerReplyMessage;
import com.ard.work.domain.message.UavControlType;
import com.ard.work.domain.receiver.*;
import com.ard.work.service.IArdDroneInfoService;
import com.ard.work.service.IArdFlightTaskPartService;
import com.ard.work.service.IArdServerInfoService;
import com.ard.work.service.ITyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
/**
 * TyServiceImpl
 *
 * @author liusuyi
 * @date 2024年10月22日8:37
 **/
@Slf4j
@Service
public class TyServiceImpl implements ITyService {
    @Resource
    private IArdServerInfoService ardServerService;
    @Resource
    private IArdDroneInfoService ardDroneService;
    @Resource
    private TyClient tyClient;
    @Autowired
    private RouteStateMachineService stateMachineService;
    @Autowired
    private IArdFlightTaskPartService ardFlightTaskPartService;
 
    /**
     * 获取边缘服务器token信息
     *
     * @return AccessTokenReceiver
     */
    @Override
    public AccessTokenReceiver getAccessToken(String serverId) {
        return ardServerService.getAccessToken(serverId);
    }
 
    /**
     * 获取全部云盒列表
     *
     * @return List<BoxInfoReceiver>
     */
    @Override
    public List<BoxInfoReceiver> getBoxList() {
        List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerInfoList(new ArdServerInfo() {{
            setUseDataScope(false);
        }});
        return getBoxList(ardServerInfos);
    }
 
    /**
     * 获取指定服务器云盒列表
     *
     * @return List<BoxInfoReceiver>
     */
    @Override
    public List<BoxInfoReceiver> getBoxList(String serverId) {
        TyHttpCommonReceiver<List<BoxInfoReceiver>> boxList = tyClient.getBoxList(serverId);
        return boxList == null ? null : boxList.getContent();
    }
 
    /**
     * 获取直播地址
     *
     * @return BoxStreamUrlReceiver
     */
    @Override
    public BoxStreamUrlReceiver getBoxLiveUrl(String boxSn) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
 
 
        TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(),
                boxSn);
        return boxLiveUrl == null ? null : boxLiveUrl.getContent();
    }
 
    /**
     * 获取飞行历史
     *
     * @return List<BoxHistoryReceiver>
     */
    @Override
    public List<BoxHistoryReceiver> getBoxHistory(BoxHistoryDTO boxHistoryDTO) {
        String boxSn = boxHistoryDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(ardDroneInfo.getServerId(),
                boxHistoryDTO);
        return boxHistory == null ? null : boxHistory.getContent();
    }
 
    /**
     * 获取任务图片
     *
     * @return List<BoxPhotosReceiver>
     */
    @Override
    public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO boxPhotosDTO) {
        String boxSn = boxPhotosDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(),
                boxPhotosDTO);
        return boxPhotos == null ? null : boxPhotos.getContent();
    }
    /**
     * 获取任务视频
     *
     * @return List<BoxVideosReceiver>
     */
    @Override
    public List<BoxVideosReceiver> getBoxVideos(BoxVideosDTO boxVideosDTO) {
        String boxSn = boxVideosDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        TyHttpCommonReceiver<List<BoxVideosReceiver>> boxVideos = tyClient.getBoxVideos(ardDroneInfo.getServerId(),
                boxVideosDTO);
        return boxVideos == null ? null : boxVideos.getContent();
    }
    /**
     * 修改云盒设置
     */
    @Override
    public Boolean updateBoxSettings(BoxSettingsDTO boxSettingsDTO) {
        String boxSn = boxSettingsDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(), boxSettingsDTO);
        return result.getState() == 0;
    }
 
    /**
     * 设置返航高度
     */
    @Override
    public Boolean updateReturnHeight(ReturnHeightSettingDTO returnHeightSettingDTO) {
        String boxSn = returnHeightSettingDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        ReturnHeightSettingCmd returnHeightSettingCmd = new ReturnHeightSettingCmd(returnHeightSettingDTO);
        this.sendMessage(ardDroneInfo.getServerId(), returnHeightSettingCmd);
        return true;
    }
 
    /**
     * 设置返航点
     */
    @Override
    public Boolean updateReturnPoint(ReturnPointSettingDTO returnPointSettingDTO) {
        String boxSn = returnPointSettingDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        ReturnPointSettingCmd returnPointSettingCmd = new ReturnPointSettingCmd(returnPointSettingDTO);
        this.sendMessage(ardDroneInfo.getServerId(), returnPointSettingCmd);
        return true;
    }
 
    /**
     * 设置视频码流
     */
    @Override
    public Boolean updateVideoStream(VideoStreamSettingDTO videoStreamSettingDTO) {
        String boxSn = videoStreamSettingDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        VideoStreamSettingCmd videoStreamSettingCmd = new VideoStreamSettingCmd(videoStreamSettingDTO);
        this.sendMessage(ardDroneInfo.getServerId(), videoStreamSettingCmd);
        return true;
    }
 
    /**
     * 注册边缘服务器平台
     */
    @Override
    public Boolean registerMessage(String serverId) {
        try {
            AccessTokenReceiver tyToken = ardServerService.getAccessToken(serverId);
            RegisterCmd registerMessage = new RegisterCmd(tyToken.getCompanyId(), tyToken.getAccessToken().getBytes());
            this.sendMessage(serverId, registerMessage);
            return true;
        } catch (Exception e) {
            log.error("注册边缘服务器平台失败:{}", e.getMessage());
            return false;
        }
    }
 
    /**
     * 云台控制基于角度
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean angleControl(AngleControlDTO angleControlDto) {
        String boxSn = angleControlDto.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        AngleControlCmd controlAngleCommand = new AngleControlCmd(angleControlDto);
        this.sendMessage(ardDroneInfo.getServerId(), controlAngleCommand);
        return true;
    }
 
    /**
     * 云台绝对值控制(基于角度)
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean absAngleControl(AbsAngleControlDTO absAngleControlDto) {
        String boxSn = absAngleControlDto.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        AbsAngleControlCmd absAngleControlCommand = new AbsAngleControlCmd(absAngleControlDto);
        this.sendMessage(ardDroneInfo.getServerId(), absAngleControlCommand);
        return true;
    }
 
    /**
     * 云台转动(基于速度)
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean speedControl(SpeedControlDTO speedControlDto) {
        String boxSn = speedControlDto.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        SpeedControlCmd speedControlCommand = new SpeedControlCmd(speedControlDto);
        this.sendMessage(ardDroneInfo.getServerId(), speedControlCommand);
        return true;
    }
 
    @Override
    public Boolean formatSdCard(FormatSdCardDTO formatSdCardDTO) {
        String boxSn = formatSdCardDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        FormatSdCardCmd formatSdCardCmd = new FormatSdCardCmd(formatSdCardDTO);
        this.sendMessage(ardDroneInfo.getServerId(), formatSdCardCmd);
        return true;
    }
 
    /**
     * 设置相机模式
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean updateCameraMode(CameraModeDTO cameraModeDTO) {
        String boxSn = cameraModeDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        CameraModeCmd cameraModeCommand = new CameraModeCmd(cameraModeDTO);
        this.sendMessage(ardDroneInfo.getServerId(), cameraModeCommand);
        return true;
    }
 
    /**
     * 拍照
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean capturePic(CapturePicDTO capturePicDto) {
        String boxSn = capturePicDto.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        //设置相机模式为拍照模式
        //updateCameraMode(CameraModeDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
        //设置拍照回传
        //photoReturnToggle(PhotoReturnToggleDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01)
        // .build());
 
        CapturePicCmd capturePicCommand = new CapturePicCmd(capturePicDto);
        this.sendMessage(ardDroneInfo.getServerId(), capturePicCommand);
        return true;
    }
 
    /**
     * 录像
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean record(RecordDTO recordDto) {
        String boxSn = recordDto.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        BaseCmd baseCmd;
        if (recordDto.getIsRecord()) {
            //updateCameraMode(CameraModeDTO.builder().boxSn(recordDto.getBoxSn()).actionParam((byte) 0x02).build());
            baseCmd = new RecordStartCmd(recordDto);
        } else {
            baseCmd = new RecordStopCmd(recordDto);
        }
        this.sendMessage(ardDroneInfo.getServerId(), baseCmd);
        return true;
    }
 
    /**
     * 变倍
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean zoom(ZoomDTO zoomDTO) {
        String boxSn = zoomDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        ZoomCmd zoomCommand = new ZoomCmd(zoomDTO);
        this.sendMessage(ardDroneInfo.getServerId(), zoomCommand);
        return true;
    }
 
    /**
     * 变倍到指定倍数
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean zoomToLevel(ZoomToLevelDTO zoomToLevelDTO) {
        String boxSn = zoomToLevelDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        ZoomToLevelCmd zoomToLevelCommand = new ZoomToLevelCmd(zoomToLevelDTO);
        this.sendMessage(ardDroneInfo.getServerId(), zoomToLevelCommand);
        return true;
    }
 
    /**
     * 切换摄像头
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean switchCamera(SwitchCameraDTO switchCameraDTO) {
        String boxSn = switchCameraDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        SwitchCameraCmd switchCameraCmd = new SwitchCameraCmd(switchCameraDTO);
        this.sendMessage(ardDroneInfo.getServerId(), switchCameraCmd);
        return true;
    }
 
    /**
     * 切换视频源
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean switchSource(SwitchSourceDTO switchSourceDTO) {
        String boxSn = switchSourceDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        SwitchSourceCmd switchSourceCmd = new SwitchSourceCmd(switchSourceDTO);
        this.sendMessage(ardDroneInfo.getServerId(), switchSourceCmd);
        return true;
    }
 
    /**
     * 打开或关闭照片回传
     */
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean photoReturnToggle(PhotoReturnToggleDTO photoReturnToggleDTO) {
        String boxSn = photoReturnToggleDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        PhotoReturnToggleCmd photoReturnToggleCmd = new PhotoReturnToggleCmd(photoReturnToggleDTO);
        this.sendMessage(ardDroneInfo.getServerId(), photoReturnToggleCmd);
        return true;
    }
 
    /**
     * 切换无人机控制权
     */
    @CheckDroneStatus
    @Override
    public Boolean switchUavControl(SwitchUavControlDTO switchUavControlDTO) {
        String boxSn = switchUavControlDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        SwitchUavControlCmd switchUavControlCmd = new SwitchUavControlCmd(switchUavControlDTO);
        this.sendMessage(ardDroneInfo.getServerId(), switchUavControlCmd);
        return true;
    }
 
    /**
     * 起飞
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean takeOff(TakeOffDTO takeOffDTO) {
        String boxSn = takeOffDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        TakeOffCmd takeOffCmd = new TakeOffCmd(takeOffDTO);
        this.sendMessage(ardDroneInfo.getServerId(), takeOffCmd);
        return true;
    }
 
    /**
     * 返航
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean returnHome(ReturnHomeDTO returnHomeDTO) {
        String boxSn = returnHomeDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        ReturnHomeCmd returnHomeCmd = new ReturnHomeCmd(returnHomeDTO);
        this.sendMessage(ardDroneInfo.getServerId(), returnHomeCmd);
        return true;
    }
 
    /**
     * 取消返航
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean returnHomeCancel(ReturnHomeCancelDTO returnHomeCancelDTO) {
        String boxSn = returnHomeCancelDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        ReturnHomeCancelCmd returnHomeCancelCmd = new ReturnHomeCancelCmd(returnHomeCancelDTO);
        this.sendMessage(ardDroneInfo.getServerId(), returnHomeCancelCmd);
        return true;
    }
 
    /**
     * 降落
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean land(LandDTO landDTO) {
        String boxSn = landDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        LandCmd landCmd = new LandCmd(landDTO);
        this.sendMessage(ardDroneInfo.getServerId(), landCmd);
        return true;
    }
 
    /**
     * 取消降落
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean landCancel(LandCancelDTO landCancelDTO) {
        String boxSn = landCancelDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        LandCancelCmd landCancelCmd = new LandCancelCmd(landCancelDTO);
        this.sendMessage(ardDroneInfo.getServerId(), landCancelCmd);
        return true;
    }
 
    /**
     * 强制降落
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean landForced(LandForcedDTO landForcedDTO) {
        String boxSn = landForcedDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        LandForcedCmd landForcedCmd = new LandForcedCmd(landForcedDTO);
        this.sendMessage(ardDroneInfo.getServerId(), landForcedCmd);
        return true;
    }
 
    /**
     * 方向控制
     */
    @CheckControlRight(UavControlType.FLY)
    @CheckTakeoffAltitude
    @Override
    public Boolean flyControl(FlyControlDTO flyControlDTO) {
        String boxSn = flyControlDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        FlyControlCmd flyControlCmd = new FlyControlCmd(flyControlDTO);
        this.sendMessage(ardDroneInfo.getServerId(), flyControlCmd);
        return true;
    }
 
    /**
     * 指点飞行控制
     */
    @CheckControlRight(UavControlType.FLY)
    @CheckTakeoffAltitude
    @CheckNoFlyZone
    @Override
    public Boolean flyPointControl(FlyPointControlDTO flyPointControlDTO) {
        String boxSn = flyPointControlDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        FlyPointControlCmd flyPointControlCmd = new FlyPointControlCmd(flyPointControlDTO);
        this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCmd);
        return true;
    }
 
    /**
     * 停止指点飞行控制
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean flyPointControlCancel(FlyPointControlCancelDTO flyPointControlCancelDTO) {
        String boxSn = flyPointControlCancelDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
 
 
        FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(flyPointControlCancelDTO);
        this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCancelCmd);
        return true;
    }
 
 
    /**
     * 环绕飞行控制
     */
    @Override
    public Boolean FlyRoundControl(FlyRoundControlDTO flyRoundControlDTO) {
        String boxSn = flyRoundControlDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        FlyRoundControlCmd flyRoundControlCmd = new FlyRoundControlCmd(flyRoundControlDTO);
        this.sendMessage(ardDroneInfo.getServerId(), flyRoundControlCmd);
        return true;
    }
 
    /**
     * 停止环绕飞行控制
     */
    @Override
    public Boolean FlyRoundControlCancel(FlyRoundControlCancelDTO flyRoundControlCancelDTO) {
        String boxSn = flyRoundControlCancelDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        FlyRoundControlCancelCmd flyRoundControlCancelCmd = new FlyRoundControlCancelCmd(flyRoundControlCancelDTO);
        this.sendMessage(ardDroneInfo.getServerId(), flyRoundControlCancelCmd);
        return true;
    }
 
    /**
     * 紧急制动
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean emeragencyBrake(EmeragencyBrakeDTO emeragencyBrakeDTO) {
        String boxSn = emeragencyBrakeDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
 
 
        EmergencyBrakeCmd emergencyBrakeCmd = new EmergencyBrakeCmd(emeragencyBrakeDTO);
        this.sendMessage(ardDroneInfo.getServerId(), emergencyBrakeCmd);
        return true;
    }
 
    /**
     * 获取无人机状态
     */
    @Override
    public UavState getUavState(String boxSn) {
        return UavStateCache.get(boxSn);
    }
 
    /**
     * 获取无人机遥测数据
     */
    @Override
    public TelemetryData getUavTelemetryData(String boxSn) {
        return UavTelemetryDataCache.get(boxSn);
    }
 
    /**
     * 获取无人机遥测数据
     */
    @Override
    public SignalInfo getSignalInfo(String boxSn) {
        return UavSignalInfoCache.get(boxSn);
    }
 
    /**
     * 喊话模式切换
     */
    @Override
    public Boolean speakModeSwitch(SpeakModeSwitchDTO speakModeSwitchDTO) {
        String boxSn = speakModeSwitchDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        SpeakModeSwitchCmd speakModeSwitchCmd = new SpeakModeSwitchCmd(speakModeSwitchDTO);
        this.sendMessage(ardDroneInfo.getServerId(), speakModeSwitchCmd);
        return true;
    }
 
    /**
     * 文字喊话
     */
    @Override
    public Boolean textSpeak(TextSpeakDTO textSpeakDTO) {
        String boxSn = textSpeakDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        TextSpeakCmd textSpeakCmd = new TextSpeakCmd(textSpeakDTO);
        this.sendMessage(ardDroneInfo.getServerId(), textSpeakCmd);
        return true;
    }
 
    /**
     * 实时喊话
     */
    @Override
    public Boolean realSpeak(RealSpeakDTO realSpeakDTO) {
        String boxSn = realSpeakDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        RealSpeakCmd realSpeakCmd = new RealSpeakCmd(realSpeakDTO);
        this.sendMessage(ardDroneInfo.getServerId(), realSpeakCmd);
        return true;
    }
 
    /**
     * 录音喊话
     */
    @Override
    public Boolean recordSpeak(RecordSpeakDTO recordSpeakDTO) {
        String boxSn = recordSpeakDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        RecordSpeakCmd recordSpeakCmd = new RecordSpeakCmd(recordSpeakDTO);
        this.sendMessage(ardDroneInfo.getServerId(), recordSpeakCmd);
        return true;
    }
 
    /**
     * 设置音量
     */
    @Override
    public Boolean volumeSetting(VolumeSettingDTO volumeSettingDTO) {
        String boxSn = volumeSettingDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        VolumeSettingCmd volumeSettingCmd = new VolumeSettingCmd(volumeSettingDTO);
        this.sendMessage(ardDroneInfo.getServerId(), volumeSettingCmd);
        return true;
    }
 
    /**
     * 设置循环播放
     */
    @Override
    public Boolean loopSetting(LoopSettingDTO loopSettingDTO) {
        String boxSn = loopSettingDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        LoopSettingCmd loopSettingCmd = new LoopSettingCmd(loopSettingDTO);
        this.sendMessage(ardDroneInfo.getServerId(), loopSettingCmd);
        return true;
    }
 
    /**
     * 停止喊话
     */
    @Override
    public Boolean stopSpeak(StopSpeakDTO stopSpeakDTO) {
        String boxSn = stopSpeakDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        StopSpeakCmd stopSpeakCmd = new StopSpeakCmd(stopSpeakDTO);
        this.sendMessage(ardDroneInfo.getServerId(), stopSpeakCmd);
        return true;
    }
 
    /**
     * 航线上传
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean wayLineUpload(WayLineUploadDTO wayLineUploadDTO) {
        String boxSn = wayLineUploadDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        //wayLineUploadDTO.setWayLineData(this.CreatePlanLineData());//设置航线数据
        System.out.println("wayLineUploadDTO:-----------------" + wayLineUploadDTO);
        log.info("打印数据 ++++ wayLineUploadDTO:-----------------" + wayLineUploadDTO);
        WayLineUploadCmd wayLineUploadCmd = new WayLineUploadCmd(wayLineUploadDTO);
        System.out.println("wayLineUploadCmd:-----------------" + wayLineUploadCmd);
        this.sendMessage(ardDroneInfo.getServerId(), wayLineUploadCmd);
        return true;
    }
 
    //创建航线
    private PlanLineData CreatePlanLineData() {
        TelemetryDataPB.PointData pointData1 = TelemetryDataPB.PointData.newBuilder()
                .setLng(124.12345).setLat(45.12345).setHeight(80).setSpeed(10)
                .setFlightPathMode(1)//航线飞行模式:1=直线飞行,2=协调转弯,3=曲线飞行(停),4=曲线飞行(不停)
                .setSafeGohomeFlag(0)//是否为安全返航点 0=不是,1=是
                .build();
        TelemetryDataPB.PointData pointData2 = TelemetryDataPB.PointData.newBuilder()
                .setLng(124.22222).setLat(45.22222).setHeight(80).setSpeed(10)
                .setFlightPathMode(1)//航线飞行模式:1=直线飞行,2=协调转弯,3=曲线飞行(停),4=曲线飞行(不停)
                .setSafeGohomeFlag(0)//是否为安全返航点 0=不是,1=是
                .build();
        TelemetryDataPB.PointData pointData3 = TelemetryDataPB.PointData.newBuilder()
                .setLng(124.33333).setLat(45.33333).setHeight(80).setSpeed(10)
                .setFlightPathMode(1)//航线飞行模式:1=直线飞行,2=协调转弯,3=曲线飞行(停),4=曲线飞行(不停)
                .setSafeGohomeFlag(0)//是否为安全返航点 0=不是,1=是
                .build();
 
        //创建航线
        TelemetryDataPB.PlanLineData PlanLineDataPB = TelemetryDataPB.PlanLineData.newBuilder()
                .setFinishedAction(2)//结束航线后动作:1=返航,2=原地悬停,3=原地降落,4=原地绕飞
                .setMaxSpeed(10)//最大飞行速度
                .setAutoSpeed(10)//自动飞行速度
                .addPoints(pointData1)//航线点1
                .addPoints(pointData2)//航线点2
                .addPoints(pointData3)//航线点3
                .setLoseAction(1)//网络失联后动作:0=返回HOME点,1=继续航线,默认0
                .setHomeHeight(6)//返航高度:(单位:米,范围20~1500)
                .setIsSaveEnergyMode(0)////是否开启节能模式:0=不是,1=是(说明:节能模式下,飞机沿最短直线距离由起飞点到航线第一个航点,非升高到第一个航点高度再飞往第一个航点)
                .build();
 
        return PlanLineDataConverter.convertProtoToEntity(PlanLineDataPB);
    }
 
    /**
     * 航线开始
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean wayLineBegin(WayLineBeginDTO wayLineBeginDTO) {
        String boxSn = wayLineBeginDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        WayLineBeginCmd wayLineBeginCmd = new WayLineBeginCmd(wayLineBeginDTO);
        this.sendMessage(ardDroneInfo.getServerId(), wayLineBeginCmd);
        return true;
    }
 
    /**
     * 航线暂停
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean wayLinePause(WayLinePauseDTO wayLinePauseDTO) {
        String boxSn = wayLinePauseDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        WayLinePauseCmd wayLinePauseCmd = new WayLinePauseCmd(wayLinePauseDTO);
        this.sendMessage(ardDroneInfo.getServerId(), wayLinePauseCmd);
        return true;
    }
 
    /**
     * 航线恢复
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean wayLineResume(WayLineResumeDTO wayLineResumeDTO) {
        String boxSn = wayLineResumeDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        WayLineResumeCmd wayLineResumeCmd = new WayLineResumeCmd(wayLineResumeDTO);
        this.sendMessage(ardDroneInfo.getServerId(), wayLineResumeCmd);
        return true;
    }
 
    /**
     * 航线结束
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean wayLineEnd(WayLineEndDTO wayLineEndDTO) {
        String boxSn = wayLineEndDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        WayLineEndCmd wayLineEndCmd = new WayLineEndCmd(wayLineEndDTO);
        this.sendMessage(ardDroneInfo.getServerId(), wayLineEndCmd);
        return true;
    }
 
    /**
     * 处理边缘服务器返回的消息
     */
    @Override
    public void processReplyMessage(String key, BaseCmd tyCommand) {
        byte cmdCode = tyCommand.getCmdCode();
        switch (cmdCode) {
            case 0x01:
                // 处理心跳消息
                RegisterReplyCmd registerReplyCommand = (RegisterReplyCmd) tyCommand;
                logPrint("注册消息", registerReplyCommand.getSuccess());
                if (registerReplyCommand.getSuccess() != 1) {
                    // 注册失败,重新注册
                    log.info("注册失败,重新注册");
                    registerMessage(key);
                }
                break;
            case 0x02:
                // 处理注册消息
                HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
                //logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
                break;
            case 0x03:
                // 处理订阅消息
                break;
            case 0x04:
                // 处理取消订阅消息
                break;
            case 0x09:
                // 处理图片上传完成通知
                PicUploadCompletedReplyCmd picUploadCompletedReplyCmd = (PicUploadCompletedReplyCmd) tyCommand;
                logPrint("图片上传完成", picUploadCompletedReplyCmd.getPicUrl());
                break;
            case 0x0A:
                // 处理云盒开关机通知消息
                BoxPowerStatusReplyCmd boxPowerStatusReplyCmd = (BoxPowerStatusReplyCmd) tyCommand;
                logPrint("云盒开关机通知消息", boxPowerStatusReplyCmd.getStatus());
                break;
            case (byte) 0xA8:
                // 处理无人机状态消息
                UavStateCmd uavStateCmd = (UavStateCmd) tyCommand;
                UavStateCache.put(uavStateCmd.getUavState());
                //logPrint("无人机状态", uavStateCmd.getUavState().getBoxSn());
                // WebSocketUtil.sendMessageAll(uavStateCmd.getUavState());
                break;
            case (byte) 0xA9:
                // 处理无人机遥测消息
                UavTelemetryDataCmd uavTelemetryDataCmd = (UavTelemetryDataCmd) tyCommand;
                TelemetryData telemetryData = uavTelemetryDataCmd.getTelemetryData();
                telemetryData.setTimestamp(System.currentTimeMillis());//由于六合提供的状态时间戳不准,先以接收状态作为时间戳
                UavTelemetryDataCache.put(telemetryData);
                //logPrint("无人机遥测", uavTelemetryDataCmd.getTelemetryData().getBoxSn());
                //WebSocketUtil.sendMessageAll(uavTelemetryDataCmd.getTelemetryData());
                break;
 
            case (byte) 0x0C:
                // 处理无人机信道质量数据
                SignalInfoCmd signalInfoCmd = (SignalInfoCmd) tyCommand;
                UavSignalInfoCache.put(signalInfoCmd.getSignalInfo());
                //logPrint("无人机信道质量", signalInfoCmd.getSignalInfo().getBoxSn());
                break;
            case (byte) 0xD1:
                // 处理无人机
                if (tyCommand instanceof UavInitReplyCmd) {
                    UavInitReplyCmd uavInitReplyCmd = (UavInitReplyCmd) tyCommand;
                    UavInitInfoCmd uavInitCommand = new UavInitInfoCmd(uavInitReplyCmd.getBoxSn());
                    this.sendMessage(key, uavInitCommand);
                    logPrint("无人机初始化详情", uavInitCommand.getBoxSn());
                }
                if (tyCommand instanceof UavReadyReplyCmd) {
                    UavReadyReplyCmd uavReadyReplyCmd = (UavReadyReplyCmd) tyCommand;
                    logPrint("无人机准备完成通知", uavReadyReplyCmd.getBatteryPower());
                }
                if (tyCommand instanceof CameraModeReplyCmd) {
                    CameraModeReplyCmd cameraModeReplyCommand = (CameraModeReplyCmd) tyCommand;
                    logPrint("无人机设置相机模式", cameraModeReplyCommand.getResult(), cameraModeReplyCommand.getErrorCode());
                }
                //格式化存储卡
                if (tyCommand instanceof FormatSdCardReplyCmd) {
                    FormatSdCardReplyCmd formatSdCardReplyCmd = (FormatSdCardReplyCmd) tyCommand;
                    logPrint("格式化存储卡", formatSdCardReplyCmd.getResult(), formatSdCardReplyCmd.getErrorCode());
                }
                if (tyCommand instanceof CapturePicReplyCmd) {
                    CapturePicReplyCmd capturePicReplyCommand = (CapturePicReplyCmd) tyCommand;
                    logPrint("无人机拍照", capturePicReplyCommand.getResult(), capturePicReplyCommand.getErrorCode());
                }
                if (tyCommand instanceof RecordStartReplyCmd) {
                    RecordStartReplyCmd recordStartReplyCommand = (RecordStartReplyCmd) tyCommand;
                    logPrint("无人机开始录像", recordStartReplyCommand.getResult(), recordStartReplyCommand.getErrorCode());
                }
                if (tyCommand instanceof RecordStopReplyCmd) {
                    RecordStopReplyCmd recordStopReplyCommand = (RecordStopReplyCmd) tyCommand;
                    logPrint("无人机停止录像", recordStopReplyCommand.getResult(), recordStopReplyCommand.getErrorCode());
                }
                //起飞回复
                if (tyCommand instanceof TakeOffReplyCmd) {
                    TakeOffReplyCmd takeOffReplyCommand = (TakeOffReplyCmd) tyCommand;
                    logPrint("无人机起飞", takeOffReplyCommand.getResult(), takeOffReplyCommand.getErrorCode());
                }
                //返航回复
                if (tyCommand instanceof ReturnHomeReplyCmd) {
                    ReturnHomeReplyCmd returnHomeReplyCmd = (ReturnHomeReplyCmd) tyCommand;
                    logPrint("无人机返航", returnHomeReplyCmd.getResult(), returnHomeReplyCmd.getErrorCode());
                }
                //取消返航回复
                if (tyCommand instanceof ReturnHomeCancelReplyCmd) {
                    ReturnHomeCancelReplyCmd returnHomeCancelReplyCmd = (ReturnHomeCancelReplyCmd) tyCommand;
                    logPrint("取消无人机返航", returnHomeCancelReplyCmd.getResult(), returnHomeCancelReplyCmd.getErrorCode());
                }
                //降落回复
                if (tyCommand instanceof LandReplyCmd) {
                    LandReplyCmd landReplyCmd = (LandReplyCmd) tyCommand;
                    logPrint("降落", landReplyCmd.getResult(), landReplyCmd.getErrorCode());
                }
                //取消降落回复
                if (tyCommand instanceof LandCancelReplyCmd) {
                    LandCancelReplyCmd landCancelReplyCmd = (LandCancelReplyCmd) tyCommand;
                    logPrint("取消降落", landCancelReplyCmd.getResult(), landCancelReplyCmd.getErrorCode());
                }
                //强制降落回复
                if (tyCommand instanceof LandForcedReplyCmd) {
                    LandForcedReplyCmd landForcedReplyCmd = (LandForcedReplyCmd) tyCommand;
                    logPrint("强制降落", landForcedReplyCmd.getResult(), landForcedReplyCmd.getErrorCode());
                }
                //到达指点飞行位置回复
                if (tyCommand instanceof PointControlReachedReplyCmd) {
                    PointControlReachedReplyCmd pointControlReachedReplyCmd = (PointControlReachedReplyCmd) tyCommand;
                    logPrint("到达指点飞行位置", pointControlReachedReplyCmd.getResult(),
                            pointControlReachedReplyCmd.getErrorCode());
                }
                //紧急制动回复
                if (tyCommand instanceof EmergencyBrakeReplyCmd) {
                    EmergencyBrakeReplyCmd emergencyBrakeReplyCmd = (EmergencyBrakeReplyCmd) tyCommand;
                    logPrint("紧急制动", emergencyBrakeReplyCmd.getResult(), emergencyBrakeReplyCmd.getErrorCode());
                }
                //上传航线回复
                if (tyCommand instanceof WayLineUploadReplyCmd) {
                    WayLineUploadReplyCmd wayLineUploadReplyCmd = (WayLineUploadReplyCmd) tyCommand;
                    logPrint("上传航线", wayLineUploadReplyCmd.getResult(), wayLineUploadReplyCmd.getErrorCode());
                }
                //开始航线回复
                if (tyCommand instanceof WayLineBeginReplyCmd) {
 
                    WayLineBeginReplyCmd wayLineBeginReplyCmd = (WayLineBeginReplyCmd) tyCommand;
                    logPrint("开始航线", wayLineBeginReplyCmd.getResult(), wayLineBeginReplyCmd.getErrorCode());
                    if (wayLineBeginReplyCmd.getResult() == 0) {
                        byte[] boxSnBytes = tyCommand.getBoxSn();
                        String boxSn = new String(boxSnBytes);
                        stateMachineService.sendEvent(boxSn, RouteEvent.START_SUCCESS);
                    }
                }
                //暂停航线回复
                if (tyCommand instanceof WayLinePauseReplyCmd) {
                    WayLinePauseReplyCmd wayLinePauseReplyCmd = (WayLinePauseReplyCmd) tyCommand;
                    logPrint("暂停航线", wayLinePauseReplyCmd.getResult(), wayLinePauseReplyCmd.getErrorCode());
                    if (wayLinePauseReplyCmd.getResult() == 0) {
                        byte[] boxSnBytes = tyCommand.getBoxSn();
                        String boxSn = new String(boxSnBytes);
                        stateMachineService.sendEvent(boxSn, RouteEvent.PAUSE_SUCCESS);
                    }
                }
                //恢复航线回复
                if (tyCommand instanceof WayLineResumeReplyCmd) {
                    WayLineResumeReplyCmd wayLineResumeReplyCmd = (WayLineResumeReplyCmd) tyCommand;
                    logPrint("恢复航线", wayLineResumeReplyCmd.getResult(), wayLineResumeReplyCmd.getErrorCode());
                    if (wayLineResumeReplyCmd.getResult() == 0) {
                        byte[] boxSnBytes = tyCommand.getBoxSn();
                        String boxSn = new String(boxSnBytes);
                        stateMachineService.sendEvent(boxSn, RouteEvent.RESUME_SUCCESS);
                    }
                }
                //结束航线回复
                if (tyCommand instanceof WayLineEndReplyCmd) {
                    WayLineEndReplyCmd wayLineEndReplyCmd = (WayLineEndReplyCmd) tyCommand;
                    logPrint("结束航线", wayLineEndReplyCmd.getResult(), wayLineEndReplyCmd.getErrorCode());
                    if (wayLineEndReplyCmd.getResult() == 0) {
                        byte[] boxSnBytes = tyCommand.getBoxSn();
                        String boxSn = new String(boxSnBytes);
                        stateMachineService.sendEvent(boxSn, RouteEvent.STOP_SUCCESS);
                    }
                }
                if (tyCommand instanceof WayLineFinishedReplyCmd) {
                    WayLineFinishedReplyCmd wayLineFinishedReplyCmd = (WayLineFinishedReplyCmd) tyCommand;
                    logPrint("航线执行完成", wayLineFinishedReplyCmd.getResult(), wayLineFinishedReplyCmd.getErrorCode());
                    if (wayLineFinishedReplyCmd.getResult() == 0) {
                        byte[] boxSnBytes = tyCommand.getBoxSn();
                        String boxSn = new String(boxSnBytes);
                        stateMachineService.sendEvent(boxSn, RouteEvent.RESET_ROUTE);
                    }
                }
                //设置返航高度回复
                if (tyCommand instanceof ReturnHeightSettingReplyCmd) {
                    ReturnHeightSettingReplyCmd returnHeightSettingReplyCmd = (ReturnHeightSettingReplyCmd) tyCommand;
                    logPrint("设置返航高度", returnHeightSettingReplyCmd.getResult(),
                            returnHeightSettingReplyCmd.getErrorCode());
                }
                //设置返航点回复
                if (tyCommand instanceof ReturnPointSettingReplyCmd) {
                    ReturnPointSettingReplyCmd returnPointSettingReplyCmd = (ReturnPointSettingReplyCmd) tyCommand;
                    logPrint("设置返航点", returnPointSettingReplyCmd.getResult(),
                            returnPointSettingReplyCmd.getErrorCode());
                }
                //到达环绕位置回复
                if (tyCommand instanceof FlyRoundReplyCmd) {
                    FlyRoundReplyCmd flyRoundReplyCmd = (FlyRoundReplyCmd) tyCommand;
                    logPrint("到达环绕位置", flyRoundReplyCmd.getResult(),
                            flyRoundReplyCmd.getErrorCode());
                }
                break;
            case (byte) 0xD2:
                //设置视频码流回复
                if (tyCommand instanceof VideoStreamSettingReplyCmd) {
                    VideoStreamSettingReplyCmd videoStreamSettingReplyCmd = (VideoStreamSettingReplyCmd) tyCommand;
                    logPrint("设置视频码流", videoStreamSettingReplyCmd.getResult(),
                            videoStreamSettingReplyCmd.getErrorCode());
                }
                break;
            default:
                // 处理其他消息
                log.warn("收到其他消息-->{}", tyCommand.getCmdCode());
        }
    }
 
    /**
     * 根据[服务器id]获取边缘服务器盒子列表
     */
    @Override
    public List<BoxInfoReceiver> getBoxSnToList(String id) {
        try {
            List<BoxInfoReceiver> remoteBoxList = tyClient.getBoxList(id).getContent();
            List<ArdDroneInfo> existingDrones = getDroneLs(id);
            return existingDrones.isEmpty() ? remoteBoxList : filterBoxInfoReceivers(remoteBoxList, existingDrones);
        } catch (Exception e) {
            log.error("获取云盒列表失败, 服务器id: {}", id, e);
            return Collections.emptyList(); // 返回不可变空列表,更安全
        }
    }
 
    /**
     * 根据[服务器id]查询无人机盒子列表
     */
    private List<ArdDroneInfo> getDroneLs(String serverId) {
        ArdDroneInfo query = new ArdDroneInfo();
        query.setServerId(serverId);
        return ardDroneService.selectArdDroneList(query);
    }
 
    /**
     * 过滤掉在ardDroneInfos中已存在的boxSn
     */
    public List<BoxInfoReceiver> filterBoxInfoReceivers(
            List<BoxInfoReceiver> boxInfoReceivers,
            List<ArdDroneInfo> ardDroneInfos) {
 
        Set<String> existingBoxSns = ardDroneInfos.stream()
                .map(ArdDroneInfo::getBoxSn)
                .filter(Objects::nonNull)
                .collect(Collectors.toSet());
 
        return boxInfoReceivers.stream()
                .filter(box -> box.getBoxSn() != null && !existingBoxSns.contains(box.getBoxSn()))
                .collect(Collectors.toList());
    }
 
    private List<BoxInfoReceiver> getBoxList(List<ArdServerInfo> ls) {
        return ls.stream()
                .filter(ardServerInfo -> ardServerInfo.getServerStatus().equals("1"))
                .flatMap(ardServerInfo -> {
                    try {
                        List<BoxInfoReceiver> boxes = tyClient.getBoxList(ardServerInfo.getId()).getContent();
                        return Optional.ofNullable(boxes).orElse(Collections.emptyList()).stream();
                    } catch (Exception e) {
                        log.error("获取云盒列表失败: {}", ardServerInfo.getId(), e);
                        return Stream.empty();
                    }
                })
                .collect(Collectors.toList());
    }
 
    //公共日志打印
    private void logPrint(String message, Object obj) {
        String text = String.format("收到%s回复 %s", message, obj);
        ServerReplyMessage serverReplyMessage = ServerReplyMessage.builder().message(text).build();
        WebSocketUtil.sendMessage("reply", serverReplyMessage);
        log.debug(text);
    }
 
    //公共日志打印
    private void logPrint(String message, byte result, Integer errorCode) {
        String text = String.format(
                "收到%s回复 状态码:%d【%s】",
                message,
                //ByteUtils.byteToHex(result),
                errorCode,
                ErrorCodeEnum.getDescByCode(errorCode)
        );
        ServerReplyMessage serverReplyMessage = ServerReplyMessage.builder().message(text).build();
        WebSocketUtil.sendMessage("reply", serverReplyMessage);
        log.debug(text);
    }
 
 
    /**
     * 发送tcp消息
     */
    private void sendMessage(String key, BaseCmd msg) {
        TcpClientUtil.sendMessage(key, msg);
    }
}