using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;
using PropertyChanged;
namespace FLY.Thick.Base.Client
{
public class GetSampleServiceClient : FObj, IGetSampleService
{
IFConn mConn;
UInt32 mServerID;
public GetSampleServiceClient(UInt32 id)
{
mServerID = id;
for (int i = 0; i < Samples.Count(); i++)
{
SampleCell sampleCell = new SampleCell();
sampleCell.Index = i;
Samples[i] = sampleCell;
}
Features[0] = new SampleFeature() { Name = "正向" };
Features[1] = new SampleFeature() { Name = "反向" };
}
public class SampleCell : ISampleCell
{
public int Index { get; set; }
///
/// 使能
///
public bool Enable { get; set; }
///
/// 参数:只检查不标定
///
public bool JustForCheck { get; set; }
///
/// 原始AD值
///
public int OrgAD { get; set; }
///
/// 位置
///
public int Position { get; set; }
///
/// 状态:当前测量的AD值
///
public int AD { get; set; }
///
/// 状态:当前测量的AD值 对应的 样品值
///
public int SampleValue { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
public class SampleFeature : ISampleFeature
{
public string Name { get; set; }
///
/// 使能
///
public bool Enable { get; set; }
///
/// 开始位置
///
public int StartPos { get; set; }
///
/// 结束位置
///
public int EndPos { get; set; }
///
/// 状态:相似度必须高于0.8,失败-1
///
public double MaxRelevancy { get; set; } = -1;
///
/// 状态:最大相似度对应的偏移
///
public int MaxOffset { get; set; }
///
/// 状态:扫描数据,从扫描数据提取的相似的一段
/// 它的单位是 grid, 需要 posOfGrid, 转换为 pos
/// 开始位置是 StartPos - Search
///
[DoNotCheckEquality]
public int[] ScanData { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
#region IGetSampleService 成员
///
/// 参数:使能
///
public bool Enable { get; set; }
///
/// 参数:间隔
///
public int Interval { get; set; }
///
/// 采样计数
///
public int Timer { get; set; }
///
/// 参数:速度
///
public UInt32 Velocity { get; set; }
///
/// 参数:样品点范围
///
public int Range { get; set; }
///
/// 滤波窗口
///
public int Window { get; set; }
///
/// 样品
///
public ISampleCell[] Samples { get; } = new ISampleCell[3];
///
/// 查找公差
///
public int Search { get; set; }
///
/// 特征 相识度 0 正, 1 反
///
public ISampleFeature[] Features { get; } = new ISampleFeature[2];
///
/// 状态:从flyad7 得到的。 用于绘制图
///
public int PosOfGrid { get; set; } = 10;
///
///
///
public void Apply()
{
GETSAMPLE_OBJ_INTERFACE.Pack_Params p = new GETSAMPLE_OBJ_INTERFACE.Pack_Params
{
enable = Enable,
interval = Interval,
velocity = Velocity,
range = Range,
window = Window,
samples = new GETSAMPLE_OBJ_INTERFACE.Pack_Params_SampleCell[Samples.Count()],
search = Search,
features = new GETSAMPLE_OBJ_INTERFACE.Pack_Params_SampleFeature[Features.Count()]
};
for (int i = 0; i < Samples.Count(); i++)
{
p.samples[i] = new GETSAMPLE_OBJ_INTERFACE.Pack_Params_SampleCell
{
enable = Samples[i].Enable,
justForCheck = Samples[i].JustForCheck,
orgad = Samples[i].OrgAD,
position = Samples[i].Position
};
}
for (int i = 0; i < Features.Count(); i++)
{
p.features[i] = new GETSAMPLE_OBJ_INTERFACE.Pack_Params_SampleFeature
{
enable = Features[i].Enable,
startpos = Features[i].StartPos,
endpos = Features[i].EndPos
};
}
//获取所有数据,设置推送
CurrObjSys.SetValueEx(
mConn, mServerID, ID,
GETSAMPLE_OBJ_INTERFACE.SET_PARAMS,
p.ToBytes()
);
}
#endregion
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
#endregion
public override void Dispose()
{
CurrObjSys.ObjRemove(
this, mConn);
}
public override void ConnectNotify(IFConn from)
{
mConn = from;
if (from.IsConnected)
{
//获取所有数据,设置推送
CurrObjSys.GetValueEx(
mConn, mServerID, ID,
GETSAMPLE_OBJ_INTERFACE.GET_PARAMS);
CurrObjSys.GetValueEx(
mConn, mServerID, ID,
GETSAMPLE_OBJ_INTERFACE.GET_STATE);
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID,
0xffffffff, SENSE_CONFIG.ADD);
}
}
public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
switch (memid)
{
case GETSAMPLE_OBJ_INTERFACE.GET_PARAMS:
{
GETSAMPLE_OBJ_INTERFACE.Pack_Params p = new GETSAMPLE_OBJ_INTERFACE.Pack_Params();
if (!p.TryParse(infodata))
return;
Enable = p.enable;
Interval = p.interval;
Velocity = p.velocity;
Range = p.range;
Window = p.window;
for (int i = 0; i < Samples.Count() && i < p.samples.Count(); i++)
{
Samples[i].Enable = p.samples[i].enable;
Samples[i].JustForCheck = p.samples[i].justForCheck;
Samples[i].OrgAD = p.samples[i].orgad;
Samples[i].Position = p.samples[i].position;
}
Search = p.search;
for (int i = 0; i < Features.Count() && i < p.features.Count(); i++)
{
Features[i].Enable = p.features[i].enable;
Features[i].StartPos = p.features[i].startpos;
Features[i].EndPos = p.features[i].endpos;
}
} break;
case GETSAMPLE_OBJ_INTERFACE.GET_STATE:
{
GETSAMPLE_OBJ_INTERFACE.Pack_State p = new GETSAMPLE_OBJ_INTERFACE.Pack_State();
if (!p.TryParse(infodata ))
return;
PosOfGrid = p.posOfGrid;
for (int i = 0; i < Samples.Count() && i < p.samples.Count(); i++)
{
Samples[i].AD = p.samples[i].ad;
Samples[i].SampleValue = p.samples[i].value;
}
for (int i = 0; i < Features.Count() && i < p.features.Count(); i++)
{
Features[i].MaxRelevancy = p.features[i].maxRelevancy;
Features[i].MaxOffset = p.features[i].maxOffset;
Features[i].ScanData = p.features[i].scanData;
}
} break;
}
}
public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
{
PushGetValue(from, srcid, infoid, infodata);
}
}
}