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

修改 timeGridAdvHelper 的bug

parent e3af7e40
......@@ -52,11 +52,12 @@ namespace FLY.Simulation.Flyad7.OBJProxy
void mPosGrid_PushEvent(bool isMini, Misc.DIRECTION dir, int grid_start, int[] data)
{
FLYAD7_OBJ_INTERFACE.PUSH_DATA_INTERFACE.Pack_PushGrid p = new FLYAD7_OBJ_INTERFACE.PUSH_DATA_INTERFACE.Pack_PushGrid();
FLYAD7_OBJ_INTERFACE.PUSH_DATA_INTERFACE.Pack_PushGrid_2 p = new FLYAD7_OBJ_INTERFACE.PUSH_DATA_INTERFACE.Pack_PushGrid_2();
p.grid_start = grid_start;
p.direction = dir;
p.data = data;
p.systick = Data.GetSysTick(Data.Now);
p.marker = Data.Marker;
if (isMini)
CurrObjSys.PushObjInfoEx(this, FLYAD7_OBJ_INTERFACE.PUSH_DATA_INTERFACE.PUSH_MINIGRID,
p.ToBytes());
......
......@@ -288,8 +288,9 @@ namespace FlyADBase
ForwToCheck
}
/// <summary>
/// 找到 时间 dt 落在 [idx,idx+1] 之间的 idx,
/// 找到 时间 dt 落在 [idx,idx+1] 之间的 idx;
/// 返回 -1,证明dt 在列表在前面, 或列表数据量为=0,
/// 当dt 大于 列表最后一个数, 返回最后一个数据的id
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list">列表</param>
......@@ -302,78 +303,77 @@ namespace FlyADBase
return -1;
int max_index = list.Count() - 1;
if (dt >= list[max_index].dt)
return max_index;
if (dt < list[0].dt)
return -1;
int index = searchStartIdx;
SearchState state = SearchState.ContinueLastTime;
if ((index < 0) || (index >= max_index))//重新开始
{
index = max_index;
state = SearchState.Back;
}
//从上次位置开始查找
while (true)
{
DateTime time = list[index].dt;
switch (state)
else if (state == SearchState.ContinueLastTime)
{
case SearchState.ContinueLastTime:
{
if (time <= dt)
if (list[index].dt <= dt)
{
//可能找到了
//再向前看看
//再向正方向看看
state = SearchState.ForwToCheck;
index++;
}
else
{
state = SearchState.Back;
index--;
}
}
break;
case SearchState.ForwToCheck:
if (state == SearchState.ForwToCheck)
{
if (index > max_index)
while (true)
{
index--;
//最后一个就是了
goto _finish;
}
DateTime time = list[index].dt;
if (time > dt)
{
//就是之前那个
index--;
goto _finish;
return index;
}
else
{
//找过头了
index++;
}
if (index > max_index)
{
//最后一个就是了
throw new Exception("之前没有判断出 时间点在列表后,异常!!");
//return max_index;
}
break;
case SearchState.Back:
}
}
else//SearchState.Back
{
while (true)
{
DateTime time = list[index].dt;
if (time <= dt)
{
//就是它
goto _finish;
return index;
}
index--;
}
break;
default:
if(index<0)
{
throw new Exception("程序出错, 不可以有第4种情况");
//不可能发生
throw new Exception("之前没有判断出 时间点在列表前,异常!!");
}
break;
}
}
_finish:
return index;
}
......
......@@ -353,6 +353,7 @@
<Button Content="反向获取" Height="23" Name="button2" Width="75" Click="button2_Click" Margin="3" />
<Button Content="正向获取" Height="23" Name="button1" Width="75" Click="button1_Click" Margin="3" />
<Button Content="清除" Height="23" Width="75" Click="button_cleargrid_Click" Margin="3" />
<Button Content="保存" Height="23" Width="75" Click="button_gridSave_Click" Margin="3" />
<CheckBox Content="接收Grid" IsChecked="{Binding DataContext.HasGrid,ElementName=grid_param}" VerticalAlignment="Center" Margin="3" />
<TextBlock Margin="3">
<Run Text="Grid Marker:"/>
......
......@@ -579,6 +579,35 @@ namespace Flyad7_WPF
{
flyad.RuntoMax();
}
private void button_gridSave_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.DataVisualization.Charting.Series series_forw = chart1.Series["Series 1"];
System.Windows.Forms.DataVisualization.Charting.Series series_backw = chart1.Series["Series 2"];
string strDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string path = System.IO.Path.Combine(strDesktopPath, $"grid_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.csv");
StreamWriter sw = new StreamWriter(path);
//int count = Math.Max(series_forw.Points.Count(), series_backw.Points.Count());
sw.WriteLine($"Index,Forw,Backw");
int gridLen = flyad.PosLen / flyad.PosOfGrid;
for (int i = 0; i < gridLen; i++)
{
int f_v = Misc.MyBase.NULL_VALUE;
int b_v = Misc.MyBase.NULL_VALUE;
if (i < series_forw.Points.Count)
f_v = (int)(series_forw.Points[i].YValues[0]);
if (i < series_backw.Points.Count)
b_v = (int)(series_backw.Points[i].YValues[0]);
sw.WriteLine($"{i},{f_v},{b_v}");
}
sw.Flush();
sw.Close();
MessageBox.Show($"成功保存到 {path}");
}
}
}
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