Commit ae600239 authored by 潘栩锋's avatar 潘栩锋 🚴

修复 AD盒的时间与电脑时间不一致时,出错

parent 400001aa
......@@ -424,7 +424,9 @@ namespace FLY.Thick.Blowing.Server
{
bool bchanged = false;//信号更新?
DateTime dt = e.Time;//信号更新发生的时间
//TODO,不使用AD盒的时间
//DateTime dt = e.Time;//信号更新发生的时间
DateTime dt = DateTime.Now;
int no = -1;//信号序号
bool status = false;//信号的状态 true开始, false结束
......@@ -912,7 +914,9 @@ namespace FLY.Thick.Blowing.Server
//信号的状态
bool status = !Misc.MyBase.CHECKBIT(e.IStatus, Roll_bit - 1);
DateTime dt = e.Time;//信号更新发生的时间
//TODO,不使用AD盒的时间
//DateTime dt = e.Time;//信号更新发生的时间
DateTime dt = DateTime.Now;
if (status)//1->0 触发!!!
......@@ -1045,7 +1049,7 @@ namespace FLY.Thick.Blowing.Server
else
dt = lc.dt_begin;
}
//因为没有使用AD盒的时间,所以可以用DateTime.Now 比较
PastTime = DateTime.Now - dt;
if (PastTime > TimeSpan.FromMinutes(25))//25min
{
......@@ -1082,6 +1086,8 @@ namespace FLY.Thick.Blowing.Server
DateTime dt11 = mRollList[mRollList.Count - (cnt - 1)].dt;
TimeSpan ts_last = TimeSpan.FromTicks((dt1 - dt2).Ticks / (cnt - 1));//5次的平均滤波
//因为没有使用AD盒的时间,所以可以用DateTime.Now 比较
TimeSpan ts_now = TimeSpan.FromTicks((DateTime.Now - dt11).Ticks / (cnt - 1));
TimeSpan ts_max;
if (ts_now > (ts_last + ts_last))
......@@ -1106,6 +1112,7 @@ namespace FLY.Thick.Blowing.Server
if (mRollList.Count > 0)
{
DateTime dt = mRollList[mRollList.Count - 1].dt;
//因为没有使用AD盒的时间,所以可以用DateTime.Now 比较
TimeSpan ts = DateTime.Now - dt;
if (ts.TotalMinutes > 1)//1min
{
......
......@@ -660,6 +660,8 @@ namespace FLY.Thick.Blowing.Server
void mPDetect_ClearEvent(object sender)
{
//没信号,清空所有数据!!!
Clear();
}
/// <summary>
/// 从1幅数据,获取头部,尾部,为于 ADList 的位置
......@@ -894,18 +896,28 @@ namespace FLY.Thick.Blowing.Server
TimeSpan datOf1s_ts = TimeSpan.Zero;
TimeSpan datOf1s_interval = TimeSpan.FromSeconds(1);
List<int> datOf1s = new List<int>();
List<int> datOf1s = new List<int>();//1秒数据缓存,用于求均值
void ClearDatOf1s() {
datOf1s_ts = TimeSpan.Zero;
datOf1s.Clear();
}
void flyad_TimeGridEvent(object sender, FlyADBase.TimeGridEventArgs e)
{
bool issample = false;
TimeSpan ts = e.Ts;//准确
//不使用AD盒的时间
//DateTime dt = e.Time;//准确
DateTime dt = DateTime.Now;//数据的尾
DateTime dt = e.Time;//准确
int[] data = e.Data;
//这个数据包的总耗时
TimeSpan data_interval = TimeSpan.FromTicks((long)(ts.TotalMilliseconds * data.Count() * TimeSpan.TicksPerMillisecond));
DateTime datOf100ms_dt = DateTime.MinValue;
//这个数据包开始的时间
DateTime data_begin_dt = dt - data_interval;
//当前循环处理的数据
DateTime datOf100ms_dt = data_begin_dt - ts;
for (int i = 0; i < data.Length; i++)
{
if (issample)//采样中,数据都是无效的
......@@ -925,23 +937,19 @@ namespace FLY.Thick.Blowing.Server
datOf1s.Add(data[i]);
}
datOf1s_ts = datOf1s_ts + ts;
if (datOf100ms_dt == DateTime.MinValue)
datOf100ms_dt = dt;
else
datOf1s_ts = datOf1s_ts + ts;
datOf100ms_dt = datOf100ms_dt + ts;
if (datOf1s_ts >= datOf1s_interval)//1s 一个数据
{
datOf1s_ts = datOf1s_ts - datOf1s_interval;
int avgad = Misc.MyBase.NULL_VALUE;
if (datOf1s.Count() > 0)
{
avgad = Misc.MyMath.Avg(datOf1s.ToArray());
datOf1s.Clear();
avgad = Misc.MyMath.Avg(datOf1s);
}
else if (mADList.Count() > 0)
{
......@@ -956,6 +964,7 @@ namespace FLY.Thick.Blowing.Server
Ad = avgad
});
ClearDatOf1s();
}
}
}
......@@ -984,6 +993,7 @@ namespace FLY.Thick.Blowing.Server
{
mFrameInfoList.Clear();
}
ClearDatOf1s();
}
int Angle2BoltIndex(double angle)
......
......@@ -2004,37 +2004,70 @@ namespace FLY.Thick.BlowingScan.Server
/// </summary>
class PosCell
{
public DateTime dt;
public DateTime sysTime;
public int position;
public override string ToString()
{
return dt.ToString() + " pos=" + position.ToString();
return $"{sysTime} pos={position}";
}
}
class PosCellList
{
public int scanNo;
/// <summary>
/// 这次扫描 的开始电脑时间
/// </summary>
public DateTime beginTime;
/// <summary>
/// 这次扫描 的开始AD盒时间
/// </summary>
public DateTime beginSysTime;
/// <summary>
/// 扫描号
/// </summary>
public int ScanNo { get; private set; }
public PosCellList(int scanNo, DateTime beginTime, DateTime beginSysTime) {
this.ScanNo = scanNo;
this.beginSysTime = beginSysTime;
this.beginTime = beginTime;
}
private List<PosCell> mPosList = new List<PosCell>();
public void Add(int position, DateTime dt)
/// <summary>
///
/// </summary>
/// <param name="position">脉冲</param>
/// <param name="systime">AD盒的时间,用于时间偏移量</param>
/// <param name="dt">电脑的时间</param>
public void Add(int position, DateTime systime)
{
if (mPosList.Count() == 0) {
mPosList.Add(new PosCell() { position = position, sysTime = systime });
return;
}
if (mPosList.Count() > 0)
{
if (mPosList.Last().position == position)
{
mPosList.Last().dt = dt;
mPosList.Last().sysTime = systime;
return;
}
else {
mPosList.Add(new PosCell() { position = position, sysTime = systime });
}
}
mPosList.Add(new PosCell() { position = position, dt = dt });
}
private DateTime GetTime(int position, int idx)
{
var timeOffset = beginTime - beginSysTime;
double d_pos = mPosList[idx].position - mPosList[idx + 1].position;
TimeSpan ts = mPosList[idx].dt - mPosList[idx + 1].dt;
TimeSpan ts = mPosList[idx].sysTime - mPosList[idx + 1].sysTime;
long ticks = (long)((position - mPosList[idx + 1].position) / d_pos * ts.Ticks);
return mPosList[idx + 1].dt + new TimeSpan(ticks);
return mPosList[idx + 1].sysTime + new TimeSpan(ticks) + timeOffset;
}
/// <summary>
/// 获取位置对应的数据点.
......@@ -2120,7 +2153,7 @@ namespace FLY.Thick.BlowingScan.Server
if (mPosLists.Count == 0)//没数据
return;
int index = mPosLists.FindIndex(pl => pl.scanNo == scanNo);
int index = mPosLists.FindIndex(pl => pl.ScanNo == scanNo);
if (index == -1)
return;//可能还没出现
index += offset;
......@@ -2145,26 +2178,18 @@ namespace FLY.Thick.BlowingScan.Server
{
PosCellList poslist;
if (mPosLists.Count == 0)
mPosLists.Add(new PosCellList() { scanNo = ScanNo });
mPosLists.Add(new PosCellList(ScanNo, DateTime.Now, e.Time));
else
{
poslist = mPosLists.Last();
if (poslist.scanNo != ScanNo)
if (poslist.ScanNo != ScanNo)
{
mPosLists.Add(new PosCellList() { scanNo = ScanNo });
mPosLists.Add(new PosCellList(ScanNo, DateTime.Now, e.Time));
}
}
poslist = mPosLists.Last();
poslist.Add(e.Position, e.Time);
//保持20个
//if (mPosLists.Count() > 20)
//{
// mPosLists.RemoveAt(0);
//}
}
......@@ -2189,7 +2214,7 @@ namespace FLY.Thick.BlowingScan.Server
if (mPosLists.Count == 0)//没数据
return 1;
int d = scanNo - mPosLists[0].scanNo;
int d = scanNo - mPosLists[0].ScanNo;
if (d < 0)
{
//发生在过去
......@@ -2197,7 +2222,7 @@ namespace FLY.Thick.BlowingScan.Server
return -2;
}
int index = mPosLists.FindIndex(pl => pl.scanNo == scanNo);
int index = mPosLists.FindIndex(pl => pl.ScanNo == scanNo);
if (index == -1)
return 1;//可能还没出现
......
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