You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
434 lines
16 KiB
434 lines
16 KiB
using Autofac;
|
|
using AutoMapper;
|
|
using Entity.Attr;
|
|
using Entity.Constant;
|
|
using Entity.DbModel.Station;
|
|
using HybirdFrameworkCore.Autofac;
|
|
using HybirdFrameworkCore.Configuration;
|
|
using log4net;
|
|
using Repository.Station;
|
|
using Service.Charger.Client;
|
|
using Service.Execute.Api;
|
|
using Service.Execute.Model;
|
|
using Service.Execute.Model.Tbox;
|
|
using Service.Execute.SwapException;
|
|
using Service.Execute.Utils;
|
|
using Service.Init;
|
|
using Service.Led;
|
|
using Service.Padar.Client;
|
|
using Service.Sound.SoundClient;
|
|
|
|
namespace Service.Execute.Step;
|
|
|
|
public class DoSwappingState : IState
|
|
{
|
|
private readonly ILog _log = LogManager.GetLogger(typeof(DoSwappingState));
|
|
private readonly CommonMgr _CommonMgr = AppInfo.Container.Resolve<CommonMgr>();
|
|
|
|
public BinInfoRepository _binInfoRepository { get; set; }
|
|
|
|
public static SoundClient? SoundClient { get; set; }
|
|
|
|
|
|
public StateResult Handle(SwappingStateMachine machine)
|
|
{
|
|
//上报云平台换电开始
|
|
// 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();
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//下发启动换电
|
|
InvokeStatus startSwapping = StartSwapping(machine);
|
|
if (startSwapping != InvokeStatus.Done)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(startSwapping, ExceptionReason.None);
|
|
}
|
|
|
|
//旧电池拆卸
|
|
InvokeStatus unPack = UnPack(machine);
|
|
if (unPack != InvokeStatus.Done)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(unPack, ExceptionReason.None);
|
|
}
|
|
|
|
|
|
//安装
|
|
InvokeStatus pack = Pack(machine);
|
|
if (pack != InvokeStatus.Done)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(pack, ExceptionReason.None);
|
|
}
|
|
//安装完成
|
|
InvokeStatus packFinish = PackFinish(machine);
|
|
if (packFinish != InvokeStatus.Done)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(packFinish, ExceptionReason.None);
|
|
}
|
|
|
|
//车辆上锁
|
|
InvokeStatus lockCar = LockCar(machine);
|
|
if (lockCar != InvokeStatus.Done)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(lockCar, ExceptionReason.None);
|
|
}
|
|
|
|
//开启雷达
|
|
var beginRadar = ControlRadar(machine, 1);
|
|
if (InvokeStatus.Done != beginRadar)
|
|
{
|
|
return SwappingStateMachine.ReturnWithInvokeErr(beginRadar, ExceptionReason.None);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new StateResult()
|
|
{
|
|
|
|
SwappingState = SwappingState.SwapDone
|
|
};
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 控制雷达启停
|
|
/// </summary>
|
|
/// <param name="machine"></param>
|
|
/// <param name="flag"></param>
|
|
/// <returns></returns>
|
|
public InvokeStatus ControlRadar(SwappingStateMachine machine, byte flag)
|
|
{
|
|
return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled, () => PadarMgr._PadarClient?.CarState > 0,
|
|
() => { PadarMgr._PadarClient?.PadarControl(flag); });
|
|
}
|
|
|
|
|
|
//public void leida ()
|
|
//{
|
|
|
|
// switch (PadarMgr._PadarClient?.CarState)
|
|
// {
|
|
// case 1:
|
|
// _log.Info("radar 无车");
|
|
// break;
|
|
// case 2:
|
|
// _log.Info("radar 无电池");
|
|
// break;
|
|
// case 3:
|
|
// _log.Info("radar 角度偏移过大");
|
|
// break;
|
|
// case 4:
|
|
// _log.Info("radar 车辆靠后");
|
|
// break;
|
|
// case 5:
|
|
// _log.Info("radar 车辆靠前");
|
|
// break;
|
|
// ;
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 下发plc启动换电
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public InvokeStatus StartSwapping(SwappingStateMachine machine)
|
|
{
|
|
int c = 0;
|
|
return Invoker.Invoke("StartSwapping", 1000, 5, machine.IsCanceled,
|
|
() => machine.StartSwappingFlag, () =>
|
|
{
|
|
Task<bool> result = TBoxApi.UnLockCarManyTimes(machine.RfidReadModel.VelVin);
|
|
bool unLock = result.Result;
|
|
if (unLock)
|
|
{
|
|
var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
|
|
machine.SwapOrderBatteryInfo.UpBinInfo.No);
|
|
|
|
|
|
//查詢當前任務狀態是否被更改
|
|
if (startSwapping)
|
|
{
|
|
machine.SwapOrder.SwapBeginTime = DateTime.Now;
|
|
_CommonMgr.UpdateSwapOrder(machine);
|
|
machine.SwapStatus = 0;
|
|
machine.StartSwappingFlag = true;
|
|
|
|
}
|
|
|
|
}
|
|
}, () =>
|
|
{
|
|
//SoundClient = AppInfo.Container.Resolve<SoundClient>();
|
|
//SoundClient.SoundPlay(SoundEnum.music70);
|
|
LedClient.SendMsgByKey(InfoEnum.SwapInfo.ErrStartSwap.GetLed());
|
|
},false, () => { },10,InvokeStatus.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取plc任务状态电池拆卸中
|
|
/// 读取plc任务状态电池入库搬运中
|
|
/// 读取plc任务状态电池出库搬运中
|
|
/// 读取plc任务状态电池安装中
|
|
/// 读取plc任务状态电池安装完成
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public InvokeStatus UnPack(SwappingStateMachine machine)
|
|
{
|
|
int s = 0;
|
|
int i = 0;
|
|
return Invoker.Invoke("plc UnPack", 500, 5, machine.IsCanceled,
|
|
() => machine.UnOldBatteryFlag, () =>
|
|
{
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoUnPack.GetLed());
|
|
|
|
LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoUnPack.GetLed());
|
|
SoundClient = AppInfo.Container.Resolve<SoundClient>();
|
|
//SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address11"));
|
|
if (s==0)
|
|
{
|
|
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag,
|
|
machine);
|
|
//SoundClient.SoundPlay(SoundEnum.music51);
|
|
//s = 1;
|
|
}
|
|
|
|
machine.UnOldBatteryFlag = ClientMgr.PlcClient.DisassembleDone;
|
|
|
|
if (machine.UnOldBatteryFlag)
|
|
{
|
|
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag,
|
|
machine);
|
|
}
|
|
|
|
},
|
|
() =>
|
|
{
|
|
|
|
if(i==0)
|
|
{
|
|
SoundClient = AppInfo.Container.Resolve<SoundClient>();
|
|
|
|
SoundClient.SoundPlay(SoundEnum.music51);
|
|
//SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoUnPack);
|
|
i = 1;
|
|
}
|
|
|
|
|
|
}, false, () => { }, 10,
|
|
InvokeStatus.None);
|
|
}
|
|
|
|
public InvokeStatus Pack(SwappingStateMachine machine)
|
|
{
|
|
int a = 0;
|
|
return Invoker.Invoke("plc Pack ing", 500, 5, machine.IsCanceled,
|
|
() => machine.InstallNewBatteryFlag, () =>
|
|
{
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed());
|
|
LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoPack.GetLed());
|
|
|
|
machine.InstallNewBatteryFlag = ClientMgr.PlcClient.SwapDone;
|
|
|
|
if (machine.InstallNewBatteryFlag)
|
|
{
|
|
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag,
|
|
machine);
|
|
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StorageOldBatteryFlag,
|
|
machine);
|
|
}
|
|
}, () =>
|
|
{
|
|
//SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack);
|
|
SoundClient = AppInfo.Container.Resolve<SoundClient>();
|
|
//SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address12"));
|
|
if (a == 0)
|
|
{
|
|
SoundClient.SoundPlay(SoundEnum.music52);
|
|
LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoPack.GetLed());
|
|
a = 1;
|
|
}
|
|
|
|
|
|
},false, () => { },
|
|
10,InvokeStatus.None);
|
|
}
|
|
|
|
public InvokeStatus PackFinish(SwappingStateMachine machine)
|
|
{
|
|
int b = 0;
|
|
return Invoker.Invoke("plc Pack Finish", 500, 5, machine.IsCanceled,
|
|
() => machine.FinishNewBatteryFlag, () =>
|
|
{
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPackFinish.GetLed());
|
|
if (ClientMgr.PlcClient.SwapDone)
|
|
{
|
|
machine.FinishNewBatteryFlag = true;
|
|
machine.BusinessSwappingForCloudState =
|
|
InfoEnum.BusinessSwappingForCloudState.SwapFinish;
|
|
// CloudApi.SendStateLog(machine.SwapOrder, machine.BusinessSwappingForCloudState);
|
|
machine.BusinessSwappingStateUpdateTime = DateTime.Now;
|
|
SoundClient = AppInfo.Container.Resolve<SoundClient>();
|
|
if (b==0)
|
|
{
|
|
// SoundClient.SoundPlay(SoundEnum.music77);
|
|
|
|
LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoPackFinish.GetLed());
|
|
b = 1;
|
|
}
|
|
|
|
|
|
_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;
|
|
|
|
machine.SwapStatus = 1;
|
|
}
|
|
}, () => { },false, () => { },
|
|
10,InvokeStatus.None);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 车辆上锁
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public InvokeStatus LockCar(SwappingStateMachine machine)
|
|
{
|
|
int v = 0;
|
|
return Invoker.Invoke("LockCar", 500, 100, machine.IsCanceled, machine.IsManualSwapSucc,
|
|
() => machine.VelLockFlag, () =>
|
|
{
|
|
Task<bool> result = TBoxApi.LockCarManyTimes(machine.RfidReadModel.VelVin);
|
|
|
|
bool unLock = result.Result;
|
|
if (unLock)
|
|
{
|
|
//查询车辆锁止状态
|
|
Task<TboxCarInfoModel> carInfo = TBoxApi.GetCarInfo(machine.RfidReadModel.VelVin);
|
|
if (carInfo.Result?.CarStatus?.LockStatus == 2)
|
|
{
|
|
|
|
machine.BoxCarInfoModel = carInfo.Result;
|
|
SoundApi.PlayOneSound(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
? (int)InfoEnum.SwapInfo.InfoCarLeave
|
|
: (int)InfoEnum.SwapInfo.ErrInfoCarLeave);
|
|
|
|
LedClient.SendMsgByKey(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
|
|
? InfoEnum.SwapInfo.InfoCarLeave.GetLed()
|
|
: InfoEnum.SwapInfo.ErrInfoCarLeave.GetLed());
|
|
machine.VelLockFlag = true;
|
|
var SoundClient = AppInfo.Container.Resolve<SoundClient>();
|
|
//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);
|
|
|
|
v = 1;
|
|
}
|
|
//断连Tbox
|
|
if (StaticStationInfo.TboxStateDisConnect)
|
|
{
|
|
TBoxApi.DisConnect(machine.BoxCarInfoModel.CarNo);
|
|
}
|
|
//新增小步
|
|
|
|
}
|
|
}
|
|
}, () =>
|
|
{
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrLockCar.GetLed());
|
|
// SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrLockCar);
|
|
|
|
|
|
LedClient.SendMsgByKey(InfoEnum.SwapInfo.ErrLockCar.GetLed());
|
|
}, false, () => { machine.ExceptionReason = ExceptionReason.LockCarError; }
|
|
, 10, InvokeStatus.None);
|
|
}
|
|
}
|