|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using log4net;
|
|
|
|
|
|
|
|
|
|
namespace Service.Led;
|
|
|
|
|
|
|
|
|
|
public class LedClient
|
|
|
|
|
{
|
|
|
|
|
#region msg
|
|
|
|
|
|
|
|
|
|
public static Dictionary<string, byte[]> Dictionary = new Dictionary<string, byte[]>()
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
"houtui",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
|
|
|
|
|
0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x34, 0xBA, 0xF3, 0xCD, 0xCB, 0x00, 0x00,
|
|
|
|
|
0x0D, 0x0A
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"qianjin",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
|
|
|
|
|
0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x37, 0xC7, 0xB0, 0xBD, 0xF8, 0x00, 0x00,
|
|
|
|
|
0x0D, 0x0A
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"xiangzuo",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
|
|
|
|
|
0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x31, 0xCF, 0xF2, 0xD7, 0xF3, 0x00, 0x00,
|
|
|
|
|
0x0D, 0x0A
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"xiangyou",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
|
|
|
|
|
0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x31, 0xCF, 0xF2, 0xD3, 0xD2, 0x00, 0x00,
|
|
|
|
|
0x0D, 0x0A
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"tingzhunle",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00,
|
|
|
|
|
0x00, 0x0E, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3B, 0x31, 0xCD, 0xA3, 0xD7, 0xBC, 0xC1, 0xCB,
|
|
|
|
|
0x00, 0x00, 0x0D, 0x0A
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"wuche",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
|
|
|
|
|
0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x36, 0xCE, 0xDE, 0xB3, 0xB5, 0x00, 0x00,
|
|
|
|
|
0x0D, 0x0A
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"zuoqian",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
|
|
|
|
|
0x00, 0x10, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x31, 0xCF, 0xF2, 0xD7, 0xF3, 0xC7, 0xB0,
|
|
|
|
|
0xB7, 0xBD, 0x00, 0x00, 0x0D, 0x0A
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"youqian",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
|
|
|
|
|
0x00, 0x10, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x31, 0xCF, 0xF2, 0xD3, 0xD2, 0xC7, 0xB0,
|
|
|
|
|
0xB7, 0xBD, 0x00, 0x00, 0x0D, 0x0A
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"zuohou",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
|
|
|
|
|
0x00, 0x10, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x31, 0xCF, 0xF2, 0xD7, 0xF3, 0xBA, 0xF3,
|
|
|
|
|
0xB7, 0xBD, 0x00, 0x00, 0x0D, 0x0A
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(LedClient));
|
|
|
|
|
private static TcpClient? _tcpClient;
|
|
|
|
|
|
|
|
|
|
public static bool Init(string ip, int port)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"begin connect {ip}:{port}");
|
|
|
|
|
_tcpClient = new TcpClient();
|
|
|
|
|
_tcpClient.Connect(ip, port);
|
|
|
|
|
Log.Info($"end connect {ip}:{port} {_tcpClient.Connected}");
|
|
|
|
|
return _tcpClient.Connected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool InnerSend(byte[] bytes)
|
|
|
|
|
{
|
|
|
|
|
if (_tcpClient?.Connected ?? true)
|
|
|
|
|
{
|
|
|
|
|
_tcpClient.GetStream().Write(bytes, 0, bytes.Length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool SendMsgByKey(string key)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"send by {key}");
|
|
|
|
|
if (Dictionary.TryGetValue(key, out var bytes))
|
|
|
|
|
{
|
|
|
|
|
return InnerSend(bytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|