|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using Entity.Attr;
|
|
|
|
|
using Entity.Constant;
|
|
|
|
|
using HybirdFrameworkCore.Utils;
|
|
|
|
|
using log4net;
|
|
|
|
|
|
|
|
|
@ -179,6 +181,9 @@ public class LedClient
|
|
|
|
|
//private static string _ip = "127.0.0.1";
|
|
|
|
|
private static int _port = 10000;
|
|
|
|
|
|
|
|
|
|
private static DateTime LastestSendTime;
|
|
|
|
|
private static string LastestKey=InfoEnum.SwapInfo.IDEI.GetLed();
|
|
|
|
|
|
|
|
|
|
public static bool Init(string ip, int port)
|
|
|
|
|
{
|
|
|
|
|
_ip = ip;
|
|
|
|
@ -192,6 +197,34 @@ public class LedClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void ListenHeart()
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (_socket?.Connected ?? false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (LastestSendTime == null )
|
|
|
|
|
{
|
|
|
|
|
SendMsgByKey(LastestKey);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var now = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
if ((now - LastestSendTime).TotalSeconds > 3)
|
|
|
|
|
{
|
|
|
|
|
SendMsgByKey(LastestKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Connect()
|
|
|
|
|
{
|
|
|
|
@ -202,6 +235,7 @@ public class LedClient
|
|
|
|
|
_socket.NoDelay = true;
|
|
|
|
|
_socket.Connect(_ip, _port);
|
|
|
|
|
Log.Info($"end connect {_ip}:{_port} {_socket.Connected}");
|
|
|
|
|
Task.Run(ListenHeart);
|
|
|
|
|
}
|
|
|
|
|
catch (SocketException ex)
|
|
|
|
|
{
|
|
|
|
@ -254,12 +288,13 @@ public class LedClient
|
|
|
|
|
int count = 0;
|
|
|
|
|
if (Dictionary.TryGetValue(key, out var bytes))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
LastestKey = key;
|
|
|
|
|
LastestSendTime=DateTime.Now;
|
|
|
|
|
while (!InnerSend(bytes))
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
count++;
|
|
|
|
|
if (count > 10)
|
|
|
|
|
if (count > 5)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|