换电主流程

master
rszn 5 months ago
parent e97ae2e5f8
commit 7d704e1355

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

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

@ -1,11 +1,7 @@
using System.Collections.Concurrent; using Autofac;
using Autofac;
using Common.Const;
using DotNetty.Transport.Channels;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.Session;
using log4net; using log4net;
using Service.Charger.Server; using Service.Charger.Server;
@ -19,53 +15,12 @@ public static class ClientMgr
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(ClientMgr)); private static readonly ILog Log = LogManager.GetLogger(typeof(ClientMgr));
public static readonly ConcurrentDictionary<string, PlcClient> Dictionary = new(); public static PlcClient? PlcClient { get; set; }
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;
}
//TODO 连接、鉴权,开始充电,结束充电,设置尖峰平谷,读取尖峰平谷,发送功率调节指令,发送辅助源控制指令,下发掉线停止充电, //TODO 连接、鉴权,开始充电,结束充电,设置尖峰平谷,读取尖峰平谷,发送功率调节指令,发送辅助源控制指令,下发掉线停止充电,
public static void InitClient() public static void InitClient()
{ {
Task.Run(() => Task.Run(ConnClient);
{
ConnClient();
});
} }
private static void ConnClient() private static void ConnClient()
@ -79,39 +34,33 @@ public static class ClientMgr
DestAddr = "132,208,208,224" DestAddr = "132,208,208,224"
}; };
Log.Info($"begin to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}"); Log.Info($"begin to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}");
PlcClient client = AppInfo.Container.Resolve<PlcClient>(); PlcClient = AppInfo.Container.Resolve<PlcClient>();
client.AutoReconnect = true; PlcClient.AutoReconnect = true;
//Plc编号 PlcClient.Sn = PlcConst.ChargeEqpCode;
client.Sn = PlcConst.ChargeEqpCode; PlcClient.ConnectedEventHandler += (sender, b) =>
//电池仓编号
//client.BinNo = binInfo?.No;
//client.BatteryNo = binInfo?.BatteryNo;
client.LogName = "Charger" + netInfo.Code;
client.ConnectedEventHandler += (sender, b) =>
{ {
client.SessionAttr(netInfo.Code, netInfo.DestAddr); PlcClient.SessionAttr(netInfo.Code, netInfo.DestAddr);
//鉴权 //鉴权
// client.SendAuth(); // client.SendAuth();
}; };
//ip //ip
client.InitBootstrap(netInfo.NetAddr, int.Parse(netInfo.NetPort)); PlcClient.InitBootstrap(netInfo.NetAddr, int.Parse(netInfo.NetPort));
/*Task.Run(() => /*Task.Run(() =>
{*/ {*/
try try
{ {
client.Connect(); PlcClient.Connect();
client.SessionAttr(netInfo.Code, netInfo.DestAddr); PlcClient.SessionAttr(netInfo.Code, netInfo.DestAddr);
Log.Info($"succeed to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}"); Log.Info($"succeed to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}");
} }
catch (Exception ex) 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}"); Log.Info($"begin to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}");
} }
} }

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

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

