From 7f7a9ad088c00d069895495b1195db85e1cacf50 Mon Sep 17 00:00:00 2001 From: lxw Date: Fri, 31 May 2024 17:20:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E5=9C=BA=E6=B5=8B=E8=AF=95=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Cloud/Client/CloudClient.cs | 58 +++++++++++++++-------------- Service/Execute/Api/CloudApi.cs | 2 +- Service/Execute/Api/TboxApi.cs | 13 ++++++- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs index 2d499b2..3688969 100644 --- a/Service/Cloud/Client/CloudClient.cs +++ b/Service/Cloud/Client/CloudClient.cs @@ -237,38 +237,42 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR public void Publish(T data) where T : ICmd { - Model model = new Model + if (MqttClient.IsConnected) { - Header = new Header() + Model model = new Model { - cmd = data.GetCmd(), - cipherFlag = Encrypt, - id = GetIncrementId(), - sid = StationNo, - timeStamp = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000 - }, - body = data - }; + Header = new Header() + { + cmd = data.GetCmd(), + cipherFlag = Encrypt, + id = GetIncrementId(), + sid = StationNo, + timeStamp = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000 + }, + body = data + }; - model.dataSign = "";//SignData(model); + model.dataSign = "";//SignData(model); - var settings = new JsonSerializerSettings() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - DateFormatString = "yyyy-MM-dd HH:mm:ss", - NullValueHandling = NullValueHandling.Ignore - }; - Log.Info(JsonConvert.SerializeObject(model, settings)); - var appMsg = new MqttApplicationMessage - { - Topic = PubTopic, - Payload = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(model, settings)), - QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce, - Retain = false - }; + var settings = new JsonSerializerSettings() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + DateFormatString = "yyyy-MM-dd HH:mm:ss", + NullValueHandling = NullValueHandling.Ignore + }; + Log.Info(JsonConvert.SerializeObject(model, settings)); + var appMsg = new MqttApplicationMessage + { + Topic = PubTopic, + Payload = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(model, settings)), + QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce, + Retain = false + }; - MqttClient.PublishAsync(appMsg); - MqttClient.PublishAsync(appMsg); + MqttClient.PublishAsync(appMsg); + MqttClient.PublishAsync(appMsg); + } + } private string SignData(Model model) where T : ICmd diff --git a/Service/Execute/Api/CloudApi.cs b/Service/Execute/Api/CloudApi.cs index 1ef9d97..636cb15 100644 --- a/Service/Execute/Api/CloudApi.cs +++ b/Service/Execute/Api/CloudApi.cs @@ -57,7 +57,7 @@ public abstract class CloudApi UploadSwapOrder uploadSwapOrder = new() { sn=StaticStationInfo.StationNo, - son = swapOrder.CloudSn, + son = swapOrder.Sn, cn = swapOrder.VehicleNo, so = seq, ct = swapOrder.VehicleEnterTime, diff --git a/Service/Execute/Api/TboxApi.cs b/Service/Execute/Api/TboxApi.cs index 9019585..203fff4 100644 --- a/Service/Execute/Api/TboxApi.cs +++ b/Service/Execute/Api/TboxApi.cs @@ -91,7 +91,12 @@ public class TBoxApi { Thread.Sleep(100); var unLockCar = await UnLockCar(carNo); - bools.Add(unLockCar); + if (unLockCar) + { + + bools.Add(unLockCar); + } + } return bools.Select(i => i).Count() > _successTimes; @@ -105,7 +110,11 @@ public class TBoxApi { Thread.Sleep(100); var unLockCar = await LockCar(carNo); - bools.Add(unLockCar); + if (unLockCar) + { + + bools.Add(unLockCar); + } } return bools.Select(i => i).Count() > _successTimes;