|
|
|
@ -6,6 +6,7 @@ using Newtonsoft.Json;
|
|
|
|
|
using Service.Charger.Codec;
|
|
|
|
|
using Service.Charger.Common;
|
|
|
|
|
using Service.Charger.Handler;
|
|
|
|
|
using Service.Charger.Msg;
|
|
|
|
|
using Service.Charger.Msg.Charger.Req;
|
|
|
|
|
using Service.Charger.Msg.Charger.Resp;
|
|
|
|
|
using Service.Charger.Msg.Host.Req;
|
|
|
|
@ -19,6 +20,9 @@ namespace Service.Charger.Client;
|
|
|
|
|
[Scope("InstancePerDependency")]
|
|
|
|
|
public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region 属性
|
|
|
|
|
|
|
|
|
|
public ushort AuthTimes { get; set; } = 0;
|
|
|
|
|
public bool IsAuthed { get; set; } = false;
|
|
|
|
|
|
|
|
|
@ -95,8 +99,6 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
/// 充电机告警-遥信数据包总告警 00H正常、01H告警
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool TotalWarning { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 充电机遥测数据
|
|
|
|
|
/// </summary>
|
|
|
|
@ -113,13 +115,34 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 电池编码
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string BatterSn { get; set; }
|
|
|
|
|
public string? BatterSn { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 远程升级-监控网关上送升级完成确认帧
|
|
|
|
|
/// </summary>
|
|
|
|
|
public UplinkUpgrade UplinkUpgrade { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 充电订单号
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string? ChargeOrderNo { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前指令
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string? CurrentCmd { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前接收报文
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string? CurrentMsg { get; set; }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="asdu"></param>
|
|
|
|
|
public void ReceiveMsgHandle(ASDU asdu)
|
|
|
|
|
{
|
|
|
|
|
this.CurrentMsg = CurrentCmd = JsonConvert.SerializeObject(asdu, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(asdu.ToBytes());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 发送指令
|
|
|
|
|
|
|
|
|
@ -146,7 +169,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
byte authCodeKey = ChargerUtils.GetByteRandomNum(); //鉴码KEY[随机数]
|
|
|
|
|
byte[] authCodes = ChargerUtils.GetAuthCodesResult(ChargerConst.AuthCode, authCodeKey); //鉴权码
|
|
|
|
|
Auth auth = new Auth(IncreAuthTimes(), authCodes, authCodeKey);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(auth)+ "\r\n" + BitUtls.BytesToHexStr(auth.ToBytes());
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(auth, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(auth.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(auth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -157,7 +180,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
/// <param name="changePowerCmdType">功率调节指令类型.默认1 绝对功率值</param>
|
|
|
|
|
/// <param name="changePower">0.1kw/位,默认3600</param>
|
|
|
|
|
/// <param name="chargeOrderNo">充电流水号</param>
|
|
|
|
|
public void SendRemoteStartCharging(byte socLimit, float changePower, byte changePowerCmdType=1,
|
|
|
|
|
public string SendRemoteStartCharging(byte socLimit, float changePower=3600, byte changePowerCmdType=1,
|
|
|
|
|
string? chargeOrderNo = null)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(chargeOrderNo))
|
|
|
|
@ -165,8 +188,10 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
chargeOrderNo = ChargerUtils.GenChargeOrderSn();
|
|
|
|
|
}
|
|
|
|
|
var remoteStartCharging = new RemoteStartCharging(socLimit, changePowerCmdType, changePower, chargeOrderNo);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(remoteStartCharging)+ "\r\n" + BitUtls.BytesToHexStr(remoteStartCharging.ToBytes());
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(remoteStartCharging, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(remoteStartCharging.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(remoteStartCharging);
|
|
|
|
|
|
|
|
|
|
return chargeOrderNo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -176,7 +201,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
public void SendRemoteStopCharging(byte reason)
|
|
|
|
|
{
|
|
|
|
|
RemoteStopCharging remoteStopCharging = new RemoteStopCharging(reason);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(remoteStopCharging) + "\r\n" + BitUtls.BytesToHexStr(remoteStopCharging.ToBytes());
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(remoteStopCharging, Formatting.Indented) + "\r\n" + BitUtls.BytesToHexStr(remoteStopCharging.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(remoteStopCharging);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -184,12 +209,22 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
/// 监控平台发送功率调节指令
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="expectedOperatingPower">期望运行功率</param>
|
|
|
|
|
public void SendPowerRegulation(ushort expectedOperatingPower)
|
|
|
|
|
public void SendPowerRegulation(float expectedOperatingPower)
|
|
|
|
|
{
|
|
|
|
|
PowerRegulation powerRegulation = new PowerRegulation(expectedOperatingPower);
|
|
|
|
|
this.Channel.WriteAndFlushAsync(powerRegulation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 倍率 例如,0.单5C位该0值.1C为 5 ,1C 时该值为 10
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rate"></param>
|
|
|
|
|
public void SendAdjustChargeRate(float rate)
|
|
|
|
|
{
|
|
|
|
|
AdjustChargeRate adjustChargeRate = new AdjustChargeRate(rate);
|
|
|
|
|
this.Channel.WriteAndFlushAsync(adjustChargeRate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 监控平台下发辅源控制指令
|
|
|
|
|
/// </summary>
|
|
|
|
@ -197,6 +232,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
public void SendAuxiliaryPower(byte openFlag)
|
|
|
|
|
{
|
|
|
|
|
AuxiliaryPower auxiliaryPower = new AuxiliaryPower(openFlag);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(auxiliaryPower, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(auxiliaryPower.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(auxiliaryPower);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -209,6 +245,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
public void SendBatteryHolderStatus(byte battery, byte connectionState, byte waterCondition)
|
|
|
|
|
{
|
|
|
|
|
BatteryHolderStatus batteryHolderStatus = new BatteryHolderStatus(battery, connectionState, waterCondition);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(batteryHolderStatus, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(batteryHolderStatus.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(batteryHolderStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -240,6 +277,36 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
this.Channel.WriteAndFlushAsync(upgradeRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置尖峰平谷时间段
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="setPeakValleyTime"></param>
|
|
|
|
|
public void SendSetPeakValleyTime(SetPeakValleyTime setPeakValleyTime)
|
|
|
|
|
{
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(setPeakValleyTime, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(setPeakValleyTime.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(setPeakValleyTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 3.4.7 监控平台下发掉线停止充电
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="enabled"> 0:不使能 1:使能</param>
|
|
|
|
|
public void SendOfflineStopCharging(byte enabled)
|
|
|
|
|
{
|
|
|
|
|
OfflineStopCharging offlineStopCharging = new OfflineStopCharging(enabled);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(offlineStopCharging, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(offlineStopCharging.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(offlineStopCharging);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 3.4.12 站控设备切换站内/站外充电切换
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="chargeMode">00:无效 01:站内 02:站外</param>
|
|
|
|
|
public void SendChangeChargeMode(byte chargeMode)
|
|
|
|
|
{
|
|
|
|
|
ChangeChargeMode req = new ChangeChargeMode(chargeMode);
|
|
|
|
|
this.Channel.WriteAndFlushAsync(req);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
@ -247,7 +314,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
public void SendQueryBattery()
|
|
|
|
|
{
|
|
|
|
|
QueryBattery queryBattery = new QueryBattery(ChargerConst.BatteryNo);
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(queryBattery)+ "\r\n" + BitUtls.BytesToHexStr(queryBattery.ToBytes());
|
|
|
|
|
CurrentCmd = JsonConvert.SerializeObject(queryBattery, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(queryBattery.ToBytes());
|
|
|
|
|
this.Channel.WriteAndFlushAsync(queryBattery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|