首次上传
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<UserControl x:Class="MECF.Framework.Simulator.Core.RFs.AE.SimAePowerView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:deviceControl="clr-namespace:MECF.Framework.UI.Core.DeviceControl;assembly=MECF.Framework.UI.Core"
|
||||
xmlns:commons="clr-namespace:MECF.Framework.Simulator.Core.Commons"
|
||||
Height="900" Width="900">
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="100"></RowDefinition>
|
||||
<RowDefinition Height="150"></RowDefinition>
|
||||
<RowDefinition Height="50"></RowDefinition>
|
||||
<RowDefinition Height="400"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<commons:SocketTitleView Grid.Row="0"></commons:SocketTitleView>
|
||||
|
||||
<Canvas Grid.Row="1" Width="900">
|
||||
<CheckBox Content="Fail" IsChecked="{Binding IsFailed}" Canvas.Left="36" Canvas.Top="31"></CheckBox>
|
||||
|
||||
<CheckBox Content="HALO" IsChecked="{Binding IsHalo}" Canvas.Left="36" Canvas.Top="62"></CheckBox>
|
||||
|
||||
<CheckBox Content="ON" IsChecked="{Binding IsOn}" Canvas.Left="36" Canvas.Top="90"></CheckBox>
|
||||
|
||||
<CheckBox Content="ACK Together with response" IsChecked="{Binding IsContinueAck}" Canvas.Left="36" Canvas.Top="126"></CheckBox>
|
||||
|
||||
<TextBlock Text="Result:" Canvas.Left="155" Canvas.Top="42"></TextBlock>
|
||||
<TextBox Text="{Binding ResultValue, UpdateSourceTrigger=PropertyChanged }" Canvas.Left="212" Canvas.Top="31" Margin="0" Width="284"></TextBox>
|
||||
|
||||
</Canvas>
|
||||
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" Width="900">
|
||||
<Button Content="Clear Log" Width="100" Height="35" Command="{Binding ClearLogCommand}"></Button>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
|
||||
<DataGrid Grid.Row="3" FontSize="16" AutoGenerateColumns="False" CanUserAddRows="False" CanUserResizeRows="False" CanUserSortColumns="False" ItemsSource="{Binding TransactionLogItems}"
|
||||
ScrollViewer.CanContentScroll="True"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||
Width="900" Height="380" VerticalAlignment="Top">
|
||||
<DataGrid.Columns>
|
||||
|
||||
<DataGridTextColumn Header="Time" Width="160" IsReadOnly="True" Binding="{Binding OccurTime, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<DataGridTextColumn Header="Incoming" Width="350" IsReadOnly="True" Binding="{Binding Incoming, UpdateSourceTrigger=PropertyChanged}">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="TextWrapping" Value="Wrap"/>
|
||||
<Setter Property="Height" Value="auto"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.ElementStyle>
|
||||
</DataGridTextColumn>
|
||||
|
||||
|
||||
<DataGridTextColumn Header="Outgoing" Width="350" IsReadOnly="True" Binding="{Binding Outgoing, UpdateSourceTrigger=PropertyChanged}">
|
||||
<DataGridTextColumn.ElementStyle>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="TextWrapping" Value="Wrap"/>
|
||||
<Setter Property="Height" Value="auto"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.ElementStyle>
|
||||
</DataGridTextColumn>
|
||||
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
||||
@@ -0,0 +1,145 @@
|
||||
using Aitex.Core.UI.MVVM;
|
||||
using Aitex.Core.Utilities;
|
||||
using MECF.Framework.Simulator.Core.Commons;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.RFs.AE
|
||||
{
|
||||
/// <summary>
|
||||
/// SimAePowerView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SimAePowerView : UserControl
|
||||
{
|
||||
|
||||
public static readonly DependencyProperty PortProperty = DependencyProperty.Register(
|
||||
"Port", typeof(string), typeof(SimAePowerView),
|
||||
new FrameworkPropertyMetadata("COM5", FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
public string Port
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this.GetValue(PortProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.SetValue(PortProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public SimAePowerView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Loaded += OnViewLoaded;
|
||||
}
|
||||
|
||||
private void OnViewLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DesignerProperties.GetIsInDesignMode(this))
|
||||
return;
|
||||
|
||||
if (DataContext == null)
|
||||
{
|
||||
DataContext = new SimRfPowerViewModel(Port);
|
||||
(DataContext as TimerViewModelBase).Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SimRfPowerViewModel : SerialPortDeviceViewModel
|
||||
{
|
||||
public string Title
|
||||
{
|
||||
get { return "AE RF Power Simulator"; }
|
||||
}
|
||||
|
||||
private SimAeRfPower _sim;
|
||||
|
||||
public bool IsFailed
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sim.Failed;
|
||||
}
|
||||
set
|
||||
{
|
||||
_sim.Failed = value;
|
||||
}
|
||||
}
|
||||
public bool IsHalo
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sim.IsHalo;
|
||||
}
|
||||
set
|
||||
{
|
||||
_sim.IsHalo = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsOn
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sim.IsOn;
|
||||
}
|
||||
set
|
||||
{
|
||||
_sim.IsOn = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsContinueAck
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sim.IsContinueAck;
|
||||
}
|
||||
set
|
||||
{
|
||||
_sim.IsContinueAck = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//private string _value;
|
||||
|
||||
[IgnorePropertyChange]
|
||||
public string ResultValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sim.ResultValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
_sim.ResultValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public SimRfPowerViewModel(string port) : base("SimRfPowerViewModel")
|
||||
{
|
||||
_sim = new SimAeRfPower(port);
|
||||
|
||||
Init(_sim);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
using MECF.Framework.Simulator.Core.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
|
||||
namespace MECF.Framework.Simulator.Core.RFs.AE
|
||||
{
|
||||
class SimAeRfPower : SerialPortDeviceSimulator
|
||||
{
|
||||
public bool Failed { get; set; }
|
||||
|
||||
public bool IsOn { get; set; }
|
||||
|
||||
public bool IsHalo { get; set; }
|
||||
|
||||
public bool IsContinueAck { get; set; }
|
||||
|
||||
Stopwatch _timer = new Stopwatch();
|
||||
|
||||
private System.Timers.Timer _tick;
|
||||
Random _rd = new Random();
|
||||
|
||||
private object _locker = new object();
|
||||
|
||||
public string ResultValue { get; set; }
|
||||
|
||||
public SimAeRfPower(string port)
|
||||
: base(port, -1, "\r", ' ', false)
|
||||
{
|
||||
ResultValue = "";
|
||||
|
||||
_tick = new System.Timers.Timer();
|
||||
_tick.Interval = 200;
|
||||
|
||||
_tick.Elapsed += _tick_Elapsed;
|
||||
_tick.Start();
|
||||
|
||||
}
|
||||
|
||||
private void _tick_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
|
||||
lock (_locker)
|
||||
{
|
||||
if (_timer.IsRunning && _timer.Elapsed > TimeSpan.FromSeconds(10))
|
||||
{
|
||||
_timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<byte> _cached = new List<byte>();
|
||||
|
||||
private int _mode;
|
||||
private int _powerSetPoint;
|
||||
|
||||
protected override void ProcessUnsplitMessage(byte[] message1)
|
||||
{
|
||||
_cached.AddRange(message1);
|
||||
|
||||
if (_cached[0] == 0x06)
|
||||
_cached.RemoveAt(0);
|
||||
|
||||
if (_cached.Count < 3)
|
||||
return;
|
||||
|
||||
byte[] msgIn = _cached.ToArray();
|
||||
|
||||
_cached.Clear();
|
||||
|
||||
List<byte> lstAck = new List<byte>();
|
||||
lstAck.Add(0x06);
|
||||
|
||||
byte[] response = BuildMessage((byte)(msgIn[0] >> 3), msgIn[1], new byte[] { 0 });
|
||||
|
||||
switch (msgIn[1])
|
||||
{
|
||||
case 1:
|
||||
IsOn = false;
|
||||
break;
|
||||
case 2:
|
||||
IsOn = true;
|
||||
break;
|
||||
case 3: //reg mode
|
||||
_mode = msgIn[2];
|
||||
break;
|
||||
case 8:
|
||||
_powerSetPoint = msgIn[2] + (msgIn[3] << 8);
|
||||
break;
|
||||
case 155://mode comm
|
||||
response = BuildMessage((byte)(msgIn[0] >> 3), msgIn[1], new byte[] { 0x8 });
|
||||
break;
|
||||
case 162://status
|
||||
response = BuildMessage((byte)(msgIn[0] >> 3), msgIn[1], new byte[] { IsOn ? (byte)0x40 : (byte)0, 0, 0, 0 });
|
||||
break;
|
||||
case 164: //setpoint
|
||||
response = BuildMessage((byte)(msgIn[0] >> 3), msgIn[1], new byte[] { (byte)_powerSetPoint, (byte)(_powerSetPoint >> 8), (byte)_mode });
|
||||
break;
|
||||
case 165: //forward
|
||||
int forward = (int)(_powerSetPoint * 0.8);
|
||||
response = BuildMessage((byte)(msgIn[0] >> 3), msgIn[1], new byte[] { (byte)forward, (byte)(forward >> 8) });
|
||||
break;
|
||||
case 166: //reflect
|
||||
int reflect = (int)(_powerSetPoint * 0.2);
|
||||
response = BuildMessage((byte)(msgIn[0] >> 3), msgIn[1], new byte[] { (byte)reflect, (byte)(reflect >> 8) });
|
||||
break;
|
||||
case 221://pin
|
||||
List<byte> pin = new List<byte>();
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if (i == 20 && IsHalo)
|
||||
{
|
||||
pin.Add(0x31);
|
||||
continue;
|
||||
}
|
||||
pin.Add(0);
|
||||
}
|
||||
response = BuildMessage((byte)(msgIn[0] >> 3), msgIn[1], pin.ToArray());
|
||||
break;
|
||||
}
|
||||
|
||||
if (!IsContinueAck)
|
||||
{
|
||||
OnWriteMessage(lstAck.ToArray());
|
||||
OnWriteMessage(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
lstAck.AddRange(response);
|
||||
OnWriteMessage(lstAck.ToArray());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private static byte[] BuildMessage(byte address, byte command, byte[] data)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
|
||||
if (data.Length < 7)
|
||||
{
|
||||
buffer.Add((byte)((address << 3) + (data == null ? 0 : data.Length)));
|
||||
buffer.Add(command);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add((byte)((address << 3) + 7));
|
||||
buffer.Add(command);
|
||||
buffer.Add((byte)data.Length);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (data != null && data.Length > 0)
|
||||
{
|
||||
buffer.AddRange(data);
|
||||
}
|
||||
|
||||
buffer.Add(CalcSum(buffer, buffer.Count));
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
private static byte CalcSum(List<byte> data, int length)
|
||||
{
|
||||
byte ret = 0x00;
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
ret ^= data[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user