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.

146 lines
5.2 KiB

using Autofac;
using Entity.Attr;
using Entity.Constant;
using HybirdFrameworkCore.Autofac;
using log4net;
using Service.Execute.Api;
using Service.Execute.Model;
using Service.Execute.Model.Tbox;
using Service.Execute.StaticTools;
using Service.Execute.SwapException;
using Service.Execute.Utils;
using Service.Plc.Client;
using Service.Station;
namespace Service.Execute.Step;
public class CarCtrlState : IState
{
private readonly ILog _log = LogManager.GetLogger(typeof(CarCtrlState));
private readonly CommonMgr _CommonMgr = AppInfo.Container.Resolve<CommonMgr>();
public StateResult Handle(SwappingStateMachine machine)
{
//写选包 --判断是否允许换电
InvokeStatus issuedPlcPack = IssuedPlcPack(machine);
if (issuedPlcPack != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(issuedPlcPack, ExceptionReason.None);
}
//解锁车辆
InvokeStatus unLockCar = UnLockCar(machine);
if (unLockCar != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(unLockCar, ExceptionReason.None);
}
return new StateResult()
{
SwappingState = SwappingState.DoSwapping
};
}
/// <summary>
/// 下发plc選報
/// </summary>
/// <returns></returns>
public InvokeStatus IssuedPlcPack(SwappingStateMachine machine)
{
return Invoker.Invoke("IssuedPlcPack", 1000, 5, machine.IsCanceled,
() => machine.StartSwappingFlag, () =>
{
//查询当前是否有任务执行
var readTaskNo = PlcMgr.PlcClient?.ReadTaskNo();
if (readTaskNo == 0 || readTaskNo == 1)
{
PlcMgr.PlcClient?.ExChangeTaskNo(1);
//查询车辆锁止状态
var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.SwapOrderBatteryInfo.UpBinInfo.No);
//当前允许换电
var readPlcTaskStatus = PlcApi.ReadSwapReady();
if (startSwapping && readPlcTaskStatus)
{
machine.SwapOrder.SwapBeginTime = DateTime.Now;
_CommonMgr.UpdateSwapOrder(machine);
machine.SwapStatus = 0;
machine.StartSwappingFlag = true;
}
}
else
{
_log.Info("当前有任务在执行");
}
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap); }, false, () => { }, 10,
InvokeStatus.None);
}
/// <summary>
/// 车辆解锁
/// </summary>
/// <returns></returns>
public InvokeStatus UnLockCar(SwappingStateMachine machine)
{
return Invoker.Invoke("UnLockCar", 500, 10, machine.IsCanceled,
() => machine.VelUnlockFlag, () =>
{
Task<bool> result = TBoxApi.UnLockCarManyTimes(machine.RfidReadModel.VelVin);
bool unLock = result.Result;
if (unLock)
{
//查询车辆锁止状态
Task<TboxCarInfoModel> carInfo = TBoxApi.GetCarInfo(machine.RfidReadModel.VelVin);
var resultHeartBeatMsg = carInfo.Result.CarStatus;
if (resultHeartBeatMsg?.LockStatus == 1 || machine.ManualConfirmCarUnlockFlag)
{
machine.ManualConfirmCarUnlockFlag = false;
machine.BoxCarInfoModel = carInfo.Result;
machine.VelUnlockFlag = true;
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelUnlockFlag,
machine);
}
}
}, () =>
{
//z轴上升
PlcApi.ZPushUp();
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrUnLockCar.GetLed());
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrUnLockCar);
}, false, () => { machine.ExceptionReason = ExceptionReason.UnLockCarError; }
, 10, InvokeStatus.None);
}
/// <summary>
/// 下发选包
/// </summary>
/// <returns></returns>
public InvokeStatus DistributeSelectPack(SwappingStateMachine machine)
{
return Invoker.Invoke("DistributeSelectPack", 500, 10, machine.IsCanceled,
() => machine.DistributeSelectPackFlag, () =>
{
var swapOrderBatteryInfo = machine.SwapOrderBatteryInfo;
machine.DistributeSelectPackFlag =
PlcApi.DistributeSelectPack(swapOrderBatteryInfo.InBinInfo.No, swapOrderBatteryInfo.UpBinInfo.No);
// if (machine.DistributeSelectPackFlag)
// {
// _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.DistributeSelectPackFlag,
// machine);
// }
}, () =>
{
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrDistributeSelectPack.GetLed());
});
}
}