Browse Source

fixed Platform class and changed all GD.Print to EG.Print

master
jkpete 5 months ago
parent
commit
e49ca8486a
  1. 39
      addons/EGFramework/EGPlatform.cs
  2. 1
      addons/EGFramework/Module/ProtocolExtension/EGModbusExtension.cs
  3. 23
      addons/EGFramework/Module/ProtocolTools/EGBacnet.cs
  4. 2
      addons/EGFramework/Module/ProtocolTools/EGFileStream.cs
  5. 2
      addons/EGFramework/Module/ProtocolTools/EGHttpClient.cs
  6. 2
      addons/EGFramework/Module/ProtocolTools/EGHttpServer.cs
  7. 15
      addons/EGFramework/Module/ProtocolTools/EGMQTT.cs
  8. 9
      addons/EGFramework/Module/ProtocolTools/EGModbus.cs
  9. 4
      addons/EGFramework/Module/ProtocolTools/EGSerialPort.cs
  10. 5
      addons/EGFramework/Module/ProtocolTools/EGSsh.cs
  11. 10
      addons/EGFramework/Module/ProtocolTools/EGUDP.cs
  12. 4
      addons/EGFramework/Module/SaveTools/EGByteSave.cs
  13. 4
      addons/EGFramework/Module/SaveTools/EGCsvSave.cs
  14. 4
      addons/EGFramework/Module/SaveTools/EGSqlite.cs

39
addons/EGFramework/EGPlatform.cs

@ -0,0 +1,39 @@
using System;
using System.Diagnostics;
namespace EGFramework{
public interface IPlatform{
void Log(string message);
void Log(params object[] what);
}
public class EGPlatformGodot : IPlatform{
public void Log(string message){
Godot.GD.Print(message);
// Console.WriteLine(message);
}
public void Log(params object[] what){
Godot.GD.Print(what);
// Console.WriteLine(what);
}
}
public static class EG
{
public static EGPlatformGodot Platform = new EGPlatformGodot();
public static void Print(string message){
Platform.Log(message);
}
public static void Print(params object[] what){
Platform.Log(what);
}
}
// public enum SupportPlatform{
// Godot = 0x01,
// Unity = 0x02,
// WebApi = 0x03,
// WPF = 0x04,
// Form = 0x05,
// }
}

1
addons/EGFramework/Module/ProtocolExtension/EGModbusExtension.cs

@ -1,6 +1,5 @@
using System; using System;
using System.Linq; using System.Linq;
using log4net.Core;
namespace EGFramework{ namespace EGFramework{
/// <summary> /// <summary>

23
addons/EGFramework/Module/ProtocolTools/EGBacnet.cs

@ -4,7 +4,6 @@ using System.IO.BACnet;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Godot;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace EGFramework{ namespace EGFramework{
@ -86,7 +85,7 @@ namespace EGFramework{
public async void WaitForIamResponse(){ public async void WaitForIamResponse(){
IsWaitForIam = true; IsWaitForIam = true;
await Task.Delay(2000); await Task.Delay(2000);
GD.Print("-----Get device----"); EG.Print("-----Get device----");
string serializeData = JsonConvert.SerializeObject(new EGBacnetWhoIsResponse(DevicesList.Keys.ToList())); string serializeData = JsonConvert.SerializeObject(new EGBacnetWhoIsResponse(DevicesList.Keys.ToList()));
this.ResponseMsgs.Enqueue(new ResponseMsg(serializeData,StringEncoding.GetBytes(serializeData),"Who Is",ProtocolType.Bacnet)); this.ResponseMsgs.Enqueue(new ResponseMsg(serializeData,StringEncoding.GetBytes(serializeData),"Who Is",ProtocolType.Bacnet));
IsWaitForIam = false; IsWaitForIam = false;
@ -114,9 +113,9 @@ namespace EGFramework{
} }
public bool ExecuteBacnetData(EGBacnetRequest bacnetRequest){ public bool ExecuteBacnetData(EGBacnetRequest bacnetRequest){
bool executeResult = false; bool executeResult = false;
GD.Print("Execute bacnet request"); EG.Print("Execute bacnet request");
if(bacnetRequest.OperateCode == EGBacnetOperateCode.WhoIsRequest){ if(bacnetRequest.OperateCode == EGBacnetOperateCode.WhoIsRequest){
GD.Print("Request for Who Is"); EG.Print("Request for Who Is");
BacnetClient.WhoIs(); BacnetClient.WhoIs();
return true; return true;
} }
@ -156,7 +155,7 @@ namespace EGFramework{
break; break;
} }
GD.Print(bacnetValueQuery[0].Value.GetType()); EG.Print(bacnetValueQuery[0].Value.GetType());
EGBacnetResponse response = new EGBacnetResponse(bacnetRequest,bacnetValueQuery); EGBacnetResponse response = new EGBacnetResponse(bacnetRequest,bacnetValueQuery);
response.IsSuccess = executeResult; response.IsSuccess = executeResult;
return response; return response;
@ -177,7 +176,7 @@ namespace EGFramework{
if(bacnetRequest.ValueType != BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL){ if(bacnetRequest.ValueType != BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL){
bacnetRequest.Value = bacnetRequest.Value.ConvertBacnetValueType(bacnetRequest.ValueType); bacnetRequest.Value = bacnetRequest.Value.ConvertBacnetValueType(bacnetRequest.ValueType);
} }
GD.Print(bacnetRequest.Value.GetType()); EG.Print(bacnetRequest.Value.GetType());
BacnetAddress address = DevicesList[bacnetRequest.DeviceId]; BacnetAddress address = DevicesList[bacnetRequest.DeviceId];
switch(bacnetRequest.OperateCode){ switch(bacnetRequest.OperateCode){
case EGBacnetOperateCode.WritePropertyRequest: case EGBacnetOperateCode.WritePropertyRequest:
@ -246,7 +245,7 @@ namespace EGFramework{
} }
catch (System.Exception e) catch (System.Exception e)
{ {
GD.Print(e); EG.Print(e);
throw; throw;
} }
return value; return value;
@ -274,7 +273,7 @@ namespace EGFramework{
} }
catch (System.Exception e) catch (System.Exception e)
{ {
GD.PrintErr(e); EG.Print("Error:"+e);
throw; throw;
} }
} }
@ -319,7 +318,7 @@ namespace EGFramework{
} }
catch (System.Exception e) catch (System.Exception e)
{ {
GD.PrintErr("Who is error:"+ e); EG.Print("Who is error:"+ e);
return false; return false;
} }
} }
@ -377,7 +376,7 @@ namespace EGFramework{
} }
catch (System.Exception e) catch (System.Exception e)
{ {
GD.PrintErr(e); EG.Print("Error:"+e);
return false; return false;
} }
} }
@ -467,7 +466,7 @@ namespace EGFramework{
} }
catch (System.Exception e) catch (System.Exception e)
{ {
GD.PrintErr(e); EG.Print("Error:"+e);
return false; return false;
} }
} }
@ -502,7 +501,7 @@ namespace EGFramework{
} }
catch (System.Exception e) catch (System.Exception e)
{ {
GD.Print(e); EG.Print("Error:"+e);
return false; return false;
} }
//throw new System.NotImplementedException(); //throw new System.NotImplementedException();

2
addons/EGFramework/Module/ProtocolTools/EGFileStream.cs

@ -73,7 +73,7 @@ namespace EGFramework{
} }
catch (System.Exception e) catch (System.Exception e)
{ {
Godot.GD.Print("e:" + e); EG.Print("e:" + e);
throw; throw;
} }
} }

2
addons/EGFramework/Module/ProtocolTools/EGHttpClient.cs

@ -71,7 +71,7 @@ namespace EGFramework{
} }
catch (HttpRequestException e) catch (HttpRequestException e)
{ {
Godot.GD.Print("Exception Message : "+e.Message); EG.Print("Exception Message : "+e.Message);
return default; return default;
} }
} }

2
addons/EGFramework/Module/ProtocolTools/EGHttpServer.cs

@ -125,7 +125,7 @@ namespace EGFramework{
} }
} }
Godot.GD.Print("Server Overed"); EG.Print("Server Overed");
} }
public IArchitecture GetArchitecture() public IArchitecture GetArchitecture()

15
addons/EGFramework/Module/ProtocolTools/EGMQTT.cs

