diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml b/Correlator/Dialog/SoundSpeedDialog.xaml index 83a2a87..385a68b 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml +++ b/Correlator/Dialog/SoundSpeedDialog.xaml @@ -32,8 +32,7 @@ - - + @@ -41,7 +40,6 @@ - - - - - - - - + + + + + + + + + @@ -169,30 +144,6 @@ - - diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml b/Correlator/Dialog/SoundSpeedDialog.xaml index 83a2a87..385a68b 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml +++ b/Correlator/Dialog/SoundSpeedDialog.xaml @@ -32,8 +32,7 @@ - - + @@ -41,7 +40,6 @@ - - - - - - - - + + + + + + + + + @@ -169,30 +144,6 @@ - - diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml.cs b/Correlator/Dialog/SoundSpeedDialog.xaml.cs index 229a704..8cd8898 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml.cs +++ b/Correlator/Dialog/SoundSpeedDialog.xaml.cs @@ -10,6 +10,8 @@ { InitializeComponent(); + SelectedPipeTextBlock.Text = materialName; + Messenger.Default.Send(materialName, MessengerToken.SoundSpeed); GoBackButton.Click += delegate { Close(); }; diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml b/Correlator/Dialog/SoundSpeedDialog.xaml index 83a2a87..385a68b 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml +++ b/Correlator/Dialog/SoundSpeedDialog.xaml @@ -32,8 +32,7 @@ - - + @@ -41,7 +40,6 @@ - - - - - - - - + + + + + + + + + @@ -169,30 +144,6 @@ - - diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml.cs b/Correlator/Dialog/SoundSpeedDialog.xaml.cs index 229a704..8cd8898 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml.cs +++ b/Correlator/Dialog/SoundSpeedDialog.xaml.cs @@ -10,6 +10,8 @@ { InitializeComponent(); + SelectedPipeTextBlock.Text = materialName; + Messenger.Default.Send(materialName, MessengerToken.SoundSpeed); GoBackButton.Click += delegate { Close(); }; diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index 26b8d79..eb3d4f3 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -156,6 +156,97 @@ } /// + /// 水听器点名指令 + /// + /// + /// + /// + public static void StartCheckResponse(SerialPort sp, string devCode, byte[] timeBytes) + { + try + { + //A3 20 + //00 1F + //21 17 00 08 22 02 + //01 + //FF FF + //01 82 + //01 + //40 00 00 02 00 01 00 + //10 00 00 51 00 06 17 06 19 0F 3B 14 + + const string preamble = "A3"; + var preambleByte = byte.Parse(preamble, NumberStyles.HexNumber); + + const string version = "20"; + var btVersion = byte.Parse(version, NumberStyles.HexNumber); + + //后续到CRC字段前的字节总长度(不包括长度字段和CRC字段)。 + byte[] totalLen = { 0x00, 0x1F }; + + var btDevId = new byte[6]; + btDevId[0] = byte.Parse(devCode.Substring(0, 2), NumberStyles.HexNumber); + btDevId[1] = byte.Parse(devCode.Substring(2, 2), NumberStyles.HexNumber); + btDevId[2] = byte.Parse(devCode.Substring(4, 2), NumberStyles.HexNumber); + btDevId[3] = byte.Parse(devCode.Substring(6, 2), NumberStyles.HexNumber); + btDevId[4] = byte.Parse(devCode.Substring(8, 2), NumberStyles.HexNumber); + btDevId[5] = byte.Parse(devCode.Substring(10, 2), NumberStyles.HexNumber); + + //通信方式 + const string routeFlag = "1"; + var btRouteFlag = byte.Parse(routeFlag, NumberStyles.HexNumber); + + byte[] btDstNode = { 0xFF, 0xFF }; + + byte[] btPdu = { 0x01, 0x82 }; + + const string seq = "1"; + var btSeq = byte.Parse(seq, NumberStyles.HexNumber); + + byte[] oidTag = { 0x40, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00 }; + + byte[] timeTag = + { + 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, + timeBytes[0], timeBytes[1], timeBytes[2], timeBytes[3], timeBytes[4], timeBytes[5] + }; //时间oid + + //wrap the whole data + var result = new byte[35]; + result[0] = preambleByte; + result[1] = btVersion; + totalLen.CopyTo(result, 2); + btDevId.CopyTo(result, 4); + result[10] = btRouteFlag; + btDstNode.CopyTo(result, 11); + btPdu.CopyTo(result, 13); + result[15] = btSeq; + oidTag.CopyTo(result, 16); + timeTag.CopyTo(result, 23); + + //增加CRC校验 + var strCrc = $"{(int)CodeUtil.CRC16_AD(result):X}".To16HexString(); + byte[] crcByte = + { + CodeUtil.String2Byte(strCrc.Substring(0, 2)), + CodeUtil.String2Byte(strCrc.Substring(2, 2)) + }; + + var afCrc = new byte[result.Length + 2]; + result.CopyTo(afCrc, 0); + crcByte.CopyTo(afCrc, result.Length); + + "CommandSender".WriteLog("下发水听器水听器点名指令 => " + BitConverter.ToString(afCrc)); + + sp.Write(afCrc, 0, afCrc.Length); + } + catch (Exception e) + { + LogHelper.Info(e.ToString()); + } + } + + /// /// 下发状态采集指令 /// /// diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml b/Correlator/Dialog/SoundSpeedDialog.xaml index 83a2a87..385a68b 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml +++ b/Correlator/Dialog/SoundSpeedDialog.xaml @@ -32,8 +32,7 @@ - - + @@ -41,7 +40,6 @@ - - - - - - - - + + + + + + + + + @@ -169,30 +144,6 @@ - - diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml.cs b/Correlator/Dialog/SoundSpeedDialog.xaml.cs index 229a704..8cd8898 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml.cs +++ b/Correlator/Dialog/SoundSpeedDialog.xaml.cs @@ -10,6 +10,8 @@ { InitializeComponent(); + SelectedPipeTextBlock.Text = materialName; + Messenger.Default.Send(materialName, MessengerToken.SoundSpeed); GoBackButton.Click += delegate { Close(); }; diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index 26b8d79..eb3d4f3 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -156,6 +156,97 @@ } /// + /// 水听器点名指令 + /// + /// + /// + /// + public static void StartCheckResponse(SerialPort sp, string devCode, byte[] timeBytes) + { + try + { + //A3 20 + //00 1F + //21 17 00 08 22 02 + //01 + //FF FF + //01 82 + //01 + //40 00 00 02 00 01 00 + //10 00 00 51 00 06 17 06 19 0F 3B 14 + + const string preamble = "A3"; + var preambleByte = byte.Parse(preamble, NumberStyles.HexNumber); + + const string version = "20"; + var btVersion = byte.Parse(version, NumberStyles.HexNumber); + + //后续到CRC字段前的字节总长度(不包括长度字段和CRC字段)。 + byte[] totalLen = { 0x00, 0x1F }; + + var btDevId = new byte[6]; + btDevId[0] = byte.Parse(devCode.Substring(0, 2), NumberStyles.HexNumber); + btDevId[1] = byte.Parse(devCode.Substring(2, 2), NumberStyles.HexNumber); + btDevId[2] = byte.Parse(devCode.Substring(4, 2), NumberStyles.HexNumber); + btDevId[3] = byte.Parse(devCode.Substring(6, 2), NumberStyles.HexNumber); + btDevId[4] = byte.Parse(devCode.Substring(8, 2), NumberStyles.HexNumber); + btDevId[5] = byte.Parse(devCode.Substring(10, 2), NumberStyles.HexNumber); + + //通信方式 + const string routeFlag = "1"; + var btRouteFlag = byte.Parse(routeFlag, NumberStyles.HexNumber); + + byte[] btDstNode = { 0xFF, 0xFF }; + + byte[] btPdu = { 0x01, 0x82 }; + + const string seq = "1"; + var btSeq = byte.Parse(seq, NumberStyles.HexNumber); + + byte[] oidTag = { 0x40, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00 }; + + byte[] timeTag = + { + 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, + timeBytes[0], timeBytes[1], timeBytes[2], timeBytes[3], timeBytes[4], timeBytes[5] + }; //时间oid + + //wrap the whole data + var result = new byte[35]; + result[0] = preambleByte; + result[1] = btVersion; + totalLen.CopyTo(result, 2); + btDevId.CopyTo(result, 4); + result[10] = btRouteFlag; + btDstNode.CopyTo(result, 11); + btPdu.CopyTo(result, 13); + result[15] = btSeq; + oidTag.CopyTo(result, 16); + timeTag.CopyTo(result, 23); + + //增加CRC校验 + var strCrc = $"{(int)CodeUtil.CRC16_AD(result):X}".To16HexString(); + byte[] crcByte = + { + CodeUtil.String2Byte(strCrc.Substring(0, 2)), + CodeUtil.String2Byte(strCrc.Substring(2, 2)) + }; + + var afCrc = new byte[result.Length + 2]; + result.CopyTo(afCrc, 0); + crcByte.CopyTo(afCrc, result.Length); + + "CommandSender".WriteLog("下发水听器水听器点名指令 => " + BitConverter.ToString(afCrc)); + + sp.Write(afCrc, 0, afCrc.Length); + } + catch (Exception e) + { + LogHelper.Info(e.ToString()); + } + } + + /// /// 下发状态采集指令 /// /// diff --git a/Correlator/Util/SerialPortManager.cs b/Correlator/Util/SerialPortManager.cs index ad2e6b9..ddcab54 100644 --- a/Correlator/Util/SerialPortManager.cs +++ b/Correlator/Util/SerialPortManager.cs @@ -11,7 +11,6 @@ using Correlator.SensorHubTag; using GalaSoft.MvvmLight.Messaging; using MessageBox = HandyControl.Controls.MessageBox; -using Tag = Correlator.SensorHubTag.Tag; namespace Correlator.Util { @@ -78,39 +77,30 @@ case 11293: //数据采集 HandleCorrelatorData(strDeviceId, tags); break; + case 30: //显示点名弹窗 + if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + { + //A3 20 00 18 21 17 00 08 22 01 01 22 01 0B 82 01 10 00 00 51 00 06 17 06 19 02 1A 04 88 38 + // 解析年月日时分秒 + var timeBytes = new byte[6]; + Array.Copy(receiveData, 22, timeBytes, 0, 6); + Application.Current.Dispatcher.Invoke(delegate + { + Messenger.Default.Send(timeBytes, MessengerToken.ShowCheckResponseDialog); + }); + } + + break; + case 1: + + break; case 15024: //听音 HandleListenData(tags); break; default: - "SerialPortManager".WriteLog("receiveData.Length:" + receiveData.Length); + Debug.WriteLine("SerialPortManager => " + receiveData.Length); break; } - - if (operateType != "WakeupResponse") return; - Sp.Write("+++"); - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) - { - //显示点名弹窗 - Messenger.Default.Send("", MessengerToken.ShowCheckResponseDialog); - } - } - else if (strResult != "") - { - //信号数据 - if (strResult.Contains("NO CARRIER")) - { - Sp.Write("ATS124?" + Environment.NewLine); - } - else if (strResult.Contains("ATS124?")) - { - var strReceiveDate = strResult.Replace("\r\n", ","); - var signalArray = strReceiveDate.Split(','); - - _devStatus.Signal = signalArray[1]; - - //收到信号就可以工作了 - Messenger.Default.Send("", MessengerToken.HomePageSignal); - } } else { @@ -192,8 +182,8 @@ //发送消息更新界面 Messenger.Default.Send(_devStatus, devCode.Equals(DevCode.Dev1) - ? MessengerToken.SensorADevStatus - : MessengerToken.SensorBDevStatus + ? MessengerToken.RedSensorStatus + : MessengerToken.BlueSensorStatus ); } diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml b/Correlator/Dialog/SoundSpeedDialog.xaml index 83a2a87..385a68b 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml +++ b/Correlator/Dialog/SoundSpeedDialog.xaml @@ -32,8 +32,7 @@ - - + @@ -41,7 +40,6 @@ - - - - - - - - + + + + + + + + + @@ -169,30 +144,6 @@ - - diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml.cs b/Correlator/Dialog/SoundSpeedDialog.xaml.cs index 229a704..8cd8898 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml.cs +++ b/Correlator/Dialog/SoundSpeedDialog.xaml.cs @@ -10,6 +10,8 @@ { InitializeComponent(); + SelectedPipeTextBlock.Text = materialName; + Messenger.Default.Send(materialName, MessengerToken.SoundSpeed); GoBackButton.Click += delegate { Close(); }; diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index 26b8d79..eb3d4f3 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -156,6 +156,97 @@ } /// + /// 水听器点名指令 + /// + /// + /// + /// + public static void StartCheckResponse(SerialPort sp, string devCode, byte[] timeBytes) + { + try + { + //A3 20 + //00 1F + //21 17 00 08 22 02 + //01 + //FF FF + //01 82 + //01 + //40 00 00 02 00 01 00 + //10 00 00 51 00 06 17 06 19 0F 3B 14 + + const string preamble = "A3"; + var preambleByte = byte.Parse(preamble, NumberStyles.HexNumber); + + const string version = "20"; + var btVersion = byte.Parse(version, NumberStyles.HexNumber); + + //后续到CRC字段前的字节总长度(不包括长度字段和CRC字段)。 + byte[] totalLen = { 0x00, 0x1F }; + + var btDevId = new byte[6]; + btDevId[0] = byte.Parse(devCode.Substring(0, 2), NumberStyles.HexNumber); + btDevId[1] = byte.Parse(devCode.Substring(2, 2), NumberStyles.HexNumber); + btDevId[2] = byte.Parse(devCode.Substring(4, 2), NumberStyles.HexNumber); + btDevId[3] = byte.Parse(devCode.Substring(6, 2), NumberStyles.HexNumber); + btDevId[4] = byte.Parse(devCode.Substring(8, 2), NumberStyles.HexNumber); + btDevId[5] = byte.Parse(devCode.Substring(10, 2), NumberStyles.HexNumber); + + //通信方式 + const string routeFlag = "1"; + var btRouteFlag = byte.Parse(routeFlag, NumberStyles.HexNumber); + + byte[] btDstNode = { 0xFF, 0xFF }; + + byte[] btPdu = { 0x01, 0x82 }; + + const string seq = "1"; + var btSeq = byte.Parse(seq, NumberStyles.HexNumber); + + byte[] oidTag = { 0x40, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00 }; + + byte[] timeTag = + { + 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, + timeBytes[0], timeBytes[1], timeBytes[2], timeBytes[3], timeBytes[4], timeBytes[5] + }; //时间oid + + //wrap the whole data + var result = new byte[35]; + result[0] = preambleByte; + result[1] = btVersion; + totalLen.CopyTo(result, 2); + btDevId.CopyTo(result, 4); + result[10] = btRouteFlag; + btDstNode.CopyTo(result, 11); + btPdu.CopyTo(result, 13); + result[15] = btSeq; + oidTag.CopyTo(result, 16); + timeTag.CopyTo(result, 23); + + //增加CRC校验 + var strCrc = $"{(int)CodeUtil.CRC16_AD(result):X}".To16HexString(); + byte[] crcByte = + { + CodeUtil.String2Byte(strCrc.Substring(0, 2)), + CodeUtil.String2Byte(strCrc.Substring(2, 2)) + }; + + var afCrc = new byte[result.Length + 2]; + result.CopyTo(afCrc, 0); + crcByte.CopyTo(afCrc, result.Length); + + "CommandSender".WriteLog("下发水听器水听器点名指令 => " + BitConverter.ToString(afCrc)); + + sp.Write(afCrc, 0, afCrc.Length); + } + catch (Exception e) + { + LogHelper.Info(e.ToString()); + } + } + + /// /// 下发状态采集指令 /// /// diff --git a/Correlator/Util/SerialPortManager.cs b/Correlator/Util/SerialPortManager.cs index ad2e6b9..ddcab54 100644 --- a/Correlator/Util/SerialPortManager.cs +++ b/Correlator/Util/SerialPortManager.cs @@ -11,7 +11,6 @@ using Correlator.SensorHubTag; using GalaSoft.MvvmLight.Messaging; using MessageBox = HandyControl.Controls.MessageBox; -using Tag = Correlator.SensorHubTag.Tag; namespace Correlator.Util { @@ -78,39 +77,30 @@ case 11293: //数据采集 HandleCorrelatorData(strDeviceId, tags); break; + case 30: //显示点名弹窗 + if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + { + //A3 20 00 18 21 17 00 08 22 01 01 22 01 0B 82 01 10 00 00 51 00 06 17 06 19 02 1A 04 88 38 + // 解析年月日时分秒 + var timeBytes = new byte[6]; + Array.Copy(receiveData, 22, timeBytes, 0, 6); + Application.Current.Dispatcher.Invoke(delegate + { + Messenger.Default.Send(timeBytes, MessengerToken.ShowCheckResponseDialog); + }); + } + + break; + case 1: + + break; case 15024: //听音 HandleListenData(tags); break; default: - "SerialPortManager".WriteLog("receiveData.Length:" + receiveData.Length); + Debug.WriteLine("SerialPortManager => " + receiveData.Length); break; } - - if (operateType != "WakeupResponse") return; - Sp.Write("+++"); - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) - { - //显示点名弹窗 - Messenger.Default.Send("", MessengerToken.ShowCheckResponseDialog); - } - } - else if (strResult != "") - { - //信号数据 - if (strResult.Contains("NO CARRIER")) - { - Sp.Write("ATS124?" + Environment.NewLine); - } - else if (strResult.Contains("ATS124?")) - { - var strReceiveDate = strResult.Replace("\r\n", ","); - var signalArray = strReceiveDate.Split(','); - - _devStatus.Signal = signalArray[1]; - - //收到信号就可以工作了 - Messenger.Default.Send("", MessengerToken.HomePageSignal); - } } else { @@ -192,8 +182,8 @@ //发送消息更新界面 Messenger.Default.Send(_devStatus, devCode.Equals(DevCode.Dev1) - ? MessengerToken.SensorADevStatus - : MessengerToken.SensorBDevStatus + ? MessengerToken.RedSensorStatus + : MessengerToken.BlueSensorStatus ); } diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index 0b63310..1b0096a 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -249,9 +249,9 @@ diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml b/Correlator/Dialog/SoundSpeedDialog.xaml index 83a2a87..385a68b 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml +++ b/Correlator/Dialog/SoundSpeedDialog.xaml @@ -32,8 +32,7 @@ - - + @@ -41,7 +40,6 @@ - - - - - - - - + + + + + + + + + @@ -169,30 +144,6 @@ - - diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml.cs b/Correlator/Dialog/SoundSpeedDialog.xaml.cs index 229a704..8cd8898 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml.cs +++ b/Correlator/Dialog/SoundSpeedDialog.xaml.cs @@ -10,6 +10,8 @@ { InitializeComponent(); + SelectedPipeTextBlock.Text = materialName; + Messenger.Default.Send(materialName, MessengerToken.SoundSpeed); GoBackButton.Click += delegate { Close(); }; diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index 26b8d79..eb3d4f3 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -156,6 +156,97 @@ } /// + /// 水听器点名指令 + /// + /// + /// + /// + public static void StartCheckResponse(SerialPort sp, string devCode, byte[] timeBytes) + { + try + { + //A3 20 + //00 1F + //21 17 00 08 22 02 + //01 + //FF FF + //01 82 + //01 + //40 00 00 02 00 01 00 + //10 00 00 51 00 06 17 06 19 0F 3B 14 + + const string preamble = "A3"; + var preambleByte = byte.Parse(preamble, NumberStyles.HexNumber); + + const string version = "20"; + var btVersion = byte.Parse(version, NumberStyles.HexNumber); + + //后续到CRC字段前的字节总长度(不包括长度字段和CRC字段)。 + byte[] totalLen = { 0x00, 0x1F }; + + var btDevId = new byte[6]; + btDevId[0] = byte.Parse(devCode.Substring(0, 2), NumberStyles.HexNumber); + btDevId[1] = byte.Parse(devCode.Substring(2, 2), NumberStyles.HexNumber); + btDevId[2] = byte.Parse(devCode.Substring(4, 2), NumberStyles.HexNumber); + btDevId[3] = byte.Parse(devCode.Substring(6, 2), NumberStyles.HexNumber); + btDevId[4] = byte.Parse(devCode.Substring(8, 2), NumberStyles.HexNumber); + btDevId[5] = byte.Parse(devCode.Substring(10, 2), NumberStyles.HexNumber); + + //通信方式 + const string routeFlag = "1"; + var btRouteFlag = byte.Parse(routeFlag, NumberStyles.HexNumber); + + byte[] btDstNode = { 0xFF, 0xFF }; + + byte[] btPdu = { 0x01, 0x82 }; + + const string seq = "1"; + var btSeq = byte.Parse(seq, NumberStyles.HexNumber); + + byte[] oidTag = { 0x40, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00 }; + + byte[] timeTag = + { + 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, + timeBytes[0], timeBytes[1], timeBytes[2], timeBytes[3], timeBytes[4], timeBytes[5] + }; //时间oid + + //wrap the whole data + var result = new byte[35]; + result[0] = preambleByte; + result[1] = btVersion; + totalLen.CopyTo(result, 2); + btDevId.CopyTo(result, 4); + result[10] = btRouteFlag; + btDstNode.CopyTo(result, 11); + btPdu.CopyTo(result, 13); + result[15] = btSeq; + oidTag.CopyTo(result, 16); + timeTag.CopyTo(result, 23); + + //增加CRC校验 + var strCrc = $"{(int)CodeUtil.CRC16_AD(result):X}".To16HexString(); + byte[] crcByte = + { + CodeUtil.String2Byte(strCrc.Substring(0, 2)), + CodeUtil.String2Byte(strCrc.Substring(2, 2)) + }; + + var afCrc = new byte[result.Length + 2]; + result.CopyTo(afCrc, 0); + crcByte.CopyTo(afCrc, result.Length); + + "CommandSender".WriteLog("下发水听器水听器点名指令 => " + BitConverter.ToString(afCrc)); + + sp.Write(afCrc, 0, afCrc.Length); + } + catch (Exception e) + { + LogHelper.Info(e.ToString()); + } + } + + /// /// 下发状态采集指令 /// /// diff --git a/Correlator/Util/SerialPortManager.cs b/Correlator/Util/SerialPortManager.cs index ad2e6b9..ddcab54 100644 --- a/Correlator/Util/SerialPortManager.cs +++ b/Correlator/Util/SerialPortManager.cs @@ -11,7 +11,6 @@ using Correlator.SensorHubTag; using GalaSoft.MvvmLight.Messaging; using MessageBox = HandyControl.Controls.MessageBox; -using Tag = Correlator.SensorHubTag.Tag; namespace Correlator.Util { @@ -78,39 +77,30 @@ case 11293: //数据采集 HandleCorrelatorData(strDeviceId, tags); break; + case 30: //显示点名弹窗 + if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + { + //A3 20 00 18 21 17 00 08 22 01 01 22 01 0B 82 01 10 00 00 51 00 06 17 06 19 02 1A 04 88 38 + // 解析年月日时分秒 + var timeBytes = new byte[6]; + Array.Copy(receiveData, 22, timeBytes, 0, 6); + Application.Current.Dispatcher.Invoke(delegate + { + Messenger.Default.Send(timeBytes, MessengerToken.ShowCheckResponseDialog); + }); + } + + break; + case 1: + + break; case 15024: //听音 HandleListenData(tags); break; default: - "SerialPortManager".WriteLog("receiveData.Length:" + receiveData.Length); + Debug.WriteLine("SerialPortManager => " + receiveData.Length); break; } - - if (operateType != "WakeupResponse") return; - Sp.Write("+++"); - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) - { - //显示点名弹窗 - Messenger.Default.Send("", MessengerToken.ShowCheckResponseDialog); - } - } - else if (strResult != "") - { - //信号数据 - if (strResult.Contains("NO CARRIER")) - { - Sp.Write("ATS124?" + Environment.NewLine); - } - else if (strResult.Contains("ATS124?")) - { - var strReceiveDate = strResult.Replace("\r\n", ","); - var signalArray = strReceiveDate.Split(','); - - _devStatus.Signal = signalArray[1]; - - //收到信号就可以工作了 - Messenger.Default.Send("", MessengerToken.HomePageSignal); - } } else { @@ -192,8 +182,8 @@ //发送消息更新界面 Messenger.Default.Send(_devStatus, devCode.Equals(DevCode.Dev1) - ? MessengerToken.SensorADevStatus - : MessengerToken.SensorBDevStatus + ? MessengerToken.RedSensorStatus + : MessengerToken.BlueSensorStatus ); } diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index 0b63310..1b0096a 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -249,9 +249,9 @@ diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index dcf6b2e..6593596 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -115,12 +115,6 @@ #endregion - #region 设置 - - SettingsButton.Click += delegate { }; - - #endregion - #region 管径输入监听 PipeDiameterTextBox.PreviewTextInput += delegate(object sender, TextCompositionEventArgs e) diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml b/Correlator/Dialog/SoundSpeedDialog.xaml index 83a2a87..385a68b 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml +++ b/Correlator/Dialog/SoundSpeedDialog.xaml @@ -32,8 +32,7 @@ - - + @@ -41,7 +40,6 @@ - - - - - - - - + + + + + + + + + @@ -169,30 +144,6 @@ - - diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml.cs b/Correlator/Dialog/SoundSpeedDialog.xaml.cs index 229a704..8cd8898 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml.cs +++ b/Correlator/Dialog/SoundSpeedDialog.xaml.cs @@ -10,6 +10,8 @@ { InitializeComponent(); + SelectedPipeTextBlock.Text = materialName; + Messenger.Default.Send(materialName, MessengerToken.SoundSpeed); GoBackButton.Click += delegate { Close(); }; diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index 26b8d79..eb3d4f3 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -156,6 +156,97 @@ } /// + /// 水听器点名指令 + /// + /// + /// + /// + public static void StartCheckResponse(SerialPort sp, string devCode, byte[] timeBytes) + { + try + { + //A3 20 + //00 1F + //21 17 00 08 22 02 + //01 + //FF FF + //01 82 + //01 + //40 00 00 02 00 01 00 + //10 00 00 51 00 06 17 06 19 0F 3B 14 + + const string preamble = "A3"; + var preambleByte = byte.Parse(preamble, NumberStyles.HexNumber); + + const string version = "20"; + var btVersion = byte.Parse(version, NumberStyles.HexNumber); + + //后续到CRC字段前的字节总长度(不包括长度字段和CRC字段)。 + byte[] totalLen = { 0x00, 0x1F }; + + var btDevId = new byte[6]; + btDevId[0] = byte.Parse(devCode.Substring(0, 2), NumberStyles.HexNumber); + btDevId[1] = byte.Parse(devCode.Substring(2, 2), NumberStyles.HexNumber); + btDevId[2] = byte.Parse(devCode.Substring(4, 2), NumberStyles.HexNumber); + btDevId[3] = byte.Parse(devCode.Substring(6, 2), NumberStyles.HexNumber); + btDevId[4] = byte.Parse(devCode.Substring(8, 2), NumberStyles.HexNumber); + btDevId[5] = byte.Parse(devCode.Substring(10, 2), NumberStyles.HexNumber); + + //通信方式 + const string routeFlag = "1"; + var btRouteFlag = byte.Parse(routeFlag, NumberStyles.HexNumber); + + byte[] btDstNode = { 0xFF, 0xFF }; + + byte[] btPdu = { 0x01, 0x82 }; + + const string seq = "1"; + var btSeq = byte.Parse(seq, NumberStyles.HexNumber); + + byte[] oidTag = { 0x40, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00 }; + + byte[] timeTag = + { + 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, + timeBytes[0], timeBytes[1], timeBytes[2], timeBytes[3], timeBytes[4], timeBytes[5] + }; //时间oid + + //wrap the whole data + var result = new byte[35]; + result[0] = preambleByte; + result[1] = btVersion; + totalLen.CopyTo(result, 2); + btDevId.CopyTo(result, 4); + result[10] = btRouteFlag; + btDstNode.CopyTo(result, 11); + btPdu.CopyTo(result, 13); + result[15] = btSeq; + oidTag.CopyTo(result, 16); + timeTag.CopyTo(result, 23); + + //增加CRC校验 + var strCrc = $"{(int)CodeUtil.CRC16_AD(result):X}".To16HexString(); + byte[] crcByte = + { + CodeUtil.String2Byte(strCrc.Substring(0, 2)), + CodeUtil.String2Byte(strCrc.Substring(2, 2)) + }; + + var afCrc = new byte[result.Length + 2]; + result.CopyTo(afCrc, 0); + crcByte.CopyTo(afCrc, result.Length); + + "CommandSender".WriteLog("下发水听器水听器点名指令 => " + BitConverter.ToString(afCrc)); + + sp.Write(afCrc, 0, afCrc.Length); + } + catch (Exception e) + { + LogHelper.Info(e.ToString()); + } + } + + /// /// 下发状态采集指令 /// /// diff --git a/Correlator/Util/SerialPortManager.cs b/Correlator/Util/SerialPortManager.cs index ad2e6b9..ddcab54 100644 --- a/Correlator/Util/SerialPortManager.cs +++ b/Correlator/Util/SerialPortManager.cs @@ -11,7 +11,6 @@ using Correlator.SensorHubTag; using GalaSoft.MvvmLight.Messaging; using MessageBox = HandyControl.Controls.MessageBox; -using Tag = Correlator.SensorHubTag.Tag; namespace Correlator.Util { @@ -78,39 +77,30 @@ case 11293: //数据采集 HandleCorrelatorData(strDeviceId, tags); break; + case 30: //显示点名弹窗 + if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + { + //A3 20 00 18 21 17 00 08 22 01 01 22 01 0B 82 01 10 00 00 51 00 06 17 06 19 02 1A 04 88 38 + // 解析年月日时分秒 + var timeBytes = new byte[6]; + Array.Copy(receiveData, 22, timeBytes, 0, 6); + Application.Current.Dispatcher.Invoke(delegate + { + Messenger.Default.Send(timeBytes, MessengerToken.ShowCheckResponseDialog); + }); + } + + break; + case 1: + + break; case 15024: //听音 HandleListenData(tags); break; default: - "SerialPortManager".WriteLog("receiveData.Length:" + receiveData.Length); + Debug.WriteLine("SerialPortManager => " + receiveData.Length); break; } - - if (operateType != "WakeupResponse") return; - Sp.Write("+++"); - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) - { - //显示点名弹窗 - Messenger.Default.Send("", MessengerToken.ShowCheckResponseDialog); - } - } - else if (strResult != "") - { - //信号数据 - if (strResult.Contains("NO CARRIER")) - { - Sp.Write("ATS124?" + Environment.NewLine); - } - else if (strResult.Contains("ATS124?")) - { - var strReceiveDate = strResult.Replace("\r\n", ","); - var signalArray = strReceiveDate.Split(','); - - _devStatus.Signal = signalArray[1]; - - //收到信号就可以工作了 - Messenger.Default.Send("", MessengerToken.HomePageSignal); - } } else { @@ -192,8 +182,8 @@ //发送消息更新界面 Messenger.Default.Send(_devStatus, devCode.Equals(DevCode.Dev1) - ? MessengerToken.SensorADevStatus - : MessengerToken.SensorBDevStatus + ? MessengerToken.RedSensorStatus + : MessengerToken.BlueSensorStatus ); } diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index 0b63310..1b0096a 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -249,9 +249,9 @@ diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index dcf6b2e..6593596 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -115,12 +115,6 @@ #endregion - #region 设置 - - SettingsButton.Click += delegate { }; - - #endregion - #region 管径输入监听 PipeDiameterTextBox.PreviewTextInput += delegate(object sender, TextCompositionEventArgs e) diff --git a/Correlator/ViewModel/AddSoundSpeedViewModel.cs b/Correlator/ViewModel/AddSoundSpeedViewModel.cs index eed497d..117992a 100644 --- a/Correlator/ViewModel/AddSoundSpeedViewModel.cs +++ b/Correlator/ViewModel/AddSoundSpeedViewModel.cs @@ -12,7 +12,7 @@ private readonly ISoundSpeedDataService _dataService; private string _materialName; - private string _minDiameter; + private string _minDiameter = string.Empty; public string MinDiameter { @@ -20,11 +20,11 @@ set { _minDiameter = value; - RaisePropertyChanged(() => MinDiameter); + RaisePropertyChanged(); } } - private string _maxDiameter; + private string _maxDiameter = string.Empty; public string MaxDiameter { @@ -32,11 +32,11 @@ set { _maxDiameter = value; - RaisePropertyChanged(() => MaxDiameter); + RaisePropertyChanged(); } } - private string _soundSpeed; + private string _soundSpeed = string.Empty; public string SoundSpeed { @@ -44,7 +44,7 @@ set { _soundSpeed = value; - RaisePropertyChanged(() => SoundSpeed); + RaisePropertyChanged(); } } @@ -53,14 +53,8 @@ public AddSoundSpeedViewModel(ISoundSpeedDataService dataService) { _dataService = dataService; - Messenger.Default.Register(this, MessengerToken.AddSoundSpeedMessage, it => - { - _materialName = it; - - MinDiameter = ""; - MaxDiameter = ""; - SoundSpeed = ""; - }); + Messenger.Default.Register(this, MessengerToken.AddSoundSpeedMessage, + it => { _materialName = it; }); DetermineParamCommand = new RelayCommand(AddSoundSpeed); } diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml b/Correlator/Dialog/SoundSpeedDialog.xaml index 83a2a87..385a68b 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml +++ b/Correlator/Dialog/SoundSpeedDialog.xaml @@ -32,8 +32,7 @@ - - + @@ -41,7 +40,6 @@ - - - - - - - - + + + + + + + + + @@ -169,30 +144,6 @@ - - diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml.cs b/Correlator/Dialog/SoundSpeedDialog.xaml.cs index 229a704..8cd8898 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml.cs +++ b/Correlator/Dialog/SoundSpeedDialog.xaml.cs @@ -10,6 +10,8 @@ { InitializeComponent(); + SelectedPipeTextBlock.Text = materialName; + Messenger.Default.Send(materialName, MessengerToken.SoundSpeed); GoBackButton.Click += delegate { Close(); }; diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index 26b8d79..eb3d4f3 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -156,6 +156,97 @@ } /// + /// 水听器点名指令 + /// + /// + /// + /// + public static void StartCheckResponse(SerialPort sp, string devCode, byte[] timeBytes) + { + try + { + //A3 20 + //00 1F + //21 17 00 08 22 02 + //01 + //FF FF + //01 82 + //01 + //40 00 00 02 00 01 00 + //10 00 00 51 00 06 17 06 19 0F 3B 14 + + const string preamble = "A3"; + var preambleByte = byte.Parse(preamble, NumberStyles.HexNumber); + + const string version = "20"; + var btVersion = byte.Parse(version, NumberStyles.HexNumber); + + //后续到CRC字段前的字节总长度(不包括长度字段和CRC字段)。 + byte[] totalLen = { 0x00, 0x1F }; + + var btDevId = new byte[6]; + btDevId[0] = byte.Parse(devCode.Substring(0, 2), NumberStyles.HexNumber); + btDevId[1] = byte.Parse(devCode.Substring(2, 2), NumberStyles.HexNumber); + btDevId[2] = byte.Parse(devCode.Substring(4, 2), NumberStyles.HexNumber); + btDevId[3] = byte.Parse(devCode.Substring(6, 2), NumberStyles.HexNumber); + btDevId[4] = byte.Parse(devCode.Substring(8, 2), NumberStyles.HexNumber); + btDevId[5] = byte.Parse(devCode.Substring(10, 2), NumberStyles.HexNumber); + + //通信方式 + const string routeFlag = "1"; + var btRouteFlag = byte.Parse(routeFlag, NumberStyles.HexNumber); + + byte[] btDstNode = { 0xFF, 0xFF }; + + byte[] btPdu = { 0x01, 0x82 }; + + const string seq = "1"; + var btSeq = byte.Parse(seq, NumberStyles.HexNumber); + + byte[] oidTag = { 0x40, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00 }; + + byte[] timeTag = + { + 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, + timeBytes[0], timeBytes[1], timeBytes[2], timeBytes[3], timeBytes[4], timeBytes[5] + }; //时间oid + + //wrap the whole data + var result = new byte[35]; + result[0] = preambleByte; + result[1] = btVersion; + totalLen.CopyTo(result, 2); + btDevId.CopyTo(result, 4); + result[10] = btRouteFlag; + btDstNode.CopyTo(result, 11); + btPdu.CopyTo(result, 13); + result[15] = btSeq; + oidTag.CopyTo(result, 16); + timeTag.CopyTo(result, 23); + + //增加CRC校验 + var strCrc = $"{(int)CodeUtil.CRC16_AD(result):X}".To16HexString(); + byte[] crcByte = + { + CodeUtil.String2Byte(strCrc.Substring(0, 2)), + CodeUtil.String2Byte(strCrc.Substring(2, 2)) + }; + + var afCrc = new byte[result.Length + 2]; + result.CopyTo(afCrc, 0); + crcByte.CopyTo(afCrc, result.Length); + + "CommandSender".WriteLog("下发水听器水听器点名指令 => " + BitConverter.ToString(afCrc)); + + sp.Write(afCrc, 0, afCrc.Length); + } + catch (Exception e) + { + LogHelper.Info(e.ToString()); + } + } + + /// /// 下发状态采集指令 /// /// diff --git a/Correlator/Util/SerialPortManager.cs b/Correlator/Util/SerialPortManager.cs index ad2e6b9..ddcab54 100644 --- a/Correlator/Util/SerialPortManager.cs +++ b/Correlator/Util/SerialPortManager.cs @@ -11,7 +11,6 @@ using Correlator.SensorHubTag; using GalaSoft.MvvmLight.Messaging; using MessageBox = HandyControl.Controls.MessageBox; -using Tag = Correlator.SensorHubTag.Tag; namespace Correlator.Util { @@ -78,39 +77,30 @@ case 11293: //数据采集 HandleCorrelatorData(strDeviceId, tags); break; + case 30: //显示点名弹窗 + if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + { + //A3 20 00 18 21 17 00 08 22 01 01 22 01 0B 82 01 10 00 00 51 00 06 17 06 19 02 1A 04 88 38 + // 解析年月日时分秒 + var timeBytes = new byte[6]; + Array.Copy(receiveData, 22, timeBytes, 0, 6); + Application.Current.Dispatcher.Invoke(delegate + { + Messenger.Default.Send(timeBytes, MessengerToken.ShowCheckResponseDialog); + }); + } + + break; + case 1: + + break; case 15024: //听音 HandleListenData(tags); break; default: - "SerialPortManager".WriteLog("receiveData.Length:" + receiveData.Length); + Debug.WriteLine("SerialPortManager => " + receiveData.Length); break; } - - if (operateType != "WakeupResponse") return; - Sp.Write("+++"); - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) - { - //显示点名弹窗 - Messenger.Default.Send("", MessengerToken.ShowCheckResponseDialog); - } - } - else if (strResult != "") - { - //信号数据 - if (strResult.Contains("NO CARRIER")) - { - Sp.Write("ATS124?" + Environment.NewLine); - } - else if (strResult.Contains("ATS124?")) - { - var strReceiveDate = strResult.Replace("\r\n", ","); - var signalArray = strReceiveDate.Split(','); - - _devStatus.Signal = signalArray[1]; - - //收到信号就可以工作了 - Messenger.Default.Send("", MessengerToken.HomePageSignal); - } } else { @@ -192,8 +182,8 @@ //发送消息更新界面 Messenger.Default.Send(_devStatus, devCode.Equals(DevCode.Dev1) - ? MessengerToken.SensorADevStatus - : MessengerToken.SensorBDevStatus + ? MessengerToken.RedSensorStatus + : MessengerToken.BlueSensorStatus ); } diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index 0b63310..1b0096a 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -249,9 +249,9 @@ diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index dcf6b2e..6593596 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -115,12 +115,6 @@ #endregion - #region 设置 - - SettingsButton.Click += delegate { }; - - #endregion - #region 管径输入监听 PipeDiameterTextBox.PreviewTextInput += delegate(object sender, TextCompositionEventArgs e) diff --git a/Correlator/ViewModel/AddSoundSpeedViewModel.cs b/Correlator/ViewModel/AddSoundSpeedViewModel.cs index eed497d..117992a 100644 --- a/Correlator/ViewModel/AddSoundSpeedViewModel.cs +++ b/Correlator/ViewModel/AddSoundSpeedViewModel.cs @@ -12,7 +12,7 @@ private readonly ISoundSpeedDataService _dataService; private string _materialName; - private string _minDiameter; + private string _minDiameter = string.Empty; public string MinDiameter { @@ -20,11 +20,11 @@ set { _minDiameter = value; - RaisePropertyChanged(() => MinDiameter); + RaisePropertyChanged(); } } - private string _maxDiameter; + private string _maxDiameter = string.Empty; public string MaxDiameter { @@ -32,11 +32,11 @@ set { _maxDiameter = value; - RaisePropertyChanged(() => MaxDiameter); + RaisePropertyChanged(); } } - private string _soundSpeed; + private string _soundSpeed = string.Empty; public string SoundSpeed { @@ -44,7 +44,7 @@ set { _soundSpeed = value; - RaisePropertyChanged(() => SoundSpeed); + RaisePropertyChanged(); } } @@ -53,14 +53,8 @@ public AddSoundSpeedViewModel(ISoundSpeedDataService dataService) { _dataService = dataService; - Messenger.Default.Register(this, MessengerToken.AddSoundSpeedMessage, it => - { - _materialName = it; - - MinDiameter = ""; - MaxDiameter = ""; - SoundSpeed = ""; - }); + Messenger.Default.Register(this, MessengerToken.AddSoundSpeedMessage, + it => { _materialName = it; }); DetermineParamCommand = new RelayCommand(AddSoundSpeed); } diff --git a/Correlator/ViewModel/EditSoundSpeedViewModel.cs b/Correlator/ViewModel/EditSoundSpeedViewModel.cs index 48747db..5b9d97d 100644 --- a/Correlator/ViewModel/EditSoundSpeedViewModel.cs +++ b/Correlator/ViewModel/EditSoundSpeedViewModel.cs @@ -21,7 +21,7 @@ set { _minDiameter = value; - RaisePropertyChanged(() => MinDiameter); + RaisePropertyChanged(); } } @@ -33,7 +33,7 @@ set { _maxDiameter = value; - RaisePropertyChanged(() => MaxDiameter); + RaisePropertyChanged(); } } @@ -45,7 +45,7 @@ set { _soundSpeed = value; - RaisePropertyChanged(() => SoundSpeed); + RaisePropertyChanged(); } } diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml b/Correlator/Dialog/SoundSpeedDialog.xaml index 83a2a87..385a68b 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml +++ b/Correlator/Dialog/SoundSpeedDialog.xaml @@ -32,8 +32,7 @@ - - + @@ -41,7 +40,6 @@ - - - - - - - - + + + + + + + + + @@ -169,30 +144,6 @@ - - diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml.cs b/Correlator/Dialog/SoundSpeedDialog.xaml.cs index 229a704..8cd8898 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml.cs +++ b/Correlator/Dialog/SoundSpeedDialog.xaml.cs @@ -10,6 +10,8 @@ { InitializeComponent(); + SelectedPipeTextBlock.Text = materialName; + Messenger.Default.Send(materialName, MessengerToken.SoundSpeed); GoBackButton.Click += delegate { Close(); }; diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index 26b8d79..eb3d4f3 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -156,6 +156,97 @@ } /// + /// 水听器点名指令 + /// + /// + /// + /// + public static void StartCheckResponse(SerialPort sp, string devCode, byte[] timeBytes) + { + try + { + //A3 20 + //00 1F + //21 17 00 08 22 02 + //01 + //FF FF + //01 82 + //01 + //40 00 00 02 00 01 00 + //10 00 00 51 00 06 17 06 19 0F 3B 14 + + const string preamble = "A3"; + var preambleByte = byte.Parse(preamble, NumberStyles.HexNumber); + + const string version = "20"; + var btVersion = byte.Parse(version, NumberStyles.HexNumber); + + //后续到CRC字段前的字节总长度(不包括长度字段和CRC字段)。 + byte[] totalLen = { 0x00, 0x1F }; + + var btDevId = new byte[6]; + btDevId[0] = byte.Parse(devCode.Substring(0, 2), NumberStyles.HexNumber); + btDevId[1] = byte.Parse(devCode.Substring(2, 2), NumberStyles.HexNumber); + btDevId[2] = byte.Parse(devCode.Substring(4, 2), NumberStyles.HexNumber); + btDevId[3] = byte.Parse(devCode.Substring(6, 2), NumberStyles.HexNumber); + btDevId[4] = byte.Parse(devCode.Substring(8, 2), NumberStyles.HexNumber); + btDevId[5] = byte.Parse(devCode.Substring(10, 2), NumberStyles.HexNumber); + + //通信方式 + const string routeFlag = "1"; + var btRouteFlag = byte.Parse(routeFlag, NumberStyles.HexNumber); + + byte[] btDstNode = { 0xFF, 0xFF }; + + byte[] btPdu = { 0x01, 0x82 }; + + const string seq = "1"; + var btSeq = byte.Parse(seq, NumberStyles.HexNumber); + + byte[] oidTag = { 0x40, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00 }; + + byte[] timeTag = + { + 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, + timeBytes[0], timeBytes[1], timeBytes[2], timeBytes[3], timeBytes[4], timeBytes[5] + }; //时间oid + + //wrap the whole data + var result = new byte[35]; + result[0] = preambleByte; + result[1] = btVersion; + totalLen.CopyTo(result, 2); + btDevId.CopyTo(result, 4); + result[10] = btRouteFlag; + btDstNode.CopyTo(result, 11); + btPdu.CopyTo(result, 13); + result[15] = btSeq; + oidTag.CopyTo(result, 16); + timeTag.CopyTo(result, 23); + + //增加CRC校验 + var strCrc = $"{(int)CodeUtil.CRC16_AD(result):X}".To16HexString(); + byte[] crcByte = + { + CodeUtil.String2Byte(strCrc.Substring(0, 2)), + CodeUtil.String2Byte(strCrc.Substring(2, 2)) + }; + + var afCrc = new byte[result.Length + 2]; + result.CopyTo(afCrc, 0); + crcByte.CopyTo(afCrc, result.Length); + + "CommandSender".WriteLog("下发水听器水听器点名指令 => " + BitConverter.ToString(afCrc)); + + sp.Write(afCrc, 0, afCrc.Length); + } + catch (Exception e) + { + LogHelper.Info(e.ToString()); + } + } + + /// /// 下发状态采集指令 /// /// diff --git a/Correlator/Util/SerialPortManager.cs b/Correlator/Util/SerialPortManager.cs index ad2e6b9..ddcab54 100644 --- a/Correlator/Util/SerialPortManager.cs +++ b/Correlator/Util/SerialPortManager.cs @@ -11,7 +11,6 @@ using Correlator.SensorHubTag; using GalaSoft.MvvmLight.Messaging; using MessageBox = HandyControl.Controls.MessageBox; -using Tag = Correlator.SensorHubTag.Tag; namespace Correlator.Util { @@ -78,39 +77,30 @@ case 11293: //数据采集 HandleCorrelatorData(strDeviceId, tags); break; + case 30: //显示点名弹窗 + if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + { + //A3 20 00 18 21 17 00 08 22 01 01 22 01 0B 82 01 10 00 00 51 00 06 17 06 19 02 1A 04 88 38 + // 解析年月日时分秒 + var timeBytes = new byte[6]; + Array.Copy(receiveData, 22, timeBytes, 0, 6); + Application.Current.Dispatcher.Invoke(delegate + { + Messenger.Default.Send(timeBytes, MessengerToken.ShowCheckResponseDialog); + }); + } + + break; + case 1: + + break; case 15024: //听音 HandleListenData(tags); break; default: - "SerialPortManager".WriteLog("receiveData.Length:" + receiveData.Length); + Debug.WriteLine("SerialPortManager => " + receiveData.Length); break; } - - if (operateType != "WakeupResponse") return; - Sp.Write("+++"); - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) - { - //显示点名弹窗 - Messenger.Default.Send("", MessengerToken.ShowCheckResponseDialog); - } - } - else if (strResult != "") - { - //信号数据 - if (strResult.Contains("NO CARRIER")) - { - Sp.Write("ATS124?" + Environment.NewLine); - } - else if (strResult.Contains("ATS124?")) - { - var strReceiveDate = strResult.Replace("\r\n", ","); - var signalArray = strReceiveDate.Split(','); - - _devStatus.Signal = signalArray[1]; - - //收到信号就可以工作了 - Messenger.Default.Send("", MessengerToken.HomePageSignal); - } } else { @@ -192,8 +182,8 @@ //发送消息更新界面 Messenger.Default.Send(_devStatus, devCode.Equals(DevCode.Dev1) - ? MessengerToken.SensorADevStatus - : MessengerToken.SensorBDevStatus + ? MessengerToken.RedSensorStatus + : MessengerToken.BlueSensorStatus ); } diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index 0b63310..1b0096a 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -249,9 +249,9 @@ diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index dcf6b2e..6593596 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -115,12 +115,6 @@ #endregion - #region 设置 - - SettingsButton.Click += delegate { }; - - #endregion - #region 管径输入监听 PipeDiameterTextBox.PreviewTextInput += delegate(object sender, TextCompositionEventArgs e) diff --git a/Correlator/ViewModel/AddSoundSpeedViewModel.cs b/Correlator/ViewModel/AddSoundSpeedViewModel.cs index eed497d..117992a 100644 --- a/Correlator/ViewModel/AddSoundSpeedViewModel.cs +++ b/Correlator/ViewModel/AddSoundSpeedViewModel.cs @@ -12,7 +12,7 @@ private readonly ISoundSpeedDataService _dataService; private string _materialName; - private string _minDiameter; + private string _minDiameter = string.Empty; public string MinDiameter { @@ -20,11 +20,11 @@ set { _minDiameter = value; - RaisePropertyChanged(() => MinDiameter); + RaisePropertyChanged(); } } - private string _maxDiameter; + private string _maxDiameter = string.Empty; public string MaxDiameter { @@ -32,11 +32,11 @@ set { _maxDiameter = value; - RaisePropertyChanged(() => MaxDiameter); + RaisePropertyChanged(); } } - private string _soundSpeed; + private string _soundSpeed = string.Empty; public string SoundSpeed { @@ -44,7 +44,7 @@ set { _soundSpeed = value; - RaisePropertyChanged(() => SoundSpeed); + RaisePropertyChanged(); } } @@ -53,14 +53,8 @@ public AddSoundSpeedViewModel(ISoundSpeedDataService dataService) { _dataService = dataService; - Messenger.Default.Register(this, MessengerToken.AddSoundSpeedMessage, it => - { - _materialName = it; - - MinDiameter = ""; - MaxDiameter = ""; - SoundSpeed = ""; - }); + Messenger.Default.Register(this, MessengerToken.AddSoundSpeedMessage, + it => { _materialName = it; }); DetermineParamCommand = new RelayCommand(AddSoundSpeed); } diff --git a/Correlator/ViewModel/EditSoundSpeedViewModel.cs b/Correlator/ViewModel/EditSoundSpeedViewModel.cs index 48747db..5b9d97d 100644 --- a/Correlator/ViewModel/EditSoundSpeedViewModel.cs +++ b/Correlator/ViewModel/EditSoundSpeedViewModel.cs @@ -21,7 +21,7 @@ set { _minDiameter = value; - RaisePropertyChanged(() => MinDiameter); + RaisePropertyChanged(); } } @@ -33,7 +33,7 @@ set { _maxDiameter = value; - RaisePropertyChanged(() => MaxDiameter); + RaisePropertyChanged(); } } @@ -45,7 +45,7 @@ set { _soundSpeed = value; - RaisePropertyChanged(() => SoundSpeed); + RaisePropertyChanged(); } } diff --git a/Correlator/ViewModel/HomePageProViewModel.cs b/Correlator/ViewModel/HomePageProViewModel.cs index 7c3656a..cc14ec9 100644 --- a/Correlator/ViewModel/HomePageProViewModel.cs +++ b/Correlator/ViewModel/HomePageProViewModel.cs @@ -325,7 +325,8 @@ } } - private string _pipeName = string.Empty; + // private string _pipeName = string.Empty; + private string _pipeName = "铸铁"; public string PipeName { @@ -337,7 +338,8 @@ } } - private string _pipeDiameter = string.Empty; + // private string _pipeDiameter = string.Empty; + private string _pipeDiameter = "300"; public string PipeDiameter { @@ -349,7 +351,8 @@ } } - private string _pipeLength = string.Empty; + // private string _pipeLength = string.Empty; + private string _pipeLength = "150"; public string PipeLength { @@ -373,7 +376,8 @@ } } - private string _lowFrequency; + // private string _lowFrequency = string.Empty; + private string _lowFrequency = "100"; public string LowFrequency { @@ -385,7 +389,7 @@ } } - private string _highFrequency; + private string _highFrequency = string.Empty; public string HighFrequency { @@ -435,6 +439,7 @@ public RelayCommand WindowLoadedCommand { set; get; } public RelayCommand PipeItemSelectedCommand { set; get; } + public RelayCommand SoundSettingsCommand { private set; get; } public RelayCommand SaveAudioCommand { private set; get; } public RelayCommand ResetParamCommand { private set; get; } public RelayCommand SnapShotCommand { private set; get; } @@ -663,6 +668,15 @@ PipeName = box.SelectedItem.ToString(); }); + SoundSettingsCommand = new RelayCommand(delegate + { + var speedDialog = new SoundSpeedDialog(_pipeName) + { + Owner = _homePageWindow + }; + speedDialog.ShowDialog(); + }); + SaveAudioCommand = new RelayCommand(delegate { if (FlowStatus.CorrelatorData != null) @@ -791,9 +805,14 @@ { if (_isResetParam) { - PipeDiameter = string.Empty; - PipeLength = string.Empty; - LowFrequency = string.Empty; + // PipeDiameter = string.Empty; + // PipeLength = string.Empty; + // LowFrequency = string.Empty; + + PipeDiameter = "300"; + PipeLength = "150"; + LowFrequency = "100"; + HighFrequency = string.Empty; SoundSpeed = "0"; diff --git a/Correlator/Dialog/AddSoundSpeedDialog.xaml b/Correlator/Dialog/AddSoundSpeedDialog.xaml index a7aa2a9..a47b750 100644 --- a/Correlator/Dialog/AddSoundSpeedDialog.xaml +++ b/Correlator/Dialog/AddSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="AddSoundSpeedDialog" Width="660" Height="330" AllowsTransparency="True" @@ -35,7 +34,10 @@ - + @@ -46,16 +48,15 @@ @@ -63,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -87,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -111,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -130,7 +126,6 @@ diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8f06cb0..78902ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Windows; +using System.Windows; using System.Windows.Media; using System.Windows.Shapes; using Correlator.SensorHubTag; @@ -30,7 +29,7 @@ RedResponsePanel.Children.Add(ellipse); } - RedCheckButton.Click += delegate(object sender, RoutedEventArgs args) + RedCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev1, timeBytes); for (var i = 0; i < RedResponsePanel.Children.Count; i++) @@ -38,7 +37,6 @@ var child = RedResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; @@ -55,7 +53,7 @@ BlueResponsePanel.Children.Add(ellipse); } - BlueCheckButton.Click += delegate(object sender, RoutedEventArgs args) + BlueCheckButton.Click += delegate { CommandSender.StartCheckResponse(SerialPortManager.Get.Sp, DevCode.Dev2, timeBytes); for (var i = 0; i < BlueResponsePanel.Children.Count; i++) @@ -63,7 +61,6 @@ var child = BlueResponsePanel.Children[i] as Ellipse; if (child?.Fill.ToString() == "#FFD3D3D3") { - Debug.WriteLine($"CheckResponseDialog.xaml => {i}"); } } }; diff --git a/Correlator/Dialog/EditSoundSpeedDialog.xaml b/Correlator/Dialog/EditSoundSpeedDialog.xaml index 161be3c..46b9888 100644 --- a/Correlator/Dialog/EditSoundSpeedDialog.xaml +++ b/Correlator/Dialog/EditSoundSpeedDialog.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="EditSoundSpeedDialog" Width="600" Height="300" AllowsTransparency="True" @@ -49,16 +48,15 @@ @@ -66,23 +64,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -90,23 +86,21 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="mm" /> @@ -114,7 +108,6 @@ Margin="3,0" VerticalAlignment="Center" FontSize="18" - Foreground="#545454" Text="m/s" /> @@ -133,7 +126,6 @@ diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml b/Correlator/Dialog/SoundSpeedDialog.xaml index 83a2a87..385a68b 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml +++ b/Correlator/Dialog/SoundSpeedDialog.xaml @@ -32,8 +32,7 @@ - - + @@ -41,7 +40,6 @@ - - - - - - - - + + + + + + + + + @@ -169,30 +144,6 @@ - - diff --git a/Correlator/Dialog/SoundSpeedDialog.xaml.cs b/Correlator/Dialog/SoundSpeedDialog.xaml.cs index 229a704..8cd8898 100644 --- a/Correlator/Dialog/SoundSpeedDialog.xaml.cs +++ b/Correlator/Dialog/SoundSpeedDialog.xaml.cs @@ -10,6 +10,8 @@ { InitializeComponent(); + SelectedPipeTextBlock.Text = materialName; + Messenger.Default.Send(materialName, MessengerToken.SoundSpeed); GoBackButton.Click += delegate { Close(); }; diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index 26b8d79..eb3d4f3 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -156,6 +156,97 @@ } /// + /// 水听器点名指令 + /// + /// + /// + /// + public static void StartCheckResponse(SerialPort sp, string devCode, byte[] timeBytes) + { + try + { + //A3 20 + //00 1F + //21 17 00 08 22 02 + //01 + //FF FF + //01 82 + //01 + //40 00 00 02 00 01 00 + //10 00 00 51 00 06 17 06 19 0F 3B 14 + + const string preamble = "A3"; + var preambleByte = byte.Parse(preamble, NumberStyles.HexNumber); + + const string version = "20"; + var btVersion = byte.Parse(version, NumberStyles.HexNumber); + + //后续到CRC字段前的字节总长度(不包括长度字段和CRC字段)。 + byte[] totalLen = { 0x00, 0x1F }; + + var btDevId = new byte[6]; + btDevId[0] = byte.Parse(devCode.Substring(0, 2), NumberStyles.HexNumber); + btDevId[1] = byte.Parse(devCode.Substring(2, 2), NumberStyles.HexNumber); + btDevId[2] = byte.Parse(devCode.Substring(4, 2), NumberStyles.HexNumber); + btDevId[3] = byte.Parse(devCode.Substring(6, 2), NumberStyles.HexNumber); + btDevId[4] = byte.Parse(devCode.Substring(8, 2), NumberStyles.HexNumber); + btDevId[5] = byte.Parse(devCode.Substring(10, 2), NumberStyles.HexNumber); + + //通信方式 + const string routeFlag = "1"; + var btRouteFlag = byte.Parse(routeFlag, NumberStyles.HexNumber); + + byte[] btDstNode = { 0xFF, 0xFF }; + + byte[] btPdu = { 0x01, 0x82 }; + + const string seq = "1"; + var btSeq = byte.Parse(seq, NumberStyles.HexNumber); + + byte[] oidTag = { 0x40, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00 }; + + byte[] timeTag = + { + 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, + timeBytes[0], timeBytes[1], timeBytes[2], timeBytes[3], timeBytes[4], timeBytes[5] + }; //时间oid + + //wrap the whole data + var result = new byte[35]; + result[0] = preambleByte; + result[1] = btVersion; + totalLen.CopyTo(result, 2); + btDevId.CopyTo(result, 4); + result[10] = btRouteFlag; + btDstNode.CopyTo(result, 11); + btPdu.CopyTo(result, 13); + result[15] = btSeq; + oidTag.CopyTo(result, 16); + timeTag.CopyTo(result, 23); + + //增加CRC校验 + var strCrc = $"{(int)CodeUtil.CRC16_AD(result):X}".To16HexString(); + byte[] crcByte = + { + CodeUtil.String2Byte(strCrc.Substring(0, 2)), + CodeUtil.String2Byte(strCrc.Substring(2, 2)) + }; + + var afCrc = new byte[result.Length + 2]; + result.CopyTo(afCrc, 0); + crcByte.CopyTo(afCrc, result.Length); + + "CommandSender".WriteLog("下发水听器水听器点名指令 => " + BitConverter.ToString(afCrc)); + + sp.Write(afCrc, 0, afCrc.Length); + } + catch (Exception e) + { + LogHelper.Info(e.ToString()); + } + } + + /// /// 下发状态采集指令 /// /// diff --git a/Correlator/Util/SerialPortManager.cs b/Correlator/Util/SerialPortManager.cs index ad2e6b9..ddcab54 100644 --- a/Correlator/Util/SerialPortManager.cs +++ b/Correlator/Util/SerialPortManager.cs @@ -11,7 +11,6 @@ using Correlator.SensorHubTag; using GalaSoft.MvvmLight.Messaging; using MessageBox = HandyControl.Controls.MessageBox; -using Tag = Correlator.SensorHubTag.Tag; namespace Correlator.Util { @@ -78,39 +77,30 @@ case 11293: //数据采集 HandleCorrelatorData(strDeviceId, tags); break; + case 30: //显示点名弹窗 + if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + { + //A3 20 00 18 21 17 00 08 22 01 01 22 01 0B 82 01 10 00 00 51 00 06 17 06 19 02 1A 04 88 38 + // 解析年月日时分秒 + var timeBytes = new byte[6]; + Array.Copy(receiveData, 22, timeBytes, 0, 6); + Application.Current.Dispatcher.Invoke(delegate + { + Messenger.Default.Send(timeBytes, MessengerToken.ShowCheckResponseDialog); + }); + } + + break; + case 1: + + break; case 15024: //听音 HandleListenData(tags); break; default: - "SerialPortManager".WriteLog("receiveData.Length:" + receiveData.Length); + Debug.WriteLine("SerialPortManager => " + receiveData.Length); break; } - - if (operateType != "WakeupResponse") return; - Sp.Write("+++"); - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) - { - //显示点名弹窗 - Messenger.Default.Send("", MessengerToken.ShowCheckResponseDialog); - } - } - else if (strResult != "") - { - //信号数据 - if (strResult.Contains("NO CARRIER")) - { - Sp.Write("ATS124?" + Environment.NewLine); - } - else if (strResult.Contains("ATS124?")) - { - var strReceiveDate = strResult.Replace("\r\n", ","); - var signalArray = strReceiveDate.Split(','); - - _devStatus.Signal = signalArray[1]; - - //收到信号就可以工作了 - Messenger.Default.Send("", MessengerToken.HomePageSignal); - } } else { @@ -192,8 +182,8 @@ //发送消息更新界面 Messenger.Default.Send(_devStatus, devCode.Equals(DevCode.Dev1) - ? MessengerToken.SensorADevStatus - : MessengerToken.SensorBDevStatus + ? MessengerToken.RedSensorStatus + : MessengerToken.BlueSensorStatus ); } diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index 0b63310..1b0096a 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -249,9 +249,9 @@ diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index dcf6b2e..6593596 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -115,12 +115,6 @@ #endregion - #region 设置 - - SettingsButton.Click += delegate { }; - - #endregion - #region 管径输入监听 PipeDiameterTextBox.PreviewTextInput += delegate(object sender, TextCompositionEventArgs e) diff --git a/Correlator/ViewModel/AddSoundSpeedViewModel.cs b/Correlator/ViewModel/AddSoundSpeedViewModel.cs index eed497d..117992a 100644 --- a/Correlator/ViewModel/AddSoundSpeedViewModel.cs +++ b/Correlator/ViewModel/AddSoundSpeedViewModel.cs @@ -12,7 +12,7 @@ private readonly ISoundSpeedDataService _dataService; private string _materialName; - private string _minDiameter; + private string _minDiameter = string.Empty; public string MinDiameter { @@ -20,11 +20,11 @@ set { _minDiameter = value; - RaisePropertyChanged(() => MinDiameter); + RaisePropertyChanged(); } } - private string _maxDiameter; + private string _maxDiameter = string.Empty; public string MaxDiameter { @@ -32,11 +32,11 @@ set { _maxDiameter = value; - RaisePropertyChanged(() => MaxDiameter); + RaisePropertyChanged(); } } - private string _soundSpeed; + private string _soundSpeed = string.Empty; public string SoundSpeed { @@ -44,7 +44,7 @@ set { _soundSpeed = value; - RaisePropertyChanged(() => SoundSpeed); + RaisePropertyChanged(); } } @@ -53,14 +53,8 @@ public AddSoundSpeedViewModel(ISoundSpeedDataService dataService) { _dataService = dataService; - Messenger.Default.Register(this, MessengerToken.AddSoundSpeedMessage, it => - { - _materialName = it; - - MinDiameter = ""; - MaxDiameter = ""; - SoundSpeed = ""; - }); + Messenger.Default.Register(this, MessengerToken.AddSoundSpeedMessage, + it => { _materialName = it; }); DetermineParamCommand = new RelayCommand(AddSoundSpeed); } diff --git a/Correlator/ViewModel/EditSoundSpeedViewModel.cs b/Correlator/ViewModel/EditSoundSpeedViewModel.cs index 48747db..5b9d97d 100644 --- a/Correlator/ViewModel/EditSoundSpeedViewModel.cs +++ b/Correlator/ViewModel/EditSoundSpeedViewModel.cs @@ -21,7 +21,7 @@ set { _minDiameter = value; - RaisePropertyChanged(() => MinDiameter); + RaisePropertyChanged(); } } @@ -33,7 +33,7 @@ set { _maxDiameter = value; - RaisePropertyChanged(() => MaxDiameter); + RaisePropertyChanged(); } } @@ -45,7 +45,7 @@ set { _soundSpeed = value; - RaisePropertyChanged(() => SoundSpeed); + RaisePropertyChanged(); } } diff --git a/Correlator/ViewModel/HomePageProViewModel.cs b/Correlator/ViewModel/HomePageProViewModel.cs index 7c3656a..cc14ec9 100644 --- a/Correlator/ViewModel/HomePageProViewModel.cs +++ b/Correlator/ViewModel/HomePageProViewModel.cs @@ -325,7 +325,8 @@ } } - private string _pipeName = string.Empty; + // private string _pipeName = string.Empty; + private string _pipeName = "铸铁"; public string PipeName { @@ -337,7 +338,8 @@ } } - private string _pipeDiameter = string.Empty; + // private string _pipeDiameter = string.Empty; + private string _pipeDiameter = "300"; public string PipeDiameter { @@ -349,7 +351,8 @@ } } - private string _pipeLength = string.Empty; + // private string _pipeLength = string.Empty; + private string _pipeLength = "150"; public string PipeLength { @@ -373,7 +376,8 @@ } } - private string _lowFrequency; + // private string _lowFrequency = string.Empty; + private string _lowFrequency = "100"; public string LowFrequency { @@ -385,7 +389,7 @@ } } - private string _highFrequency; + private string _highFrequency = string.Empty; public string HighFrequency { @@ -435,6 +439,7 @@ public RelayCommand WindowLoadedCommand { set; get; } public RelayCommand PipeItemSelectedCommand { set; get; } + public RelayCommand SoundSettingsCommand { private set; get; } public RelayCommand SaveAudioCommand { private set; get; } public RelayCommand ResetParamCommand { private set; get; } public RelayCommand SnapShotCommand { private set; get; } @@ -663,6 +668,15 @@ PipeName = box.SelectedItem.ToString(); }); + SoundSettingsCommand = new RelayCommand(delegate + { + var speedDialog = new SoundSpeedDialog(_pipeName) + { + Owner = _homePageWindow + }; + speedDialog.ShowDialog(); + }); + SaveAudioCommand = new RelayCommand(delegate { if (FlowStatus.CorrelatorData != null) @@ -791,9 +805,14 @@ { if (_isResetParam) { - PipeDiameter = string.Empty; - PipeLength = string.Empty; - LowFrequency = string.Empty; + // PipeDiameter = string.Empty; + // PipeLength = string.Empty; + // LowFrequency = string.Empty; + + PipeDiameter = "300"; + PipeLength = "150"; + LowFrequency = "100"; + HighFrequency = string.Empty; SoundSpeed = "0"; diff --git a/Correlator/ViewModel/SoundSpeedViewModel.cs b/Correlator/ViewModel/SoundSpeedViewModel.cs index 63bdf84..35b8a0b 100644 --- a/Correlator/ViewModel/SoundSpeedViewModel.cs +++ b/Correlator/ViewModel/SoundSpeedViewModel.cs @@ -26,7 +26,7 @@ private set { _velocityCollection = value; - RaisePropertyChanged(() => VelocityCollection); + RaisePropertyChanged(); } } @@ -34,7 +34,6 @@ public RelayCommand AddSpeedCommand { get; set; } public RelayCommand EditSpeedCommand { get; set; } public RelayCommand ItemSelectedCommand { get; set; } - public RelayCommand NextStepCommand { get; set; } public SoundSpeedViewModel(ISoundSpeedDataService dataService) { @@ -56,8 +55,6 @@ AddSpeedCommand = new RelayCommand(AddSpeed); EditSpeedCommand = new RelayCommand(EditSpeed); - - NextStepCommand = new RelayCommand(UpdatePipeMaterial); } private void ItemSelected(object sender) @@ -110,23 +107,5 @@ }; editSoundSpeedDialog.ShowDialog(); } - - private void UpdatePipeMaterial(SoundSpeedDialog it) - { - if (_materialVelocity == null) - { - MessageBox.Show("还未选择任何材料,无法进行下一步操作", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - _dataService.UpdatePipeMaterial(_materialName, _materialVelocity); - - //更新界面数据 - Messenger.Default.Send("", MessengerToken.UpdateMaterialSoundSpeed); - - //返回选择材质界面 - it.Close(); - } } } \ No newline at end of file