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

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

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

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

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

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

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

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

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

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

@ -5,7 +5,6 @@ using System.Net.Sockets; @@ -5,7 +5,6 @@ using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Godot;
using MQTTnet;
using MQTTnet.Client;
@ -53,16 +52,16 @@ namespace EGFramework{ @@ -53,16 +52,16 @@ namespace EGFramework{
};
await mqttClient.ConnectAsync(mqttClientOptions,CancellationToken.None);
MqttDevices.Add(serverURL,mqttClient);
GD.Print("Success Connect!"+MqttDevices[serverURL].IsConnected);
EG.Print("Success Connect!"+MqttDevices[serverURL].IsConnected);
OnMqttConnect.Invoke(serverURL);
}else{
if(!MqttDevices[serverURL].IsConnected){
var mqttClientOptions = new MqttClientOptionsBuilder().WithTcpServer(serverURL).Build();
await MqttDevices[serverURL].ConnectAsync(mqttClientOptions,CancellationToken.None);
GD.Print("Success Connect!"+MqttDevices[serverURL].IsConnected);
EG.Print("Success Connect!"+MqttDevices[serverURL].IsConnected);
OnMqttConnect.Invoke(serverURL);
}else{
GD.Print("Server has been Connected"+MqttDevices[serverURL].IsConnected);
EG.Print("Server has been Connected"+MqttDevices[serverURL].IsConnected);
OnMqttConnect.Invoke(serverURL);
}
}
@ -72,7 +71,7 @@ namespace EGFramework{ @@ -72,7 +71,7 @@ namespace EGFramework{
if(MqttDevices.ContainsKey(serverURL) && MqttDevices[serverURL].IsConnected){
await MqttDevices[serverURL].DisconnectAsync(new MqttClientDisconnectOptionsBuilder().WithReason(MqttClientDisconnectOptionsReason.NormalDisconnection).Build());
}else{
GD.Print("Not connect");
EG.Print("Not connect");
}
}
@ -86,9 +85,9 @@ namespace EGFramework{ @@ -86,9 +85,9 @@ namespace EGFramework{
.Build();
if(MqttDevices.ContainsKey(serverURL) && MqttDevices[serverURL].IsConnected){
await MqttDevices[serverURL].SubscribeAsync(mqttSubscribeOptions,CancellationToken.None);
GD.Print("Subscribe "+Theme+" success!");
EG.Print("Subscribe "+Theme+" success!");
}else{
GD.Print("Not connect");
EG.Print("Not connect");
}
}
@ -118,7 +117,7 @@ namespace EGFramework{ @@ -118,7 +117,7 @@ namespace EGFramework{
.Build();
if(MqttDevices.ContainsKey(serverURL) && MqttDevices[serverURL].IsConnected){
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 @@ @@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Godot;
namespace EGFramework{
/// <summary>
@ -55,7 +54,7 @@ namespace EGFramework{ @@ -55,7 +54,7 @@ namespace EGFramework{
//break;
}
});
GD.Print("-----Read"+messageId+" ----");
EG.Print("-----Read"+messageId+" ----");
//return null;
}
RTUCache.Clear();
@ -118,7 +117,7 @@ namespace EGFramework{ @@ -118,7 +117,7 @@ namespace EGFramework{
//break;
}
});
GD.Print("-----Write"+messageId+" ----");
EG.Print("-----Write"+messageId+" ----");
//return null;
}
RTUCache.Clear();
@ -175,7 +174,7 @@ namespace EGFramework{ @@ -175,7 +174,7 @@ namespace EGFramework{
//break;
}
});
GD.Print("-----Read"+messageId+" ----");
EG.Print("-----Read"+messageId+" ----");
//return null;
}
TCPCache.Clear();
@ -222,7 +221,7 @@ namespace EGFramework{ @@ -222,7 +221,7 @@ namespace EGFramework{
//break;
}
});
GD.Print("-----Write"+messageId+" ----");
EG.Print("-----Write"+messageId+" ----");
//return null;
}
TCPCache.Clear();

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

@ -181,13 +181,13 @@ namespace EGFramework{ @@ -181,13 +181,13 @@ namespace EGFramework{
}
if(ReceivedCache[serialPort.PortName].Length >= MinDataPackLength){
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));
ReceivedCache[serialPort.PortName] = new byte[0];
MinDataPackLength = 0;
//this.EGOnReceivedData(new ResponseMsg(str,buffer,serialPort.PortName,ProtocolType.SerialPort));
}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]);
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; @@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Godot;
using Renci.SshNet;
namespace EGFramework{
@ -43,7 +42,7 @@ namespace EGFramework{ @@ -43,7 +42,7 @@ namespace EGFramework{
}else{
CancellationTokenSource sourceReconnect = new CancellationTokenSource();
CancellationToken tokenReconnect = sourceReconnect.Token;
tokenReconnect.Register(() => Godot.GD.Print("Ssh connect timeout!"));
tokenReconnect.Register(() => EG.Print("Ssh connect timeout!"));
await SshClientDevices[host].ConnectAsync(tokenReconnect);
if(!SshClientDevices[host].IsConnected){
return false;
@ -56,7 +55,7 @@ namespace EGFramework{ @@ -56,7 +55,7 @@ namespace EGFramework{
SshClient client = new SshClient(host, username, password);
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token;
token.Register(() => Godot.GD.Print("Ssh connect timeout!"));
token.Register(() => EG.Print("Ssh connect timeout!"));
source.CancelAfter(TimeOutDelay);
await client.ConnectAsync(token);
if(!client.IsConnected){

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

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

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

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

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

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

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

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

Loading…
Cancel
Save