Commit 76aa78aa 刘韬

1

1 个父辈 45ed6db8
...@@ -16,10 +16,14 @@ namespace DeviceLibrary ...@@ -16,10 +16,14 @@ namespace DeviceLibrary
/// </summary> /// </summary>
static Dictionary<string,IWebSocketConnection> allClients; static Dictionary<string,IWebSocketConnection> allClients;
static WebSocketServer server; static WebSocketServer server;
/// <summary>
/// 初始化监听服务
/// </summary>
public static void Init() { public static void Init() {
FleckLog.Level = LogLevel.Debug; FleckLog.Level = LogLevel.Debug;
allClients = new Dictionary<string, IWebSocketConnection>(); allClients = new Dictionary<string, IWebSocketConnection>();
server = new WebSocketServer("ws://0.0.0.0:26901"); server = new WebSocketServer("ws://0.0.0.0:26901");
server.RestartAfterListenError=true;
server.Start(client => server.Start(client =>
{ {
client.OnOpen = () => client.OnOpen = () =>
...@@ -46,7 +50,6 @@ namespace DeviceLibrary ...@@ -46,7 +50,6 @@ namespace DeviceLibrary
client.OnMessage = message => client.OnMessage = message =>
{ {
var deviceGroupName = client.ConnectionInfo.Path.Substring(1); var deviceGroupName = client.ConnectionInfo.Path.Substring(1);
//SetINCall(deviceGroupName, JsonConvert.DeserializeObject<RemoteLoad>(message));
ProcessMessage(deviceGroupName,message); ProcessMessage(deviceGroupName,message);
}; };
}); });
...@@ -100,6 +103,11 @@ namespace DeviceLibrary ...@@ -100,6 +103,11 @@ namespace DeviceLibrary
} }
SendResult(deviceGroupName, isok, Seq); SendResult(deviceGroupName, isok, Seq);
} }
/// <summary>
/// 发送消息,不接收返回信息
/// </summary>
/// <param name="deviceGroupName">设备ID</param>
/// <param name="message"></param>
public static void SendMessage(string deviceGroupName,RemoteLoad message) { public static void SendMessage(string deviceGroupName,RemoteLoad message) {
if (!allClients.ContainsKey(deviceGroupName)) if (!allClients.ContainsKey(deviceGroupName))
{ {
...@@ -115,6 +123,13 @@ namespace DeviceLibrary ...@@ -115,6 +123,13 @@ namespace DeviceLibrary
} }
} }
/// <summary>
/// 发送并等待返回
/// </summary>
/// <param name="GroupName">设备ID</param>
/// <param name="remoteLoad">载荷信息</param>
/// <param name="waittime">等待时间默认3000毫秒</param>
/// <returns></returns>
public static RemoteResult SendAndWait(string GroupName, RemoteLoad remoteLoad, int waittime = 3000) public static RemoteResult SendAndWait(string GroupName, RemoteLoad remoteLoad, int waittime = 3000)
{ {
remoteLoad.GroupName = GroupName; remoteLoad.GroupName = GroupName;
...@@ -157,7 +172,7 @@ namespace DeviceLibrary ...@@ -157,7 +172,7 @@ namespace DeviceLibrary
return RemoteResult.Timeout; return RemoteResult.Timeout;
} }
} }
public static void SendResult(string deviceGroupName, bool result,long Seq) static void SendResult(string deviceGroupName, bool result,long Seq)
{ {
RemoteLoad remoteLoad = new RemoteLoad(); RemoteLoad remoteLoad = new RemoteLoad();
remoteLoad.Seq = Seq; remoteLoad.Seq = Seq;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!