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.

293 lines
9.9 KiB

using Autofac;
3 months ago
using AutoMapper;
5 months ago
using Entity.Attr;
using Entity.Constant;
3 months ago
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using log4net;
using Newtonsoft.Json;
3 months ago
using Repository.Station;
5 months ago
using Service.Charger.Client;
using Service.Execute.Api;
3 months ago
using Service.Execute.Model;
using Service.Execute.Model.Tbox;
using Service.Execute.SwapException;
using Service.Execute.Utils;
using Service.Init;
5 months ago
using Service.Led;
3 months ago
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>();
3 months ago
public BinInfoRepository _binInfoRepository { get; set; }
public static SoundClient? SoundClient { get; set; }
1 month ago
private int a = 0;
private int b = 0;
public StateResult Handle(SwappingStateMachine machine)
{
//上报云平台换电开始
machine.BusinessSwappingStateUpdateTime = DateTime.Now;
//记录为 换电任务
1 month ago
//下发启动换电
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);
}
5 months ago
//安装
InvokeStatus pack = Pack(machine);
if (pack != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(pack, ExceptionReason.None);
}
5 months ago
//安装完成
InvokeStatus packFinish = PackFinish(machine);
if (packFinish != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(packFinish, ExceptionReason.None);
}
ClientMgr.PlcClient.ResetTaskNo();
3 months ago
return new StateResult()
{
SwappingState = SwappingState.SwapDone
};
}
3 months ago
3 months ago
3 months ago
/// <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;
// ;
// }
//}
3 months ago
/// <summary>
/// 下发plc启动换电
/// </summary>
/// <returns></returns>
public InvokeStatus StartSwapping(SwappingStateMachine machine)
{
return Invoker.Invoke("StartSwapping", 1000, 5, machine.IsCanceled,
() => machine.StartSwappingFlag, () =>
{
if (ClientMgr.PlcClient.IsTaskFree())
{
// ClientMgr.PlcClient.ExChangeTaskNo(1);
var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.SwapOrderBatteryInfo.UpBinInfo.No);
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.DistributeSelectPackFlag,
machine,param: $"InBin:{JsonConvert.SerializeObject(machine.SwapOrderBatteryInfo.InBinInfo)};" +
$"UpBin: {JsonConvert.SerializeObject(machine.SwapOrderBatteryInfo.UpBinInfo)}");
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag,
machine);
1 month ago
if (a == 0)
{
LedClient.SendMsgByKey(InfoEnum.SwapInfo.StartSwap.GetLed());
a = 1;
}
Thread.Sleep(1000);
//LedClient.SendMsgByKey(InfoEnum.SwapInfo.StartSwap.GetLed());
//查詢當前任務狀態是否被更改
if (startSwapping)
{
ClientMgr.PlcClient.ExChangeTaskNo(1);
machine.SwapOrder.SwapBeginTime = DateTime.Now;
_CommonMgr.UpdateSwapOrder(machine);
machine.SwapStatus = 0;
machine.StartSwappingFlag = true;
SoundClient = AppInfo.Container.Resolve<SoundClient>();
SoundClient.SoundPlay(SoundEnum.music91);
Thread.Sleep(5000);
SoundClient.SoundPlay(SoundEnum.music90);
}
}
3 months ago
3 months ago
// }
}, () =>
{
3 months ago
//SoundClient = AppInfo.Container.Resolve<SoundClient>();
//SoundClient.SoundPlay(SoundEnum.music70);
2 months ago
// LedClient.SendMsgByKey(InfoEnum.SwapInfo.ErrStartSwap.GetLed());
},false, () => { },10,InvokeStatus.None);
}
/// <summary>
/// 读取plc任务状态电池拆卸中
/// 读取plc任务状态电池入库搬运中
/// 读取plc任务状态电池出库搬运中
/// 读取plc任务状态电池安装中
/// 读取plc任务状态电池安装完成
/// </summary>
/// <returns></returns>
public InvokeStatus UnPack(SwappingStateMachine machine)
{
3 months ago
int i = 0;
return Invoker.Invoke("plc UnPack", 500, 5, machine.IsCanceled,
() => machine.UnOldBatteryFlag, () =>
{
1 month ago
if (b==0)
{
LedClient.SendMsgByKey(InfoEnum.SwapInfo.StartSwap.GetLed());
b = 1;
}
SoundClient = AppInfo.Container.Resolve<SoundClient>();
5 months ago
machine.UnOldBatteryFlag = ClientMgr.PlcClient.DisassembleDone;
if (machine.UnOldBatteryFlag)
{
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag,
machine);
}
3 months ago
4 months ago
},
() =>
{
2 months ago
if (i==0)
{
3 months ago
SoundClient = AppInfo.Container.Resolve<SoundClient>();
SoundClient.SoundPlay(SoundEnum.music51);
2 months ago
i = 1;
}
}, false, () => { }, 30,
InvokeStatus.None);
}
public InvokeStatus Pack(SwappingStateMachine machine)
{
2 months ago
int f = 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());
5 months ago
5 months ago
machine.InstallNewBatteryFlag = ClientMgr.PlcClient.SwapDone;
if (machine.InstallNewBatteryFlag)
{
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag,
machine);
}
}, () =>
{
//SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack);
SoundClient = AppInfo.Container.Resolve<SoundClient>();
4 months ago
//SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address12"));
2 months ago
if (f==0)
{
3 months ago
SoundClient.SoundPlay(SoundEnum.music52);
// LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoPack.GetLed());
2 months ago
f = 1;
}
3 months ago
},false, () => { },
30,InvokeStatus.None);
}
public InvokeStatus PackFinish(SwappingStateMachine machine)
{
3 months ago
int b = 0;
return Invoker.Invoke("plc Pack Finish", 500, 5, machine.IsCanceled,
() => machine.FinishNewBatteryFlag, () =>
{
5 months ago
if (ClientMgr.PlcClient.SwapDone)
{
machine.FinishNewBatteryFlag = true;
machine.BusinessSwappingForCloudState =
InfoEnum.BusinessSwappingForCloudState.SwapFinish;
machine.BusinessSwappingStateUpdateTime = DateTime.Now;
3 months ago
SoundClient = AppInfo.Container.Resolve<SoundClient>();
SoundClient.SoundPlay(SoundEnum.music53);
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag,
machine);
5 months ago
machine.ToSafePositionFlag = true;
machine.BusinessSwappingStateUpdateTime = DateTime.Now;
machine.SwapStatus = 1;
}
}, () =>
{
2 months ago
// LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoPackFinish.GetLed());
},false, () => { },
30,InvokeStatus.None);
}
3 months ago
5 months ago
}