You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.3 KiB
108 lines
3.3 KiB
using HybirdFrameworkCore.Autofac.Attribute;
|
|
using HybirdFrameworkDriver.Session;
|
|
using HybirdFrameworkDriver.TcpClient;
|
|
using Service.Charger.Codec;
|
|
using Service.Charger.Common;
|
|
using Service.Charger.Handler;
|
|
using Service.Charger.Msg.Host.Req;
|
|
|
|
namespace Service.Charger.Client;
|
|
|
|
/// <summary>
|
|
/// 示例程序
|
|
/// </summary>
|
|
[Scope("InstancePerDependency")]
|
|
public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
{
|
|
public ushort AuthTimes { get; set; } = 0;
|
|
public bool IsAuthed { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// 参考 ChargingStatus
|
|
/// </summary>
|
|
public UInt16 ChargingStatus { get; set; }
|
|
public bool IsCharged { get; set; } = false;
|
|
public bool IsStopped { get; set; } = false;
|
|
public bool IsCanSendStopCmd { get; set; } = true;
|
|
|
|
public DateTime? ChargingStartTime { get; set; }
|
|
|
|
public DateTime? ChargingStopTime { get; set; }
|
|
|
|
|
|
#region 发送指令
|
|
|
|
private ushort IncreAuthTimes()
|
|
{
|
|
if (AuthTimes < 65535)
|
|
{
|
|
AuthTimes += 1;
|
|
}
|
|
else
|
|
{
|
|
AuthTimes = 1;
|
|
}
|
|
|
|
return AuthTimes;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送鉴权
|
|
/// </summary>
|
|
public void SendAuth()
|
|
{
|
|
byte authCodeKey = ChargerUtils.GetByteRandomNum(); //鉴码KEY[随机数]
|
|
byte[] authCodes = ChargerUtils.GetAuthCodesResult(ChargerConst.AuthCode, authCodeKey); //鉴权码
|
|
Auth auth = new Auth(IncreAuthTimes(), authCodes, authCodeKey);
|
|
this.Channel.WriteAndFlushAsync(auth);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 监控平台发送远程开始充电指令
|
|
/// </summary>
|
|
/// <param name="socLimit">SOC限制.百分比</param>
|
|
/// <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,
|
|
string? chargeOrderNo = null)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(chargeOrderNo))
|
|
{
|
|
chargeOrderNo = ChargerUtils.GenChargeOrderSn();
|
|
}
|
|
var remoteStartCharging = new RemoteStartCharging(socLimit, changePowerCmdType, changePower, chargeOrderNo);
|
|
this.Channel.WriteAndFlushAsync(remoteStartCharging);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 监控平台发送远程停止充电指令
|
|
/// </summary>
|
|
/// <param name="reason">0 正常停机 1 服务器发现桩异常,强制停机</param>
|
|
public void SendRemoteStopCharging(byte reason)
|
|
{
|
|
RemoteStopCharging remoteStopCharging = new RemoteStopCharging(reason);
|
|
this.Channel.WriteAndFlushAsync(remoteStopCharging);
|
|
}
|
|
|
|
public bool Connect()
|
|
{
|
|
base.BaseConnect();
|
|
if (Connected)
|
|
{
|
|
SendAuth();
|
|
}
|
|
|
|
return Connected;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void SessionAttr(int sn, int eqmTypeNo, string eqmCode, string destAddr)
|
|
{
|
|
ChannelUtils.AddAttr(Channel, ChargerConst.ChargerSn, sn.ToString());
|
|
ChannelUtils.AddAttr(Channel, ChargerConst.EqmTypeNo, eqmTypeNo.ToString());
|
|
ChannelUtils.AddAttr(Channel, ChargerConst.EqmCode, eqmCode);
|
|
ChannelUtils.AddAttr(Channel, ChargerConst.DestAddr, destAddr);
|
|
}
|
|
} |