From cb64fd625a291769e2626c3f2e56e9cf99244100 Mon Sep 17 00:00:00 2001 From: zxd Date: Sat, 3 Nov 2018 10:28:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A9=BA=E4=B8=AD=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=20=E4=BF=AE=E6=94=B9=E6=96=AD=E7=BA=BF=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8F=90=E9=86=92=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommunicationManagement/CommModule.cs | 21 ++++++++++++++----- .../CommModuleGenerateMavLink.cs | 2 +- .../CommModulePacketAnalysis.cs | 10 ++++++++- PlaneGcsSdk_Shared/Protocols/MavCommTypes.cs | 14 ++++++++++++- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/PlaneGcsSdk_Shared/CommunicationManagement/CommModule.cs b/PlaneGcsSdk_Shared/CommunicationManagement/CommModule.cs index 77773a6..60bc87f 100644 --- a/PlaneGcsSdk_Shared/CommunicationManagement/CommModule.cs +++ b/PlaneGcsSdk_Shared/CommunicationManagement/CommModule.cs @@ -69,11 +69,13 @@ namespace Plane.CommunicationManagement if (Connection.IsOnline) { + Message.Connect(true); SendQuery(); await StartReadingPacketsAsync(); } else { + Message.Connect(false); Reconnect(); } } @@ -112,11 +114,12 @@ namespace Plane.CommunicationManagement int times = 1; private void Reconnect() { + //Message.Show($"正在重新连接..."); Task.Run(async () => { CloseConnection(); await Task.Delay(250).ConfigureAwait(false); - Message.Show($"正在重连:次数{times++}"); + //Message.Show($"正在重连:次数{times++}"); await Task.Delay(250).ConfigureAwait(false); await ConnectAsync(); @@ -183,7 +186,7 @@ namespace Plane.CommunicationManagement string msg = string.Format("错误Id={0}, 检测飞机总数={1},工作模式={2} 流水号={3}", errorId, copterCount, curMode, serialNum); CommModuleCopterCount = copterCount; CommModuleCurMode = curMode; - //Message.Show(msg); + //Message.Show(msg); break; } } @@ -254,6 +257,14 @@ namespace Plane.CommunicationManagement await WriteCommPacketAsync(copterId, messageType, data); } + public async Task UpdateCommModule() + { + MavComm.comm_update_copter_module commUpdate = new MavComm.comm_update_copter_module(); + commUpdate.mav_count = (short)CommModuleCopterCount; + commUpdate.update_code = 0x7713; + await GenerateDataAsync(0, MavComm.COMM_UPDATE_COPTER_MODULE, commUpdate); + } + bool temp = false; //测试用 灯光间隔1S闪烁 public async Task TestLED(short id) @@ -265,9 +276,9 @@ namespace Plane.CommunicationManagement led.pattern = 0; led.custom_len = 4; led.custom_bytes = new byte[24]; - led.custom_bytes[0] = 80; - led.custom_bytes[1] = 0; - led.custom_bytes[2] = 0; + led.custom_bytes[0] = 175; + led.custom_bytes[1] = 30; + led.custom_bytes[2] = 50; led.custom_bytes[3] = 3; byte[] data; data = MavlinkUtil.StructureToByteArray(led); diff --git a/PlaneGcsSdk_Shared/CommunicationManagement/CommModuleGenerateMavLink.cs b/PlaneGcsSdk_Shared/CommunicationManagement/CommModuleGenerateMavLink.cs index e04c0f6..b200449 100644 --- a/PlaneGcsSdk_Shared/CommunicationManagement/CommModuleGenerateMavLink.cs +++ b/PlaneGcsSdk_Shared/CommunicationManagement/CommModuleGenerateMavLink.cs @@ -118,7 +118,7 @@ namespace Plane.CommunicationManagement /// public async Task DoMissionStartAsync(int hour_utc, int minute_utc, int second_utc, double Missionlng, double Missionlat) { - byte[] packet = DoCommandAsync(MAVLink.MAV_CMD.MISSION_START, hour_utc, minute_utc, second_utc, (float)Missionlng, (float)Missionlat, 0, 0); + byte[] packet = DoCommandAsync(MAVLink.MAV_CMD.MISSION_START, hour_utc, minute_utc, second_utc, (float)Missionlng, (float)Missionlat, 0, -1); await WriteCommPacketAsync(0, MavComm.COMM_DOWNLOAD_COMM, packet).ConfigureAwait(false); } diff --git a/PlaneGcsSdk_Shared/CommunicationManagement/CommModulePacketAnalysis.cs b/PlaneGcsSdk_Shared/CommunicationManagement/CommModulePacketAnalysis.cs index 981a9e9..dca8b7b 100644 --- a/PlaneGcsSdk_Shared/CommunicationManagement/CommModulePacketAnalysis.cs +++ b/PlaneGcsSdk_Shared/CommunicationManagement/CommModulePacketAnalysis.cs @@ -43,7 +43,8 @@ namespace Plane.CommunicationManagement private void AnalyzeStringPacket(short copterId, byte[] buffer) { - string msg = System.Text.Encoding.Default.GetString(buffer).Replace("tcpserver", "flicube"); + int count = Array.IndexOf(buffer, (byte)0); + string msg = System.Text.Encoding.Default.GetString(buffer, 0, count).Replace("tcpserver", "flicube"); Message.Show(msg); } @@ -102,6 +103,13 @@ namespace Plane.CommunicationManagement case 0x03: SaveMissionWriteStat(copterId, buffer[1]); break; + + case 0x0e: + if (copterId == 0) + Message.Show("----------全部更新完成----------"); + else + Message.Show($"飞机{copterId}:更新进度{buffer[1]}%"); + break; } } diff --git a/PlaneGcsSdk_Shared/Protocols/MavCommTypes.cs b/PlaneGcsSdk_Shared/Protocols/MavCommTypes.cs index 180863d..92a91fc 100644 --- a/PlaneGcsSdk_Shared/Protocols/MavCommTypes.cs +++ b/PlaneGcsSdk_Shared/Protocols/MavCommTypes.cs @@ -79,6 +79,11 @@ namespace Plane.Protocols /// public const short COMM_NOTIFICATION = 0x1234; + /// + /// 空中升级(更新通信模块飞机端) + /// + public const short COMM_UPDATE_COPTER_MODULE = 0xFD; + #endregion public enum CommMode @@ -119,7 +124,14 @@ namespace Plane.Protocols public Int16 mav_count; //飞机总数 }; - + [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)] + public struct comm_update_copter_module + { + public Int16 mav_count; //飞机总数 + public Int16 update_code; + }; + + [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 8)] public struct comm_asyn_time {