Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
96e1113f
Commit
96e1113f
authored
Apr 05, 2021
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化 TimeGridAdvHelper 的第1个 AD包,也计算它的 时间间隔(不是用1.28ms)
parent
7a078aec
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
49 deletions
+45
-49
TimeGridAdvHelper.cs
Project.FLY.FlyADBase/FlyADBase/TimeGridAdvHelper.cs
+45
-49
No files found.
Project.FLY.FlyADBase/FlyADBase/TimeGridAdvHelper.cs
View file @
96e1113f
...
...
@@ -41,7 +41,7 @@ namespace FlyADBase
/// <summary>
/// AD数据池时间间隔为1.28ms, 肯定最少有一个数据
/// 每个数据包(200个数据)理论间隔是200*1.28ms, 但实际上不是。
/// 数据输出时,输出的每个数据必须是1
.28
ms, 需要通过数据包的systick线性填充数据
/// 数据输出时,输出的每个数据必须是1ms, 需要通过数据包的systick线性填充数据
/// </summary>
public
List
<
DateTimeUnit3
>
ADPool
=
new
List
<
DateTimeUnit3
>();
...
...
@@ -474,6 +474,7 @@ namespace FlyADBase
/// </summary>
public
int
[]
datas
;
public
override
string
ToString
()
{
return
$"
{
dt
.
Ticks
}
| cnt=
{
datas
.
Count
()}
"
;
...
...
@@ -500,37 +501,54 @@ namespace FlyADBase
public
static
class
TimeGridAdvHelperExt
{
/// <summary>
/// 每个ad数据的时间间隔 1.28ms
/// 每个ad数据的时间间隔 1
ms//1
.28ms
/// </summary>
public
const
double
ad_ts_ms
=
1.28
;
public
static
TimeSpan
ad_ts
=>
TimeSpan
.
FromTicks
((
long
)
TimeGridAdvHelperExt
.
ad_ts_ms
*
TimeSpan
.
TicksPerMillisecond
);
public
static
TimeSpan
ad_ts
=>
TimeSpan
.
FromTicks
((
long
)
(
ad_ts_ms
*
TimeSpan
.
TicksPerMillisecond
)
);
public
static
List
<
int
>
GetAD
(
List
<
DateTimeUnit3
>
adPool
,
DateTime
begin
,
DateTime
end
,
out
DateTime
reponse_endTime
)
{
return
GetAD
(
adPool
,
ad_ts_ms
,
begin
,
end
,
out
reponse_endTime
);
reponse_endTime
=
DateTime
.
MinValue
;
var
reponse2
=
GetAD2
(
adPool
,
begin
,
end
);
if
(
reponse2
.
Count
()
==
0
)
return
new
List
<
int
>();
DateTime
lastTime
=
reponse2
.
Last
().
dt
;
reponse_endTime
=
lastTime
;
return
GetAD
(
reponse2
,
begin
);
}
public
static
List
<
int
>
GetAD
(
List
<
DateTimeUnit3
>
adPool
)
{
//通过adPool[0].dt 与 adPool[1].dt 的时间差,计算adPool[0].dt的开始时间
//如果没有adPool[1].dt,就当 adPool[0].dt 的开始时间为 adPool[0].dt - adPool[0].datas.Count() * ad_ts_ms;
DateTime
begin
;
if
(
adPool
.
Count
()
>=
2
)
{
begin
=
adPool
[
0
].
dt
-
(
adPool
[
1
].
dt
-
adPool
[
0
].
dt
);
}
else
{
double
t_ms
=
adPool
.
First
().
datas
.
Count
()
*
ad_ts_ms
;
begin
=
adPool
.
First
().
dt
-
TimeSpan
.
FromTicks
((
long
)(
t_ms
*
TimeSpan
.
TicksPerMillisecond
));
DateTime
begin
=
adPool
.
First
().
dt
-
TimeSpan
.
FromTicks
((
long
)(
t_ms
*
TimeSpan
.
TicksPerMillisecond
));
}
return
GetAD
(
adPool
,
begin
);
}
public
static
List
<
int
>
GetAD
(
List
<
DateTimeUnit3
>
adPool
,
DateTime
begin
)
{
var
ts
=
TimeSpan
.
FromTicks
((
long
)(
ad_ts_ms
*
TimeSpan
.
TicksPerMillisecond
));
List
<
int
>
reponse
=
new
List
<
int
>();
DateTime
lastTime
=
adPool
.
Last
().
dt
;
//每个ad包的每个数据不是准确的1.28ms,肯定比1.28ms大,每次需要准确计算
for
(
int
i
=
0
;
i
<
adPool
.
Count
();
i
++)
{
int
idx
=
adPool
.
Count
()
-
1
-
i
;
double
curr_ad_ts_ms
=
ad_ts_ms
;
double
curr_ad_ts_ms
;
//计算这个包每个数据的时间间隔
DateTime
end_dt
=
adPool
[
idx
].
dt
;
...
...
@@ -540,10 +558,21 @@ namespace FlyADBase
double
total_ms
=
(
end_dt
-
begin_dt
).
Ticks
/
TimeSpan
.
TicksPerMillisecond
;
curr_ad_ts_ms
=
total_ms
/
adPool
[
idx
].
datas
.
Count
();
}
else
if
(
adPool
.
Count
()
>
1
)
{
var
begin_dt
=
adPool
[
idx
].
dt
-
(
adPool
[
idx
+
1
].
dt
-
adPool
[
idx
].
dt
);
double
total_ms
=
(
end_dt
-
begin_dt
).
Ticks
/
TimeSpan
.
TicksPerMillisecond
;
curr_ad_ts_ms
=
total_ms
/
adPool
[
idx
].
datas
.
Count
();
}
else
{
curr_ad_ts_ms
=
ad_ts_ms
;
}
double
act_ms
=
0
;
double
ideal_ms
=
0
;
double
ideal_ms
=
0
;
//插值,让输出可以有准确的间隔为 ad_ts_ms
for
(
int
j
=
0
;
j
<
adPool
[
idx
].
datas
.
Count
();
j
++)
{
int
idx2
=
adPool
[
idx
].
datas
.
Count
()
-
1
-
j
;
...
...
@@ -554,7 +583,7 @@ namespace FlyADBase
{
reponse
.
Add
(
ad
);
ideal_ms
+=
ad_ts_ms
;
lastTime
-=
ts
;
lastTime
-=
ad_
ts
;
}
if
(
lastTime
<
begin
)
goto
_end
;
//完成
...
...
@@ -567,29 +596,7 @@ namespace FlyADBase
}
/// <summary>
/// adPool 每个包内,数据间隔不为1.28ms,肯定比1.28ms大;
/// 输出的数据列,必须是 间隔为1.28ms
/// </summary>
/// <param name="adPool"></param>
/// <param name="ad_ts_ms"></param>
/// <param name="begin">开始时间</param>
/// <param name="end">结束时间</param>
/// <param name="reponse_endTime">返回数据的最后一个数据的时间,数据间隔为1.28ms</param>
/// <returns></returns>
static
List
<
int
>
GetAD
(
List
<
DateTimeUnit3
>
adPool
,
double
ad_ts_ms
,
DateTime
begin
,
DateTime
end
,
out
DateTime
reponse_endTime
)
{
reponse_endTime
=
DateTime
.
MinValue
;
var
reponse2
=
GetAD2
(
adPool
,
begin
,
end
);
if
(
reponse2
.
Count
()
==
0
)
return
new
List
<
int
>();
DateTime
lastTime
=
reponse2
.
Last
().
dt
;
reponse_endTime
=
lastTime
;
return
GetAD
(
reponse2
,
begin
);
}
...
...
@@ -631,22 +638,18 @@ namespace FlyADBase
int
begin_pos
=
GetPos
(
posPool
,
begin
,
ref
searchIdx
);
return
(
end_pos
-
begin_pos
)
/
(
end
-
begin
).
TotalMinutes
;
}
public
static
List
<
int
>
GetPos
(
List
<
DateTimeUnit
>
posPool
,
DateTime
end_dt
,
int
cnt
)
{
return
GetPos
(
posPool
,
ad_ts_ms
,
end_dt
,
cnt
);
}
/// <summary>
/// 输出以 ad_ts_ms 为间隔脉冲列表
/// </summary>
/// <param name="posPool"></param>
/// <param name="ad_ts_ms"></param>
/// <param name="end_dt"></param>
/// <param name="cnt"></param>
/// <returns></returns>
static
List
<
int
>
GetPos
(
List
<
DateTimeUnit
>
posPool
,
double
ad_ts_ms
,
DateTime
end_dt
,
int
cnt
)
public
static
List
<
int
>
GetPos
(
List
<
DateTimeUnit
>
posPool
,
DateTime
end_dt
,
int
cnt
)
{
//从后面开始找
int
searchIdx
=
posPool
.
Count
()
-
1
;
long
ticks
=
(
long
)(
ad_ts_ms
*
TimeSpan
.
TicksPerMillisecond
);
var
ts
=
TimeSpan
.
FromTicks
(
ticks
);
List
<
int
>
reponse
=
new
List
<
int
>();
...
...
@@ -654,7 +657,7 @@ namespace FlyADBase
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
{
reponse
.
Add
(
GetPos
(
posPool
,
lastTime
,
ref
searchIdx
));
lastTime
-=
ts
;
lastTime
-=
ad_
ts
;
}
//反转
reponse
.
Reverse
();
...
...
@@ -824,22 +827,15 @@ namespace FlyADBase
public
static
List
<
UInt16
>
GetIStatus
(
List
<
DateTimeUnit2
>
iStatusPool
,
DateTime
end_dt
,
int
cnt
)
{
return
GetIStatus
(
iStatusPool
,
ad_ts_ms
,
end_dt
,
cnt
);
}
static
List
<
UInt16
>
GetIStatus
(
List
<
DateTimeUnit2
>
iStatusPool
,
double
ad_ts_ms
,
DateTime
end_dt
,
int
cnt
)
{
int
searchIdx
=
iStatusPool
.
Count
()
-
1
;
long
ticks
=
(
long
)(
ad_ts_ms
*
TimeSpan
.
TicksPerMillisecond
);
var
ts
=
TimeSpan
.
FromTicks
(
ticks
);
List
<
UInt16
>
reponse
=
new
List
<
UInt16
>();
DateTime
lastTime
=
end_dt
;
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
{
reponse
.
Add
(
GetIStatus
(
iStatusPool
,
lastTime
,
ref
searchIdx
));
lastTime
-=
ts
;
lastTime
-=
ad_
ts
;
}
//反转
reponse
.
Reverse
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment