换电主流程

master
rszn 5 months ago
parent e97ae2e5f8
commit 7d704e1355

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="SqlSugar.IOC" Version="2.0.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.115" />
</ItemGroup>

@ -2,6 +2,8 @@ using Entity.Constant;
using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Newtonsoft.Json;
using SqlSugar;
namespace Repository.Station;
@ -9,6 +11,7 @@ namespace Repository.Station;
[Scope("SingleInstance")]
public class BinInfoRepository : BaseRepository<BinInfo>
{
private static readonly ILog _log = LogManager.GetLogger(typeof(BinInfoRepository));
public BinInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
@ -19,55 +22,65 @@ public class BinInfoRepository : BaseRepository<BinInfo>
/// <param name="swapSoc"> StaticStationInfo.SwapSoc </param>
/// <param name="swapFinishChargeTime">StaticStationInfo.SwapFinishChargeTime</param>
/// <returns></returns>
public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime)
public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime, string upMoveNo=default)
{
_log.Info($"BinInfoRepository SelectPack swapSoc={swapSoc}, swapFinishChargeTime={swapFinishChargeTime},upMoveNo={upMoveNo}");
SelectPackDto selectPackDto = new()
{
SuccessFlag = false,
};
List<BinInfo> list =
QueryListByClause(i => i.CacheBinFlag == 0 && i.CanSwapFlag==1 &&
QueryListByClause(i => i.CanSwapFlag == 1 &&
i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock,
"in_time asc");
BinInfo? cacheBinBattery = ChooseCacheBinBattery();
if (list.Count <= 0 && cacheBinBattery == null)
_log.Info($"BinInfoRepository SelectPack list1={JsonConvert.SerializeObject(list)}");
// BinInfo? cacheBinBattery = ChooseCacheBinBattery(swapSoc);
if (list.Count <= 0)
{
_log.Info($"list1 return");
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.NoBattery;
return selectPackDto;
}
list = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus==4).ToList();
if (list.Count <= 0 && cacheBinBattery == null)
list = list.OrderBy(i => i.CacheBinFlag).ToList();
_log.Info($"BinInfoRepository SelectPack list2={JsonConvert.SerializeObject(list)}");
if (!string.IsNullOrWhiteSpace(upMoveNo))
{
list = list.Where(i => !upMoveNo.Equals(i.No) && i.No != "" && i.No != "-1").ToList();
_log.Info($"BinInfoRepository SelectPack list3={JsonConvert.SerializeObject(list)},upMoveNo={upMoveNo}");
}
list = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus == 4).ToList();
if (list.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging;
return selectPackDto;
}
list = list.Where(i => i.Soc != null && i.Soc >= swapSoc).ToList();
if (list.Count <= 0 && cacheBinBattery == null)
list = list.Where(i => i.Soc != null &&i.Soc >= swapSoc).ToList();
if (list.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc;
return selectPackDto;
}
list = list.Where(i => i.LastChargeFinishTime != null && new TimeSpan(DateTime.Now.Ticks -
/*list = list.Where(i => i.LastChargeFinishTime != null || new TimeSpan(DateTime.Now.Ticks -
i.LastChargeFinishTime.ToDateTime().Ticks)
.TotalMinutes > swapFinishChargeTime).ToList();
if (list.Count <= 0 && cacheBinBattery == null)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute;
if (list.Count <= 0)
{ selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute;
return selectPackDto;
}
}*/
if (list.Count > 0)
{
selectPackDto.BinInfo = list[0];
}
else
{
selectPackDto.BinInfo = cacheBinBattery;
}
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success;
selectPackDto.SuccessFlag = true;

@ -1,11 +1,7 @@
using System.Collections.Concurrent;
using Autofac;
using Common.Const;
using DotNetty.Transport.Channels;
using Autofac;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.Session;
using log4net;
using Service.Charger.Server;
@ -19,53 +15,12 @@ public static class ClientMgr
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ClientMgr));
public static readonly ConcurrentDictionary<string, PlcClient> Dictionary = new();
public static PlcClient? GetBySn(string sn)
{
Dictionary.TryGetValue(sn, out var o);
return o;
}
/// <summary>
/// 通过channel获取client
/// </summary>
/// <param name="channel"></param>
/// <param name="sn"></param>
/// <param name="client">获取不到client则为空</param>
/// <returns></returns>
public static bool TryGetClient(IChannel channel, out string sn, out PlcClient? client)
{
string? snt = ChannelUtils.GetAttr(channel, PlcConst.ChargerSn);
if (!string.IsNullOrWhiteSpace(snt))
{
var chargerClient = GetBySn(snt);
if (chargerClient != null)
{
sn = snt;
client = chargerClient;
return true;
}
}
sn = string.Empty;
client = null;
return false;
}
public static void AddBySn(string sn, PlcClient client)
{
Dictionary[sn] = client;
}
public static PlcClient? PlcClient { get; set; }
//TODO 连接、鉴权,开始充电,结束充电,设置尖峰平谷,读取尖峰平谷,发送功率调节指令,发送辅助源控制指令,下发掉线停止充电,
public static void InitClient()
{
Task.Run(() =>
{
ConnClient();
});
Task.Run(ConnClient);
}
private static void ConnClient()
@ -79,39 +34,33 @@ public static class ClientMgr
DestAddr = "132,208,208,224"
};
Log.Info($"begin to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}");
PlcClient client = AppInfo.Container.Resolve<PlcClient>();
client.AutoReconnect = true;
//Plc编号
client.Sn = PlcConst.ChargeEqpCode;
//电池仓编号
//client.BinNo = binInfo?.No;
//client.BatteryNo = binInfo?.BatteryNo;
client.LogName = "Charger" + netInfo.Code;
client.ConnectedEventHandler += (sender, b) =>
PlcClient = AppInfo.Container.Resolve<PlcClient>();
PlcClient.AutoReconnect = true;
PlcClient.Sn = PlcConst.ChargeEqpCode;
PlcClient.ConnectedEventHandler += (sender, b) =>
{
client.SessionAttr(netInfo.Code, netInfo.DestAddr);
PlcClient.SessionAttr(netInfo.Code, netInfo.DestAddr);
//鉴权
// client.SendAuth();
};
//ip
client.InitBootstrap(netInfo.NetAddr, int.Parse(netInfo.NetPort));
PlcClient.InitBootstrap(netInfo.NetAddr, int.Parse(netInfo.NetPort));
/*Task.Run(() =>
{*/
try
{
client.Connect();
client.SessionAttr(netInfo.Code, netInfo.DestAddr);
PlcClient.Connect();
PlcClient.SessionAttr(netInfo.Code, netInfo.DestAddr);
Log.Info($"succeed to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}");
}
catch (Exception ex)
{
Log.Error($"conn plc error ={ex.StackTrace}");
}
//});
AddBySn(netInfo.Code, client);
Log.Info($"begin to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}");
}
}

@ -2,12 +2,10 @@ using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkDriver.Session;
using HybirdFrameworkDriver.TcpClient;
using HybirdFrameworkDriver.TcpServer;
using log4net;
using Service.Charger.Client;
using Service.Charger.Codec;
using Service.Charger.Handler;
using Service.Charger.Msg;
using Service.Charger.Msg.Host.Req;
namespace Service.Charger.Server;
@ -22,6 +20,11 @@ public class PlcClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// Plc编号
/// </summary>
public string Sn { get; set; }
public bool SwapDone { get; set; }
public bool DisassembleDone { get; set; }
#endregion
#region send
@ -295,6 +298,11 @@ public class PlcClient : TcpClient<IBaseHandler, Decoder, Encoder>
public void Reset()
{
SwapDone = false;
DisassembleDone = false;
}
private ILog Log()
{
var name = "Charger" + this.Sn;

@ -1,11 +1,9 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Utils;
using log4net;
using Newtonsoft.Json;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Msg.Host.Resp;
namespace Service.Charger.Handler;
@ -20,14 +18,7 @@ public class BatteryPackDisassembledReqHandler : SimpleChannelInboundHandler<Bat
/// <summary>
///
/// </summary>
private static ILog Log(string? sn)
{
if (ObjUtils.IsNotNullOrWhiteSpace(sn))
{
return LogManager.GetLogger("Charger" + sn);
}
return LogManager.GetLogger(typeof(BatteryPackDisassembledReqHandler));
}
private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackDisassembledReqHandler));
/// <summary>
@ -35,10 +26,7 @@ public class BatteryPackDisassembledReqHandler : SimpleChannelInboundHandler<Bat
/// </summary>
protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackDisassembledReq msg)
{
if (Client.ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log(sn).Info($"process {JsonConvert.SerializeObject(msg)}");
ctx.Channel.WriteAndFlushAsync(new Msg.Host.Resp.BatteryPackDisassembledResq());
}
ClientMgr.PlcClient.DisassembleDone = true;
ctx.Channel.WriteAndFlushAsync(new BatteryPackDisassembledResq());
}
}

@ -1,11 +1,9 @@
using DotNetty.Transport.Channels;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Utils;
using log4net;
using Newtonsoft.Json;
using Repository.Station;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp;
namespace Service.Charger.Handler;
@ -17,17 +15,9 @@ namespace Service.Charger.Handler;
public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<BatteryStatusReportedReq>, IBaseHandler
{
/// <summary>
///
/// </summary>
private static ILog Log(string? sn)
{
if (ObjUtils.IsNotNullOrWhiteSpace(sn))
{
return LogManager.GetLogger("Charger" + sn);
}
return LogManager.GetLogger(typeof(BatteryStatusReportedReqHandler));
}
private static readonly ILog Log =LogManager.GetLogger(typeof(BatteryStatusReportedReqHandler));
public BinInfoRepository BinInfoRepository { get; set; }
/// <summary>
@ -35,11 +25,33 @@ public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<Batte
/// </summary>
protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryStatusReportedReq msg)
{
if (Client.ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log(sn).Info($"process {JsonConvert.SerializeObject(msg)}");
//TODO::
//ctx.Channel.WriteAndFlushAsync("");
UpdateBinInfo(msg.granary01, "1");
UpdateBinInfo(msg.granary02, "2");
UpdateBinInfo(msg.granary03, "3");
UpdateBinInfo(msg.granary04, "4");
UpdateBinInfo(msg.granary05, "5");
UpdateBinInfo(msg.granary06, "6");
UpdateBinInfo(msg.granary07, "7");
UpdateBinInfo(msg.granary08, "8");
}
private void UpdateBinInfo(int exists, string binNo)
{
if (exists == 0)
BinInfoRepository.Update(
it =>
new BinInfo(){
Exists = 0,
BatteryNo = "-1",
Soc = (decimal)-1,
Soe = (decimal)-1,
Soh = (decimal)-1,
},
it => it.No == binNo);
else
BinInfoRepository.Update(it => it.Exists == 1,
it => it.No == binNo);
}
}

@ -1,11 +1,9 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Utils;
using log4net;
using Newtonsoft.Json;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Msg.Host.Resp;
namespace Service.Charger.Handler;
@ -17,17 +15,7 @@ namespace Service.Charger.Handler;
public class SwapBatteryFinishReqHandler : SimpleChannelInboundHandler<SwapBatteryFinishReq>, IBaseHandler
{
/// <summary>
///
/// </summary>
private static ILog Log(string? sn)
{
if (ObjUtils.IsNotNullOrWhiteSpace(sn))
{
return LogManager.GetLogger("Charger" + sn);
}
return LogManager.GetLogger(typeof(SwapBatteryFinishReqHandler));
}
private static readonly ILog Log = LogManager.GetLogger(typeof(SwapBatteryFinishReqHandler));
/// <summary>
@ -35,10 +23,8 @@ public class SwapBatteryFinishReqHandler : SimpleChannelInboundHandler<SwapBatte
/// </summary>
protected override void ChannelRead0(IChannelHandlerContext ctx, SwapBatteryFinishReq msg)
{
if (Client.ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log(sn).Info($"process {JsonConvert.SerializeObject(msg)}");
ctx.Channel.WriteAndFlushAsync(new Msg.Host.Resp.SwapBatteryFinishResq());
}
Log.Info("swap finish");
ctx.Channel.WriteAndFlushAsync(new SwapBatteryFinishResq());
ClientMgr.PlcClient.SwapDone = true;
}
}

@ -1,4 +1,5 @@
using log4net;
using Service.Charger.Client;
using Service.Plc.Client;
namespace Service.Execute.Api;
@ -110,10 +111,10 @@ public class PlcApi
{
Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}");
var distributeTask = PlcMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo), 1);
ClientMgr.PlcClient.SendStartBatterySwapReq(Convert.ToByte(outBinNo), Convert.ToByte(inBinNo));
Log.Info($"PlcApi StartSwapping resp={distributeTask}");
return distributeTask;
Log.Info($"PlcApi StartSwapping done");
return true;
}

@ -41,12 +41,12 @@ public class CarPrepareState : IState
};
}
//云平台车辆认证
var cloudCheckVel = CloudCheckVel(machine);
if (cloudCheckVel != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(cloudCheckVel, ExceptionReason.None);
}
// 云平台车辆认证
// var cloudCheckVel = CloudCheckVel(machine);
// if (cloudCheckVel != InvokeStatus.Done)
// {
// return SwappingStateMachine.ReturnWithInvokeErr(cloudCheckVel, ExceptionReason.None);
// }
//TBox连接
if (StaticStationInfo.TboxStateConnect)

@ -1,17 +1,13 @@
using Autofac;
using Entity.Attr;
using Entity.Constant;
using HybirdFrameworkCore.Autofac;
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.StaticTools;
using Service.Execute.SwapException;
using Service.Execute.Utils;
using Service.Init;
using Service.Station;
namespace Service.Execute.Step;
@ -30,11 +26,11 @@ public class DoSwappingState : IState
//再次读锁止状态防止plc需要挪车
InvokeStatus carInPosition2 = CarInPosition2(machine);
if (carInPosition2 != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(carInPosition2, ExceptionReason.None);
}
//InvokeStatus carInPosition2 = CarInPosition2(machine);
//if (carInPosition2 != InvokeStatus.Done)
//{
// return SwappingStateMachine.ReturnWithInvokeErr(carInPosition2, ExceptionReason.None);
//}
//下发启动换电
@ -44,19 +40,19 @@ public class DoSwappingState : IState
return SwappingStateMachine.ReturnWithInvokeErr(startSwapping, ExceptionReason.None);
}
InvokeStatus holdOn = HoldOn(machine);
if (holdOn != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(holdOn, ExceptionReason.None);
}
//InvokeStatus holdOn = HoldOn(machine);
//if (holdOn != InvokeStatus.Done)
//{
// return SwappingStateMachine.ReturnWithInvokeErr(holdOn, ExceptionReason.None);
//}
//查看通道状态
StateResult checkChannelStatus = CheckChannelStatus(machine);
if (checkChannelStatus != null)
{
return checkChannelStatus;
}
// StateResult checkChannelStatus = CheckChannelStatus(machine);
// if (checkChannelStatus != null)
// {
// return checkChannelStatus;
// }
//旧电池拆卸
InvokeStatus unPack = UnPack(machine);
@ -66,18 +62,18 @@ public class DoSwappingState : IState
}
//旧电池搬运
InvokeStatus oldBatteryCarryIn = OldBatteryCarryIn(machine);
if (oldBatteryCarryIn != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(oldBatteryCarryIn, ExceptionReason.None);
}
// InvokeStatus oldBatteryCarryIn = OldBatteryCarryIn(machine);
// if (oldBatteryCarryIn != InvokeStatus.Done)
// {
// return SwappingStateMachine.ReturnWithInvokeErr(oldBatteryCarryIn, ExceptionReason.None);
// }
//新电池搬运
InvokeStatus newBatteryCarryOut = NewBatteryCarryOut(machine);
if (newBatteryCarryOut != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(newBatteryCarryOut, ExceptionReason.None);
}
// InvokeStatus newBatteryCarryOut = NewBatteryCarryOut(machine);
// if (newBatteryCarryOut != InvokeStatus.Done)
// {
// return SwappingStateMachine.ReturnWithInvokeErr(newBatteryCarryOut, ExceptionReason.None);
// }
//安装
InvokeStatus pack = Pack(machine);
@ -87,19 +83,18 @@ public class DoSwappingState : IState
}
//安装完成
InvokeStatus packFinish = PackFinish(machine);
if (packFinish != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(packFinish, ExceptionReason.None);
}
//InvokeStatus packFinish = PackFinish(machine);
//if (packFinish != InvokeStatus.Done)
//{
// return SwappingStateMachine.ReturnWithInvokeErr(packFinish, ExceptionReason.None);
//}
//航车回归安全位置
InvokeStatus toInvokeStatus = ToSafePosition(machine);
if (toInvokeStatus != InvokeStatus.Done)
{
return SwappingStateMachine.ReturnWithInvokeErr(toInvokeStatus, ExceptionReason.None);
}
////航车回归安全位置
//InvokeStatus toInvokeStatus = ToSafePosition(machine);
//if (toInvokeStatus != InvokeStatus.Done)
//{
// return SwappingStateMachine.ReturnWithInvokeErr(toInvokeStatus, ExceptionReason.None);
//}
return new StateResult()
@ -121,13 +116,11 @@ public class DoSwappingState : IState
bool unLock = result.Result;
if (unLock)
{
//查询车辆锁止状态
var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.SwapOrderBatteryInfo.UpBinInfo.No);
//查詢當前任務狀態是否被更改
var readPlcTaskStatus = PlcApi.ReadTaskStatus(1);
if (startSwapping && readPlcTaskStatus)
if (startSwapping)
{
machine.SwapOrder.SwapBeginTime = DateTime.Now;
_CommonMgr.UpdateSwapOrder(machine);
@ -185,15 +178,7 @@ public class DoSwappingState : IState
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoUnPack.GetLed());
int status = PlcApi.ReadPlcTaskStatus();
//处理程序太快plc还没有初始值的状态
if (status == 1002 || status != 1003)
{
}
else
{
machine.UnOldBatteryFlag = true;
}
machine.UnOldBatteryFlag = ClientMgr.PlcClient.DisassembleDone;
if (machine.UnOldBatteryFlag)
{
@ -263,14 +248,7 @@ public class DoSwappingState : IState
() => machine.InstallNewBatteryFlag, () =>
{
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed());
if (PlcApi.ReadPlcTaskStatus() == 1005)
{
}
else
{
machine.InstallNewBatteryFlag = true;
}
machine.InstallNewBatteryFlag = ClientMgr.PlcClient.SwapDone;
if (machine.InstallNewBatteryFlag)
{

@ -1,19 +1,15 @@
using System.Text;
using Autofac;
using Entity.Attr;
using Autofac;
using Entity.Constant;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using log4net;
using Newtonsoft.Json;
using Repository.Station;
using Service.Execute.Api;
using Service.Execute.Model;
using Service.Execute.StaticTools;
using Service.Execute.SwapException;
using Service.Execute.Utils;
using Service.Init;
using Service.Station;
using Service.Padar.Client;
using Swapping.Business.Common;
namespace Service.Execute.Step;
@ -54,16 +50,6 @@ public class StationReadyState : IState
return SwappingStateMachine.ReturnWithInvokeErr(plcIsRemote, ExceptionReason.None);
}
//监测雷达
var entranceRadar = EntranceRadar(machine);
if (InvokeStatus.Done != entranceRadar)
{
return SwappingStateMachine.ReturnWithInvokeErr(entranceRadar, ExceptionReason.None);
}
//开始读rifd
var beginRfid = BeginRead(machine);
if (InvokeStatus.Done != beginRfid)
@ -79,6 +65,20 @@ public class StationReadyState : IState
return SwappingStateMachine.ReturnWithInvokeErr(readRfid, ExceptionReason.ReadRfidError);
}
//开启雷达
var beginRadar = ControlRadar(machine, 1);
if (InvokeStatus.Done != beginRadar)
{
return SwappingStateMachine.ReturnWithInvokeErr(beginRadar, ExceptionReason.None);
}
//调整车辆
var adjustCarByRadar = AdjustCarByRadar(machine);
if (InvokeStatus.Done != adjustCarByRadar)
{
return SwappingStateMachine.ReturnWithInvokeErr(adjustCarByRadar, ExceptionReason.None);
}
return new StateResult()
{
SwappingState = SwappingState.CarPrepare,
@ -130,6 +130,37 @@ public class StationReadyState : IState
}, true, () => { }, 5, InvokeStatus.None);
}
/// <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 InvokeStatus AdjustCarByRadar(SwappingStateMachine machine)
{
return Invoker.Invoke("begin Radar", 1000, 20, machine.IsCanceled, () => PadarMgr._PadarClient?.CarState == 6,
() =>
{
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;
}
});
}
public InvokeStatus EntranceRadar(SwappingStateMachine machine)
{
return Invoker.Invoke("wait entrance radar", 1000, 5, machine.IsCanceled,

@ -1,17 +1,13 @@
using Autofac;
using Entity.Attr;
using Entity.Constant;
using HybirdFrameworkCore.Autofac;
using log4net;
using Repository.Station;
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.Init;
using Service.Station;
using Service.Padar.Client;
namespace Service.Execute.Step;
@ -48,7 +44,7 @@ public class SwapDoneState : IState
Task.Run(() =>
{
//新增换电成功上报云平台数据
_CommonMgr.InsertCloudReportForSwapSuccess(machine);
// _CommonMgr.InsertCloudReportForSwapSuccess(machine);
//换电成功关于bininfo表的更新
_CommonMgr.UpdateBinInfoForSwapSuccess(machine);
@ -79,7 +75,12 @@ public class SwapDoneState : IState
{
return SwappingStateMachine.ReturnWithInvokeErr(existRadar, ExceptionReason.None);
}
//关闭雷达
var closeRadar = ControlRadar(machine, 0);
if (InvokeStatus.Done != closeRadar)
{
return SwappingStateMachine.ReturnWithInvokeErr(closeRadar, ExceptionReason.None);
}
return new StateResult()
{
@ -87,6 +88,22 @@ public class SwapDoneState : IState
};
}
/// <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);
});
}
/// <summary>
/// 车辆上锁
/// </summary>
@ -106,13 +123,6 @@ public class SwapDoneState : IState
if (carInfo.Result?.CarStatus?.LockStatus == 2)
{
machine.BoxCarInfoModel = carInfo.Result;
//设置出口的是绿灯
if (PlcApi.WriteExistLamp(1000))
{
/*machine.LedTool?.WriteProgramContent(
machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
? InfoEnum.SwapInfo.InfoCarLeave.GetLed()
: InfoEnum.SwapInfo.ErrInfoCarLeave.GetLed());*/
SoundApi.PlayOneSound(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
? (int)InfoEnum.SwapInfo.InfoCarLeave
: (int)InfoEnum.SwapInfo.ErrInfoCarLeave);
@ -127,7 +137,6 @@ public class SwapDoneState : IState
machine);
}
}
}
}, () =>
{
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrLockCar.GetLed());
@ -142,7 +151,9 @@ public class SwapDoneState : IState
return Invoker.Invoke("wait exist radar", 1000, 5, machine.IsCanceled, machine.IsManualSwapSucc,
() => machine.RadarOutFlag, () =>
{
if (PlcApi.ExitRadar())
if (PadarMgr._PadarClient.CarState != 1)
{
_log.Info("exist radar false");
}
@ -152,8 +163,6 @@ public class SwapDoneState : IState
_log.Info("exist radar true");
if (PlcApi.WriteExistLamp(1020))
{
//出口写红灯
//更新车辆离场时间,上报云平台
machine.BusinessSwappingForCloudState =
@ -169,7 +178,6 @@ public class SwapDoneState : IState
: InfoEnum.BusinessSwappingStep.RadarOutFailFlag,
machine);
}
}
}, () =>
{
SoundApi.PlayOneSound(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success

@ -1,11 +1,10 @@
using Autofac;
using DotNetty.Common.Utilities;
using Entity.Constant;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using log4net;
using Newtonsoft.Json;
using Repository.Station;
using Service.Charger.Client;
using Service.Execute.Api;
using Service.Execute.Model;
using Service.Execute.Model.Tbox;
@ -252,6 +251,8 @@ public class SwappingStateMachine : IDisposable
TBoxApi.Reset(RfidReadModel.VelVin);
}
ClientMgr.PlcClient?.Reset();
//重置所有小步状态
ResetStep();

@ -10,7 +10,7 @@ public class PadarMgr
{
private static readonly ILog Log = LogManager.GetLogger(typeof(PadarMgr));
public static PadarClient _PadarClient;
public static PadarClient? _PadarClient;
public static void InitClient()
{
//TODO::查询 服务器 连接

@ -27,7 +27,7 @@ public class PlcController : ControllerBase
[Route("SendInitializeCommandReq/{code}")]
public Result<bool> SendInitializeCommandReq(string code)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendInitializeCommandReq();
@ -44,7 +44,7 @@ public class PlcController : ControllerBase
[Route("SendOutboundCommandReq/{code}/{outboundMode}/{takePositionNumber}")]
public Result<bool> SendOutboundCommandReq(string code, byte outboundMode, byte takePositionNumber)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendOutboundCommandReq(outboundMode, takePositionNumber);
@ -61,7 +61,7 @@ public class PlcController : ControllerBase
[Route("SendStartBatterySwapReq/{code}/{takePositionNumber}/{positionNumber}")]
public Result<bool> SendStartBatterySwapReq(string code, byte takePositionNumber, byte positionNumber)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendStartBatterySwapReq(takePositionNumber, positionNumber);
@ -78,7 +78,7 @@ public class PlcController : ControllerBase
[Route("SendStartMovElectricityReq/{code}/{takeBatteryShelfNumber}/{saveBatteryShelfNumber}")]
public Result<bool> SendStartMovElectricityReq(string code, byte takeBatteryShelfNumber, byte saveBatteryShelfNumber)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendStartMovElectricityReq(takeBatteryShelfNumber, saveBatteryShelfNumber);
@ -95,7 +95,7 @@ public class PlcController : ControllerBase
[Route("SendVehicleModelReq/{code}/{cartNo}")]
public Result<bool> SendVehicleModelReq(string code, byte cartNo)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendVehicleModelReq(cartNo);
@ -112,7 +112,7 @@ public class PlcController : ControllerBase
[Route("SendMoveCommandReq/{code}/{takePositionNumber}/{positionNumber}")]
public Result<bool> SendMoveCommandReq(string code, byte takePositionNumber, byte positionNumber)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendMoveCommandReq(takePositionNumber, positionNumber);
@ -129,7 +129,7 @@ public class PlcController : ControllerBase
[Route("SendContinueCommandReq/{code}")]
public Result<bool> SendContinueCommandReq(string code)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendContinueCommandReq();
@ -146,7 +146,7 @@ public class PlcController : ControllerBase
[Route("SendPauseCommandReq/{code}")]
public Result<bool> SendPauseCommandReq(string code)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendPauseCommandReq();
@ -163,7 +163,7 @@ public class PlcController : ControllerBase
[Route("SendInboundCommandsReq/{code}/{positionNumber}")]
public Result<bool> SendInboundCommandsReq(string code, byte positionNumber)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendInboundCommandsReq(positionNumber);
@ -180,7 +180,7 @@ public class PlcController : ControllerBase
[Route("SendTerminationOrderReq/{code}")]
public Result<bool> SendTerminationOrderReq(string code)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendTerminationOrderReq();
@ -197,7 +197,7 @@ public class PlcController : ControllerBase
[Route("SendFaultResetReq/{code}")]
public Result<bool> SendFaultResetReq(string code)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendFaultResetReq();
@ -214,7 +214,7 @@ public class PlcController : ControllerBase
//[Route("SendParameterSettingsReq/{code}/{messageBodyAddress}/{parameterType}/{parameter}")]
//public Result<bool> SendParameterSettingsReq(string code, byte[] messageBodyAddress, byte parameterType, byte parameter)
//{
// Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
// Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
// if (chargerClient != null)
// {
// return chargerClient.SendParameterSettingsReq(messageBodyAddress, parameterType, parameter);
@ -234,7 +234,7 @@ public class PlcController : ControllerBase
[Route("SendParameterSettingsReq/{code}/{parameterType}/{parameter}")]
public Result<bool> SendParameterSettingsReq(string code, byte parameterType, byte parameter)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendParameterSettingsReq( parameterType, parameter);
@ -252,7 +252,7 @@ public class PlcController : ControllerBase
[Route("SendPrepareBatteryOnReq/{code}/{readyBatterySign}/{takePositionNumber}")]
public Result<bool> SendPrepareBatteryOnReq(string code, byte readyBatterySign, byte takePositionNumber)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.GetBySn(code);
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendPrepareBatteryOnReq(readyBatterySign, takePositionNumber);

Loading…
Cancel
Save