@ -1,11 +1,9 @@
using DotNetty.Transport.Channels; using DotNetty.Transport.Channels;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Utils;
using log4net; using log4net;
using Newtonsoft.Json; using Repository.Station;
using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp;
namespace Service.Charger.Handler; namespace Service.Charger.Handler;
@ -17,17 +15,9 @@ namespace Service.Charger.Handler;
public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<BatteryStatusReportedReq>, IBaseHandler public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<BatteryStatusReportedReq>, IBaseHandler
{ {
/// <summary> private static readonly ILog Log =LogManager.GetLogger(typeof(BatteryStatusReportedReqHandler));
///
/// </summary> public BinInfoRepository BinInfoRepository { get; set; }
private static ILog Log(string? sn)
{
if (ObjUtils.IsNotNullOrWhiteSpace(sn))
{
return LogManager.GetLogger("Charger" + sn);
}
return LogManager.GetLogger(typeof(BatteryStatusReportedReqHandler));
}
/// <summary> /// <summary>
@ -35,11 +25,33 @@ public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<Batte
/// </summary> /// </summary>
protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryStatusReportedReq msg) protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryStatusReportedReq msg)
{ {
if (Client.ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) UpdateBinInfo(msg.granary01, "1");
{ UpdateBinInfo(msg.granary02, "2");
Log(sn).Info($"process {JsonConvert.SerializeObject(msg)}"); UpdateBinInfo(msg.granary03, "3");
//TODO:: UpdateBinInfo(msg.granary04, "4");
//ctx.Channel.WriteAndFlushAsync(""); 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 DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Utils;
using log4net; using log4net;
using Newtonsoft.Json; using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp; using Service.Charger.Msg.Host.Resp;
namespace Service.Charger.Handler; namespace Service.Charger.Handler;
@ -17,17 +15,7 @@ namespace Service.Charger.Handler;
public class SwapBatteryFinishReqHandler : SimpleChannelInboundHandler<SwapBatteryFinishReq>, IBaseHandler public class SwapBatteryFinishReqHandler : SimpleChannelInboundHandler<SwapBatteryFinishReq>, IBaseHandler
{ {
/// <summary> private static readonly ILog Log = LogManager.GetLogger(typeof(SwapBatteryFinishReqHandler));
///
/// </summary>
private static ILog Log(string? sn)
{
if (ObjUtils.IsNotNullOrWhiteSpace(sn))
{
return LogManager.GetLogger("Charger" + sn);
}
return LogManager.GetLogger(typeof(SwapBatteryFinishReqHandler));
}
/// <summary> /// <summary>
@ -35,10 +23,8 @@ public class SwapBatteryFinishReqHandler : SimpleChannelInboundHandler<SwapBatte
/// </summary> /// </summary>
protected override void ChannelRead0(IChannelHandlerContext ctx, SwapBatteryFinishReq msg) protected override void ChannelRead0(IChannelHandlerContext ctx, SwapBatteryFinishReq msg)
{ {
if (Client.ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) Log.Info("swap finish");
{ ctx.Channel.WriteAndFlushAsync(new SwapBatteryFinishResq());
Log(sn).Info($"process {JsonConvert.SerializeObject(msg)}"); ClientMgr.PlcClient.SwapDone = true;
ctx.Channel.WriteAndFlushAsync(new Msg.Host.Resp.SwapBatteryFinishResq());
}
} }
} }

@ -1,4 +1,5 @@
using log4net; using log4net;
using Service.Charger.Client;
using Service.Plc.Client; using Service.Plc.Client;
namespace Service.Execute.Api; namespace Service.Execute.Api;
@ -110,10 +111,10 @@ public class PlcApi
{ {
Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}"); 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}"); Log.Info($"PlcApi StartSwapping done");
return distributeTask; return true;
} }

@ -41,12 +41,12 @@ public class CarPrepareState : IState
}; };
} }
//云平台车辆认证 // 云平台车辆认证
var cloudCheckVel = CloudCheckVel(machine); // var cloudCheckVel = CloudCheckVel(machine);
if (cloudCheckVel != InvokeStatus.Done) // if (cloudCheckVel != InvokeStatus.Done)
{ // {
return SwappingStateMachine.ReturnWithInvokeErr(cloudCheckVel, ExceptionReason.None); // return SwappingStateMachine.ReturnWithInvokeErr(cloudCheckVel, ExceptionReason.None);
} // }
//TBox连接 //TBox连接
if (StaticStationInfo.TboxStateConnect) if (StaticStationInfo.TboxStateConnect)
@ -268,7 +268,7 @@ public class CarPrepareState : IState
bool isConnect = result.Result; bool isConnect = result.Result;
if (isConnect) if (isConnect)
{ {
//读取车辆carNo=carVin //读取车辆carNo=carVin
Task<TboxCarInfoModel> carInfoResult = TBoxApi.GetCarInfo(machine.RfidReadModel.VelVin); Task<TboxCarInfoModel> carInfoResult = TBoxApi.GetCarInfo(machine.RfidReadModel.VelVin);
var tboxCarInfoModel = carInfoResult.Result; var tboxCarInfoModel = carInfoResult.Result;
var carInfo = tboxCarInfoModel?.CarInfo; var carInfo = tboxCarInfoModel?.CarInfo;
@ -399,4 +399,4 @@ public class CarPrepareState : IState
} }
, false, () => { }, 10, InvokeStatus.None); , false, () => { }, 10, InvokeStatus.None);
} }
} }

@ -1,17 +1,13 @@
using Autofac; using Autofac;
using Entity.Attr;
using Entity.Constant; using Entity.Constant;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using log4net; using log4net;
using Repository.Station; using Service.Charger.Client;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Model;
using Service.Execute.Model.Tbox; using Service.Execute.Model.Tbox;
using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Execute.Utils; using Service.Execute.Utils;
using Service.Init; using Service.Init;
using Service.Station;
namespace Service.Execute.Step; namespace Service.Execute.Step;
@ -30,11 +26,11 @@ public class DoSwappingState : IState
//再次读锁止状态防止plc需要挪车 //再次读锁止状态防止plc需要挪车
InvokeStatus carInPosition2 = CarInPosition2(machine); //InvokeStatus carInPosition2 = CarInPosition2(machine);
if (carInPosition2 != InvokeStatus.Done) //if (carInPosition2 != InvokeStatus.Done)
{ //{
return SwappingStateMachine.ReturnWithInvokeErr(carInPosition2, ExceptionReason.None); // return SwappingStateMachine.ReturnWithInvokeErr(carInPosition2, ExceptionReason.None);
} //}
//下发启动换电 //下发启动换电
@ -44,19 +40,19 @@ public class DoSwappingState : IState
return SwappingStateMachine.ReturnWithInvokeErr(startSwapping, ExceptionReason.None); return SwappingStateMachine.ReturnWithInvokeErr(startSwapping, ExceptionReason.None);
} }
InvokeStatus holdOn = HoldOn(machine); //InvokeStatus holdOn = HoldOn(machine);
if (holdOn != InvokeStatus.Done) //if (holdOn != InvokeStatus.Done)
{ //{
return SwappingStateMachine.ReturnWithInvokeErr(holdOn, ExceptionReason.None); // return SwappingStateMachine.ReturnWithInvokeErr(holdOn, ExceptionReason.None);
} //}
//查看通道状态 //查看通道状态
StateResult checkChannelStatus = CheckChannelStatus(machine); // StateResult checkChannelStatus = CheckChannelStatus(machine);
if (checkChannelStatus != null) // if (checkChannelStatus != null)
{ // {
return checkChannelStatus; // return checkChannelStatus;
} // }
//旧电池拆卸 //旧电池拆卸
InvokeStatus unPack = UnPack(machine); InvokeStatus unPack = UnPack(machine);
@ -66,18 +62,18 @@ public class DoSwappingState : IState
} }
//旧电池搬运 //旧电池搬运
InvokeStatus oldBatteryCarryIn = OldBatteryCarryIn(machine); // InvokeStatus oldBatteryCarryIn = OldBatteryCarryIn(machine);
if (oldBatteryCarryIn != InvokeStatus.Done) // if (oldBatteryCarryIn != InvokeStatus.Done)
{ // {
return SwappingStateMachine.ReturnWithInvokeErr(oldBatteryCarryIn, ExceptionReason.None); // return SwappingStateMachine.ReturnWithInvokeErr(oldBatteryCarryIn, ExceptionReason.None);
} // }
//新电池搬运 //新电池搬运
InvokeStatus newBatteryCarryOut = NewBatteryCarryOut(machine); // InvokeStatus newBatteryCarryOut = NewBatteryCarryOut(machine);
if (newBatteryCarryOut != InvokeStatus.Done) // if (newBatteryCarryOut != InvokeStatus.Done)
{ // {
return SwappingStateMachine.ReturnWithInvokeErr(newBatteryCarryOut, ExceptionReason.None); // return SwappingStateMachine.ReturnWithInvokeErr(newBatteryCarryOut, ExceptionReason.None);
} // }
//安装 //安装
InvokeStatus pack = Pack(machine); InvokeStatus pack = Pack(machine);
@ -87,19 +83,18 @@ public class DoSwappingState : IState
} }
//安装完成 //安装完成
InvokeStatus packFinish = PackFinish(machine); //InvokeStatus packFinish = PackFinish(machine);
if (packFinish != InvokeStatus.Done) //if (packFinish != InvokeStatus.Done)
{ //{
return SwappingStateMachine.ReturnWithInvokeErr(packFinish, ExceptionReason.None); // return SwappingStateMachine.ReturnWithInvokeErr(packFinish, ExceptionReason.None);
} //}
////航车回归安全位置
//航车回归安全位置 //InvokeStatus toInvokeStatus = ToSafePosition(machine);
InvokeStatus toInvokeStatus = ToSafePosition(machine); //if (toInvokeStatus != InvokeStatus.Done)
if (toInvokeStatus != InvokeStatus.Done) //{
{ // return SwappingStateMachine.ReturnWithInvokeErr(toInvokeStatus, ExceptionReason.None);
return SwappingStateMachine.ReturnWithInvokeErr(toInvokeStatus, ExceptionReason.None); //}
}
return new StateResult() return new StateResult()
@ -121,13 +116,11 @@ public class DoSwappingState : IState
bool unLock = result.Result; bool unLock = result.Result;
if (unLock) if (unLock)
{ {
//查询车辆锁止状态
var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No, var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.SwapOrderBatteryInfo.UpBinInfo.No); machine.SwapOrderBatteryInfo.UpBinInfo.No);
//查詢當前任務狀態是否被更改 //查詢當前任務狀態是否被更改
var readPlcTaskStatus = PlcApi.ReadTaskStatus(1); if (startSwapping)
if (startSwapping && readPlcTaskStatus)
{ {
machine.SwapOrder.SwapBeginTime = DateTime.Now; machine.SwapOrder.SwapBeginTime = DateTime.Now;
_CommonMgr.UpdateSwapOrder(machine); _CommonMgr.UpdateSwapOrder(machine);
@ -139,7 +132,7 @@ public class DoSwappingState : IState
} }
}, () => }, () =>
{ {
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap); SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap);
},false, () => { },10,InvokeStatus.None); },false, () => { },10,InvokeStatus.None);
} }
@ -185,15 +178,7 @@ public class DoSwappingState : IState
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoUnPack.GetLed()); // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoUnPack.GetLed());
int status = PlcApi.ReadPlcTaskStatus(); machine.UnOldBatteryFlag = ClientMgr.PlcClient.DisassembleDone;
//处理程序太快plc还没有初始值的状态
if (status == 1002 || status != 1003)
{
}
else
{
machine.UnOldBatteryFlag = true;
}
if (machine.UnOldBatteryFlag) if (machine.UnOldBatteryFlag)
{ {
@ -240,7 +225,7 @@ public class DoSwappingState : IState
if (PlcApi.ReadPlcTaskStatus() == 1004) if (PlcApi.ReadPlcTaskStatus() == 1004)
{ {
} }
else else
{ {
@ -263,14 +248,7 @@ public class DoSwappingState : IState
() => machine.InstallNewBatteryFlag, () => () => machine.InstallNewBatteryFlag, () =>
{ {
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed()); // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed());
if (PlcApi.ReadPlcTaskStatus() == 1005) machine.InstallNewBatteryFlag = ClientMgr.PlcClient.SwapDone;
{
}
else
{
machine.InstallNewBatteryFlag = true;
}
if (machine.InstallNewBatteryFlag) if (machine.InstallNewBatteryFlag)
{ {
@ -318,7 +296,7 @@ public class DoSwappingState : IState
() => machine.ToSafePositionFlag, () => () => machine.ToSafePositionFlag, () =>
{ {
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPackFinish.GetLed()); // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPackFinish.GetLed());
if (PlcApi.ReadPlcTaskStatus() == 1007) if (PlcApi.ReadPlcTaskStatus() == 1007)
{ {
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition); SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition);
@ -344,13 +322,13 @@ public class DoSwappingState : IState
int count = 0; int count = 0;
while (!machine.ChannelStatusOkFlag) while (!machine.ChannelStatusOkFlag)
{ {
if (machine.CancelFlag) if (machine.CancelFlag)
{ {
_log.Info($" CheckChannelStatus canceled"); _log.Info($" CheckChannelStatus canceled");
return StateResult.Cancel; return StateResult.Cancel;
} }
_log.Info("begin plc CheckChannelStatus"); _log.Info("begin plc CheckChannelStatus");
Thread.Sleep(2000); Thread.Sleep(2000);
var channelStatus = PlcApi.ChannelStatus(); var channelStatus = PlcApi.ChannelStatus();
@ -448,7 +426,7 @@ public class DoSwappingState : IState
succCount++; succCount++;
} }
} }
if (succCount==successCount) if (succCount==successCount)
{ {
machine.VehiclesInPlace2Flag = true; machine.VehiclesInPlace2Flag = true;
@ -461,4 +439,4 @@ public class DoSwappingState : IState
}, false, () => { } }, false, () => { }
, 20, InvokeStatus.None); , 20, InvokeStatus.None);
} }
} }

@ -1,19 +1,15 @@
using System.Text; using Autofac;
using Autofac;
using Entity.Attr;
using Entity.Constant; using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using log4net; using log4net;
using Newtonsoft.Json; using Newtonsoft.Json;
using Repository.Station;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Execute.Utils; using Service.Execute.Utils;
using Service.Init; using Service.Init;
using Service.Station; using Service.Padar.Client;
using Swapping.Business.Common; using Swapping.Business.Common;
namespace Service.Execute.Step; namespace Service.Execute.Step;
@ -54,16 +50,6 @@ public class StationReadyState : IState
return SwappingStateMachine.ReturnWithInvokeErr(plcIsRemote, ExceptionReason.None); return SwappingStateMachine.ReturnWithInvokeErr(plcIsRemote, ExceptionReason.None);
} }
//监测雷达
var entranceRadar = EntranceRadar(machine);
if (InvokeStatus.Done != entranceRadar)
{
return SwappingStateMachine.ReturnWithInvokeErr(entranceRadar, ExceptionReason.None);
}
//开始读rifd //开始读rifd
var beginRfid = BeginRead(machine); var beginRfid = BeginRead(machine);
if (InvokeStatus.Done != beginRfid) if (InvokeStatus.Done != beginRfid)
@ -79,6 +65,20 @@ public class StationReadyState : IState
return SwappingStateMachine.ReturnWithInvokeErr(readRfid, ExceptionReason.ReadRfidError); 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() return new StateResult()
{ {
SwappingState = SwappingState.CarPrepare, SwappingState = SwappingState.CarPrepare,
@ -130,6 +130,37 @@ public class StationReadyState : IState
}, true, () => { }, 5, InvokeStatus.None); }, 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) public InvokeStatus EntranceRadar(SwappingStateMachine machine)
{ {
return Invoker.Invoke("wait entrance radar", 1000, 5, machine.IsCanceled, return Invoker.Invoke("wait entrance radar", 1000, 5, machine.IsCanceled,
@ -211,9 +242,9 @@ public class StationReadyState : IState
Task<RfidReadModel?> rfidReadModel = RfidApi.ReadRfid(); Task<RfidReadModel?> rfidReadModel = RfidApi.ReadRfid();
rfidReadModel.Wait(); rfidReadModel.Wait();
var machineRfidReadModel = rfidReadModel.Result; var machineRfidReadModel = rfidReadModel.Result;
if ( rfidReadModel.IsCompletedSuccessfully && machineRfidReadModel != null if ( rfidReadModel.IsCompletedSuccessfully && machineRfidReadModel != null
&& machineRfidReadModel.Result==1 && machineRfidReadModel.Result==1
&& !string.IsNullOrEmpty(machineRfidReadModel.VelVin)) && !string.IsNullOrEmpty(machineRfidReadModel.VelVin))
{ {
@ -260,4 +291,4 @@ public class StationReadyState : IState
return swapOrder; return swapOrder;
} }
} }

@ -1,17 +1,13 @@
using Autofac; using Autofac;
using Entity.Attr;
using Entity.Constant; using Entity.Constant;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using log4net; using log4net;
using Repository.Station;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Model;
using Service.Execute.Model.Tbox; using Service.Execute.Model.Tbox;
using Service.Execute.StaticTools;
using Service.Execute.SwapException; using Service.Execute.SwapException;
using Service.Execute.Utils; using Service.Execute.Utils;
using Service.Init; using Service.Init;
using Service.Station; using Service.Padar.Client;
namespace Service.Execute.Step; namespace Service.Execute.Step;
@ -48,7 +44,7 @@ public class SwapDoneState : IState
Task.Run(() => Task.Run(() =>
{ {
//新增换电成功上报云平台数据 //新增换电成功上报云平台数据
_CommonMgr.InsertCloudReportForSwapSuccess(machine); // _CommonMgr.InsertCloudReportForSwapSuccess(machine);
//换电成功关于bininfo表的更新 //换电成功关于bininfo表的更新
_CommonMgr.UpdateBinInfoForSwapSuccess(machine); _CommonMgr.UpdateBinInfoForSwapSuccess(machine);
@ -74,12 +70,17 @@ public class SwapDoneState : IState
} }
//出口雷达监测 //出口雷达监测
InvokeStatus existRadar = ExistRadar(machine); InvokeStatus existRadar = ExistRadar(machine);
if (existRadar != InvokeStatus.Done) if (existRadar != InvokeStatus.Done)
{ {
return SwappingStateMachine.ReturnWithInvokeErr(existRadar, ExceptionReason.None); return SwappingStateMachine.ReturnWithInvokeErr(existRadar, ExceptionReason.None);
} }
//关闭雷达
var closeRadar = ControlRadar(machine, 0);
if (InvokeStatus.Done != closeRadar)
{
return SwappingStateMachine.ReturnWithInvokeErr(closeRadar, ExceptionReason.None);
}
return new StateResult() 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>
/// 车辆上锁 /// 车辆上锁
/// </summary> /// </summary>
@ -106,26 +123,18 @@ public class SwapDoneState : IState
if (carInfo.Result?.CarStatus?.LockStatus == 2) if (carInfo.Result?.CarStatus?.LockStatus == 2)
{ {
machine.BoxCarInfoModel = carInfo.Result; machine.BoxCarInfoModel = carInfo.Result;
//设置出口的是绿灯 SoundApi.PlayOneSound(machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
if (PlcApi.WriteExistLamp(1000)) ? (int)InfoEnum.SwapInfo.InfoCarLeave
: (int)InfoEnum.SwapInfo.ErrInfoCarLeave);
machine.VelLockFlag = true;
//断连Tbox
if (StaticStationInfo.TboxStateDisConnect)
{ {
/*machine.LedTool?.WriteProgramContent( TBoxApi.DisConnect(machine.BoxCarInfoModel.CarNo);
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);
machine.VelLockFlag = true;
//断连Tbox
if (StaticStationInfo.TboxStateDisConnect)
{
TBoxApi.DisConnect(machine.BoxCarInfoModel.CarNo);
}
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag,
machine);
} }
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.VelLockFlag,
machine);
} }
} }
}, () => }, () =>
@ -142,7 +151,9 @@ public class SwapDoneState : IState
return Invoker.Invoke("wait exist radar", 1000, 5, machine.IsCanceled, machine.IsManualSwapSucc, return Invoker.Invoke("wait exist radar", 1000, 5, machine.IsCanceled, machine.IsManualSwapSucc,
() => machine.RadarOutFlag, () => () => machine.RadarOutFlag, () =>
{ {
if (PlcApi.ExitRadar())
if (PadarMgr._PadarClient.CarState != 1)
{ {
_log.Info("exist radar false"); _log.Info("exist radar false");
} }
@ -152,23 +163,20 @@ public class SwapDoneState : IState
_log.Info("exist radar true"); _log.Info("exist radar true");
if (PlcApi.WriteExistLamp(1020)) //出口写红灯
{ //更新车辆离场时间,上报云平台
//出口写红灯 machine.BusinessSwappingForCloudState =
//更新车辆离场时间,上报云平台 InfoEnum.BusinessSwappingForCloudState.SwapDoneWithoutVel;
machine.BusinessSwappingForCloudState = machine.SwapOrder!.VehicleLeaveTime = DateTime.Now;
InfoEnum.BusinessSwappingForCloudState.SwapDoneWithoutVel; _CommonMgr.UpdateSwapOrder(machine);
machine.SwapOrder!.VehicleLeaveTime = DateTime.Now;
_CommonMgr.UpdateSwapOrder(machine); machine.RadarOutFlag = true;
machine.RadarOutFlag = true; _CommonMgr.InsertStep(
machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success
_CommonMgr.InsertStep( ? InfoEnum.BusinessSwappingStep.RadarOutFlag
machine.SwapStatus == (int)InfoEnum.SwapOrderResult.Success : InfoEnum.BusinessSwappingStep.RadarOutFailFlag,
? InfoEnum.BusinessSwappingStep.RadarOutFlag machine);
: InfoEnum.BusinessSwappingStep.RadarOutFailFlag,
machine);
}
} }
}, () => }, () =>
{ {
@ -177,4 +185,4 @@ public class SwapDoneState : IState
: (int)InfoEnum.SwapInfo.ErrInfoCarLeave); : (int)InfoEnum.SwapInfo.ErrInfoCarLeave);
}, false, () => { }, 10, InvokeStatus.None); }, false, () => { }, 10, InvokeStatus.None);
} }
} }

@ -1,11 +1,10 @@
using Autofac; using Autofac;
using DotNetty.Common.Utilities;
using Entity.Constant; using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using log4net; using log4net;
using Newtonsoft.Json;
using Repository.Station; using Repository.Station;
using Service.Charger.Client;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Model; using Service.Execute.Model;
using Service.Execute.Model.Tbox; using Service.Execute.Model.Tbox;
@ -252,6 +251,8 @@ public class SwappingStateMachine : IDisposable
TBoxApi.Reset(RfidReadModel.VelVin); TBoxApi.Reset(RfidReadModel.VelVin);
} }
ClientMgr.PlcClient?.Reset();
//重置所有小步状态 //重置所有小步状态
ResetStep(); ResetStep();
@ -395,7 +396,7 @@ public class SwappingStateMachine : IDisposable
} }
} }
//预约单 //预约单
List<SwapAmtOrder> amtOrderInfos = AmtOrderRepository.QueryListByClause(it => List<SwapAmtOrder> amtOrderInfos = AmtOrderRepository.QueryListByClause(it =>
it.ExpireTime < DateTime.Now it.ExpireTime < DateTime.Now
&& it.Status == (byte)InfoEnum.AmtOrderStatus.Success).ToList(); && it.Status == (byte)InfoEnum.AmtOrderStatus.Success).ToList();
@ -432,4 +433,4 @@ public enum SwappingState
Exception, Exception,
Canceled, Canceled,
ManualSucc, ManualSucc,
} }

@ -10,13 +10,13 @@ public class PadarMgr
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(PadarMgr)); private static readonly ILog Log = LogManager.GetLogger(typeof(PadarMgr));
public static PadarClient _PadarClient; public static PadarClient? _PadarClient;
public static void InitClient() public static void InitClient()
{ {
//TODO::查询 服务器 连接 //TODO::查询 服务器 连接
Task.Run(() => { ConnClient(); }); Task.Run(() => { ConnClient(); });
} }
private static void ConnClient() private static void ConnClient()
{ {
PadarClient client = AppInfo.Container.Resolve<PadarClient>(); PadarClient client = AppInfo.Container.Resolve<PadarClient>();
@ -30,6 +30,6 @@ public class PadarMgr
Log.Info($"succeed to connect"); Log.Info($"succeed to connect");
}); });
} }
} }

@ -27,7 +27,7 @@ public class PlcController : ControllerBase
[Route("SendInitializeCommandReq/{code}")] [Route("SendInitializeCommandReq/{code}")]
public Result<bool> SendInitializeCommandReq(string 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) if (chargerClient != null)
{ {
return chargerClient.SendInitializeCommandReq(); return chargerClient.SendInitializeCommandReq();
@ -44,7 +44,7 @@ public class PlcController : ControllerBase
[Route("SendOutboundCommandReq/{code}/{outboundMode}/{takePositionNumber}")] [Route("SendOutboundCommandReq/{code}/{outboundMode}/{takePositionNumber}")]
public Result<bool> SendOutboundCommandReq(string code, byte outboundMode, byte 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) if (chargerClient != null)
{ {
return chargerClient.SendOutboundCommandReq(outboundMode, takePositionNumber); return chargerClient.SendOutboundCommandReq(outboundMode, takePositionNumber);
@ -61,7 +61,7 @@ public class PlcController : ControllerBase
[Route("SendStartBatterySwapReq/{code}/{takePositionNumber}/{positionNumber}")] [Route("SendStartBatterySwapReq/{code}/{takePositionNumber}/{positionNumber}")]
public Result<bool> SendStartBatterySwapReq(string code, byte takePositionNumber, byte 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) if (chargerClient != null)
{ {
return chargerClient.SendStartBatterySwapReq(takePositionNumber, positionNumber); return chargerClient.SendStartBatterySwapReq(takePositionNumber, positionNumber);
@ -78,7 +78,7 @@ public class PlcController : ControllerBase
[Route("SendStartMovElectricityReq/{code}/{takeBatteryShelfNumber}/{saveBatteryShelfNumber}")] [Route("SendStartMovElectricityReq/{code}/{takeBatteryShelfNumber}/{saveBatteryShelfNumber}")]
public Result<bool> SendStartMovElectricityReq(string code, byte takeBatteryShelfNumber, byte 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) if (chargerClient != null)
{ {
return chargerClient.SendStartMovElectricityReq(takeBatteryShelfNumber, saveBatteryShelfNumber); return chargerClient.SendStartMovElectricityReq(takeBatteryShelfNumber, saveBatteryShelfNumber);
@ -95,7 +95,7 @@ public class PlcController : ControllerBase
[Route("SendVehicleModelReq/{code}/{cartNo}")] [Route("SendVehicleModelReq/{code}/{cartNo}")]
public Result<bool> SendVehicleModelReq(string code, byte 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) if (chargerClient != null)
{ {
return chargerClient.SendVehicleModelReq(cartNo); return chargerClient.SendVehicleModelReq(cartNo);
@ -112,7 +112,7 @@ public class PlcController : ControllerBase
[Route("SendMoveCommandReq/{code}/{takePositionNumber}/{positionNumber}")] [Route("SendMoveCommandReq/{code}/{takePositionNumber}/{positionNumber}")]
public Result<bool> SendMoveCommandReq(string code, byte takePositionNumber, byte 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) if (chargerClient != null)
{ {
return chargerClient.SendMoveCommandReq(takePositionNumber, positionNumber); return chargerClient.SendMoveCommandReq(takePositionNumber, positionNumber);
@ -129,7 +129,7 @@ public class PlcController : ControllerBase
[Route("SendContinueCommandReq/{code}")] [Route("SendContinueCommandReq/{code}")]
public Result<bool> SendContinueCommandReq(string 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) if (chargerClient != null)
{ {
return chargerClient.SendContinueCommandReq(); return chargerClient.SendContinueCommandReq();
@ -146,7 +146,7 @@ public class PlcController : ControllerBase
[Route("SendPauseCommandReq/{code}")] [Route("SendPauseCommandReq/{code}")]
public Result<bool> SendPauseCommandReq(string 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) if (chargerClient != null)
{ {
return chargerClient.SendPauseCommandReq(); return chargerClient.SendPauseCommandReq();
@ -163,7 +163,7 @@ public class PlcController : ControllerBase
[Route("SendInboundCommandsReq/{code}/{positionNumber}")] [Route("SendInboundCommandsReq/{code}/{positionNumber}")]
public Result<bool> SendInboundCommandsReq(string code, byte 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) if (chargerClient != null)
{ {
return chargerClient.SendInboundCommandsReq(positionNumber); return chargerClient.SendInboundCommandsReq(positionNumber);
@ -180,7 +180,7 @@ public class PlcController : ControllerBase
[Route("SendTerminationOrderReq/{code}")] [Route("SendTerminationOrderReq/{code}")]
public Result<bool> SendTerminationOrderReq(string 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) if (chargerClient != null)
{ {
return chargerClient.SendTerminationOrderReq(); return chargerClient.SendTerminationOrderReq();
@ -197,7 +197,7 @@ public class PlcController : ControllerBase
[Route("SendFaultResetReq/{code}")] [Route("SendFaultResetReq/{code}")]
public Result<bool> SendFaultResetReq(string 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) if (chargerClient != null)
{ {
return chargerClient.SendFaultResetReq(); return chargerClient.SendFaultResetReq();
@ -214,7 +214,7 @@ public class PlcController : ControllerBase
//[Route("SendParameterSettingsReq/{code}/{messageBodyAddress}/{parameterType}/{parameter}")] //[Route("SendParameterSettingsReq/{code}/{messageBodyAddress}/{parameterType}/{parameter}")]
//public Result<bool> SendParameterSettingsReq(string code, byte[] messageBodyAddress, byte parameterType, byte 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) // if (chargerClient != null)
// { // {
// return chargerClient.SendParameterSettingsReq(messageBodyAddress, parameterType, parameter); // return chargerClient.SendParameterSettingsReq(messageBodyAddress, parameterType, parameter);
@ -234,11 +234,11 @@ public class PlcController : ControllerBase
[Route("SendParameterSettingsReq/{code}/{parameterType}/{parameter}")] [Route("SendParameterSettingsReq/{code}/{parameterType}/{parameter}")]
public Result<bool> SendParameterSettingsReq(string code, byte parameterType, byte 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) if (chargerClient != null)
{ {
return chargerClient.SendParameterSettingsReq( parameterType, parameter); return chargerClient.SendParameterSettingsReq( parameterType, parameter);
} }
return Result<bool>.Fail("充电机未连接"); return Result<bool>.Fail("充电机未连接");
} }
@ -252,7 +252,7 @@ public class PlcController : ControllerBase
[Route("SendPrepareBatteryOnReq/{code}/{readyBatterySign}/{takePositionNumber}")] [Route("SendPrepareBatteryOnReq/{code}/{readyBatterySign}/{takePositionNumber}")]
public Result<bool> SendPrepareBatteryOnReq(string code, byte readyBatterySign, byte 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) if (chargerClient != null)
{ {
return chargerClient.SendPrepareBatteryOnReq(readyBatterySign, takePositionNumber); return chargerClient.SendPrepareBatteryOnReq(readyBatterySign, takePositionNumber);

Loading…
Cancel
Save