@ -5,7 +5,6 @@ using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Godot;
using MQTTnet; using MQTTnet;
using MQTTnet.Client; using MQTTnet.Client;
@ -53,16 +52,16 @@ namespace EGFramework{
}; };
await mqttClient.ConnectAsync(mqttClientOptions,CancellationToken.None); await mqttClient.ConnectAsync(mqttClientOptions,CancellationToken.None);
MqttDevices.Add(serverURL,mqttClient); MqttDevices.Add(serverURL,mqttClient);
GD.Print("Success Connect!"+MqttDevices[serverURL].IsConnected); EG.Print("Success Connect!"+MqttDevices[serverURL].IsConnected);
OnMqttConnect.Invoke(serverURL); OnMqttConnect.Invoke(serverURL);
}else{ }else{
if(!MqttDevices[serverURL].IsConnected){ if(!MqttDevices[serverURL].IsConnected){
var mqttClientOptions = new MqttClientOptionsBuilder().WithTcpServer(serverURL).Build(); var mqttClientOptions = new MqttClientOptionsBuilder().WithTcpServer(serverURL).Build();
await MqttDevices[serverURL].ConnectAsync(mqttClientOptions,CancellationToken.None); await MqttDevices[serverURL].ConnectAsync(mqttClientOptions,CancellationToken.None);
GD.Print("Success Connect!"+MqttDevices[serverURL].IsConnected); EG.Print("Success Connect!"+MqttDevices[serverURL].IsConnected);
OnMqttConnect.Invoke(serverURL); OnMqttConnect.Invoke(serverURL);
}else{ }else{
GD.Print("Server has been Connected"+MqttDevices[serverURL].IsConnected); EG.Print("Server has been Connected"+MqttDevices[serverURL].IsConnected);
OnMqttConnect.Invoke(serverURL); OnMqttConnect.Invoke(serverURL);
} }
} }
@ -72,7 +71,7 @@ namespace EGFramework{
if(MqttDevices.ContainsKey(serverURL) && MqttDevices[serverURL].IsConnected){ if(MqttDevices.ContainsKey(serverURL) && MqttDevices[serverURL].IsConnected){
await MqttDevices[serverURL].DisconnectAsync(new MqttClientDisconnectOptionsBuilder().WithReason(MqttClientDisconnectOptionsReason.NormalDisconnection).Build()); await MqttDevices[serverURL].DisconnectAsync(new MqttClientDisconnectOptionsBuilder().WithReason(MqttClientDisconnectOptionsReason.NormalDisconnection).Build());
}else{ }else{
GD.Print("Not connect"); EG.Print("Not connect");
} }
} }
@ -86,9 +85,9 @@ namespace EGFramework{
.Build(); .Build();
if(MqttDevices.ContainsKey(serverURL) && MqttDevices[serverURL].IsConnected){ if(MqttDevices.ContainsKey(serverURL) && MqttDevices[serverURL].IsConnected){
await MqttDevices[serverURL].SubscribeAsync(mqttSubscribeOptions,CancellationToken.None); await MqttDevices[serverURL].SubscribeAsync(mqttSubscribeOptions,CancellationToken.None);
GD.Print("Subscribe "+Theme+" success!"); EG.Print("Subscribe "+Theme+" success!");
}else{ }else{
GD.Print("Not connect"); EG.Print("Not connect");
} }
} }
@ -118,7 +117,7 @@ namespace EGFramework{
.Build(); .Build();
if(MqttDevices.ContainsKey(serverURL) && MqttDevices[serverURL].IsConnected){ if(MqttDevices.ContainsKey(serverURL) && MqttDevices[serverURL].IsConnected){
await MqttDevices[serverURL].PublishAsync(applicationMessage, CancellationToken.None); await MqttDevices[serverURL].PublishAsync(applicationMessage, CancellationToken.None);
GD.Print("publish success!"); EG.Print("publish success!");
} }
} }

9
addons/EGFramework/Module/ProtocolTools/EGModbus.cs

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Godot;
namespace EGFramework{ namespace EGFramework{
/// <summary> /// <summary>
@ -55,7 +54,7 @@ namespace EGFramework{
//break; //break;
} }
}); });
GD.Print("-----Read"+messageId+" ----"); EG.Print("-----Read"+messageId+" ----");
//return null; //return null;
} }
RTUCache.Clear(); RTUCache.Clear();
@ -118,7 +117,7 @@ namespace EGFramework{
//break; //break;
} }
}); });
GD.Print("-----Write"+messageId+" ----"); EG.Print("-----Write"+messageId+" ----");
//return null; //return null;
} }
RTUCache.Clear(); RTUCache.Clear();
@ -175,7 +174,7 @@ namespace EGFramework{
//break; //break;
} }
}); });
GD.Print("-----Read"+messageId+" ----"); EG.Print("-----Read"+messageId+" ----");
//return null; //return null;
} }
TCPCache.Clear(); TCPCache.Clear();
@ -222,7 +221,7 @@ namespace EGFramework{
//break; //break;
} }
}); });
GD.Print("-----Write"+messageId+" ----"); EG.Print("-----Write"+messageId+" ----");
//return null; //return null;
} }
TCPCache.Clear(); TCPCache.Clear();

4
addons/EGFramework/Module/ProtocolTools/EGSerialPort.cs

@ -181,13 +181,13 @@ namespace EGFramework{
} }
if(ReceivedCache[serialPort.PortName].Length >= MinDataPackLength){ if(ReceivedCache[serialPort.PortName].Length >= MinDataPackLength){
string str = StringEncoding.GetString(ReceivedCache[serialPort.PortName]); string str = StringEncoding.GetString(ReceivedCache[serialPort.PortName]);
Godot.GD.Print("[Receive]"+ReceivedCache[serialPort.PortName].ToStringByHex()); EG.Print("[Receive]"+ReceivedCache[serialPort.PortName].ToStringByHex());
ResponseMsgs.Enqueue(new ResponseMsg(str,ReceivedCache[serialPort.PortName],serialPort.PortName,ProtocolType.SerialPort)); ResponseMsgs.Enqueue(new ResponseMsg(str,ReceivedCache[serialPort.PortName],serialPort.PortName,ProtocolType.SerialPort));
ReceivedCache[serialPort.PortName] = new byte[0]; ReceivedCache[serialPort.PortName] = new byte[0];
MinDataPackLength = 0; MinDataPackLength = 0;
//this.EGOnReceivedData(new ResponseMsg(str,buffer,serialPort.PortName,ProtocolType.SerialPort)); //this.EGOnReceivedData(new ResponseMsg(str,buffer,serialPort.PortName,ProtocolType.SerialPort));
}else{ }else{
Godot.GD.Print("[Data Get]" + ReceivedCache[serialPort.PortName].Length); EG.Print("[Data Get]" + ReceivedCache[serialPort.PortName].Length);
string str = StringEncoding.GetString(ReceivedCache[serialPort.PortName]); string str = StringEncoding.GetString(ReceivedCache[serialPort.PortName]);
ResponseMsgs.Enqueue(new ResponseMsg(str,ReceivedCache[serialPort.PortName],serialPort.PortName,ProtocolType.SerialPort)); ResponseMsgs.Enqueue(new ResponseMsg(str,ReceivedCache[serialPort.PortName],serialPort.PortName,ProtocolType.SerialPort));
} }

