Commit 51ba77ec authored by 潘栩锋's avatar 潘栩锋 🚴

1.优化 IFixService 改为轮询模式, 使用 FObj.Reflect 作为服务代理

2.添加 测试模式,DynArea.IsTest, 就是 B=100, 不需要找边界。 用于没有膜时,测试机架。
3.删除 系统参数界面 删除 编码器2 放大设置
parent aaba269c
......@@ -227,8 +227,8 @@
</Compile>
<Compile Include="UiModule\FixGraph\FixGraphItemParam.cs" />
<Compile Include="UiModule\FixGraph\FixGraphParams.cs" />
<Compile Include="UiModule\FixGraph\FixGraphViewModel.cs" />
<Compile Include="UiModule\FixGraph\FixGraphViewModel_UnitTest.cs" />
<Compile Include="UiModule\FixGraph\FixGraphVm.cs" />
<Compile Include="UiModule\FixGraph\FixGraphVmUt.cs" />
<Compile Include="UiModule\FixGraph\PgFixAnalyze.xaml.cs">
<DependentUpon>PgFixAnalyze.xaml</DependentUpon>
</Compile>
......
......@@ -117,15 +117,6 @@
</TextBlock>
</StackPanel>
</StackPanel>
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="编码器2放大" />
<StackPanel Orientation="Horizontal">
<TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding Encoder2_comp}" HorizontalAlignment="Left"/>
<TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
<Run Text="倍"/>
</TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding IsSelected,Converter={StaticResource visbilityconv},ConverterParameter=Collapsed, ElementName=comboBoxotem_ROUND}">
......
......@@ -22,16 +22,21 @@
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Border Style="{StaticResource BorderStyle_module}" Name="Border_AD" >
<Border Style="{StaticResource Styles.Module.Border}" Name="Border_AD" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid x:Name="grid_initparam"/>
<Border Background="{StaticResource Background_Title}" CornerRadius="3" Height="130" >
<Border Background="{StaticResource Brushes.TitleBar.Background}" CornerRadius="3" Height="130" >
<Grid>
<Viewbox Margin="10">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-4" Visibility="{Binding IsTest,Converter={StaticResource visbilityconv}}"
Style="{StaticResource Styles.Card.Title}"
Background="{StaticResource MahApps.Brushes.SemiTransparent}"
Foreground="{StaticResource Brushes.TitleBar.Foreground}"
Text="测试模式" />
<Viewbox Margin="10">
<TextBlock Text="{Binding Thk,StringFormat={}{0:F1}}" Foreground="White" FontSize="30" FontWeight="Bold" FontFamily="Microsoft Sans Serif" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Viewbox>
<TextBlock Text="{Binding ControllerState,Converter={StaticResource ctrlstateconv}}" FontSize="12" FontFamily="Microsoft Sans Serif" HorizontalAlignment="Right" VerticalAlignment="Bottom" Foreground="White" Margin="5"/>
......
......@@ -37,26 +37,29 @@
<Setter Property="FontSize" Value="15"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
</Style>
<local:FixGraphViewModel_UnitTest x:Key="viewModel" Max="65540" Min="655" Average="123" Sigma3="3.2"/>
<local:FixGraphVmUt x:Key="viewModel" Max="65540" Min="655" Average="123" Sigma3="3.2"/>
</ResourceDictionary>
</UserControl.Resources>
<Border Style="{StaticResource BorderStyle_module}" >
<Border Style="{StaticResource Styles.Module.Border}" >
<Grid d:DataContext="{StaticResource viewModel}">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="453"/>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="400*"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="400*"/>
</Grid.ColumnDefinitions>
<lvc:CartesianChart Grid.Row="1" Grid.ColumnSpan="2" Margin="5,-5,2,2"
<lvc:CartesianChart Grid.Row="1" Grid.ColumnSpan="4"
Margin="5,-5,2,2"
Hoverable="False" DisableAnimations="True" DataTooltip="{x:Null}" >
<lvc:CartesianChart.Series>
<lvc:LineSeries
Values="{Binding Values}"
StrokeThickness = "3"
Stroke = "{StaticResource Color_theme_activity}"
Stroke = "{StaticResource Brushes.Activity}"
Fill = "Transparent"
PointGeometry ="{x:Null}"/>
......@@ -77,26 +80,30 @@
</lvc:Axis>
</lvc:CartesianChart.AxisY >
</lvc:CartesianChart>
<Viewbox >
<StackPanel Orientation="Horizontal" Margin="5">
<Button Width="40" Height="40" VerticalAlignment="Top" Style="{StaticResource ButtonStyle_empty}"
Click="Button_info_click" Margin="5">
<Grid Style="{StaticResource GridStyle_ButtonShadow}">
<Ellipse Fill="{StaticResource Color_theme_activity}"/>
<Path Width="20" Height="20" Stretch="Uniform" Fill="White" Data="{StaticResource geometry_i}"/>
</Grid>
</Button>
<Grid Grid.Column="1" Margin="10,0" >
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="24" Foreground="{StaticResource Color_theme_activity}" Text="定点图"/>
<Button Style="{StaticResource Styles.Button.Icon}" Margin="48,0,0,-20"
Click="Button_info_click" >
<Grid Style="{StaticResource Styles.Shadow}" >
<TextBlock Padding="10,5" VerticalAlignment="Top"
FontSize="24" Foreground="{StaticResource Brushes.ThemeBackground}" Background="{StaticResource Brushes.Activity}"
>
<Run Text="{Binding InfoName}"/>定点图
</TextBlock>
</Grid>
</Button>
<Grid Grid.Column="1" Grid.RowSpan="2" Panel.ZIndex="2"
VerticalAlignment="Top" HorizontalAlignment="Left" >
<Viewbox MaxHeight="50">
<StackPanel Orientation="Horizontal">
<StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Margin="5">
<StackPanel Orientation="Horizontal" Visibility="{Binding IsADMode,Converter={StaticResource visbilityconv}}">
<TextBlock FontSize="16" Margin="3,0" Width="auto" Text="AD值"/>
<TextBlock FontSize="16" Margin="3,0" Width="auto" Text="AD值" Foreground="{StaticResource Brushes.Highlight}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Margin="5">
<TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Time,StringFormat={}{0:HH:mm:ss}}"/>
<TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Time,StringFormat={}{0:HH:mm:ss}}"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Margin="5,0">
......@@ -108,136 +115,141 @@
<TextBlock Style="{StaticResource TitleStyle}" Text="混合:" />
<TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Mix}"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="0,10">
<StackPanel.Resources>
<Style TargetType="{x:Type Path}" x:Key="PathStyle_icon">
<Setter Property="Fill" Value="{StaticResource Color_theme_activity}"/>
<Setter Property="Stretch" Value="Uniform"/>
<Setter Property="Width" Value="40"/>
<Setter Property="Height" Value="40"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
</Style>
</StackPanel.Resources>
<Button Click="button_pause_Click" Style="{StaticResource ButtonStyle_empty}" Margin="5,0">
<Grid Style="{StaticResource GridStyle_ButtonShadow}">
<Rectangle Fill="{StaticResource Color_theme_activity}" Width="40" Height="40"/>
<Path Fill="White" Stretch="Uniform" Width="20" Height="20">
<Path.Style>
<Style TargetType="Path" >
<Setter Property="Data" Value="{StaticResource Geometry_stop}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsPaused}" Value="True">
<Setter Property="Data" Value="{StaticResource Geometry_play}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
</Grid>
</Button>
<Button Click="button_save_Click" Style="{StaticResource ButtonStyle_empty}" Margin="5,0" IsEnabled="{Binding IsPaused}">
<Grid Style="{StaticResource GridStyle_ButtonShadow}">
<Rectangle Width="40" Height="40">
<Rectangle.Style>
<Style TargetType="Rectangle" >
<Setter Property="Fill" Value="{StaticResource Color_theme_activity}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsPaused}" Value="false">
<Setter Property="Fill" Value="{StaticResource Color_theme_noact}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
<Path Data="{StaticResource Geometry_floppy}" Fill="White" Stretch="Uniform" Width="20" Height="20"/>
</Grid>
</Button>
<Button Click="button_analyze_Click" Style="{StaticResource ButtonStyle_empty}" Margin="5,0" IsEnabled="{Binding IsPaused}">
<Grid Style="{StaticResource GridStyle_ButtonShadow}">
<Rectangle Width="40" Height="40">
<Rectangle.Style>
<Style TargetType="Rectangle" >
<Setter Property="Fill" Value="{StaticResource Color_theme_activity}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsPaused}" Value="False">
<Setter Property="Fill" Value="{StaticResource Color_theme_noact}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
<Path Data="{StaticResource Geometry_chart-line}" Fill="White" Stretch="Uniform" Width="20" Height="20"/>
</Grid>
</Button>
</StackPanel>
</StackPanel>
</Viewbox>
</Viewbox>
</Grid>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="0,10" Grid.Column="2" Grid.RowSpan="2">
<StackPanel.Resources>
<Style TargetType="{x:Type Path}" x:Key="PathStyle_icon">
<Setter Property="Fill" Value="{StaticResource Color_theme_activity}"/>
<Setter Property="Stretch" Value="Uniform"/>
<Setter Property="Width" Value="40"/>
<Setter Property="Height" Value="40"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
</Style>
</StackPanel.Resources>
<Button Click="button_pause_Click" Style="{StaticResource ButtonStyle_empty}" Margin="5,0">
<Grid Style="{StaticResource GridStyle_ButtonShadow}">
<Rectangle Fill="{StaticResource Color_theme_activity}" Width="40" Height="40"/>
<Path Fill="White" Stretch="Uniform" Width="20" Height="20">
<Path.Style>
<Style TargetType="Path" >
<Setter Property="Data" Value="{StaticResource Geometry_stop}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsPaused}" Value="True">
<Setter Property="Data" Value="{StaticResource Geometry_play}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
</Grid>
</Button>
<Button Click="button_save_Click" Style="{StaticResource ButtonStyle_empty}" Margin="5,0" IsEnabled="{Binding IsPaused}">
<Grid Style="{StaticResource GridStyle_ButtonShadow}">
<Rectangle Width="40" Height="40">
<Rectangle.Style>
<Grid Grid.Column="1" Grid.RowSpan="2" Margin="10,0" VerticalAlignment="Top" HorizontalAlignment="Right" Panel.ZIndex="1"
<Style TargetType="Rectangle" >
<Setter Property="Fill" Value="{StaticResource Color_theme_activity}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsPaused}" Value="false">
<Setter Property="Fill" Value="{StaticResource Color_theme_noact}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
<Path Data="{StaticResource Geometry_floppy}" Fill="White" Stretch="Uniform" Width="20" Height="20"/>
</Grid>
</Button>
<Button Click="button_analyze_Click" Style="{StaticResource ButtonStyle_empty}" Margin="5,0" IsEnabled="{Binding IsPaused}">
<Grid Style="{StaticResource GridStyle_ButtonShadow}">
<Rectangle Width="40" Height="40">
<Rectangle.Style>
<Style TargetType="Rectangle" >
<Setter Property="Fill" Value="{StaticResource Color_theme_activity}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsPaused}" Value="False">
<Setter Property="Fill" Value="{StaticResource Color_theme_noact}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
<Path Data="{StaticResource Geometry_chart-line}" Fill="White" Stretch="Uniform" Width="20" Height="20"/>
</Grid>
</Button>
</StackPanel>
<Grid Grid.Column="3" Grid.RowSpan="2" Panel.ZIndex="1"
Margin="10,0" VerticalAlignment="Top" HorizontalAlignment="Right"
Background="{StaticResource SemiTransparentGreyBrush}" >
<WrapPanel Orientation="Horizontal" Margin="10">
<WrapPanel.Resources>
<Style TargetType="Viewbox">
<Setter Property="Height" Value="25"/>
<Setter Property="Width" Value="130"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
</Style>
</WrapPanel.Resources>
<StackPanel>
<Viewbox >
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TitleStyle}" Text="最大: "/>
<TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Max,StringFormat={}{0:F1}}"/>
</StackPanel>
</Viewbox>
<Viewbox >
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TitleStyle}" Text="最小: "/>
<TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Min,StringFormat={}{0:F1}}"/>
</StackPanel>
</Viewbox>
</StackPanel>
<StackPanel >
<Viewbox >
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TitleStyle}"
Foreground="{StaticResource WhiteBrush}"
Background="{StaticResource TextBrush}"
<Viewbox MaxHeight="50">
<StackPanel Margin="5">
<StackPanel.Resources>
<Style TargetType="Viewbox">
<Setter Property="Height" Value="25"/>
<Setter Property="Width" Value="120"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
</Style>
</StackPanel.Resources>
<StackPanel Orientation="Horizontal">
<Viewbox >
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TitleStyle}"
Foreground="{DynamicResource WhiteBrush}"
Background="{DynamicResource TextBrush}"
Opacity="0.8"
Text="平均: "
/>
<TextBlock Style="{StaticResource ValueStyle}"
Foreground="{StaticResource WhiteBrush}"
Background="{StaticResource TextBrush}"
<TextBlock Style="{StaticResource ValueStyle}"
Foreground="{DynamicResource WhiteBrush}"
Background="{DynamicResource TextBrush}"
Text="{Binding Average,StringFormat={}{0:F1}}"
/>
</StackPanel>
</Viewbox>
<Viewbox>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TitleStyle}"
</StackPanel>
</Viewbox>
<Viewbox>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TitleStyle}"
Foreground="Black"
Background="{StaticResource WhiteBrush}"
Opacity="0.8"
Text="3σ: "
/>
<TextBlock Style="{StaticResource ValueStyle}"
<TextBlock Style="{StaticResource ValueStyle}"
Foreground="{StaticResource TextBrush}"
Background="{StaticResource WhiteBrush}"
Text="{Binding Sigma3,StringFormat={}{0:F1}}"
/>
</StackPanel>
</Viewbox>
</StackPanel>
</Viewbox>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Viewbox >
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TitleStyle}" Text="最大: "/>
<TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Max,StringFormat={}{0:F1}}"/>
</StackPanel>
</Viewbox>
<Viewbox >
<StackPanel Orientation="Horizontal" >
<TextBlock Style="{StaticResource TitleStyle}"
Text="最小: " />
<TextBlock Style="{StaticResource ValueStyle}"
Text="{Binding Min,StringFormat={}{0:F1}}"/>
</StackPanel>
</Viewbox>
</StackPanel>
</StackPanel>
</WrapPanel>
</Viewbox>
</Grid>
</Grid>
</Border>
......
......@@ -31,7 +31,7 @@ namespace FLY.Thick.Base.UI.UiModule
/// </summary>
public partial class FixGraph : UserControl
{
FixGraphViewModel viewModel;
FixGraphVm viewModel;
FixGraphItemParam graphparam;
public FixGraph()
{
......@@ -51,7 +51,7 @@ namespace FLY.Thick.Base.UI.UiModule
}
//获取设备
viewModel = new FixGraphViewModel();
viewModel = new FixGraphVm();
viewModel.Init(fixService, graphparam);
this.DataContext = viewModel;
......
......@@ -13,7 +13,7 @@ using FLY.Thick.Base.UI;
namespace FLY.Thick.Base.UI.UiModule
{
public class FixGraphViewModel : ISaveManager, INotifyPropertyChanged
public class FixGraphVm : ISaveManager, INotifyPropertyChanged
{
#region 图表控制
/// <summary>
......@@ -113,10 +113,10 @@ namespace FLY.Thick.Base.UI.UiModule
/// </summary>
const int values_cap = 1000;
IFixService mFixService;
IFixService fixService;
FixGraphItemParam graphparam;
public FixGraphViewModel()
DateTime updateTime;
public FixGraphVm()
{
#region 与数据无关界面参数
XFormatter = (x) =>
......@@ -132,18 +132,31 @@ namespace FLY.Thick.Base.UI.UiModule
}
public void Init(IFixService fixService, FixGraphItemParam bulkGraphItemFix)
{
mFixService = fixService;
this.fixService = fixService;
graphparam = bulkGraphItemFix;
Update4Graphparam();
graphparam.PropertyChanged += Graphparam_PropertyChanged;
mFixService.RegistTimeGridEvent(new FixEventHandler(mFixService_TimeGridEvent));
this.fixService.PropertyChanged += FixService_PropertyChanged;
this.PropertyChanged += FixGraphViewModel_PropertyChanged;
}
private void FixService_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(fixService.UpdateTime))
{
//检测是哪个变化了
if (fixService.UpdateTime != updateTime)
{
//变化了
//向服务获取数据
fixService.GetFixDatas(fixService_GetFixDatas, this);
}
}
}
private void FixGraphViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "AutoTarget")
......@@ -358,18 +371,19 @@ namespace FLY.Thick.Base.UI.UiModule
List<double> data_mix = new List<double>();
#endregion
void mFixService_TimeGridEvent(object sender, FixEventArgs e)
void fixService_GetFixDatas(object asyncContext, object retData)
{
var reponse = retData as GetFixDatasReponse;
if (IsPaused)
return;
//输入1.28ms 的数据, 输出 混合为mix,间隔为 interval 的数据
List<double> data_out = new List<double>();
for (int i = 0; i < e.thicks.Length; i++)
for (int i = 0; i < reponse.thicks.Length; i++)
{
double v = (IsADMode) ? e.ADs[i] : e.thicks[i];
double v = (IsADMode) ? reponse.ADs[i] : reponse.thicks[i];
data_interval.Add(v);
data_interval_totaltime += e.ts;
data_interval_totaltime += reponse.ts;
if (data_interval_totaltime >= Interval)
{
......@@ -387,10 +401,11 @@ namespace FLY.Thick.Base.UI.UiModule
if (data_out.Count() > 0)
{
Time = e.time;
Time = reponse.time;
AddPoint(data_out);
}
}
void UpdateStat()
{
if (mDatas.Count() == 0)
......
......@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace FLY.Thick.Base.UI.UiModule
{
public class FixGraphViewModel_UnitTest : INotifyPropertyChanged
public class FixGraphVmUt : INotifyPropertyChanged
{
#region 图表控制
public double YMax { get; set; } = double.NaN;
......@@ -56,7 +56,7 @@ namespace FLY.Thick.Base.UI.UiModule
const int TotalValueCountInView = 1000;
public FixGraphViewModel_UnitTest()
public FixGraphVmUt()
{
#region 与数据无关界面参数
XFormatter = (x) =>
......
......@@ -9,84 +9,29 @@ using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;
using FObjBase.Reflect;
namespace FLY.Thick.Base.Client
{
public class FixServiceClient : FObjServiceClient, IFixService
public class FixServiceClient : FObjBase.Reflect.Reflect_SeviceClient, IFixService
{
protected override Type InterfaceType => typeof(IFixService);
public FixServiceClient(UInt32 serviceId) : base(serviceId) { }
public FixServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
#region IFlyAD接口
/// <summary>
/// 注册timegrid 事件
/// </summary>
/// <param name="handler"></param>
public void RegistTimeGridEvent(FixEventHandler handler)
{
FixEvent += handler;
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID,
Misc.MyBase.BIT(FIX_OBJ_INTERFACE.PUSH_TIMEGRID),
SENSE_CONFIG.ADD);
}
/// <summary>
/// 关闭注册timegrid 事件
/// </summary>
/// <param name="handler"></param>
public void UnRegistTimeGridEvent(FixEventHandler handler)
{
FixEvent -= handler;
if (FixEvent == null)
{
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID,
Misc.MyBase.BIT(FIX_OBJ_INTERFACE.PUSH_TIMEGRID),
SENSE_CONFIG.REMOVE);
}
}
event FixEventHandler FixEvent;
public DateTime UpdateTime { get; set; }
#endregion
public override void ConnectNotify(IFConn from)
[Call(typeof(GetFixDatasReponse))]
public void GetFixDatas(AsyncCBHandler asyncDelegate, object asyncContext)
{
base.ConnectNotify(from);
if (from.IsConnected)
{
//设置推送
if (FixEvent != null)
{
UInt32 sense_mask = Misc.MyBase.BIT(FIX_OBJ_INTERFACE.PUSH_TIMEGRID);
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID,
sense_mask,
SENSE_CONFIG.ADD);
}
}
Call(nameof(GetFixDatas), null, asyncDelegate, asyncContext);
}
public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
{
switch (infoid)
{
case FIX_OBJ_INTERFACE.PUSH_TIMEGRID:
{
string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FixEventArgs>(json);
FixEvent?.Invoke(this, p);
} break;
}
}
}
}
\ No newline at end of file
......@@ -116,6 +116,11 @@ namespace FLY.Thick.Base.Common
/// </summary>
public int AutoScanCounter { get; set; } = 5;
/// <summary>
/// 测试模式
/// </summary>
public bool IsTest { get; set; }
#endregion
#region IO
......
......@@ -58,6 +58,7 @@
<Compile Include="Client\FlyADServiceClient.cs" />
<Compile Include="Client\GageInfoServiceClient.cs" />
<Compile Include="Client\GetSampleServiceClient.cs" />
<Compile Include="Client\FlyAdIoDefineServiceClient.cs" />
<Compile Include="Client\InitParamServiceClient.cs" />
<Compile Include="Client\RejectServiceClient.cs" />
<Compile Include="Client\ScanCorrServiceClient.cs" />
......@@ -78,6 +79,7 @@
<Compile Include="IService\IBorderSearchService.cs" />
<Compile Include="IService\ICurveService.cs" />
<Compile Include="IService\IFixService.cs" />
<Compile Include="IService\IFlyAdIoDefineService.cs" />
<Compile Include="IService\IFlyADService.cs" />
<Compile Include="IService\IGageInfoService.cs" />
<Compile Include="IService\IGetSampleService.cs" />
......@@ -93,8 +95,6 @@
<Compile Include="OBJ_INTERFACE\GETSAMPLE_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\SCANCORR_OBJ_INTERFACE.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server.OBJProxy\Fix_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\Gage_ObjProxy.cs" />
<Compile Include="Server.OBJProxy\GetSample_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\ScanCorr_OBJProxy.cs" />
<Compile Include="Server\BoltMapImg.cs" />
......
using System;
using FObjBase;
using FObjBase.Reflect;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
......@@ -8,23 +11,16 @@ namespace FLY.Thick.Base.IService
/// <summary>
/// 定点测量服务
/// </summary>
public interface IFixService
public interface IFixService : INotifyPropertyChanged
{
/// <summary>
/// 注册timegrid 事件
/// </summary>
/// <param name="handler"></param>
void RegistTimeGridEvent(FixEventHandler handler);
/// <summary>
/// 关闭注册timegrid 事件
/// </summary>
/// <param name="handler"></param>
void UnRegistTimeGridEvent(FixEventHandler handler);
DateTime UpdateTime { get; }
[Call(typeof(GetFixDatasReponse))]
void GetFixDatas(AsyncCBHandler asyncDelegate, object asyncContext);
}
public delegate void FixEventHandler(object sender, FixEventArgs e);
public class FixEventArgs : EventArgs
public class GetFixDatasReponse
{
/// <summary>
/// 数据, AD数据!!!!!
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.Base.Server;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.Common;
namespace FLY.Thick.Base.Server.OBJProxy
{
public class Fix_OBJProxy: FObj
{
#region 延时推送 MARKNO
#endregion
IFixService mFix;
public Fix_OBJProxy(int objsys_idx, UInt32 id, IFixService fix)
: base(objsys_idx)
{
ID = id;
mFix = fix;
mFix.RegistTimeGridEvent(new FixEventHandler(GM_Fix_TimeGridEvent));
}
void GM_Fix_TimeGridEvent(object sender, FixEventArgs e)
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(e);
CurrObjSys.PushObjInfoEx(
this, FIX_OBJ_INTERFACE.PUSH_TIMEGRID,
Misc.Converter.StringToBytes(json));
}
#region FObj 重载
#endregion
}
}
using FObjBase;
using FObjBase.Reflect;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
namespace FLY.Thick.Base.Server.OBJProxy
{
public class Gage_ObjProxy : FObj
{
Type interfaceType;
object obj;
public bool ignoreSet = false;
List<AnyEvent> anyEvents = new List<AnyEvent>();
Dictionary<object, string> subProperties = new Dictionary<object, string>();
List<string> properties = new List<string>();
public Gage_ObjProxy(int objsys_idx, UInt32 id, Type interfaceType, object obj) : base(objsys_idx)
{
ID = id;
this.interfaceType = interfaceType;
this.obj = obj;
InitPropertyChanged();
//处理[PropertyPush]
InitPropertyPush();
//处理[Push]
InitEventPush();
}
void InitPropertyChanged()
{
if (!typeof(INotifyPropertyChanged).IsAssignableFrom(interfaceType))
return;
//继承了INotifyPropertyChanged
((INotifyPropertyChanged)(this.obj)).PropertyChanged += Obj_PropertyChanged;
var interfaceTypes = new List<Type>();
interfaceTypes.Add(this.interfaceType);
interfaceTypes.AddRange(this.interfaceType.GetInterfaces());
var propertyInfos = new List<PropertyInfo>();
foreach (var ifaceType in interfaceTypes)
{
propertyInfos.AddRange(ifaceType.GetProperties());
}
foreach (var propertyInfo in propertyInfos)
{
if (propertyInfo.GetCustomAttribute<JsonIgnoreAttribute>() != null)
continue;//这个不需要推送
if (properties.Contains(propertyInfo.Name))
continue;
properties.Add(propertyInfo.Name);
}
}
void InitEventPush()
{
var interfaceTypes = new List<Type>();
interfaceTypes.Add(this.interfaceType);
interfaceTypes.AddRange(this.interfaceType.GetInterfaces());
var eventInfos = new List<EventInfo>();
foreach (var ifaceType in interfaceTypes)
{
eventInfos.AddRange(ifaceType.GetEvents());
}
foreach (var eventInfo in eventInfos)
{
var pushAttribute = eventInfo.GetCustomAttribute<PushAttribute>();
if (pushAttribute == null)
continue;
if (anyEvents.Any(ae => ae.eventName == eventInfo.Name))
continue;//已经添加了
var anyEvent = new AnyEvent()
{
eventName = eventInfo.Name,
PushObjInfoEx = (msg) =>
{
var buf = Misc.Converter.StringToBytes(msg);
CurrObjSys.PushObjInfoEx(
this, Reflect_OBJ_INTERFACE.PUSH_Event,
buf);
}
};
//这个事件需要推送
eventInfo.AddEventHandler(obj, anyEvent.eventHandler);
anyEvents.Add(anyEvent);
}
}
void InitPropertyPush()
{
//处理[PropertyPush]
var interfaceTypes = new List<Type>();
interfaceTypes.Add(this.interfaceType);
interfaceTypes.AddRange(this.interfaceType.GetInterfaces());
var propertyInfos = new List<PropertyInfo>();
foreach (var ifaceType in interfaceTypes)
propertyInfos.AddRange(ifaceType.GetProperties());
foreach (var propertyInfo in propertyInfos)
{
if (!IsPropertyPush(propertyInfo))
continue;
if (!properties.Contains(propertyInfo.Name))
{
properties.Add(propertyInfo.Name);
}
InitSubPropertyPush(this.obj.GetType().GetProperty(propertyInfo.Name), this.obj, null);
}
}
bool IsPropertyPush(PropertyInfo propertyInfo)
{
if (propertyInfo.GetCustomAttribute<PropertyPushAttribute>() == null)
return false;//必须是[PropertyPush]
if (propertyInfo.CanWrite)
return false;//它只能是get,不能有set
if (!typeof(INotifyPropertyChanged).IsAssignableFrom(propertyInfo.PropertyType))
return false;//必须是从INotifyPropertyChanged派生的
return true;
}
void InitSubPropertyPush(PropertyInfo propertyInfo, object obj, string parentName)
{
//下级推送!!!!
var propertyValue = propertyInfo.GetValue(obj);
string path = parentName == null ? propertyInfo.Name : $"{parentName}.{propertyInfo.Name}";
subProperties.Add(propertyValue, path);
((INotifyPropertyChanged)(propertyValue)).PropertyChanged += Sub_PropertyChanged;
//继续向下找
var subPropertyInfos = propertyInfo.PropertyType.GetProperties();
foreach (var subPropertyInfo in subPropertyInfos)
{
if (!IsPropertyPush(subPropertyInfo))
continue;//必须是[PropertyPush]
InitSubPropertyPush(subPropertyInfo, propertyValue, path);
}
}
class AnyEvent
{
public string eventName;
public Action<string> PushObjInfoEx;
public EventHandler eventHandler;
public AnyEvent()
{
eventHandler = new EventHandler(Obj_AnyEvent);
}
void Obj_AnyEvent(object sender, EventArgs e)
{
var rData = new Reflect_OBJ_INTERFACE.ReflectData()
{
name = eventName,
data = JObject.FromObject(e)
};
string reponse = JsonConvert.SerializeObject(rData);
PushObjInfoEx?.Invoke(reponse);
}
}
private void Obj_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
//if (ignoreSet)//从服务器接收的数据,不用再推送给服务器
// return;
if (interfaceType == null)
return;
if (!properties.Contains(e.PropertyName))
return;//这个不需要推送
var v = this.obj.GetType().GetProperty(e.PropertyName).GetValue(sender);
var jObject = new JObject();
if (v == null)
jObject.Add(e.PropertyName, null);
else
jObject.Add(e.PropertyName, JToken.FromObject(v));
string json = jObject.ToString(Formatting.None);
var buf = Misc.Converter.StringToBytes(json);
CurrObjSys.PushObjInfoEx(
this, Reflect_OBJ_INTERFACE.PUSH_PropertyChanged,
buf);
}
private void Sub_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
//if (ignoreSet)//从服务器接收的数据,不用再推送给服务器
// return;
if (!subProperties.ContainsKey(sender))
return;//异常, 不是子property
var type = sender.GetType();
var propertyInfo = type.GetProperty(e.PropertyName);
if (propertyInfo == null)
return;//获取失败!!!
if (propertyInfo.GetCustomAttribute<JsonIgnoreAttribute>() != null)
return;//这个不需要推送
string path = subProperties[sender];
string[] parentNames = path.Split('.');
if (parentNames.Count() == 0)
return;//分解出错
var v = propertyInfo.GetValue(sender);
var jObject = new JObject();
if (v == null)
jObject.Add(propertyInfo.Name, null);
else
jObject.Add(propertyInfo.Name, JToken.FromObject(v));
JObject jObject_parent = null;
for (int i = 0; i < parentNames.Count(); i++)
{
int idx = parentNames.Count() - 1 - i;
jObject_parent = new JObject();
jObject_parent.Add(parentNames[idx], jObject);
jObject = jObject_parent;
}
string json = jObject_parent.ToString(Formatting.None);
CurrObjSys.PushObjInfoEx(this,
Reflect_OBJ_INTERFACE.PUSH_PropertyChanged,
Misc.Converter.StringToBytes(json));
}
public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
{
switch (funcid)
{
case Reflect_OBJ_INTERFACE.CALL_GetAllProperties:
{
var jObject = new JObject();
var type = obj.GetType();
foreach (var propertyName in properties)
{
var propertyInfo = type.GetProperty(propertyName);
var v = propertyInfo.GetValue(obj);
if (v == null)
jObject.Add(propertyInfo.Name, null);
else
jObject.Add(propertyInfo.Name, JToken.FromObject(v));
}
string json = jObject.ToString(Formatting.None);
CurrObjSys.PushCallFunctionEx(from, srcid, ID, magic, funcid, Misc.Converter.StringToBytes(json));
}
break;
case Reflect_OBJ_INTERFACE.CALL_SetProperty:
{
string json = Misc.Converter.BytesToString(infodata);
//ignoreSet = true;
JsonConvert.PopulateObject(json, obj);
//ignoreSet = false;
}
break;
case Reflect_OBJ_INTERFACE.CALL_MethodInvoke:
{
string json = Misc.Converter.BytesToString(infodata);
var rData = JsonConvert.DeserializeObject<Reflect_OBJ_INTERFACE.ReflectData>(json);
var type = obj.GetType();
var paramNames_req = rData.data.Children().OfType<JProperty>().Select(p => p.Name);
MethodInfo methodInfo = GetMethodInfo(type, rData.name, paramNames_req);
if (methodInfo == null)
{
//不能找到,
throw new Exception($"程序写错了, 不能找到 rData.name={rData.name} 或者 参数名称不对,没法完全匹配");
}
var parameterInfos = methodInfo.GetParameters();
object[] parameters = new object[parameterInfos.Count()];
for (int i = 0; i < parameters.Count(); i++)
{
var ptype = parameterInfos[i].ParameterType;
var pname = parameterInfos[i].Name;
if (string.Compare(pname, "asyncDelegate", true) == 0)
{
parameters[i] = new AsyncCBHandler(asyncDelegate);
}
else if (string.Compare(pname, "asyncContext", true) == 0)
{
parameters[i] = new CC { from = from, srcid = srcid, magic = magic, methodName = rData.name };
}
else
{
parameters[i] = rData.data[pname].ToObject(ptype);
}
}
methodInfo.Invoke(obj, parameters);
}
break;
}
}
MethodInfo GetMethodInfo(Type type, string name, IEnumerable<string> parameterNames)
{
var methodInfos = from mi in type.GetMethods() where mi.Name == name select mi;
if (methodInfos.Count() == 0)
return null;
if (methodInfos.Count() == 1)
return methodInfos.First();
//必须完全匹配
foreach (var methodInfo in methodInfos)
{
var parameterInfos = methodInfo.GetParameters();
//全部参数名称
var names = parameterInfos.Select(pi => pi.Name).ToList();
//删除掉 asyncDelegate,asyncContext
names.Remove("asyncDelegate");
names.Remove("asyncContext");
var names_req = parameterNames;
if (names.Count() != names_req.Count())
continue;//数量不一致,肯定不同
var sames = names_req.Intersect(names);
if (sames.Count() != names_req.Count())
continue;// names 与 names_req 的交集数量与names_req不一样,肯定不同
//就是它
return methodInfo;
}
return null;
}
void asyncDelegate(object asyncContext, object retData)
{
var cc = (CC)asyncContext;
var rData = new Reflect_OBJ_INTERFACE.ReflectData()
{
name = cc.methodName,
data = retData == null ? null : JToken.FromObject(retData)
};
string json = JsonConvert.SerializeObject(rData);
CurrObjSys.PushCallFunctionEx(
cc.from,
cc.srcid,
ID,
cc.magic,
Reflect_OBJ_INTERFACE.CALL_MethodInvoke,
Misc.Converter.StringToBytes(json));
}
class CC
{
public IFConn from;
public UInt32 srcid;
public UInt32 magic;
public string methodName;
}
}
}
......@@ -8,6 +8,8 @@ using System.ComponentModel;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using Misc;
using FlyADBase;
using FObjBase;
namespace FLY.Thick.Base.Server
{
......@@ -22,6 +24,11 @@ namespace FLY.Thick.Base.Server
public bool IsRunning { get; protected set; }
#endregion
#region IFixService
public DateTime UpdateTime { get; private set; }
#endregion
/// <summary>
/// 闲置时(IsRunning==false) 忽略数据
/// </summary>
......@@ -29,7 +36,7 @@ namespace FLY.Thick.Base.Server
FlyADBase.FlyAD7 mFlyAD;
DynArea mDynArea;
AD2ThkHandler Ad2Thk;
GetFixDatasReponse reponse;
public GM_Fix()
{
......@@ -53,15 +60,12 @@ namespace FLY.Thick.Base.Server
void flyad_TimeGridEvent(object sender, FlyADBase.TimeGridEventArgs e)
{
//if (IsIgnoreDataWhenIdle && !IsRunning)
// return;
DateTime dt = e.Time;
TimeSpan ts = e.Ts;
List<int> data = new List<int>(e.Data);
var datas = e.Data.ToArray();
//1秒数据
Data1s.AddRange(data);
Data1s.AddRange(datas);
if (TimeSpan.FromTicks(Data1s.Count * ts.Ticks) >= TimeSpan.FromSeconds(1))
{
int ad = (int)Data1s.Average();
......@@ -73,35 +77,16 @@ namespace FLY.Thick.Base.Server
//转换为thick
List<double> thicks = new List<double>();
foreach(int ad in data)
{
double thk = Ad2Thk(ad);
thicks.Add(thk);
}
double[] thks = datas.Select((ad) => Ad2Thk(ad)).ToArray();
//需要限制大小,push 不能太大
//分拆为多个包
int size = 200;
while (data.Count()>0)
reponse = new GetFixDatasReponse()
{
int cnt = (data.Count() > size) ? size : data.Count();
int[] ADs2 = data.Take(cnt).ToArray();
double[] thicks2 = thicks.Take(cnt).ToArray();
data.RemoveRange(0, cnt);
thicks.RemoveRange(0, cnt);
FixEvent?.Invoke(this,
new FixEventArgs()
{
time = dt,
ts = ts,
ADs = ADs2,
thicks = thicks2
});
dt += TimeSpan.FromTicks(cnt * ts.Ticks);
}
ADs = datas,
thicks = thks,
time = dt,
ts = TimeGridAdvHelperExt.ad_ts
};
UpdateTime = dt;
}
#region IGageMode
......@@ -120,24 +105,9 @@ namespace FLY.Thick.Base.Server
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
event FixEventHandler FixEvent;
/// <summary>
/// 注册定点数据事件 FixEvent += handler;
/// </summary>
/// <param name="handler"></param>
public void RegistTimeGridEvent(FixEventHandler handler)
{
FixEvent += handler;
}
/// <summary>
/// 取消注册定点数据事件 FixEvent -= handler;
/// </summary>
/// <param name="handler"></param>
public void UnRegistTimeGridEvent(FixEventHandler handler)
public void GetFixDatas(AsyncCBHandler asyncDelegate, object asyncContext)
{
FixEvent -= handler;
asyncDelegate(asyncContext, reponse);
}
}
}
......@@ -241,7 +241,7 @@ namespace FLY.Thick.Base.Server
/// <summary>
/// 保存
/// </summary>
void Save()
public void Save()
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(param_path, json);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment