Commit 7fad816d authored by 潘栩锋's avatar 潘栩锋 🚴

添加 AD盒2021.B2 导出grid数据带有每个grid的时间

parent b29fe1ad
...@@ -13,6 +13,7 @@ namespace FlyADBase ...@@ -13,6 +13,7 @@ namespace FlyADBase
public int grid_start; public int grid_start;
public int[] buf; public int[] buf;
public int[] buf2; public int[] buf2;
public DateTime[] times;
} }
public delegate void MiniGridEventHandler(object sender, MiniGridEventArgs e); public delegate void MiniGridEventHandler(object sender, MiniGridEventArgs e);
} }
...@@ -98,12 +98,39 @@ namespace FlyADBase ...@@ -98,12 +98,39 @@ namespace FlyADBase
/// </summary> /// </summary>
bool IsTimeToPushTimeGridAdv { get; } bool IsTimeToPushTimeGridAdv { get; }
/// <summary>
/// 停下来了,且数据已经可以获取了
/// </summary>
/// <returns></returns>
bool IsTimeToGetGridAfterStop();
/// <summary>
/// 正向 Grid数组 更新时间
/// </summary>
DateTime GridFrameUpdateTime_Forw { get; }
/// <summary>
/// 反向 Grid数组 更新时间
/// </summary>
DateTime GridFrameUpdateTime_Backw { get; }
/// <summary> /// <summary>
/// 以timegrid 为单位,推送数据 /// 以timegrid 为单位,推送数据
/// </summary> /// </summary>
event TimeGridAdv2EventHandler TimeGridAdv2Event; event TimeGridAdv2EventHandler TimeGridAdv2Event;
TimeGridAdv2EventArgs GetTimeGridAdv2Event(DateTime beginTime); TimeGridAdv2EventArgs GetTimeGridAdv2Event(DateTime beginTime);
TimeGridAdv2EventArgs GetTimeGridAdv2Event(int dataCnt);
/// <summary>
/// 从正反缓存区, 获取grid数据
/// </summary>
/// <param name="direction">方向, 只有 正,反</param>
/// <param name="grid_start">grid 开始位置</param>
/// <param name="grid_len">grid 长度</param>
/// <param name="dat">grid 数据</param>
void GetGrid(Misc.DIRECTION direction, out int[] buf0, out int[] buf1, out DateTime[] times);
void Save(); void Save();
bool Load(); bool Load();
......
...@@ -74,6 +74,18 @@ namespace FlyADBase ...@@ -74,6 +74,18 @@ namespace FlyADBase
{ {
Clear(); Clear();
} }
public int Time2Index(DateTime time)
{
if (time == DateTime.MinValue)
return -1;
return TimeGridAdvHelperExt.Time2Index(DataPool.Count(), NewestTime, time);
}
public DateTime Index2Time(int index)
{
return TimeGridAdvHelperExt.Index2Time(DataPool.Count(), NewestTime, index);
}
public class AddDataResponse public class AddDataResponse
{ {
public bool isChanged => isPosChanged || isPos2Changed || isIstatusChanged; public bool isChanged => isPosChanged || isPos2Changed || isIstatusChanged;
...@@ -103,10 +115,9 @@ namespace FlyADBase ...@@ -103,10 +115,9 @@ namespace FlyADBase
if (DataPool.Count()==0) if (DataPool.Count()==0)
{ {
//第1次添加 //第1次添加
DataPool.Add(new DateTimeUnit5() { ad = ad, ad2 = ad2, pos = postion, pos2 = postion2, istatus = istatus });
NewestTime = dt; NewestTime = dt;
DataPool.Add(new DateTimeUnit5() { ad = ad, ad2 = ad2, pos = postion, pos2 = postion2, istatus = istatus });
//记录脉冲改变点 //记录脉冲改变点
positionChangedTime = NewestTime; positionChangedTime = NewestTime;
position2ChangedTime = NewestTime; position2ChangedTime = NewestTime;
...@@ -116,11 +127,11 @@ namespace FlyADBase ...@@ -116,11 +127,11 @@ namespace FlyADBase
if (dt < NewestTime && NewestTime - dt > TimeSpan.FromMilliseconds(2)) //时间异常,居然早2秒了,数据全部删除 if (dt < NewestTime && NewestTime - dt > TimeSpan.FromMilliseconds(2)) //时间异常,居然早2秒了,数据全部删除
{ {
//TODO, 不能没有状态
Clear(); Clear();
NewestTime = dt;
DataPool.Add(new DateTimeUnit5() { ad = ad, ad2 = ad2, pos = postion, pos2 = postion2, istatus = istatus }); DataPool.Add(new DateTimeUnit5() { ad = ad, ad2 = ad2, pos = postion, pos2 = postion2, istatus = istatus });
NewestTime = dt;
//记录脉冲改变点 //记录脉冲改变点
positionChangedTime = NewestTime; positionChangedTime = NewestTime;
...@@ -131,11 +142,11 @@ namespace FlyADBase ...@@ -131,11 +142,11 @@ namespace FlyADBase
if ( dt > NewestTime && (dt - NewestTime > TimeSpan.FromSeconds(0.5)))//超过0.5s没放数据,异常 if ( dt > NewestTime && (dt - NewestTime > TimeSpan.FromSeconds(0.5)))//超过0.5s没放数据,异常
{ {
//TODO, 不能没有状态
Clear(); Clear();
NewestTime = dt;
DataPool.Add(new DateTimeUnit5() { ad = ad, ad2 = ad2, pos = postion, pos2 = postion2, istatus = istatus }); DataPool.Add(new DateTimeUnit5() { ad = ad, ad2 = ad2, pos = postion, pos2 = postion2, istatus = istatus });
NewestTime = dt;
//记录脉冲改变点 //记录脉冲改变点
positionChangedTime = NewestTime; positionChangedTime = NewestTime;
...@@ -150,7 +161,6 @@ namespace FlyADBase ...@@ -150,7 +161,6 @@ namespace FlyADBase
DataPool.RemoveAt(DataPool.Count() - 1); DataPool.RemoveAt(DataPool.Count() - 1);
DataPool.Add(new DateTimeUnit5() { ad = ad, ad2 = ad2, pos = postion, pos2 = postion2, istatus = istatus }); DataPool.Add(new DateTimeUnit5() { ad = ad, ad2 = ad2, pos = postion, pos2 = postion2, istatus = istatus });
NewestTime = dt; NewestTime = dt;
} }
else else
...@@ -169,6 +179,7 @@ namespace FlyADBase ...@@ -169,6 +179,7 @@ namespace FlyADBase
//填充完了,放入新的数据 //填充完了,放入新的数据
DataPool.Add(new DateTimeUnit5() { ad = ad, ad2 = ad2, pos = postion, pos2 = postion2, istatus = istatus }); DataPool.Add(new DateTimeUnit5() { ad = ad, ad2 = ad2, pos = postion, pos2 = postion2, istatus = istatus });
NewestTime = last_dt; NewestTime = last_dt;
break; break;
} }
} }
...@@ -535,6 +546,17 @@ namespace FlyADBase ...@@ -535,6 +546,17 @@ namespace FlyADBase
public static class TimeGridAdvHelperExt public static class TimeGridAdvHelperExt
{ {
public static int Time2Index(int dataCount, DateTime newestTime, DateTime time)
{
//TODO .TotalMilliseconds 是double,有机会出现0.99999问题
int index = dataCount - 1 - (int)(newestTime - time).TotalMilliseconds;
return index;
}
public static DateTime Index2Time(int dataCount, DateTime newestTime, int index)
{
return newestTime - TimeSpan.FromMilliseconds(dataCount - 1 - index);
}
/// <summary> /// <summary>
/// 导出的数据间隔是1ms 一个 /// 导出的数据间隔是1ms 一个
/// </summary> /// </summary>
...@@ -543,8 +565,10 @@ namespace FlyADBase ...@@ -543,8 +565,10 @@ namespace FlyADBase
/// <returns></returns> /// <returns></returns>
public static List<DateTimeUnit5> GetData(List<DateTimeUnit5> dataPool, DateTime newestTime, DateTime begin) public static List<DateTimeUnit5> GetData(List<DateTimeUnit5> dataPool, DateTime newestTime, DateTime begin)
{ {
int begin_idx = dataPool.Count() - (int)((newestTime - begin).TotalMilliseconds); //时间转为序号
int begin_idx = Time2Index(dataPool.Count(), newestTime, begin) + 1;
//限制序号位置
if (begin_idx < 0) if (begin_idx < 0)
begin_idx = 0; begin_idx = 0;
if (begin_idx > dataPool.Count() - 1) if (begin_idx > dataPool.Count() - 1)
...@@ -566,8 +590,10 @@ namespace FlyADBase ...@@ -566,8 +590,10 @@ namespace FlyADBase
/// <returns></returns> /// <returns></returns>
public static List<DateTimeUnit5> GetData(List<DateTimeUnit5> dataPool, DateTime newestTime, DateTime begin, DateTime end, out DateTime response_endTime) public static List<DateTimeUnit5> GetData(List<DateTimeUnit5> dataPool, DateTime newestTime, DateTime begin, DateTime end, out DateTime response_endTime)
{ {
int begin_idx = dataPool.Count() - (int)((newestTime - begin).TotalMilliseconds); //时间转为序号
int begin_idx = Time2Index(dataPool.Count(), newestTime, begin) + 1;
//限制序号位置
if (begin_idx < 0) if (begin_idx < 0)
begin_idx = 0; begin_idx = 0;
if (begin_idx > dataPool.Count() - 1) if (begin_idx > dataPool.Count() - 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