Commit 4e0d0f28 authored by 潘栩锋's avatar 潘栩锋 🚴

Window_Tip 修改为 mvvm架构 整理 flyadService

parent 9634c9f8
......@@ -208,6 +208,12 @@
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf">
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="MvvmLight">
<Version>5.4.1.1</Version>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody">
<Version>2.6.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
......
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
\ No newline at end of file
<Window x:Class="FLY.ControlLibrary.Window_Tip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="window_my"
Title="Window_Tip" Width="400" Topmost="True" WindowStyle="None" ShowInTaskbar="False" ResizeMode="NoResize" Loaded="Window_Loaded" HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom" SizeToContent="Height">
Width="400" Topmost="True" WindowStyle="None" ShowInTaskbar="False" ResizeMode="NoResize" Loaded="Window_Loaded" HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom" SizeToContent="Height">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
......@@ -14,10 +13,10 @@
<Border BorderThickness="1" BorderBrush="Black">
<Grid>
<StackPanel Margin="10,5">
<TextBlock Text="{Binding Title,ElementName=window_my}" FontWeight="Bold" FontSize="30" FontFamily="YouYuan" Margin="10,5"/>
<TextBlock Name="textblock_message" FontWeight="Bold" FontSize="15" FontFamily="YouYuan" Margin="20,5" TextWrapping="Wrap" />
<TextBlock Text="{Binding Title}" FontWeight="Bold" FontSize="30" FontFamily="YouYuan" Margin="10,5"/>
<TextBlock Text="{Binding Message}" FontWeight="Bold" FontSize="15" FontFamily="YouYuan" Margin="20,5" TextWrapping="Wrap" />
</StackPanel>
<Button Style="{StaticResource ResourceKey=ButtonStyle_empty}" Click="Button_Click" Background="Red" VerticalAlignment="Top" HorizontalAlignment="Right" >
<Button Style="{StaticResource ResourceKey=ButtonStyle_empty}" Command="{Binding CloseCmd}" Background="Red" VerticalAlignment="Top" HorizontalAlignment="Right" >
<Path Data="{StaticResource ResourceKey=Geometry_window-close}" Fill="White" Height="36" Width="36" Stretch="Fill" SnapsToDevicePixels="True" Margin="4"/>
......
......@@ -11,6 +11,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using GalaSoft.MvvmLight.Command;
namespace FLY.ControlLibrary
{
......@@ -19,24 +20,20 @@ namespace FLY.ControlLibrary
/// </summary>
public partial class Window_Tip : Window
{
public TimeSpan Duration;
public string Message;
WdTipVm viewModel;
public Window_Tip()
{
InitializeComponent();
Duration = TimeSpan.FromSeconds(2);
timer = new System.Windows.Threading.DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
public void Init(string title, string message, TimeSpan duration)
{
this.Left = SystemParameters.PrimaryScreenWidth - this.Width;
this.Top = SystemParameters.PrimaryScreenHeight - this.Height - 100;
this.textblock_message.Text = Message;
timer.Interval = Duration;
timer.Start();
if (viewModel == null)
{
viewModel = new WdTipVm();
DataContext = viewModel;
}
viewModel.Init(title, message, duration);
}
/// <summary>
/// 右下角 提示
......@@ -46,19 +43,116 @@ namespace FLY.ControlLibrary
/// <param name="duration">持续时间</param>
public static void Show(string title, string message, TimeSpan duration)
{
new Window_Tip() { Title = title, Message = message, Duration = duration }.Show();
WdTipVm.Show(title, message, duration);
}
void timer_Tick(object sender, EventArgs e)
/// <summary>
/// 右下角 短时间提示
/// </summary>
/// <param name="title">标题</param>
/// <param name="message">内容</param>
public static void ShowShortTime(string title, string message)
{
timer.Stop();
this.Close();
Show(title, message, TimeSpan.FromSeconds(2));
}
void Button_Click(object sender, RoutedEventArgs e)
/// <summary>
/// 右下角 永远显示提示
/// </summary>
/// <param name="title">标题</param>
/// <param name="message">内容</param>
public static void Show(string title, string message)
{
Show(title, message, TimeSpan.MaxValue);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
timer_Tick(null, null);
viewModel.LoadedCmd.Execute(null);
}
}
public class WdTipVm:INotifyPropertyChanged
{
private static Window_Tip Current=null;
public TimeSpan Duration { get; set; }
public string Message { get; set; }
public string Title { get; set; }
public RelayCommand LoadedCmd { get; private set; }
public RelayCommand CloseCmd { get; private set; }
public event PropertyChangedEventHandler PropertyChanged;
System.Windows.Threading.DispatcherTimer timer;
public WdTipVm()
{
timer = new System.Windows.Threading.DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
InitCmd();
}
public void Init(string title, string message, TimeSpan duration)
{
Title = title;
Message = message;
Duration = duration;
if (!Current.IsVisible)
Current.Show();
if (duration < TimeSpan.MaxValue && duration > TimeSpan.MinValue)
{
timer.Interval = duration;
timer.Start();
}
else
{
if (timer.IsEnabled)
timer.Stop();
}
}
void InitCmd()
{
LoadedCmd = new RelayCommand(() =>
{
if (Current == null)
return;//不正常
Current.Left = SystemParameters.PrimaryScreenWidth - Current.Width;
Current.Top = SystemParameters.PrimaryScreenHeight - Current.Height - 100;
if (Duration < TimeSpan.MaxValue && Duration > TimeSpan.MinValue)
{
timer.Interval = Duration;
timer.Start();
}
});
CloseCmd = new RelayCommand(() =>
{
if (Current == null)
return;//不正常
timer_Tick(null, null);
});
}
void timer_Tick(object sender, EventArgs e)
{
timer.Stop();
Current.Close();
Current = null;
}
/// <summary>
/// 右下角 提示
/// </summary>
/// <param name="title">标题</param>
/// <param name="message">内容</param>
/// <param name="duration">持续时间</param>
public static void Show(string title, string message, TimeSpan duration)
{
if (Current == null)
Current = new Window_Tip();
Current.Init(title, message, duration);
}
}
}
......@@ -24,38 +24,11 @@ namespace FLY.Thick.Base.Client
#region IFlyAD接口
private IPEndPoint ep = new IPEndPoint(IPAddress.Parse("192.168.251.10"), 20006);
public IPEndPoint EP
{
get
{
return ep;
}
set
{
if (!IPEndPoint.Equals(ep, value))
{
ep = value;
NotifyPropertyChanged("EP");
}
}
}
bool hascrc = false;
public bool HasCRC
{
get
{
return hascrc;
}
set
{
if (hascrc != value)
{
hascrc = value;
NotifyPropertyChanged("HasCRC");
}
}
}
public IPEndPoint EP { get; set; } = new IPEndPoint(IPAddress.Parse("192.168.251.10"), 20006);
public bool HasCRC { get; set; }
private int gridsmooth = 0;
/// <summary>
......@@ -71,115 +44,41 @@ namespace FLY.Thick.Base.Client
if (gridsmooth != value)
{
gridsmooth = value;
NotifyPropertyChanged("GridSmooth");
}
}
}
private int poslen;
public int PosLen
{
get { return poslen; }
set
{
if (poslen != value)
{
poslen = value;
NotifyPropertyChanged("PosLen");
}
}
}
private MOTORTYPE motortype = MOTORTYPE.SERVO;
public MOTORTYPE MotorType
{
get { return motortype; }
set
{
if (motortype != value)
{
motortype = value;
NotifyPropertyChanged("MotorType");
}
}
}
private int posofgrid;
public int PosLen { get; set; }
public MOTORTYPE MotorType { get; set; } = MOTORTYPE.SERVO;
/// <summary>
/// // 单位 pulse/grid
/// </summary>
public int PosOfGrid
{
get { return posofgrid; }
set
{
if (posofgrid != value)
{
posofgrid = value;
NotifyPropertyChanged("PosOfGrid");
}
}
}
private UInt16 ratio01;
public UInt16 Ratio01
{
get { return ratio01; }
set
{
if (ratio01 != value)
{
ratio01 = value;
NotifyPropertyChanged("Ratio01");
}
}
}
private UInt16 ratio02;
public UInt16 Ratio02
{
get { return ratio02; }
set
{
if (ratio02 != value)
{
ratio02 = value;
NotifyPropertyChanged("Ratio02");
}
}
}
private Int16 posoffset;
public Int16 PosOffset
{
get
{
return posoffset;
}
set
{
if (posoffset != value)
{
posoffset = value;
NotifyPropertyChanged("PosOffset");
}
}
}//脉冲平移
private UInt32 jogvelocity;
public UInt32 JogVelocity
{
get
{
return jogvelocity;
}
set
{
if (jogvelocity != value)
{
jogvelocity = value;
NotifyPropertyChanged("JogVelocity");
}
}
}
public int PosOfGrid { get; set; }
public UInt16 Ratio01 { get; set; }
public UInt16 Ratio02 { get; set; }
public Int16 PosOffset { get; set; }
/// <summary>
/// 脉冲平移
/// </summary>
public UInt32 JogVelocity { get; set; }
/// <summary>
/// 参数应用
/// </summary>
public void Apply()
{
FLYAD_OBJ_INTERFACE.Pack_Params p = new FLYAD_OBJ_INTERFACE.Pack_Params()
{
ep = EP,
ep = EP.ToString(),
posofgrid = (UInt16)PosOfGrid,
motortype = MotorType,
poslen = PosLen,
......@@ -190,9 +89,12 @@ namespace FLY.Thick.Base.Client
hasCRC = HasCRC,
gridsmooth = GridSmooth
};
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
CurrObjSys.SetValueEx(mConn, mServerID, ID,
FLYAD_OBJ_INTERFACE.SET_PARAMS,
p.ToBytes());
Misc.Converter.StringToBytes(json));
}
/// <summary>
/// 获取序列码
......@@ -213,9 +115,13 @@ namespace FLY.Thick.Base.Client
/// <param name="AsyncState">可为null</param>
public void SetAccess(byte[] access, AsyncCBHandler AsyncDelegate, object AsyncState)
{
var p = new FLYAD_OBJ_INTERFACE.Pack_SetAccessRequest() { data = access };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
FLYAD_OBJ_INTERFACE.CALL_SETACCESS,
new FLYAD_OBJ_INTERFACE.Pack_SetAccessRequest() { data = access }.ToBytes(),
Misc.Converter.StringToBytes(json),
AsyncDelegate, AsyncState);
}
......@@ -227,14 +133,24 @@ namespace FLY.Thick.Base.Client
/// <param name="AsyncState">可为null</param>
public void GetGrid(Misc.DIRECTION direction, AsyncCBHandler AsyncDelegate, object AsyncState)
{
var p = new FLYAD_OBJ_INTERFACE.Pack_GetGridRequest() { direction = direction };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
FLYAD_OBJ_INTERFACE.CALL_GETGRID,
new FLYAD_OBJ_INTERFACE.Pack_GetGridRequest() { direction = direction}.ToBytes(),
Misc.Converter.StringToBytes(json),
AsyncDelegate, AsyncState);
}
/// <summary>
/// 向AD盒获取数据
/// </summary>
public void UpdateParam()
{
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
FLYAD_OBJ_INTERFACE.CALL_UPDATEPARAM,null);
}
#endregion
......@@ -268,11 +184,10 @@ namespace FLY.Thick.Base.Client
{
case FLYAD_OBJ_INTERFACE.GET_PARAMS:
{
FLYAD_OBJ_INTERFACE.Pack_Params p = new FLYAD_OBJ_INTERFACE.Pack_Params();
string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FLYAD_OBJ_INTERFACE.Pack_Params>(json);
if (!p.TryParse(infodata))
return;
EP = p.ep;
EP = Misc.StringConverter.ToIPEndPoint(p.ep);
PosOffset = p.posoffset;
JogVelocity = p.jogvelocity;
......@@ -299,38 +214,33 @@ namespace FLY.Thick.Base.Client
{
case FLYAD_OBJ_INTERFACE.CALL_GETACCESSINFO:
{
AccessInfo a = new AccessInfo();
if (!a.TryParse(retdata))
return;
string json = Misc.Converter.BytesToString(retdata);
AccessInfo a = Newtonsoft.Json.JsonConvert.DeserializeObject<AccessInfo>(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, a);
} break;
case FLYAD_OBJ_INTERFACE.CALL_SETACCESS:
{
AccessInfo a = new AccessInfo();
if (!a.TryParse(retdata))
return;
string json = Misc.Converter.BytesToString(retdata);
AccessInfo a = Newtonsoft.Json.JsonConvert.DeserializeObject<AccessInfo>(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, a);
} break;
case FLYAD_OBJ_INTERFACE.CALL_GETGRID:
{
GridInfo p = new GridInfo();
if (!p.TryParse(retdata))
return;
string json = Misc.Converter.BytesToString(retdata);
GridInfo p = Newtonsoft.Json.JsonConvert.DeserializeObject<GridInfo>(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
}break;
}
}
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string propertyname)
{
if (PropertyChanged != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
}
}
#endregion
}
}
\ No newline at end of file
......@@ -5,12 +5,28 @@ using System.Text;
namespace FLY.Thick.Base.Common
{
/// <summary>
/// 电机类型
/// </summary>
public enum MOTORTYPE
{
/// <summary>
/// 没有
/// </summary>
NULL = 0,
/// <summary>
/// 变频器
/// </summary>
VF0 = 1,
/// <summary>
/// 伺服电器
/// </summary>
SERVO = 2
}
/// <summary>
/// 密码区状态
/// </summary>
public enum AREA_STATUS
{
/// <summary>
......@@ -43,6 +59,9 @@ namespace FLY.Thick.Base.Common
VALID_WRERR = 6
}
/// <summary>
/// 密码区错误内容
/// </summary>
public enum AREA_ERR
{
NO_ERR = 0, // 没有错误
......@@ -50,101 +69,54 @@ namespace FLY.Thick.Base.Common
ERR_ACCESS = 2//无效使用码
}
/// <summary>
/// 授权码包
/// </summary>
public class AccessInfo
{
/// <summary>
/// 密码区状态
/// </summary>
public AREA_STATUS status;
public AREA_ERR ret;
public byte[] code = new byte[7];
public UInt16 surplus;
public byte[] access = new byte[8];
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.Add((byte)status);
buf.Add((byte)ret);
buf.AddRange(code);
buf.AddRange(BitConverter.GetBytes(surplus));
buf.AddRange(access);
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
/// <summary>
/// 操作结果
/// </summary>
public AREA_ERR ret;
if (value.Count() < 18)
return false;
int idx = 0;
status = (AREA_STATUS)value[idx];
idx++;
ret = (AREA_ERR)value[idx];
idx++;
Array.Copy(value, idx, code, 0, code.Length);
idx += code.Length;
/// <summary>
/// 序列码
/// </summary>
public byte[] code = new byte[7];
surplus = BitConverter.ToUInt16(value, idx);
idx += 2;
Array.Copy(value, idx, access, 0,access.Length);
idx += access.Length;
return true;
}
/// <summary>
/// 剩余时间
/// </summary>
public UInt16 surplus;
#endregion
/// <summary>
/// 授权码
/// </summary>
public byte[] access = new byte[8];
}
/// <summary>
/// grid 数据包
/// </summary>
public class GridInfo
{
/// <summary>
/// 数据方向
/// </summary>
public Misc.DIRECTION direction;
public bool isall;//这就是全部
public int grid_start;
/// <summary>
/// AD值数据
/// </summary>
public int[] data;
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes((Int32)direction));
buf.AddRange(BitConverter.GetBytes(isall));
buf.AddRange(BitConverter.GetBytes(grid_start));
buf.AddRange(BitConverter.GetBytes(data.Length));
for (int i = 0; i < data.Length; i++)
buf.AddRange(BitConverter.GetBytes(data[i]));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
if (value.Length < (4 + 1 + 4 + 4))
return false;
int idx = 0;
direction = (Misc.DIRECTION)BitConverter.ToInt32(value, idx);
idx += 4;
isall = BitConverter.ToBoolean(value, idx);
idx++;
grid_start = BitConverter.ToInt32(value, idx);
idx += 4;
int len = BitConverter.ToInt32(value, idx);
idx += 4;
if (value.Length < (4 + 1 + 4 + 4 + len * 4))
return false;
data = new int[len];
for (int i = 0; i < len; i++)
{
data[i] = BitConverter.ToInt32(value, idx);
idx += 4;
}
return true;
}
#endregion
/// <summary>
/// 厚度值数据
/// </summary>
public double[] thick;
}
......
......@@ -10,7 +10,6 @@ using FObjBase;
namespace FLY.Thick.Base.IService
{
public delegate void TimeGridEventHandler(object sender, TimeGridEventArgs e);
public interface IFlyADService:INotifyPropertyChanged
{
#region 参数
......@@ -49,6 +48,10 @@ namespace FLY.Thick.Base.IService
/// <param name="AsyncState">可为null</param>
void GetGrid(Misc.DIRECTION direction, AsyncCBHandler AsyncDelegate, object AsyncState);
/// <summary>
/// 向AD盒获取数据
/// </summary>
void UpdateParam();
//event TimeGridEventHandler TimeGridEvent;
//event IStatusChangedEventHandler IStatusChangedEvent;
......
......@@ -12,10 +12,9 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
{
#region Pack
public class Pack_Params : IPack
public class Pack_Params
{
public IPEndPoint ep;
public string ep;
public int poslen;
public MOTORTYPE motortype;
public UInt16 posofgrid;
......@@ -25,158 +24,58 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
public UInt32 jogvelocity;
public bool hasCRC;
public int gridsmooth;
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
byte[] bs = Misc.Converter.IPEndPoint2Bytes(ep);
buf.AddRange(BitConverter.GetBytes(bs.Length));
buf.AddRange(bs);
buf.AddRange(BitConverter.GetBytes(poslen));
buf.AddRange(BitConverter.GetBytes((UInt16)motortype));
buf.AddRange(BitConverter.GetBytes(posofgrid));
buf.AddRange(BitConverter.GetBytes(ratio01));
buf.AddRange(BitConverter.GetBytes(ratio02));
buf.AddRange(BitConverter.GetBytes(posoffset));
buf.AddRange(BitConverter.GetBytes(jogvelocity));
buf.AddRange(BitConverter.GetBytes(hasCRC));
buf.AddRange(BitConverter.GetBytes(gridsmooth));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
int cnt = 4 + 4 + 2 * 5 + 4 + 1 + 4;
if (value.Length < cnt)
return false;
int idx = 0;
int len = BitConverter.ToInt32(value, idx);
idx += 4;
cnt += len;
if (value.Length < cnt)
return false;
ep = Misc.Converter.Bytes2IPEndPoint(value, idx, len);
idx += len;
poslen = BitConverter.ToInt32(value, idx);
idx += 4;
motortype = (MOTORTYPE)BitConverter.ToUInt16(value, idx);
idx += 2;
posofgrid = BitConverter.ToUInt16(value, idx);
idx += 2;
ratio01 = BitConverter.ToUInt16(value, idx);
idx += 2;
ratio02 = BitConverter.ToUInt16(value, idx);
idx += 2;
posoffset = BitConverter.ToInt16(value, idx);
idx += 2;
jogvelocity = BitConverter.ToUInt32(value, idx);
idx += 4;
hasCRC = BitConverter.ToBoolean(value, idx);
idx++;
gridsmooth = BitConverter.ToInt32(value, idx);
idx++;
return true;
}
#endregion
}
public class Pack_SetAccessRequest : IPack
public class Pack_SetAccessRequest
{
public byte[] data;
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(data.Length));
buf.AddRange(data);
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
if (value.Length < 4)
return false;
int idx = 0;
int len = BitConverter.ToInt32(value, idx);
idx += 4;
if (value.Length < 4 + len)
return false;
data = new byte[len];
Array.Copy(value, idx, data, 0, len);
idx += len;
return true;
}
}
public class Pack_GetGridRequest : IPack
public class Pack_GetGridRequest
{
public Misc.DIRECTION direction;
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes((int)direction));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
if (value.Length < 4)
return false;
int idx = 0;
direction = (Misc.DIRECTION)BitConverter.ToInt32(value, idx);
idx += 4;
return true;
}
}
#endregion
#region GetValue
/// <summary>
/// Pack_Params
/// json Pack_Params
/// </summary>
public const UInt16 GET_PARAMS = 0;
#endregion
#region SetValue
/// <summary>
/// Pack_Params
/// json Pack_Params
/// </summary>
public const UInt16 SET_PARAMS = 0;
#endregion
#region PushMsg
/// <summary>
/// Pack_Params
/// json Pack_Params
/// </summary>
public const UInt16 PUSH_PARAMS = 0;
#endregion
#region CallFunction
/// <summary>
/// request:null
/// reponse:AccessInfo
/// reponse:json AccessInfo
/// </summary>
public const UInt16 CALL_GETACCESSINFO = 8;
/// <summary>
/// request:Pack_SetAccessRequest
/// reponse:AccessInfo
/// reponse:json AccessInfo
/// </summary>
public const UInt16 CALL_SETACCESS = 9;
/// <summary>
/// request:Pack_GetGridReqest
/// reponse:GridInfo
/// reponse:json GridInfo
/// </summary>
public const UInt16 CALL_GETGRID = 10;
/// <summary>
/// request:null
/// reponse:null
/// </summary>
public const UInt16 CALL_UPDATEPARAM = 11;
#endregion
}
}
......@@ -8,6 +8,7 @@ using FObjBase;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using Newtonsoft.Json;
namespace FLY.Thick.Base.Server.OBJProxy
{
......@@ -19,17 +20,17 @@ namespace FLY.Thick.Base.Server.OBJProxy
#endregion
FlyADBase.FlyAD7 mFlyAD;
public FlyAD_OBJProxy(int objsys_idx, UInt32 id, FlyADBase.FlyAD7 flyad)
AD2ThickHandler AD2Thick;
public FlyAD_OBJProxy(int objsys_idx, UInt32 id, FlyADBase.FlyAD7 flyad,
AD2ThickHandler AD2Thick )
: base(objsys_idx)
{
ID = id;
mFlyAD = flyad;
this.AD2Thick = AD2Thick;
mFlyAD.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mFlyAD_PropertyChanged);
}
void mFlyAD_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if ((e.PropertyName == "LocalEP") ||
......@@ -62,11 +63,10 @@ namespace FLY.Thick.Base.Server.OBJProxy
{
case FLYAD_OBJ_INTERFACE.GET_PARAMS:
{
mFlyAD.UpdateParam();
FLYAD_OBJ_INTERFACE.Pack_Params p = new FLYAD_OBJ_INTERFACE.Pack_Params()
{
ep = mFlyAD.LocalEP,
ep = mFlyAD.LocalEP.ToString(),
hasCRC = mFlyAD.HasCRC,
gridsmooth = mFlyAD.GridSmooth,
posofgrid = mFlyAD.PosOfGrid,
......@@ -77,10 +77,11 @@ namespace FLY.Thick.Base.Server.OBJProxy
posoffset = mFlyAD.PosOffset,
jogvelocity = mFlyAD.JogVelocity
};
infodata = p.ToBytes();
}break;
string json = JsonConvert.SerializeObject(p);
infodata = Misc.Converter.StringToBytes(json);
}
break;
default:
infodata = null;
break;
......@@ -92,20 +93,21 @@ namespace FLY.Thick.Base.Server.OBJProxy
{
case FLYAD_OBJ_INTERFACE.SET_PARAMS:
{
FLYAD_OBJ_INTERFACE.Pack_Params p = new FLYAD_OBJ_INTERFACE.Pack_Params();
if (p.TryParse(infodata))
{
mFlyAD.HasCRC = p.hasCRC;
mFlyAD.GridSmooth = p.gridsmooth;
mFlyAD.Connect(p.ep);
mFlyAD.PosOffset = p.posoffset;
mFlyAD.JogVelocity = p.jogvelocity;
mFlyAD.PosOfGrid = p.posofgrid;
mFlyAD.MotorType = (FlyADBase.MOTORTYPE)p.motortype;
mFlyAD.Ratio01 = p.ratio01;
mFlyAD.Ratio02 = p.ratio02;
string json = Misc.Converter.BytesToString(infodata);
var p = JsonConvert.DeserializeObject<FLYAD_OBJ_INTERFACE.Pack_Params>(json);
mFlyAD.HasCRC = p.hasCRC;
mFlyAD.GridSmooth = p.gridsmooth;
var ep = Misc.StringConverter.ToIPEndPoint(p.ep);
mFlyAD.Connect(ep);
mFlyAD.PosOffset = p.posoffset;
mFlyAD.JogVelocity = p.jogvelocity;
mFlyAD.PosOfGrid = p.posofgrid;
mFlyAD.MotorType = (FlyADBase.MOTORTYPE)p.motortype;
mFlyAD.Ratio01 = p.ratio01;
mFlyAD.Ratio02 = p.ratio02;
}
} break;
}
}
......@@ -113,52 +115,65 @@ namespace FLY.Thick.Base.Server.OBJProxy
{
switch (funcid)
{
case FLYAD_OBJ_INTERFACE.CALL_UPDATEPARAM:
{
mFlyAD.UpdateParam();
}break;
case FLYAD_OBJ_INTERFACE.CALL_GETACCESSINFO:
{
GetAccessInfo(
new AsyncCBHandler(delegate(object AsyncState, object retdata)
{
ConnContext context = (ConnContext)AsyncState;
string json = JsonConvert.SerializeObject(retdata);
CurrObjSys.PushCallFunctionEx(
context.from,
context.srcid,
ID,
context.magic,
FLYAD_OBJ_INTERFACE.CALL_GETACCESSINFO,
((AccessInfo)retdata).ToBytes());
Misc.Converter.StringToBytes(json)
);
}), new ConnContext(from, srcid, magic));
} break;
case FLYAD_OBJ_INTERFACE.CALL_SETACCESS:
{
FLYAD_OBJ_INTERFACE.Pack_SetAccessRequest p = new FLYAD_OBJ_INTERFACE.Pack_SetAccessRequest();
if (!p.TryParse(infodata))
break;
string json = Misc.Converter.BytesToString(infodata);
var p = JsonConvert.DeserializeObject<FLYAD_OBJ_INTERFACE.Pack_SetAccessRequest>(json);
SetAccess(
p.data,
new AsyncCBHandler(delegate(object AsyncState, object retdata)
{
ConnContext context = (ConnContext)AsyncState;
string json_reponse = JsonConvert.SerializeObject(retdata);
CurrObjSys.PushCallFunctionEx(
context.from,
context.srcid,
ID,
context.magic,
FLYAD_OBJ_INTERFACE.CALL_SETACCESS,
((AccessInfo)retdata).ToBytes());
Misc.Converter.StringToBytes(json_reponse)
);
}), new ConnContext(from, srcid, magic));
} break;
case FLYAD_OBJ_INTERFACE.CALL_GETGRID:
{
FLYAD_OBJ_INTERFACE.Pack_GetGridRequest p = new FLYAD_OBJ_INTERFACE.Pack_GetGridRequest();
if (!p.TryParse(infodata))
break;
string json = Misc.Converter.BytesToString(infodata);
var p = JsonConvert.DeserializeObject<FLYAD_OBJ_INTERFACE.Pack_GetGridRequest>(json);
GetGrid(
p.direction,
new AsyncCBHandler(delegate(object AsyncState, object retdata)
{
string json_reponse = JsonConvert.SerializeObject(retdata);
ConnContext context = (ConnContext)AsyncState;
CurrObjSys.PushCallFunctionEx(
context.from,
......@@ -166,7 +181,7 @@ namespace FLY.Thick.Base.Server.OBJProxy
ID,
context.magic,
FLYAD_OBJ_INTERFACE.CALL_GETGRID,
((GridInfo)retdata).ToBytes());
Misc.Converter.StringToBytes(json_reponse));
}), new ConnContext(from, srcid, magic));
}break;
}
......@@ -251,14 +266,25 @@ namespace FLY.Thick.Base.Server.OBJProxy
/// <param name="AsyncState">可为null</param>
void GetGrid(Misc.DIRECTION direction, AsyncCBHandler AsyncDelegate, object AsyncState)
{
int[] dat;
mFlyAD.GetGrid(direction, out dat);
mFlyAD.GetGrid(direction, out int[] dat);
double[] thicks = null;
if (dat != null)
{
thicks = dat.Select(ad =>
{
int thick100 = AD2Thick(ad);
if (Misc.MyBase.ISVALIDATA(thick100))
return Math.Round(thick100 / 100.0, 2);
else
return double.NaN;
}).ToArray();
}
GridInfo p = new GridInfo()
{
data = dat,
direction = direction,
grid_start = 0,
isall = true
data = dat,
thick = thicks
};
AsyncDelegate(AsyncState, p);
}
......
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