|
|
@ -20,6 +20,13 @@ public class CarCtrlState : IState
|
|
|
|
|
|
|
|
|
|
|
|
public StateResult Handle(SwappingStateMachine machine)
|
|
|
|
public StateResult Handle(SwappingStateMachine machine)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
//拍照定位
|
|
|
|
|
|
|
|
//查看通道状态
|
|
|
|
|
|
|
|
StateResult checkChannelStatus = CheckChannelStatus(machine);
|
|
|
|
|
|
|
|
if (checkChannelStatus != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return checkChannelStatus;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//解锁车辆
|
|
|
|
//解锁车辆
|
|
|
@ -29,14 +36,40 @@ public class CarCtrlState : IState
|
|
|
|
return SwappingStateMachine.ReturnWithInvokeErr(unLockCar, ExceptionReason.None);
|
|
|
|
return SwappingStateMachine.ReturnWithInvokeErr(unLockCar, ExceptionReason.None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//下发选包
|
|
|
|
//站控下发换电启动命令到VCU和TBOX //vcu反馈换电就绪
|
|
|
|
/*InvokeStatus distributeSelectPack = DistributeSelectPack(machine);
|
|
|
|
InvokeStatus startSwapToTBox = StartSwapToTBox(machine);
|
|
|
|
|
|
|
|
if (startSwapToTBox != InvokeStatus.Done)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return SwappingStateMachine.ReturnWithInvokeErr(startSwapToTBox, ExceptionReason.None);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TBOX收到抬起到位信号
|
|
|
|
|
|
|
|
InvokeStatus tBoxHandUp = TBoxHandUp(machine);
|
|
|
|
|
|
|
|
if (tBoxHandUp != InvokeStatus.Done)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return SwappingStateMachine.ReturnWithInvokeErr(tBoxHandUp, ExceptionReason.None);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TBOX收到车辆下电OK信号
|
|
|
|
|
|
|
|
InvokeStatus tBoxEnergyDown = TBoxEnergyDown(machine);
|
|
|
|
|
|
|
|
if (tBoxEnergyDown != InvokeStatus.Done)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return SwappingStateMachine.ReturnWithInvokeErr(tBoxEnergyDown, ExceptionReason.None);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//请操作换电启动按钮
|
|
|
|
|
|
|
|
SoundApi.PlayOneSound((int) InfoEnum.SwapInfo.InfoManualStartSwap);
|
|
|
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*//下发选包
|
|
|
|
|
|
|
|
InvokeStatus distributeSelectPack = DistributeSelectPack(machine);
|
|
|
|
|
|
|
|
|
|
|
|
if (distributeSelectPack != InvokeStatus.Done)
|
|
|
|
if (distributeSelectPack != InvokeStatus.Done)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return SwappingStateMachine.ReturnWithInvokeErr(distributeSelectPack, ExceptionReason.None);
|
|
|
|
return SwappingStateMachine.ReturnWithInvokeErr(distributeSelectPack, ExceptionReason.None);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new StateResult()
|
|
|
|
return new StateResult()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -54,7 +87,7 @@ public class CarCtrlState : IState
|
|
|
|
() => machine.VelUnlockFlag, () =>
|
|
|
|
() => machine.VelUnlockFlag, () =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Task<bool> result = TBoxApi.UnLockCarManyTimes(machine.RfidReadModel.VelVin);
|
|
|
|
Task<bool> result = TBoxApi.UnLockCarManyTimes(machine.RfidReadModel.VelVin);
|
|
|
|
|
|
|
|
|
|
|
|
bool unLock = result.Result;
|
|
|
|
bool unLock = result.Result;
|
|
|
|
if (unLock)
|
|
|
|
if (unLock)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -72,12 +105,97 @@ public class CarCtrlState : IState
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, () =>
|
|
|
|
}, () =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrUnLockCar.GetLed());
|
|
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrUnLockCar.GetLed());
|
|
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrUnLockCar);
|
|
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrUnLockCar);
|
|
|
|
}, false, () => { machine.ExceptionReason = ExceptionReason.UnLockCarError; }
|
|
|
|
}, false, () => { machine.ExceptionReason = ExceptionReason.UnLockCarError; }
|
|
|
|
, 10, InvokeStatus.None);
|
|
|
|
, 10, InvokeStatus.None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
///收到抬起到位信号
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public InvokeStatus StartSwapToTBox(SwappingStateMachine machine)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Invoker.Invoke("StartSwapToTBox", 500, 10, machine.IsCanceled,
|
|
|
|
|
|
|
|
() => machine.TboxHandUpFlag, () =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Task<byte> result = TBoxApi.StartSwap(machine.RfidReadModel.VelVin);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte res = result.Result;
|
|
|
|
|
|
|
|
//换电就绪
|
|
|
|
|
|
|
|
if (res == 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//查询车辆锁止状态
|
|
|
|
|
|
|
|
machine.TboxHandUpFlag = true;
|
|
|
|
|
|
|
|
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.TBoxSwapReadyFlag,
|
|
|
|
|
|
|
|
machine);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, () =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrUnLockCar.GetLed());
|
|
|
|
|
|
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwapToTBox);
|
|
|
|
|
|
|
|
}, false, () => { machine.ExceptionReason = ExceptionReason.StartSwapToTBoxError; }
|
|
|
|
|
|
|
|
, 10, InvokeStatus.None);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
///收到抬起到位信号
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public InvokeStatus TBoxHandUp(SwappingStateMachine machine)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Invoker.Invoke("TBoxHandUp", 500, 5, machine.IsCanceled,
|
|
|
|
|
|
|
|
() => machine.TboxHandUpFlag, () =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Task<byte> result = TBoxApi.StartSwap(machine.RfidReadModel.VelVin);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte res = result.Result;
|
|
|
|
|
|
|
|
//换电就绪
|
|
|
|
|
|
|
|
if (res == 2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//查询车辆锁止状态
|
|
|
|
|
|
|
|
machine.TboxHandUpFlag = true;
|
|
|
|
|
|
|
|
// _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.TBoxSwapReadyFlag,
|
|
|
|
|
|
|
|
// machine);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, () =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrUnLockCar.GetLed());
|
|
|
|
|
|
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoTboxHandUp);
|
|
|
|
|
|
|
|
}, false, () => { }
|
|
|
|
|
|
|
|
, 10, InvokeStatus.None);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
///收到下电成功
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public InvokeStatus TBoxEnergyDown(SwappingStateMachine machine)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Invoker.Invoke("TBoxEnergyDown", 500, 5, machine.IsCanceled,
|
|
|
|
|
|
|
|
() => machine.TboxEnergyDownFlag, () =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Task<byte> result = TBoxApi.StartSwap(machine.RfidReadModel.VelVin);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte res = result.Result;
|
|
|
|
|
|
|
|
//换电就绪
|
|
|
|
|
|
|
|
if (res == 3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//查询车辆锁止状态
|
|
|
|
|
|
|
|
machine.TboxEnergyDownFlag = true;
|
|
|
|
|
|
|
|
// _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.TBoxSwapReadyFlag,
|
|
|
|
|
|
|
|
// machine);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, () =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrUnLockCar.GetLed());
|
|
|
|
|
|
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoTboxEnergyDown);
|
|
|
|
|
|
|
|
}, false, () => { }
|
|
|
|
|
|
|
|
, 10, InvokeStatus.None);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 下发选包
|
|
|
|
/// 下发选包
|
|
|
@ -99,8 +217,60 @@ public class CarCtrlState : IState
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, () =>
|
|
|
|
}, () =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrDistributeSelectPack.GetLed());
|
|
|
|
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrDistributeSelectPack.GetLed());
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 查看通道状态
|
|
|
|
|
|
|
|
/// :0:无效值
|
|
|
|
|
|
|
|
/// 1000;拍照OK
|
|
|
|
|
|
|
|
///1010;拍照NG
|
|
|
|
|
|
|
|
///1020;拍照超限,请移车
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public StateResult CheckChannelStatus(SwappingStateMachine machine)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
while (!machine.ChannelStatusOkFlag)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (machine.CancelFlag)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_log.Info($" CheckChannelStatus canceled");
|
|
|
|
|
|
|
|
return StateResult.Cancel;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_log.Info("begin plc CheckChannelStatus");
|
|
|
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
|
|
|
var channelStatus = PlcApi.ChannelStatus();
|
|
|
|
|
|
|
|
if (count % 10 == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.CarTakePhotoInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (channelStatus == 1000)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
machine.ChannelStatusOkFlag = true;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.CarTakePhotoErrRepeat);
|
|
|
|
|
|
|
|
//故障 不能继续换电,提示驶离,上报云平台,修改换电订单
|
|
|
|
|
|
|
|
machine.SwapStatus = (int)InfoEnum.SwapOrderResult.Fail;
|
|
|
|
|
|
|
|
machine.SwapFailReason = "拍照故障 plc故障码1010";
|
|
|
|
|
|
|
|
//跳转到SwappDone
|
|
|
|
|
|
|
|
return new StateResult()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SwappingState = SwappingState.SwapDone
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|