|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Autofac;
|
|
|
|
|
using DotNetty.Transport.Channels;
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using HybirdFrameworkCore.Autofac;
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
@ -22,6 +23,7 @@ using Service.Charger.Msg.Charger.Resp;
|
|
|
|
|
using Service.Charger.Msg.Host.Req;
|
|
|
|
|
using Service.Charger.Msg.Host.Req.Bms;
|
|
|
|
|
using Service.Charger.Msg.Host.Req.OutCharger.Req;
|
|
|
|
|
using Service.Charger.Server;
|
|
|
|
|
using Service.Init;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
@ -31,7 +33,7 @@ namespace Service.Charger.Client;
|
|
|
|
|
/// 示例程序
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Scope("InstancePerDependency")]
|
|
|
|
|
public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
public class ChargerClient
|
|
|
|
|
{
|
|
|
|
|
#region 属性
|
|
|
|
|
|
|
|
|
@ -39,6 +41,12 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
/// 充电机编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Sn { get; set; }
|
|
|
|
|
|
|
|
|
|
public IChannel Channel { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 充电机是否连接
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Connected { get; set; }
|
|
|
|
|
|
|
|
|
|
public readonly string Gun1 = "1";
|
|
|
|
|
public readonly string Gun2 = "2";
|
|
|
|
@ -433,26 +441,12 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
Auth auth = new Auth(IncreAuthTimes(), authCodes, authCodeKey);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(auth, Formatting.Indented) + "\r\n" +
|
|
|
|
|
BitUtls.BytesToHexStr(auth.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(auth);
|
|
|
|
|
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(auth);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Log().Info("Auth after send SetPeakValleyTime");
|
|
|
|
|
ConcurrentDictionary<string, ChargerClient> chargerClients = ClientMgr.Dictionary;
|
|
|
|
|
if (chargerClients.Values.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var chargerClientsValue in chargerClients.Values)
|
|
|
|
|
{
|
|
|
|
|
if (chargerClientsValue.Connected)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(3000);
|
|
|
|
|
chargerClientsValue.SendSetPeakValleyTime(BulidSetPeakValleyTimeObj(StaticStationInfo.Ceid));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(BulidSetPeakValleyTimeObj(StaticStationInfo.Ceid));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
@ -486,7 +480,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
var remoteStartCharging = new RemoteStartCharging(socLimit, changePowerCmdType, changePower, chargeOrderNo);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(remoteStartCharging, Formatting.Indented) + "\r\n" +
|
|
|
|
|
BitUtls.BytesToHexStr(remoteStartCharging.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(remoteStartCharging);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(remoteStartCharging);
|
|
|
|
|
|
|
|
|
|
return Result<string>.Success(chargeOrderNo);
|
|
|
|
|
}
|
|
|
|
@ -505,7 +499,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
RemoteStopCharging remoteStopCharging = new RemoteStopCharging(reason);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(remoteStopCharging, Formatting.Indented) + "\r\n" +
|
|
|
|
|
BitUtls.BytesToHexStr(remoteStopCharging.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(remoteStopCharging);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(remoteStopCharging);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -521,7 +515,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PowerRegulation powerRegulation = new PowerRegulation(expectedOperatingPower);
|
|
|
|
|
this.Channel.WriteAndFlushAsync(powerRegulation);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(powerRegulation);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -537,7 +531,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AdjustChargeRate adjustChargeRate = new AdjustChargeRate(rate);
|
|
|
|
|
this.Channel.WriteAndFlushAsync(adjustChargeRate);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(adjustChargeRate);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -555,7 +549,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
AuxiliaryPower auxiliaryPower = new AuxiliaryPower(openFlag);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(auxiliaryPower, Formatting.Indented) + "\r\n" +
|
|
|
|
|
BitUtls.BytesToHexStr(auxiliaryPower.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(auxiliaryPower);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(auxiliaryPower);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -575,7 +569,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
BatteryHolderStatus batteryHolderStatus = new BatteryHolderStatus(battery, connectionState, waterCondition);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(batteryHolderStatus, Formatting.Indented) + "\r\n" +
|
|
|
|
|
BitUtls.BytesToHexStr(batteryHolderStatus.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(batteryHolderStatus);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(batteryHolderStatus);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -592,7 +586,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AuthenticationVIN authenticationVIN = new AuthenticationVIN(vinresult);
|
|
|
|
|
this.Channel.WriteAndFlushAsync(authenticationVIN);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(authenticationVIN);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -616,7 +610,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
|
|
|
|
|
UpgradeRequest upgradeRequest = new UpgradeRequest(executionControl, downloadTimeout, versionNumber, fileName,
|
|
|
|
|
fileSize, mD5Verification, url);
|
|
|
|
|
this.Channel.WriteAndFlushAsync(upgradeRequest);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(upgradeRequest);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -641,7 +635,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(setPeakValleyTime, Formatting.Indented) + "\r\n" +
|
|
|
|
|
BitUtls.BytesToHexStr(setPeakValleyTime.ToBytes());
|
|
|
|
|
|
|
|
|
|
this.Channel.WriteAndFlushAsync(setPeakValleyTime);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(setPeakValleyTime);
|
|
|
|
|
|
|
|
|
|
Log().Info($"SendSetPeakValleyTime{CurrentCmd} to chargeOrderNo={BinNo}");
|
|
|
|
|
|
|
|
|
@ -662,7 +656,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
OfflineStopCharging offlineStopCharging = new OfflineStopCharging(enabled);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(offlineStopCharging, Formatting.Indented) + "\r\n" +
|
|
|
|
|
BitUtls.BytesToHexStr(offlineStopCharging.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(offlineStopCharging);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(offlineStopCharging);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -678,7 +672,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChangeChargeMode req = new ChangeChargeMode(chargeMode);
|
|
|
|
|
this.Channel.WriteAndFlushAsync(req);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(req);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -711,7 +705,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
PileStartCharge pileStartCharge =
|
|
|
|
|
new PileStartCharge(pn, socValue, changePowerCmdType, changePower, chargeOrderNo);
|
|
|
|
|
|
|
|
|
|
this.Channel.WriteAndFlushAsync(pileStartCharge);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(pileStartCharge);
|
|
|
|
|
|
|
|
|
|
return Result<string>.Success(chargeOrderNo);
|
|
|
|
|
}
|
|
|
|
@ -732,7 +726,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
Log().Info(
|
|
|
|
|
$"SendStartOutCharger pn={pn}, stopReason={stopReason}");
|
|
|
|
|
PileStopCharge pileStopCharge = new PileStopCharge(pn, stopReason);
|
|
|
|
|
this.Channel.WriteAndFlushAsync(pileStopCharge);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(pileStopCharge);
|
|
|
|
|
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
@ -751,7 +745,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PileAdjustPower powerRegulation = new PileAdjustPower(pn, expectedOperatingPower);
|
|
|
|
|
this.Channel.WriteAndFlushAsync(powerRegulation);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(powerRegulation);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -768,7 +762,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
QueryBattery queryBattery = new QueryBattery(ChargerConst.BatteryNo);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(queryBattery, Formatting.Indented) + "\r\n" +
|
|
|
|
|
BitUtls.BytesToHexStr(queryBattery.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(queryBattery);
|
|
|
|
|
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(queryBattery);
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -857,16 +851,6 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool Connect()
|
|
|
|
|
{
|
|
|
|
|
base.BaseConnect();
|
|
|
|
|
Log().Info($"charger {Sn} connect succeed");
|
|
|
|
|
return Connected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|