Z
8 months ago
6 changed files with 155 additions and 29 deletions
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
namespace Emergency_platform{ |
||||
public class DataServerUrl{ |
||||
public const string Url = ""; |
||||
} |
||||
} |
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Threading; |
||||
|
||||
namespace EGFramework{ |
||||
/// <summary> |
||||
/// In Godot engine, the async method return cannot operate the godot main thread such as Screen Trees Node. |
||||
/// The protocol schedule provide a main thread to check the message in protocol tools 's response message. |
||||
/// If you have more idea ,please issue to me, thanks. |
||||
/// </summary> |
||||
public partial class EGProtocolSchedule : IModule,IEGFramework |
||||
{ |
||||
public Dictionary<Type,IProtocolReceived> ProtocolTools = new Dictionary<Type, IProtocolReceived>(); |
||||
public void Init() |
||||
{ |
||||
int frameRate = 30; // 帧率 |
||||
int interval = 1000 / frameRate; // 计算每帧间隔时间 |
||||
|
||||
Timer timer = new Timer(_Process, null, 0, interval); |
||||
} |
||||
|
||||
public void _Process(object? state) |
||||
{ |
||||
foreach(IProtocolReceived tool in ProtocolTools.Values){ |
||||
if(tool.GetReceivedMsg().Count>0){ |
||||
this.GetModule<EGMessage>().OnDataReceived.Invoke(tool.GetReceivedMsg().Dequeue()); |
||||
} |
||||
} |
||||
} |
||||
public void EnabledAllTools(){ |
||||
ProtocolTools.Add(typeof(EGTCPClient),this.GetModule<EGTCPClient>()); |
||||
ProtocolTools.Add(typeof(EGTCPServer),this.GetModule<EGTCPServer>()); |
||||
ProtocolTools.Add(typeof(EGUDP),this.GetModule<EGUDP>()); |
||||
ProtocolTools.Add(typeof(EGSerialPort),this.GetModule<EGSerialPort>()); |
||||
} |
||||
public void EnabledTool<TProtocolReceived>() where TProtocolReceived : class, IModule,IProtocolReceived,new(){ |
||||
ProtocolTools.Add(typeof(TProtocolReceived),this.GetModule<TProtocolReceived>()); |
||||
} |
||||
|
||||
public void DisabledAllTools(){ |
||||
ProtocolTools.Clear(); |
||||
} |
||||
|
||||
public void DisabledTool<TProtocolReceived>() where TProtocolReceived : class, IModule,IProtocolReceived,new(){ |
||||
if(ProtocolTools.ContainsKey(typeof(TProtocolReceived))){ |
||||
ProtocolTools.Remove(typeof(TProtocolReceived)); |
||||
} |
||||
} |
||||
|
||||
public IArchitecture GetArchitecture() |
||||
{ |
||||
return EGArchitectureImplement.Interface; |
||||
} |
||||
|
||||
} |
||||
public static class CanGetEGProtocolExtension{ |
||||
public static EGProtocolSchedule EGProtocolSchedule(this IEGFramework self){ |
||||
return self.GetModule<EGProtocolSchedule>(); |
||||
} |
||||
public static void EGEnabledProtocolTools(this IEGFramework self){ |
||||
self.GetModule<EGProtocolSchedule>().EnabledAllTools(); |
||||
} |
||||
public static void EGEnabledProtocolTool<TProtocolReceived>(this IEGFramework self) where TProtocolReceived : class, IModule,IProtocolReceived,new(){ |
||||
self.GetModule<EGProtocolSchedule>().EnabledTool<TProtocolReceived>(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
using EGFramework; |
||||
namespace Emergency_platform{ |
||||
public class ModelNumericalValue : EGModule,IEGFramework |
||||
{ |
||||
public override void Init() |
||||
{ |
||||
this.EGRegisterMessageEvent<ResponseNumericalValue>((e,sender,protocol)=>{ |
||||
Console.WriteLine("Get Command " + e.action); |
||||
Console.WriteLine("Command params is" + e.halmet + "|" + e.targetname + "|" + e.taskid); |
||||
}); |
||||
this.EGOnMessage<ResponseNumericalValue>(); |
||||
Console.WriteLine("ModelNumericalValue has been Loaded!"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
using EGFramework; |
||||
using Newtonsoft.Json; |
||||
namespace Emergency_platform{ |
||||
public class ResponseNumericalValue : IResponse |
||||
{ |
||||
public string action { set; get; } |
||||
public string taskid { set; get; } |
||||
public string halmet { set; get; } |
||||
public string cabinetid { set; get; } |
||||
public string targetname { set; get; } |
||||
|
||||
public bool TrySetData(string protocolData, byte[] protocolBytes) |
||||
{ |
||||
try |
||||
{ |
||||
ResponseNumericalValue data = JsonConvert.DeserializeObject<ResponseNumericalValue>(protocolData); |
||||
if(data.action == "numericalValue"){ |
||||
this.action = data.action; |
||||
this.taskid = data.taskid; |
||||
this.halmet = data.halmet; |
||||
this.targetname = data.targetname; |
||||
this.cabinetid = data.cabinetid; |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
catch (System.Exception) |
||||
{ |
||||
return false; |
||||
throw; |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue