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
e0cc5eb7
Commit
e0cc5eb7
authored
Feb 19, 2021
by
潘栩锋
🚴
1
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'remotes/gitlab/dev6.0' into feature-feng-updateMahApp-20201203
parents
24eaa4bf
9512dcc5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
132 additions
and
70 deletions
+132
-70
PgMainEditDynArea.xaml
MultiLayout/MainEdit/PgMeDynArea/PgMainEditDynArea.xaml
+1
-0
PgMainEditGraph.xaml
MultiLayout/MainEdit/PgMeGraph/PgMainEditGraph.xaml
+5
-2
PgMeMenu.xaml
MultiLayout/MainEdit/PgMeMenu/PgMeMenu.xaml
+3
-2
TCPConn.cs
Project.FLY.FObjSys/FObjSys/TCPConn.cs
+69
-15
FlyAD7.cs
Project.FLY.FlyADBase/FlyADBase/FlyAD7.cs
+14
-18
GM_Base.cs
Project.FLY.Thick.Base/FLY.Thick.Base/Server/GM_Base.cs
+40
-33
No files found.
MultiLayout/MainEdit/PgMeDynArea/PgMainEditDynArea.xaml
View file @
e0cc5eb7
...
...
@@ -151,6 +151,7 @@
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{TemplateBinding Content}" TextWrapping = "Wrap" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20" Margin="5"/>
<Button Grid.Column="1" x:Name="button_close" Style="{StaticResource ButtonStyle_empty}" Margin="5" Background="Transparent" VerticalAlignment="Top" HorizontalAlignment="Right"
...
...
MultiLayout/MainEdit/PgMeGraph/PgMainEditGraph.xaml
View file @
e0cc5eb7
...
...
@@ -199,8 +199,11 @@
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Style="{StaticResource ButtonStyle_empty}" Background="{Binding Background}" Tag="{Binding .}" Click="button_componentNew_Click" Margin="5">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Text="{Binding Header}" FontSize="20" />
<StackPanel Margin="10">
<Viewbox Margin="3" MaxHeight="15">
<TextBlock Text="{Binding Header}" FontSize="15" />
</Viewbox>
<TextBlock Text="{Binding Count}" FontSize="15" Margin="0,20,0,0"/>
</StackPanel>
</Button>
...
...
MultiLayout/MainEdit/PgMeMenu/PgMeMenu.xaml
View file @
e0cc5eb7
...
...
@@ -153,7 +153,6 @@
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontFamily" Value="YouYuan"/>
<Setter Property="Margin" Value="3"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</ResourceDictionary>
...
...
@@ -161,7 +160,9 @@
<Border Background="Transparent" >
<StackPanel Margin="5">
<Rectangle Height="36" Width="36" Stroke="White" StrokeThickness="4"/>
<TextBlock Text="{TemplateBinding Content}"/>
<Viewbox Margin="3" MaxHeight="12">
<TextBlock Text="{TemplateBinding Content}" />
</Viewbox>
</StackPanel>
</Border>
</ControlTemplate>
...
...
Project.FLY.FObjSys/FObjSys/TCPConn.cs
View file @
e0cc5eb7
...
...
@@ -4,39 +4,82 @@ using System.Linq;
using
System.Text
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.Diagnostics
;
namespace
FObjBase
{
/// <summary>
/// 解码
/// </summary>
/// <param name="packet"></param>
/// <param name="conn"></param>
/// <returns></returns>
public
delegate
bool
ParsePacketHandler
(
byte
[]
packet
,
IFConn
conn
);
/// <summary>
///
/// </summary>
public
class
TCPConn
:
IFConn
{
static
NLog
.
Logger
logger
=
NLog
.
LogManager
.
GetCurrentClassLogger
();
/// <summary>
/// 需要CRC校验
/// </summary>
public
bool
HasCRC
=
false
;
TimeSpan
Heartbeat_Interval
=
TimeSpan
.
FromSeconds
(
3
);
// heartbeat包发送间隔时间,3秒
TimeSpan
Silent_Time
=
TimeSpan
.
FromSeconds
(
10
);
// 单位ms没有收到任何东西的时间,10秒
const
int
MAX_BUFFER
=
20
*
0x4000
;
//20个大包, 大包的尺寸在FObjSys 定义
protected
List
<
byte
>
in_buffer
=
new
List
<
byte
>(
MAX_BUFFER
);
protected
List
<
byte
>
out_buffer
=
new
List
<
byte
>(
MAX_BUFFER
);
protected
DateTime
comm_time
;
protected
DateTime
heartbeat_time
=
DateTime
.
Now
;
List
<
byte
>
in_buffer
=
new
List
<
byte
>(
MAX_BUFFER
);
List
<
byte
>
out_buffer
=
new
List
<
byte
>(
MAX_BUFFER
);
/// <summary>
/// 通信超时判断
/// </summary>
Stopwatch
stopwatch_comm
=
new
Stopwatch
();
/// <summary>
/// 心跳包判断
/// </summary>
Stopwatch
stopwatch_heatbeat
=
new
Stopwatch
();
/// <summary>
///
/// </summary>
public
ParsePacketHandler
ParsePacket
=
null
;
/// <summary>
///
/// </summary>
public
Socket
sock
;
/// <summary>
///
/// </summary>
protected
bool
first_poll
=
true
;
/// <summary>
///
/// </summary>
public
TCPConn
()
{
}
/// <summary>
///
/// </summary>
/// <param name="sock"></param>
public
TCPConn
(
Socket
sock
)
{
this
.
sock
=
sock
;
}
/// <summary>
/// 发送数据
/// </summary>
/// <param name="buffer"></param>
/// <returns></returns>
public
virtual
int
SendPacket
(
byte
[]
buffer
)
{
lock
(
out_buffer
)
...
...
@@ -49,6 +92,10 @@ namespace FObjBase
}
}
/// <summary>
/// 从包提取数据
/// </summary>
/// <returns></returns>
protected
virtual
int
GetRecvInfoPacket
()
// return length of the packet
{
int
len
=
in_buffer
.
Count
();
...
...
@@ -95,6 +142,11 @@ namespace FObjBase
return
0
;
}
/// <summary>
/// 解包
/// </summary>
/// <param name="len"></param>
/// <returns></returns>
protected
virtual
bool
Parse_Packet
(
int
len
)
{
byte
[]
packet
=
in_buffer
.
GetRange
(
0
,
len
).
ToArray
();
...
...
@@ -102,7 +154,9 @@ namespace FObjBase
return
ParsePacket
(
packet
,
this
);
}
/// <summary>
/// 发送心跳包
/// </summary>
void
Send_HeartBeat
()
{
byte
[]
buf
=
new
byte
[
2
];
...
...
@@ -115,15 +169,14 @@ namespace FObjBase
{
if
(
out_buffer
.
Count
()
==
0
)
{
if
(
(
DateTime
.
Now
-
heartbeat_time
)
>
Heartbeat_Interval
)
if
(
stopwatch_heatbeat
.
Elapsed
>
Heartbeat_Interval
)
{
Send_HeartBeat
();
//是时候把心跳包放入发送缓存!!!
}
else
return
0
;
}
heartbeat_time
=
DateTime
.
Now
;
stopwatch_heatbeat
.
Restart
();
return
Send_Poll
();
}
int
Send_Poll
()
...
...
@@ -144,6 +197,7 @@ namespace FObjBase
{
if
(
e
.
SocketErrorCode
==
SocketError
.
WouldBlock
)
//当前发不了,退出循环,等下次!!!!
break
;
logger
.
Error
(
e
,
"TCPConn Send_Poll 发送异常"
);
return
-
1
;
//异常,断开连接!!!
}
...
...
@@ -176,7 +230,7 @@ namespace FObjBase
//FDEBUG.Debug.LogMessage(this, 10, "Receive_Poll e=" + e.ToString());
if
(
reclen_total
==
0
)
{
logger
.
Debug
(
e
,
"TCPConn Receive_Poll 什么都收不到"
);
logger
.
Error
(
e
,
"TCPConn Receive_Poll 什么都收不到"
);
return
-
1
;
}
else
...
...
@@ -196,7 +250,7 @@ namespace FObjBase
//FDEBUG.Debug.LogMessage(this, 10, "Receive_Poll e=" + e.ToString());
if
(
reclen_total
==
0
)
{
logger
.
Debug
(
e
,
"TCPConn Receive_Poll 什么都收不到"
);
logger
.
Error
(
e
,
"TCPConn Receive_Poll 什么都收不到"
);
return
-
1
;
}
else
...
...
@@ -207,7 +261,7 @@ namespace FObjBase
in_buffer
.
AddRange
(
buf
);
reclen_total
+=
reclen
;
comm_time
=
DateTime
.
Now
;
stopwatch_comm
.
Restart
()
;
}
}
}
...
...
@@ -215,8 +269,8 @@ namespace FObjBase
{
if
(
first_poll
)
{
comm_time
=
DateTime
.
Now
;
heartbeat_time
=
DateTime
.
Now
;
stopwatch_comm
.
Restart
()
;
stopwatch_heatbeat
.
Restart
()
;
first_poll
=
false
;
}
}
...
...
@@ -233,7 +287,7 @@ namespace FObjBase
}
else
if
(
reclen
==
0
)
{
if
(
(
DateTime
.
Now
-
comm_time
)
>
Silent_Time
)
if
(
stopwatch_comm
.
Elapsed
>
Silent_Time
)
{
logger
.
Error
(
"TCPConn OnPoll 长时间没收到任何数据 断开连接"
);
...
...
Project.FLY.FlyADBase/FlyADBase/FlyAD7.cs
View file @
e0cc5eb7
...
...
@@ -9,7 +9,7 @@ using FObjBase;
using
System.IO
;
using
Misc
;
using
System.Collections.ObjectModel
;
using
System.Diagnostics
;
namespace
FlyADBase
{
...
...
@@ -66,15 +66,9 @@ namespace FlyADBase
DtAndBool
driveman_wait
=
new
DtAndBool
();
DtAndBool
sysinfo_wait
=
new
DtAndBool
();
/// <summary>
/// 没有收到timegrid的次数, 1秒加1次
/// </summary>
int
noTGridCnt
=
0
;
/// <summary>
/// 3次收不到timegrid, 重连
/// </summary>
const
int
ReConnectTGridMaxCnt
=
3
;
TimeSpan
NoTGridTimeOut
=
TimeSpan
.
FromSeconds
(
60
);
Stopwatch
stopwatch_noTGrid
=
new
Stopwatch
();
int
last_position
=
int
.
MinValue
;
...
...
@@ -94,21 +88,24 @@ namespace FlyADBase
//
3
秒内收不到1个timegrid ,就会重连
//
60
秒内收不到1个timegrid ,就会重连
PollModule
.
Current
.
Poll_Config
(
PollModule
.
POLL_CONFIG
.
ADD
,
()
=>
{
if
(!
IsConnected
)
{
noTGridCnt
=
0
;
stopwatch_noTGrid
.
Stop
()
;
}
else
{
noTGridCnt
++;
if
(
noTGridCnt
>=
ReConnectTGridMaxCnt
)
{
noTGridCnt
=
0
;
ReConnect
();
if
(!
stopwatch_noTGrid
.
IsRunning
)
stopwatch_noTGrid
.
Restart
();
else
{
if
(
stopwatch_noTGrid
.
Elapsed
>
NoTGridTimeOut
)
{
logger
.
Error
(
"60秒都无法接收到ad盒的timegrid,reconnect"
);
ReConnect
();
stopwatch_noTGrid
.
Restart
();
}
}
}
...
...
@@ -704,8 +701,7 @@ namespace FlyADBase
break
;
case
FLYAD7_OBJ_INTERFACE
.
PUSH_DATA_INTERFACE
.
PUSH_TIMEGRID
:
{
noTGridCnt
=
0
;
//收到timegrid!!!!!!!!!!!
stopwatch_noTGrid
.
Restart
();
//收到timegrid!!!!!!!!!!!
int
version
;
FLYAD7_OBJ_INTERFACE
.
PUSH_DATA_INTERFACE
.
Pack_PushTGrid_2
pack
=
new
FLYAD7_OBJ_INTERFACE
.
PUSH_DATA_INTERFACE
.
Pack_PushTGrid_2
();
...
...
Project.FLY.Thick.Base/FLY.Thick.Base/Server/GM_Base.cs
View file @
e0cc5eb7
...
...
@@ -7,6 +7,8 @@ using System.ComponentModel;
using
FlyADBase
;
using
FLY.Thick.Base.Common
;
using
FLY.Thick.Base.IService
;
using
System.Diagnostics
;
namespace
FLY.Thick.Base.Server
{
public
abstract
class
GM_Base
:
IGageMode
,
INotifyErrorArisen
...
...
@@ -241,7 +243,9 @@ namespace FLY.Thick.Base.Server
{
GM_AutoScan
mGMAutoScan
;
DynArea
mDynArea
;
DateTime
dt_lastscan
=
DateTime
.
MinValue
;
Stopwatch
stopwatch
=
new
Stopwatch
();
bool
isReadyToAutoScan
=
false
;
public
GM_Disconnected
(
FlyAD7
flyad
)
:
base
(
flyad
)
{
...
...
@@ -257,34 +261,50 @@ namespace FLY.Thick.Base.Server
void
mDynArea_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
e
.
PropertyName
==
"FLYADIsConnect"
)
if
(
e
.
PropertyName
==
nameof
(
mDynArea
.
FLYADIsConnect
)
)
{
if
(!
mDynArea
.
FLYADIsConnect
)
{
//AD卡已经断开
//如果刚才在扫描,在1分钟内,AD卡连接后,重新执行扫描动作
if
(
mDynArea
.
ControllerState
==
CTRL_STATE
.
SCAN
)
if
(
mDynArea
.
ControllerState
==
CTRL_STATE
.
SCAN
||
mDynArea
.
ControllerState
==
CTRL_STATE
.
AUTOSCAN
)
{
dt_lastscan
=
DateTime
.
Now
;
//之前在扫描中
isReadyToAutoScan
=
true
;
stopwatch
.
Restart
();
}
else
{
isReadyToAutoScan
=
false
;
stopwatch
.
Stop
();
}
Start
();
}
else
{
if
(
IsRunning
)
//AD盒已经重新连接上
if
(
IsRunning
)
//还在 CTRL_STATE.DISCONNECTED
{
if
((
DateTime
.
Now
-
dt_lastscan
)
<
TimeSpan
.
FromMinutes
(
1
))
//1min 内重新扫描
{
//断开连接,到现在重新连上,只过了30秒,重新执行扫描
mGMAutoScan
.
Start
(
5
);
if
(
isReadyToAutoScan
)
{
//需要自动扫描
if
(
stopwatch
.
Elapsed
>
TimeSpan
.
FromMinutes
(
3
))
{
isReadyToAutoScan
=
false
;
stopwatch
.
Stop
();
//断开连接,到现在重新连上,只过了3min,重新执行扫描
mGMAutoScan
.
Start
(
5
);
}
else
{
Stop
();
}
}
else
else
{
Stop
();
}
}
dt_lastscan
=
DateTime
.
MinValue
;
}
}
}
...
...
@@ -296,30 +316,17 @@ namespace FLY.Thick.Base.Server
public
override
void
Stop
()
{
IsRunning
=
false
;
isReadyToAutoScan
=
false
;
stopwatch
.
Stop
();
}
}
public
class
GM_AutoScan
:
GM_Base
{
public
int
Delay
{
get
;
set
;
}
private
int
counter
=
5
;
public
int
Counter
{
get
{
return
counter
;
public
int
Delay
{
get
;
set
;
}
public
int
Counter
{
get
;
set
;
}
=
5
;
}
set
{
if
(
counter
!=
value
)
{
counter
=
value
;
NotifyPropertyChanged
(
"Counter"
);
}
}
}
Action
ReScan
;
DateTime
dtLast
=
DateTime
.
MinValue
;
public
GM_AutoScan
(
FlyAD7
flyad
)
...
...
@@ -395,7 +402,7 @@ namespace FLY.Thick.Base.Server
void
GM_Pause_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
e
.
PropertyName
==
"Enable"
)
if
(
e
.
PropertyName
==
nameof
(
Enable
)
)
{
if
(
Enable
)
{
...
...
@@ -442,7 +449,7 @@ namespace FLY.Thick.Base.Server
}
void
mDynArea_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
e
.
PropertyName
==
"DataValid"
)
if
(
e
.
PropertyName
==
nameof
(
mDynArea
.
DataValid
)
)
{
if
(
Enable
)
update_datavalid
();
...
...
潘栩锋
🚴
@panruising
mentioned in commit
809883b9
·
Mar 16, 2021
mentioned in commit
809883b9
mentioned in commit 809883b99cc7ee0830e23059c8b83385e117d3ca
Toggle commit list
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