From 53c75f1c14bfc3c974992a8de0f4289433572954 Mon Sep 17 00:00:00 2001 From: zby <24947@USER> Date: Mon, 9 Sep 2024 14:24:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=A8=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/Constant/InfoEnum.cs | 1 + Service/Execute/Api/RfidApi.cs | 4 +- Service/Execute/Step/CarCtrlState.cs | 18 ++++- Service/Execute/Step/CarPrepareState.cs | 58 +++++++++++++-- Service/Execute/Step/DoSwappingState.cs | 55 ++------------ Service/Execute/Step/StationReadyState.cs | 27 ++++++- Service/Execute/Step/SwapDoneState.cs | 74 ++++++++++++++----- Service/Led/LedClient.cs | 16 +++- .../BatteryStatusReportedReqHandler.cs | 2 +- .../Plc/Handler/SummaryFailuresReqHandler.cs | 1 + Service/Sound/SoundClient/SoundClient.cs | 11 +++ Service/Ups/Client/UpsClient.cs | 7 +- WebStarter/Program.cs | 4 + WebStarter/appsettings.prod.json | 2 +- 14 files changed, 191 insertions(+), 89 deletions(-) diff --git a/Entity/Constant/InfoEnum.cs b/Entity/Constant/InfoEnum.cs index fc4d1e8..29cc499 100644 --- a/Entity/Constant/InfoEnum.cs +++ b/Entity/Constant/InfoEnum.cs @@ -58,6 +58,7 @@ public class InfoEnum [Info("前进","前进")] advance,//34 [Info("后退", "后退")] Backoff, [Info("停好了", "停好了")] Itparked, + [Info("退出重新停车", "退出重新停车")] upcar, } diff --git a/Service/Execute/Api/RfidApi.cs b/Service/Execute/Api/RfidApi.cs index a7fc8e1..a7fc1f0 100644 --- a/Service/Execute/Api/RfidApi.cs +++ b/Service/Execute/Api/RfidApi.cs @@ -103,11 +103,11 @@ public class RfidApi Log.Info("RfidApi ReadRfid"); - string readUrl = BASE_URL + "/Api/BeginRead"; + // string readUrl = BASE_URL + "/Api/BeginRead"; string url = BASE_URL + "/Api/ReadRfidData"; try { - var vBeginRead = await _httpClient.GetStringAsync(readUrl); + // var vBeginRead = await _httpClient.GetStringAsync(readUrl); string s = await _httpClient.GetStringAsync(url); Log.Info($"ReadRfid resp={s}"); if (s != String.Empty) diff --git a/Service/Execute/Step/CarCtrlState.cs b/Service/Execute/Step/CarCtrlState.cs index df4524a..8de4718 100644 --- a/Service/Execute/Step/CarCtrlState.cs +++ b/Service/Execute/Step/CarCtrlState.cs @@ -91,12 +91,22 @@ public class CarCtrlState : IState // SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrUnLockCar); LedClient.SendMsgByKey(InfoEnum.SwapInfo.ErrUnLockCar.GetLed()); SoundClient = AppInfo.Container.Resolve(); - if (b == 0) { - SoundClient.SoundPlay(SoundEnum.music48); + + + }, false, () => { machine.ExceptionReason = ExceptionReason.UnLockCarError; + if (b == 0) + { + + SoundClient = AppInfo.Container.Resolve(); + SoundClient.SoundPlay(SoundEnum.music104); + Thread.Sleep(3000); + SoundClient.SoundPlay(SoundEnum.music105); + Thread.Sleep(3000); b = 1; + } - - }, false, () => { machine.ExceptionReason = ExceptionReason.UnLockCarError; } + } + , 10, InvokeStatus.None); } } diff --git a/Service/Execute/Step/CarPrepareState.cs b/Service/Execute/Step/CarPrepareState.cs index 9a56b2c..8a98ae8 100644 --- a/Service/Execute/Step/CarPrepareState.cs +++ b/Service/Execute/Step/CarPrepareState.cs @@ -7,6 +7,7 @@ using Entity.Dto; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Configuration; using log4net; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using Repository.Station; using Service.Execute.Api; using Service.Execute.Model; @@ -161,6 +162,7 @@ public class CarPrepareState : IState /// public InvokeStatus CheckTBoxConnectFlag(SwappingStateMachine machine) { + int t = 0; return Invoker.Invoke("check TBox connect", 1000, 10, machine.IsCanceled, () => machine.BoxConnectFlag, () => { @@ -172,15 +174,30 @@ public class CarPrepareState : IState } }, () => { - SoundClient = AppInfo.Container.Resolve(); - SoundClient.SoundPlay(SoundEnum.music43); + + if (t==0) + { + SoundClient = AppInfo.Container.Resolve(); + SoundClient.SoundPlay(SoundEnum.music102); + Thread.Sleep(3000); + SoundClient.SoundPlay(SoundEnum.music103); + Thread.Sleep(3000); + } + //machine.ExceptionReason = ExceptionReason.ConnTBoxError; //SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrorTBoxConn); }, false, () => { - SoundClient = AppInfo.Container.Resolve(); + //SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address03")); - SoundClient.SoundPlay(SoundEnum.music43); + if (t == 0) + { + SoundClient = AppInfo.Container.Resolve(); + SoundClient.SoundPlay(SoundEnum.music102); + Thread.Sleep(3000); + SoundClient.SoundPlay(SoundEnum.music103); + Thread.Sleep(3000); + } //machine.ExceptionReason = ExceptionReason.ConnTBoxError; LedClient.SendMsgByKey(InfoEnum.SwapInfo.ErrorTBoxConn.GetLed()); @@ -239,6 +256,7 @@ public class CarPrepareState : IState /// public InvokeStatus CheckTBoxVelLocalFlag(SwappingStateMachine machine) { + int q = 0; return Invoker.Invoke("check TBox VelLocal", 1000, 20, machine.IsCanceled, () => machine.BoxLocalCheckFlag, () => { @@ -247,12 +265,22 @@ public class CarPrepareState : IState if (tBoxCarInfoModel.CarNo!.Trim().Equals(machine.RfidReadModel!.VelVin.Trim())) { + machine.BoxLocalCheckFlag = true; machine.BoxCarInfoModel = tBoxCarInfoModel; } }, () => { machine.ExceptionReason = ExceptionReason.LocalCheckVarError; }, true, () => { machine.ExceptionReason = ExceptionReason.LocalCheckVarError; + if (q == 0) + { + SoundClient = AppInfo.Container.Resolve(); + SoundClient.SoundPlay(SoundEnum.music108); + Thread.Sleep(3000); + SoundClient.SoundPlay(SoundEnum.music109); + Thread.Sleep(3000); + q = 1; + } } , 3, InvokeStatus.TimeOut); } @@ -304,6 +332,7 @@ public class CarPrepareState : IState /// public InvokeStatus SelectPack(SwappingStateMachine machine) { + int e = 0; SwapAmtOrder? swapAmtOrder = _CommonMgr.QueryAmtOrder(machine); @@ -327,8 +356,18 @@ public class CarPrepareState : IState LedClient.SendMsgByKey(InfoEnum.SwapInfo.ErrorSelectPack.GetLed()); SoundClient = AppInfo.Container.Resolve(); - SoundClient.SoundPlay(SoundEnum.music49); - + if (e==0) + { + + SoundClient = AppInfo.Container.Resolve(); + SoundClient.SoundPlay(SoundEnum.music106); + Thread.Sleep(3000); + SoundClient.SoundPlay(SoundEnum.music107); + Thread.Sleep(3000); + + e = 1; + } + // _log.Info($"SelectPack error CanSwap={machine.SwapOrderBatteryInfo.CanSwap}"); @@ -346,7 +385,12 @@ public class CarPrepareState : IState machine.ExceptionReason = ExceptionReason.SelectPackError; SoundClient = AppInfo.Container.Resolve(); //SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address09")); - SoundClient.SoundPlay(SoundEnum.music49); + if (e == 0) + { + SoundClient.SoundPlay(SoundEnum.music49); + e = 1; + } + // SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrorSelectPack); } , false, () => { }, 10, InvokeStatus.None); diff --git a/Service/Execute/Step/DoSwappingState.cs b/Service/Execute/Step/DoSwappingState.cs index 82768b4..98cfd44 100644 --- a/Service/Execute/Step/DoSwappingState.cs +++ b/Service/Execute/Step/DoSwappingState.cs @@ -147,13 +147,7 @@ public class DoSwappingState : IState return SwappingStateMachine.ReturnWithInvokeErr(beginRadar, ExceptionReason.None); } - //车辆离开 - var adjustCarByRadar = AdjustCarByRadar(machine); - machine.Reset(); - if (InvokeStatus.Done != adjustCarByRadar) - { - return SwappingStateMachine.ReturnWithInvokeErr(adjustCarByRadar, ExceptionReason.None); - } + @@ -207,29 +201,7 @@ public class DoSwappingState : IState //} - public InvokeStatus AdjustCarByRadar(SwappingStateMachine machine) - { - - return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled, - () => - { - //新增小步 - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarOutFlag, - machine); - var carState = PadarMgr._PadarClient?.CarState; - return carState.HasValue && (carState.Value == 1 || carState.Value == 2 || carState.Value == 3 || carState.Value == 4 || carState.Value == 5); - }, - () => - { - switch (PadarMgr._PadarClient?.CarState) - { - case 6: - _log.Info("车辆未驶离"); - break; - - } - }); - } + /// /// 下发plc启动换电 @@ -247,17 +219,7 @@ public class DoSwappingState : IState { var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No, machine.SwapOrderBatteryInfo.UpBinInfo.No); - if (c==0) - { - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag, - machine); - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.DistributeSelectPackFlag, - machine); - SoundClient = AppInfo.Container.Resolve(); - SoundClient.SoundPlay(SoundEnum.music91); - Thread.Sleep(3000); - SoundClient.SoundPlay(SoundEnum.music90); - } + //查詢當前任務狀態是否被更改 if (startSwapping) @@ -321,6 +283,7 @@ public class DoSwappingState : IState if(i==0) { SoundClient = AppInfo.Container.Resolve(); + SoundClient.SoundPlay(SoundEnum.music51); //SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoUnPack); i = 1; @@ -441,16 +404,14 @@ public class DoSwappingState : IState //SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address19")); if (v == 0) { - + SoundClient.SoundPlay(SoundEnum.music76); + Thread.Sleep(3000); + SoundClient.SoundPlay(SoundEnum.music77); _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag, machine); _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarOutFlag, machine); - - SoundClient.SoundPlay(SoundEnum.music77); - Thread.Sleep(3000); - SoundClient.SoundPlay(SoundEnum.music76); - + v = 1; } //断连Tbox diff --git a/Service/Execute/Step/StationReadyState.cs b/Service/Execute/Step/StationReadyState.cs index 0a83ed5..34fdef1 100644 --- a/Service/Execute/Step/StationReadyState.cs +++ b/Service/Execute/Step/StationReadyState.cs @@ -177,8 +177,7 @@ public class StationReadyState : IState /// public InvokeStatus ControlRadar(SwappingStateMachine machine, byte flag) { - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarInFlag, - machine); + return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled, () => PadarMgr._PadarClient?.CarState > 0, () => { PadarMgr._PadarClient?.PadarControl(flag); }); @@ -189,6 +188,7 @@ public class StationReadyState : IState public InvokeStatus AdjustCarByRadar(SwappingStateMachine machine) { + int che = 0; return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled, () => @@ -197,6 +197,8 @@ public class StationReadyState : IState if (PadarMgr._PadarClient?.CarState==6) { + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarInFlag, + machine); LedClient.SendMsgByKey(InfoEnum.SwapInfo.Backoff.GetLed()); } @@ -214,6 +216,16 @@ public class StationReadyState : IState break; case 3: _log.Info("radar 角度偏移过大"); + SoundClient = AppInfo.Container.Resolve(); + //SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address25")); + if (che == 0) + { + LedClient.SendMsgByKey(InfoEnum.SwapInfo.upcar.GetLed()); + SoundClient.SoundPlay(SoundEnum.music100); + Thread.Sleep(3000); + SoundClient.SoundPlay(SoundEnum.music101); + che = 1; + } break; case 4: _log.Info("radar 车辆靠后"); @@ -290,10 +302,12 @@ public class StationReadyState : IState private InvokeStatus ReadRfid(SwappingStateMachine machine) { + int e = 0; //开始读rifd return Invoker.Invoke("read rfid", 3000, 20, machine.IsCanceled, - () => machine.RfidReadFlag, () => + () => machine.RfidReadFlag,() => { + Task rfidReadModel = RfidApi.ReadRfid(); rfidReadModel.Wait(); var machineRfidReadModel = rfidReadModel.Result; @@ -333,7 +347,12 @@ public class StationReadyState : IState machine.LedTool!.WriteProgramContent(InfoEnum.SwapInfo.ErrorReadRfid.GetLed()); SoundClient = AppInfo.Container.Resolve(); //SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address02")); - SoundClient.SoundPlay(SoundEnum.music42); + if (e == 0) + { + SoundClient.SoundPlay(SoundEnum.music42); + e = 1; + } + //SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrorReadRfid); //LedClient.SendMsgByKey(InfoEnum.SwapInfo.ErrorReadRfid.GetLed()); }, false, () => { machine.ExceptionReason = ExceptionReason.ReadRfidError; }, 10, diff --git a/Service/Execute/Step/SwapDoneState.cs b/Service/Execute/Step/SwapDoneState.cs index fb10083..af0826c 100644 --- a/Service/Execute/Step/SwapDoneState.cs +++ b/Service/Execute/Step/SwapDoneState.cs @@ -57,16 +57,16 @@ public class SwapDoneState : IState }); - if (machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success) - { - //上传云平台换电状态 - // machine.BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.SwapDoneWithVel; - // CloudApi.SendStateLog(machine.SwapOrder, machine.BusinessSwappingForCloudState); - } + //if (machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success) + //{ + // //上传云平台换电状态 + // // machine.BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.SwapDoneWithVel; + // // CloudApi.SendStateLog(machine.SwapOrder, machine.BusinessSwappingForCloudState); + //} ////云平台没有匹配的失败状态 ////车辆上锁 ,提示请驶离 - //InvokeStatus lockCar = LockCar(machine); + InvokeStatus lockCar = LockCar(machine); //if (lockCar != InvokeStatus.Done) //{ @@ -75,18 +75,30 @@ public class SwapDoneState : IState LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoCarLeave.GetLed()); + + + //车辆离开 + var adjustCarByRadar = AdjustCarByRadar(machine); + machine.Reset(); + if (InvokeStatus.Done != adjustCarByRadar) + { + return SwappingStateMachine.ReturnWithInvokeErr(adjustCarByRadar, ExceptionReason.None); + } + + + //出口雷达监测 - //InvokeStatus existRadar = ExistRadar(machine); - //if (existRadar != InvokeStatus.Done) - //{ - // return SwappingStateMachine.ReturnWithInvokeErr(existRadar, ExceptionReason.None); - //} - ////关闭雷达 - //var closeRadar = ControlRadar(machine, 0); - //if (InvokeStatus.Done != closeRadar) - //{ - // return SwappingStateMachine.ReturnWithInvokeErr(closeRadar, ExceptionReason.None); - //} + //InvokeStatus existRadar = ExistRadar(machine); + //if (existRadar != InvokeStatus.Done) + //{ + // return SwappingStateMachine.ReturnWithInvokeErr(existRadar, ExceptionReason.None); + //} + ////关闭雷达 + //var closeRadar = ControlRadar(machine, 0); + //if (InvokeStatus.Done != closeRadar) + //{ + // return SwappingStateMachine.ReturnWithInvokeErr(closeRadar, ExceptionReason.None); + //} @@ -114,6 +126,32 @@ public class SwapDoneState : IState }); } + + + public InvokeStatus AdjustCarByRadar(SwappingStateMachine machine) + { + + return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled, + () => + { + //新增小步 + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarOutFlag, + machine); + var carState = PadarMgr._PadarClient?.CarState; + return carState.HasValue && (carState.Value == 1 || carState.Value == 2 || carState.Value == 3 || carState.Value == 4 || carState.Value == 5); + }, + () => + { + switch (PadarMgr._PadarClient?.CarState) + { + case 6: + _log.Info("车辆未驶离"); + break; + + } + }); + } + /// /// 车辆上锁 /// diff --git a/Service/Led/LedClient.cs b/Service/Led/LedClient.cs index 80ce61c..4e7d1cd 100644 --- a/Service/Led/LedClient.cs +++ b/Service/Led/LedClient.cs @@ -1,6 +1,7 @@ using System.Net.Sockets; using HybirdFrameworkCore.Utils; using log4net; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; namespace Service.Led; @@ -91,7 +92,8 @@ public class LedClient {"前进",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x0C,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3B,0x3A,0x4D,0x75,0x6B,0x61,0x00,0x00,0x0D,0x0A, }}, {"后退",new byte[]{ 0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x0E,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3B,0x3A,0x4D,0x75,0x6E,0x64,0x75,0x72,0x00,0x00,0x0D,0x0A, }}, {"停好了",new byte[]{ 0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x14,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3B,0x3A,0x49,0x74,0x75,0x20,0x64,0x69,0x70,0x61,0x72,0x6B,0x69,0x72,0x00,0x00,0x0D,0x0A,}}, - + + {"退出重新停车",new byte[]{ 0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x21, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3B, 0x3A, 0x4B, 0x65, 0x6C, 0x75, 0x61, 0x72, 0x20, 0x64, 0x61, 0x6E, 0x20, 0x70, 0x61, 0x72, 0x6B, 0x69, 0x72, 0x20, 0x6B, 0x65, 0x6D, 0x62, 0x61, 0x6C, 0x69, 0x00, 0x00, 0x0D, 0x0A, }}, }; #endregion @@ -105,10 +107,17 @@ public class LedClient { _ip = ip; _port = port; - Connect(); + InitClient(); + // Connect(); return _socket.Connected; } + public static void InitClient() + { + Task.Run(Connect); + } + + private static void Connect() { Log.Info($"begin connect {_ip}:{_port}"); @@ -120,7 +129,8 @@ public class LedClient public static bool InnerSend(byte[] bytes) { - Connect(); + InitClient(); + // Connect(); if (_socket?.Connected ?? true) { _socket?.Send(bytes); diff --git a/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs b/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs index e918605..f53fc85 100644 --- a/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs +++ b/Service/Plc/Handler/BatteryStatusReportedReqHandler.cs @@ -44,7 +44,7 @@ public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler(); public EquipAlarmRecordRepository _equipAlarmRecordRepository=AppInfo.Container.Resolve(); public EquipAlarmProcessRecordRepository _equipAlarmProcessRecordRepository=AppInfo.Container.Resolve(); - + + + + public UpsClient() { ReadAction = BatchRead; Ip = "192.168.3.100"; - Port = 23; + Port = 44; Duration = 1000; AutoReConnect = true; ByteSeq = EndingConst.ByteSeq.BA; diff --git a/WebStarter/Program.cs b/WebStarter/Program.cs index 865ecb2..3420b64 100644 --- a/WebStarter/Program.cs +++ b/WebStarter/Program.cs @@ -186,6 +186,7 @@ if (AppSettingsHelper.GetBool("padar", "enable")) } + if (AppSettingsHelper.GetBool("led", "enable")) { LedClient.Init(AppSettingsHelper.GetContent("led", "ip"), Convert.ToInt32(AppSettingsHelper.GetContent("led", "port"))); @@ -204,6 +205,9 @@ if (AppSettingsHelper.GetBool("swap", "enable")) AppInfo.Container = app.Services.GetAutofacRoot(); //ClientMgr.InitClient(); + + +//UpsMgr.UpsInit(); //ups if (AppSettingsHelper.GetBool("ups", "enable")) { diff --git a/WebStarter/appsettings.prod.json b/WebStarter/appsettings.prod.json index 6b36c37..581f8c5 100644 --- a/WebStarter/appsettings.prod.json +++ b/WebStarter/appsettings.prod.json @@ -143,7 +143,7 @@ "Enabled": false }, "led": { - "enable": true, + "enable": false, "ip": "192.168.3.79", "port": 10000 }