From e8430eb96bd6174022fcbd15ca51a40cd16797c1 Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Wed, 22 May 2024 15:04:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=85=85=E7=94=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ModbusTcpMaster/ModbusTcpMaster.cs | 1 + Service/Cloud/Client/CloudClient.cs | 8 ++++++++ Service/Cloud/Handler/CarCanStartHandler.cs | 20 +++++++++++++++++++ Service/Cloud/Handler/SignInRespHandler.cs | 6 +++++- .../{PowerChangeCommand.cs => CarCanStart.cs} | 2 +- 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 Service/Cloud/Handler/CarCanStartHandler.cs rename Service/Cloud/Msg/Cloud/Req/{PowerChangeCommand.cs => CarCanStart.cs} (95%) diff --git a/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs b/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs index e4ad4aa..380d03d 100644 --- a/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs +++ b/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs @@ -118,6 +118,7 @@ public class ModbusTcpMaster if (result.IsSuccess) return result.Content; return null; + } public bool WriteValue(ModbusProperty property) diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs index 3a6f906..efb7b77 100644 --- a/Service/Cloud/Client/CloudClient.cs +++ b/Service/Cloud/Client/CloudClient.cs @@ -18,6 +18,7 @@ using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; using Service.Cloud.Handler; using Service.Cloud.Msg; +using Service.Cloud.Msg.Cloud.Req; using Service.Cloud.Msg.Host.Req; namespace Service.Cloud.Client; @@ -55,9 +56,16 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR public int Encrypt { get; set; } public string? AesKey { get; set; } + + public bool Authed { get; set; } #endregion + #region Cmd + + public CarCanStart? CarCanStart { get; set; } + + #endregion private IMqttClient? MqttClient; diff --git a/Service/Cloud/Handler/CarCanStartHandler.cs b/Service/Cloud/Handler/CarCanStartHandler.cs new file mode 100644 index 0000000..d07833d --- /dev/null +++ b/Service/Cloud/Handler/CarCanStartHandler.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using Service.Cloud.Client; +using Service.Cloud.Common; +using Service.Cloud.Msg.Cloud.Req; + +namespace Service.Cloud.Handler; + +public class CarCanStartHandler : IBaseHandler +{ + public bool CanHandle(string cmd) + { + return CloudConst.carCanStart == cmd; + } + + public void Handle(string t) + { + CarCanStart? carCanStart = JsonConvert.DeserializeObject(t); + CloudClientMgr.CloudClient.CarCanStart = carCanStart; + } +} \ No newline at end of file diff --git a/Service/Cloud/Handler/SignInRespHandler.cs b/Service/Cloud/Handler/SignInRespHandler.cs index 2b4569a..218b52a 100644 --- a/Service/Cloud/Handler/SignInRespHandler.cs +++ b/Service/Cloud/Handler/SignInRespHandler.cs @@ -1,7 +1,7 @@ using HybirdFrameworkCore.Autofac.Attribute; using Newtonsoft.Json; +using Service.Cloud.Client; using Service.Cloud.Common; -using Service.Cloud.Msg; using Service.Cloud.Msg.Cloud.Resp; namespace Service.Cloud.Handler; @@ -13,6 +13,10 @@ public class SignInRespHandler : IBaseHandler public void Handle(string t) { SignInResp? signInResp = JsonConvert.DeserializeObject(t); + if (signInResp != null) + { + CloudClientMgr.CloudClient.Authed = signInResp.re == 0; + } } public bool CanHandle(string cmd) diff --git a/Service/Cloud/Msg/Cloud/Req/PowerChangeCommand.cs b/Service/Cloud/Msg/Cloud/Req/CarCanStart.cs similarity index 95% rename from Service/Cloud/Msg/Cloud/Req/PowerChangeCommand.cs rename to Service/Cloud/Msg/Cloud/Req/CarCanStart.cs index dad7d68..a5fe31b 100644 --- a/Service/Cloud/Msg/Cloud/Req/PowerChangeCommand.cs +++ b/Service/Cloud/Msg/Cloud/Req/CarCanStart.cs @@ -10,7 +10,7 @@ namespace Service.Cloud.Msg.Cloud.Req /// /// 1 云平台下发车辆开始换电指令 /// - public class PowerChangeCommand + public class CarCanStart { /// /// 订单号