From cacf63a3124d0d5ce425bee5f3deb280dd002ab5 Mon Sep 17 00:00:00 2001 From: zby <24947@USER> Date: Fri, 6 Sep 2024 09:22:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=89=8D=E7=AB=AF=E4=B8=8A?= =?UTF-8?q?=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/Constant/InfoEnum.cs | 12 +-- Service/Execute/Mgr/CommonMgr.cs | 3 + Service/Execute/Step/BeginState.cs | 5 +- Service/Execute/Step/CarCtrlState.cs | 2 + Service/Execute/Step/CarPrepareState.cs | 2 +- Service/Execute/Step/DoSwappingState.cs | 115 ++++++++++++++++++---- Service/Execute/Step/StationReadyState.cs | 29 ++++-- Service/Execute/SwappingStateMachine.cs | 17 ++-- Service/Led/LedClient.cs | 2 +- 9 files changed, 142 insertions(+), 45 deletions(-) diff --git a/Entity/Constant/InfoEnum.cs b/Entity/Constant/InfoEnum.cs index c6f1560..fc4d1e8 100644 --- a/Entity/Constant/InfoEnum.cs +++ b/Entity/Constant/InfoEnum.cs @@ -106,19 +106,19 @@ public class InfoEnum //小步状态 public enum BusinessSwappingStep { - [Const("空闲")] Idel, + [Const("空闲")] Idel, [Const("车辆到站(入口雷达检测到车辆驶入)")] RadarInFlag, [Const("rfid扫描完成")] RfidReadFlag, - //[Const("云平台车辆认证")] CloudVelCheckFlag, + [Const("云平台车辆认证")] CloudVelCheckFlag, [Const("车辆到位")] CarInPositionFlag, - // [Const("云平台下发换电指令")] CloudCarCanStartFlag, + [Const("云平台下发换电指令")] CloudCarCanStartFlag, [Const("车辆解锁")] VelUnlockFlag, - // [Const("下发plc选包")] DistributeSelectPackFlag, + [Const("下发plc选包")] DistributeSelectPackFlag, [Const("开始换电")] StartSwappingFlag, [Const("拆旧电池完成")] UnOldBatteryFlag, - //[Const("入库旧电池完成")] StorageOldBatteryFlag, - //[Const("搬运新电池完成")] OutNewBatteryFlag, + [Const("入库旧电池完成")] StorageOldBatteryFlag, + [Const("搬运新电池完成")] OutNewBatteryFlag, [Const("安装新电池完成")] InstallNewBatteryFlag, [Const("安装完成")] FinishNewBatteryFlag, [Const("车辆上锁")] VelLockFlag, diff --git a/Service/Execute/Mgr/CommonMgr.cs b/Service/Execute/Mgr/CommonMgr.cs index 5407947..66d36f3 100644 --- a/Service/Execute/Mgr/CommonMgr.cs +++ b/Service/Execute/Mgr/CommonMgr.cs @@ -45,8 +45,11 @@ public class CommonMgr StartTime = DateTime.Now, Status = 1 }; + + machine.StepModel[stepModel.StepNo.ToString()] = stepModel; + if (machine.SwapOrder != null) { if (!string.IsNullOrEmpty(machine.SwapOrder.Sn)) diff --git a/Service/Execute/Step/BeginState.cs b/Service/Execute/Step/BeginState.cs index 1ae4c84..3e08f3b 100644 --- a/Service/Execute/Step/BeginState.cs +++ b/Service/Execute/Step/BeginState.cs @@ -7,8 +7,9 @@ public class BeginState: IState return new StateResult() { - - SwappingState = SwappingState.StationReady + + SwappingState = SwappingState.StationReady + //SwappingState = SwappingState.DoSwapping }; } } \ No newline at end of file diff --git a/Service/Execute/Step/CarCtrlState.cs b/Service/Execute/Step/CarCtrlState.cs index 1d7ddce..df4524a 100644 --- a/Service/Execute/Step/CarCtrlState.cs +++ b/Service/Execute/Step/CarCtrlState.cs @@ -71,6 +71,8 @@ public class CarCtrlState : IState machine.ManualConfirmCarUnlockFlag = false; machine.BoxCarInfoModel = carInfo.Result; machine.VelUnlockFlag = true; + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.CloudCarCanStartFlag, + machine); _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelUnlockFlag, machine); if (a==0) diff --git a/Service/Execute/Step/CarPrepareState.cs b/Service/Execute/Step/CarPrepareState.cs index ab4588a..9a56b2c 100644 --- a/Service/Execute/Step/CarPrepareState.cs +++ b/Service/Execute/Step/CarPrepareState.cs @@ -219,7 +219,7 @@ public class CarPrepareState : IState { SoundClient = AppInfo.Container.Resolve(); //SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address03")); - SoundClient.SoundPlay(SoundEnum.music43); + // SoundClient.SoundPlay(SoundEnum.music43); //machine.ExceptionReason = ExceptionReason.ConnTBoxError; //SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrorTBoxConn); }, false, () => diff --git a/Service/Execute/Step/DoSwappingState.cs b/Service/Execute/Step/DoSwappingState.cs index 52568ce..82768b4 100644 --- a/Service/Execute/Step/DoSwappingState.cs +++ b/Service/Execute/Step/DoSwappingState.cs @@ -33,11 +33,72 @@ public class DoSwappingState : IState public StateResult Handle(SwappingStateMachine machine) { //上报云平台换电开始 - // machine.BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.BeginSwap; - // machine.BusinessSwappingStateUpdateTime = DateTime.Now; - // _log.Info($"BusinessSwappingForCloudState={machine.BusinessSwappingForCloudState}"); + // machine.BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.BeginSwap; + // machine.BusinessSwappingStateUpdateTime = DateTime.Now; + // _log.Info($"BusinessSwappingForCloudState={machine.BusinessSwappingForCloudState}"); // CloudApi.SendStateLog(machine.SwapOrder, InfoEnum.BusinessSwappingForCloudState.BeginSwap); + //while (true) + //{ + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.Idel, + // machine); + // Thread.Sleep(1000); + // //_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag, + // //machine); + + + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarInFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RfidReadFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.CloudVelCheckFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.CarInPositionFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.CloudCarCanStartFlag, + // machine); + // Thread.Sleep(1000); + + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelUnlockFlag, + // machine); + // Thread.Sleep(1000); + + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.DistributeSelectPackFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StorageOldBatteryFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag, + // machine); + // Thread.Sleep(1000); + // _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag, + // machine); + // Thread.Sleep(1000); + // //_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarOutFlag, + // // machine); + // Thread.Sleep(10000); + + // machine.Reset(); + + //} + @@ -86,12 +147,13 @@ public class DoSwappingState : IState return SwappingStateMachine.ReturnWithInvokeErr(beginRadar, ExceptionReason.None); } - // 车辆离开 - //var adjustCarByRadar = AdjustCarByRadar(machine); - //if (InvokeStatus.Done != adjustCarByRadar) - //{ - // return SwappingStateMachine.ReturnWithInvokeErr(adjustCarByRadar, ExceptionReason.None); - //} + //车辆离开 + var adjustCarByRadar = AdjustCarByRadar(machine); + machine.Reset(); + if (InvokeStatus.Done != adjustCarByRadar) + { + return SwappingStateMachine.ReturnWithInvokeErr(adjustCarByRadar, ExceptionReason.None); + } @@ -187,6 +249,10 @@ public class DoSwappingState : IState 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); @@ -200,8 +266,7 @@ public class DoSwappingState : IState _CommonMgr.UpdateSwapOrder(machine); machine.SwapStatus = 0; machine.StartSwappingFlag = true; - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag, - machine); + } } @@ -279,7 +344,9 @@ public class DoSwappingState : IState if (machine.InstallNewBatteryFlag) { - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag, + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag, + machine); + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StorageOldBatteryFlag, machine); } }, () => @@ -316,14 +383,19 @@ public class DoSwappingState : IState SoundClient = AppInfo.Container.Resolve(); if (b==0) { - SoundClient.SoundPlay(SoundEnum.music77); + // SoundClient.SoundPlay(SoundEnum.music77); + LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoPackFinish.GetLed()); b = 1; } - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag, + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag, machine); + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag, + machine); + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag, + machine); //SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition); machine.ToSafePositionFlag = true; machine.BusinessSwappingStateUpdateTime = DateTime.Now; @@ -369,9 +441,16 @@ public class DoSwappingState : IState //SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address19")); if (v == 0) { - SoundClient.SoundPlay(SoundEnum.music76); - Thread.Sleep(3000); + + _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 @@ -380,9 +459,7 @@ public class DoSwappingState : IState TBoxApi.DisConnect(machine.BoxCarInfoModel.CarNo); } //新增小步 - - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag, - machine); + } } }, () => diff --git a/Service/Execute/Step/StationReadyState.cs b/Service/Execute/Step/StationReadyState.cs index 1fbced6..0a83ed5 100644 --- a/Service/Execute/Step/StationReadyState.cs +++ b/Service/Execute/Step/StationReadyState.cs @@ -32,11 +32,14 @@ public class StationReadyState : IState public StateResult Handle(SwappingStateMachine machine) { + + + _log.Info($"'goto stationReady"); machine.Reset(); - machine.BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.Idle; - machine.BusinessSwappingStateUpdateTime = DateTime.Now; + //machine.BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.Idle; + //machine.BusinessSwappingStateUpdateTime = DateTime.Now; //判断换电站是否具备换电条件 前端页面 if (!IsAutoSwapping()) @@ -98,6 +101,9 @@ public class StationReadyState : IState public InvokeStatus PlcIsAuto(SwappingStateMachine machine) { + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.Idel, + machine); + int a = 0; bool isAuto = false; return Invoker.Invoke("check plc auto", 1000, 5, machine.IsCanceled, () => isAuto, @@ -171,6 +177,9 @@ 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); }); } @@ -185,9 +194,7 @@ public class StationReadyState : IState () => { LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoCarInPosition.GetLed()); - //新增小步 - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.CarInPositionFlag, - machine); + if (PadarMgr._PadarClient?.CarState==6) { LedClient.SendMsgByKey(InfoEnum.SwapInfo.Backoff.GetLed()); @@ -230,10 +237,12 @@ public class StationReadyState : IState beginRead.Wait(); if (!beginRead.Result) { + _log.Info("begin read rfid error"); } else { + machine.ExceptionReason = ExceptionReason.None; _log.Info("begin read done"); machine.BeginRfidReadFlag = true; @@ -243,7 +252,7 @@ public class StationReadyState : IState machine.LedTool.WriteProgramContent(InfoEnum.SwapInfo.ErrorReadRfid.GetLed()); SoundClient = AppInfo.Container.Resolve(); //SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address02")); - SoundClient.SoundPlay(SoundEnum.music74); + // SoundClient.SoundPlay(SoundEnum.music74); //SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrorReadRfid); //LedClient.SendMsgByKey(InfoEnum.SwapInfo.ErrorReadRfid.GetLed()); @@ -304,12 +313,12 @@ public class StationReadyState : IState //新增换电订单 machine.SwapOrder = _CommonMgr.SaveOrder(BuildOrder(machine.RfidReadModel)); //新增小步 - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.Idel, - machine); - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RadarInFlag, - machine); _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.RfidReadFlag, machine); + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.CloudVelCheckFlag, + machine); + + // 前端页面 _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.CarInPositionFlag, diff --git a/Service/Execute/SwappingStateMachine.cs b/Service/Execute/SwappingStateMachine.cs index d087f95..c9b9bd1 100644 --- a/Service/Execute/SwappingStateMachine.cs +++ b/Service/Execute/SwappingStateMachine.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using System.Reflection.PortableExecutable; using Autofac; using Entity.Attr; using Entity.Constant; @@ -73,16 +74,16 @@ public class SwappingStateMachine : IDisposable ["0"] = new StepModel { StepNo = 0, Status = 0, StepName = "空闲" }, ["1"] = new StepModel { StepNo = 1, Status = 0, StepName = "车辆到站(入口雷达检测到车辆驶入)" }, ["2"] = new StepModel { StepNo = 2, Status = 0, StepName = "rfid扫描完成" }, - //["3"] = new StepModel { StepNo = 3, Status = 0, StepName = "云平台车辆认证" }, + ["3"] = new StepModel { StepNo = 3, Status = 0, StepName = "云平台车辆认证" }, ["4"] = new StepModel { StepNo = 4, Status = 0, StepName = "车辆到位" }, - // ["5"] = new StepModel { StepNo = 5, Status = 0, StepName = "云平台下发换电指令" }, + ["5"] = new StepModel { StepNo = 5, Status = 0, StepName = "云平台下发换电指令" }, ["5"] = new StepModel { StepNo = 5, Status = 0, StepName = "车辆解锁" }, - //["6"] = new StepModel { StepNo = 6, Status = 0, StepName = "下发plc选包" }, + ["6"] = new StepModel { StepNo = 6, Status = 0, StepName = "下发plc选包" }, ["6"] = new StepModel { StepNo = 6, Status = 0, StepName = "开始换电" }, ["7"] = new StepModel { StepNo = 7, Status = 0, StepName = "拆旧电池完成" }, - //["8"] = new StepModel { StepNo = 8, Status = 0, StepName = "入库旧电池完成" }, - //["9"] = new StepModel { StepNo = 9, Status = 0, StepName = "搬运新电池完成" }, + ["8"] = new StepModel { StepNo = 8, Status = 0, StepName = "入库旧电池完成" }, + ["9"] = new StepModel { StepNo = 9, Status = 0, StepName = "搬运新电池完成" }, ["10"] = new StepModel { StepNo = 10, Status = 0, StepName = "安装新电池完成" }, ["11"] = new StepModel { StepNo = 11, Status = 0, StepName = "安装完成" }, ["12"] = new StepModel { StepNo = 12, Status = 0, StepName = "车辆上锁" }, @@ -270,6 +271,8 @@ public class SwappingStateMachine : IDisposable public void Reset() { + + Log.Info("reset data"); /*if (PlcMgr.PlcClient?.ReadTaskNo() == 1) @@ -441,7 +444,9 @@ public class SwappingStateMachine : IDisposable private void ResetOrderAmtStatus() { - // SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrorTBoxConn); + + + // SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrorTBoxConn); LedClient.SendMsgByKey(InfoEnum.SwapInfo.WelcomeInfo.GetLed()); diff --git a/Service/Led/LedClient.cs b/Service/Led/LedClient.cs index 1b42e42..80ce61c 100644 --- a/Service/Led/LedClient.cs +++ b/Service/Led/LedClient.cs @@ -115,7 +115,7 @@ public class LedClient _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _socket.NoDelay = true; _socket.Connect("192.168.3.79", 10000); - Log.Info($"end connect {"192.168.3.79"}:{10000} {_socket.Connected}"); + Log.Info($"end connect {"192.168.3.79"}:{10000} {_socket.Connected}"); } public static bool InnerSend(byte[] bytes)