mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 21:24:43 +00:00
Fixed undesirable auto-reconnect behavior when manually disconnecting
This commit is contained in:
@@ -170,6 +170,10 @@ namespace PepperDash.Core
|
|||||||
else
|
else
|
||||||
Debug.Console(0, this, "Error on connect:\r({0})", e);
|
Debug.Console(0, this, "Error on connect:\r({0})", e);
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Console(0, this, "Unhandled exception on connect:\r({0})", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,17 +13,64 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
public class GenericTcpIpClient : Device, IBasicCommunication, IAutoReconnect
|
public class GenericTcpIpClient : Device, IBasicCommunication, IAutoReconnect
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
|
public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
|
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
public TCPClient Client { get; private set; }
|
public TCPClient Client { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
public bool IsConnected { get { return Client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; } }
|
public bool IsConnected { get { return Client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; } }
|
||||||
public string Status { get { return Client.ClientStatus.ToString(); } }
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public SocketStatus ClientStatus { get { return Client.ClientStatus; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string ClientStatusText { get { return Client.ClientStatus.ToString(); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public ushort UClientStatus { get { return (ushort)Client.ClientStatus; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
public string ConnectionFailure { get { return Client.ClientStatus.ToString(); } }
|
public string ConnectionFailure { get { return Client.ClientStatus.ToString(); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
public bool AutoReconnect { get; set; }
|
public bool AutoReconnect { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
public int AutoReconnectIntervalMs { get; set; }
|
public int AutoReconnectIntervalMs { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set only when the disconnect method is called.
|
||||||
|
/// </summary>
|
||||||
|
bool DisconnectCalledByUser;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
public bool Connected
|
public bool Connected
|
||||||
{
|
{
|
||||||
get { return Client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; }
|
get { return Client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; }
|
||||||
@@ -52,10 +99,12 @@ namespace PepperDash.Core
|
|||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
Client.ConnectToServerAsync(null);
|
Client.ConnectToServerAsync(null);
|
||||||
|
DisconnectCalledByUser = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Disconnnect()
|
public void Disconnnect()
|
||||||
{
|
{
|
||||||
|
DisconnectCalledByUser = true;
|
||||||
Client.DisconnectFromServer();
|
Client.DisconnectFromServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,12 +175,11 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
void Client_SocketStatusChange(TCPClient client, SocketStatus clientSocketStatus)
|
void Client_SocketStatusChange(TCPClient client, SocketStatus clientSocketStatus)
|
||||||
{
|
{
|
||||||
if (client.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED &&
|
|
||||||
client.ClientStatus != SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY)
|
Debug.Console(2, this, "Socket status change {0} ({1})", clientSocketStatus, UClientStatus);
|
||||||
|
if (client.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED && !DisconnectCalledByUser)
|
||||||
WaitAndTryReconnect();
|
WaitAndTryReconnect();
|
||||||
|
|
||||||
|
|
||||||
Debug.Console(2, this, "Socket status change {0}", clientSocketStatus);
|
|
||||||
switch (clientSocketStatus)
|
switch (clientSocketStatus)
|
||||||
{
|
{
|
||||||
case SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY:
|
case SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY:
|
||||||
@@ -140,6 +188,7 @@ namespace PepperDash.Core
|
|||||||
break;
|
break;
|
||||||
case SocketStatus.SOCKET_STATUS_CONNECTED:
|
case SocketStatus.SOCKET_STATUS_CONNECTED:
|
||||||
Client.ReceiveDataAsync(Receive);
|
Client.ReceiveDataAsync(Receive);
|
||||||
|
DisconnectCalledByUser = false;
|
||||||
break;
|
break;
|
||||||
case SocketStatus.SOCKET_STATUS_CONNECT_FAILED:
|
case SocketStatus.SOCKET_STATUS_CONNECT_FAILED:
|
||||||
break;
|
break;
|
||||||
|
|||||||
18
Pepperdash Core/Pepperdash Core/Network/DiscoveryThings.cs
Normal file
18
Pepperdash Core/Pepperdash Core/Network/DiscoveryThings.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Core
|
||||||
|
{
|
||||||
|
|
||||||
|
public static class NetworkComm
|
||||||
|
{
|
||||||
|
|
||||||
|
static NetworkComm()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -72,6 +72,7 @@
|
|||||||
<Compile Include="Device.cs" />
|
<Compile Include="Device.cs" />
|
||||||
<Compile Include="EthernetHelper.cs" />
|
<Compile Include="EthernetHelper.cs" />
|
||||||
<Compile Include="Comm\GenericTcpIpClient.cs" />
|
<Compile Include="Comm\GenericTcpIpClient.cs" />
|
||||||
|
<Compile Include="Network\DiscoveryThings.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<None Include="Properties\ControlSystem.cfg" />
|
<None Include="Properties\ControlSystem.cfg" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -84,7 +85,7 @@
|
|||||||
<Programmer />
|
<Programmer />
|
||||||
<ArchiveFilename>C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz</ArchiveFilename>
|
<ArchiveFilename>C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz</ArchiveFilename>
|
||||||
<MinFirmwareVersion>1.007.0017</MinFirmwareVersion>
|
<MinFirmwareVersion>1.007.0017</MinFirmwareVersion>
|
||||||
<CompiledOn>9/2/2016 4:24:23 PM</CompiledOn>
|
<CompiledOn>9/12/2016 2:06:04 PM</CompiledOn>
|
||||||
<AdditionalInfo />
|
<AdditionalInfo />
|
||||||
<EmbedSourceArchive>False</EmbedSourceArchive>
|
<EmbedSourceArchive>False</EmbedSourceArchive>
|
||||||
<CopyTo />
|
<CopyTo />
|
||||||
|
|||||||
Binary file not shown.
@@ -10,7 +10,7 @@
|
|||||||
<ArchiveName />
|
<ArchiveName />
|
||||||
</RequiredInfo>
|
</RequiredInfo>
|
||||||
<OptionalInfo>
|
<OptionalInfo>
|
||||||
<CompiledOn>9/2/2016 4:24:23 PM</CompiledOn>
|
<CompiledOn>9/12/2016 2:06:04 PM</CompiledOn>
|
||||||
<CompilerRev>1.0.0.27730</CompilerRev>
|
<CompilerRev>1.0.0.23581</CompilerRev>
|
||||||
</OptionalInfo>
|
</OptionalInfo>
|
||||||
</ProgramInfo>
|
</ProgramInfo>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
MainAssembly=PepperDash_Core.dll:91ae222c64760e498b41b5b05b1e591d
|
MainAssembly=PepperDash_Core.dll:841414db99de3a39f802c9ba80e23ad1
|
||||||
MainAssemblyMinFirmwareVersion=1.007.0017
|
MainAssemblyMinFirmwareVersion=1.007.0017
|
||||||
ü
|
ü
|
||||||
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
|
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user