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

Merge remote-tracking branch 'remotes/gitlab/dev6.0' into feature-feng-updateMahApp-20201203

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