5
addons/EGFramework/Module/ProtocolTools/EGSsh.cs

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Godot;
using Renci.SshNet; using Renci.SshNet;
namespace EGFramework{ namespace EGFramework{
@ -43,7 +42,7 @@ namespace EGFramework{
}else{ }else{
CancellationTokenSource sourceReconnect = new CancellationTokenSource(); CancellationTokenSource sourceReconnect = new CancellationTokenSource();
CancellationToken tokenReconnect = sourceReconnect.Token; CancellationToken tokenReconnect = sourceReconnect.Token;
tokenReconnect.Register(() => Godot.GD.Print("Ssh connect timeout!")); tokenReconnect.Register(() => EG.Print("Ssh connect timeout!"));
await SshClientDevices[host].ConnectAsync(tokenReconnect); await SshClientDevices[host].ConnectAsync(tokenReconnect);
if(!SshClientDevices[host].IsConnected){ if(!SshClientDevices[host].IsConnected){
return false; return false;
@ -56,7 +55,7 @@ namespace EGFramework{
SshClient client = new SshClient(host, username, password); SshClient client = new SshClient(host, username, password);
CancellationTokenSource source = new CancellationTokenSource(); CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token; CancellationToken token = source.Token;
token.Register(() => Godot.GD.Print("Ssh connect timeout!")); token.Register(() => EG.Print("Ssh connect timeout!"));
source.CancelAfter(TimeOutDelay); source.CancelAfter(TimeOutDelay);
await client.ConnectAsync(token); await client.ConnectAsync(token);
if(!client.IsConnected){ if(!client.IsConnected){

10
addons/EGFramework/Module/ProtocolTools/EGUDP.cs

@ -38,7 +38,7 @@ namespace EGFramework{
//StartListening(localPort); //StartListening(localPort);
} }
catch (Exception e){ catch (Exception e){
Godot.GD.Print("Error" + e); EG.Print("Error" + e);
} }
} }
} }
@ -54,7 +54,7 @@ namespace EGFramework{
{ {
try try
{ {
//GD.Print("UDP listened in "+((IPEndPoint)client.Client.LocalEndPoint).Port); //EG.Print("UDP listened in "+((IPEndPoint)client.Client.LocalEndPoint).Port);
while (true) while (true)
{ {
UdpReceiveResult data = await client.ReceiveAsync(); UdpReceiveResult data = await client.ReceiveAsync();
@ -66,7 +66,7 @@ namespace EGFramework{
} }
catch (Exception e) catch (Exception e)
{ {
GD.Print("Listen false by:"+e); EG.Print("Listen false by:"+e);
} }
} }
@ -78,11 +78,11 @@ namespace EGFramework{
udpClient = new UdpClient(); udpClient = new UdpClient();
} }
try{ try{
GD.Print(udpClient.EnableBroadcast); EG.Print(udpClient.EnableBroadcast);
udpClient.Send(data, data.Length, host, port); udpClient.Send(data, data.Length, host, port);
} }
catch ( Exception e ){ catch ( Exception e ){
Godot.GD.Print(e.ToString()); EG.Print(e.ToString());
} }
if(UDPDevices.Count<=0){ if(UDPDevices.Count<=0){
udpClient.Close(); udpClient.Close();

4
addons/EGFramework/Module/SaveTools/EGByteSave.cs

@ -25,7 +25,7 @@ namespace EGFramework
} }
catch (System.Exception e) catch (System.Exception e)
{ {
Godot.GD.Print("e:" + e); EG.Print("e:" + e);
throw; throw;
} }
} }
@ -39,7 +39,7 @@ namespace EGFramework
} }
catch (System.Exception e) catch (System.Exception e)
{ {
Godot.GD.Print("e:" + e); EG.Print("e:" + e);
throw; throw;
} }
} }

4
addons/EGFramework/Module/SaveTools/EGCsvSave.cs

@ -54,7 +54,7 @@ namespace EGFramework
} }
catch (System.Exception e) catch (System.Exception e)
{ {
Godot.GD.Print("e:" + e); EG.Print("e:" + e);
throw; throw;
} }
if(ReadText != null || ReadText != ""){ if(ReadText != null || ReadText != ""){
@ -89,7 +89,7 @@ namespace EGFramework
} }
catch (System.Exception e) catch (System.Exception e)
{ {
Godot.GD.Print("e:" + e); EG.Print("e:" + e);
throw; throw;
} }
} }

4
addons/EGFramework/Module/SaveTools/EGSqlite.cs

@ -77,7 +77,7 @@ namespace EGFramework{
string sqlCommand = "CREATE TABLE " + typeof(TData).Name; string sqlCommand = "CREATE TABLE " + typeof(TData).Name;
sqlCommand += "(\"ID\" INTEGER NOT NULL UNIQUE,"; sqlCommand += "(\"ID\" INTEGER NOT NULL UNIQUE,";
var properties = typeof(TData).GetProperties(); var properties = typeof(TData).GetProperties();
Godot.GD.Print(properties.Count() + " Readed "); EG.Print(properties.Count() + " Readed ");
foreach(var property in properties){ foreach(var property in properties){
if(property.PropertyType == typeof(int) || property.PropertyType == typeof(bool) || property.PropertyType.IsEnum){ if(property.PropertyType == typeof(int) || property.PropertyType == typeof(bool) || property.PropertyType.IsEnum){
sqlCommand += "\"" + property.Name + "\" INTEGER" + " NOT NULL,"; sqlCommand += "\"" + property.Name + "\" INTEGER" + " NOT NULL,";
@ -89,7 +89,7 @@ namespace EGFramework{
} }
} }
sqlCommand += "PRIMARY KEY(\"ID\" AUTOINCREMENT))"; sqlCommand += "PRIMARY KEY(\"ID\" AUTOINCREMENT))";
Godot.GD.Print(sqlCommand); EG.Print(sqlCommand);
SqliteCommand createCommand = new SqliteCommand(sqlCommand,SqliteConn); SqliteCommand createCommand = new SqliteCommand(sqlCommand,SqliteConn);
result = result + createCommand.ExecuteNonQuery().ToString(); result = result + createCommand.ExecuteNonQuery().ToString();
} }

Loading…
Cancel
Save