充电机测试

master
smartwyy 6 months ago
parent 1d9492a4fa
commit 2672cce124

@ -117,7 +117,7 @@ namespace Entity.DbModel.Station
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="charge_time_count")]
public string ChargeTimeCount {get;set;}
public int? ChargeTimeCount {get;set;}
/// <summary>
/// Desc:充电电量

@ -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);
}

@ -1,10 +1,11 @@
using Autofac;
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac;
using DotNetty.Transport.Channels;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Redis;
using log4net;
using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
namespace Service.Charger.Handler
{
@ -21,39 +22,86 @@ namespace Service.Charger.Handler
[Order(8)]
[Scope("InstancePerDependency")]
public class RecordChargeHandler : SimpleChannelInboundHandler<RecordCharge>, IBaseHandler
{
{
private static readonly ILog Log = LogManager.GetLogger(typeof(RecordChargeHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, RecordCharge? msg)
private ChargeOrderRepository _chargeOrderRepository;
/// <summary>
///
/// </summary>
/// <param name="chargeOrderRepository"></param>
public RecordChargeHandler(ChargeOrderRepository chargeOrderRepository)
{
_chargeOrderRepository = chargeOrderRepository;
}
protected override void ChannelRead0(IChannelHandlerContext ctx, RecordCharge msg)
{
if(ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
msg.StartTime = (msg.StartYear+1900) + "-" + msg.StartMonth + "-" + msg.StartDay + " " + msg.StartHour + ":" + msg.StartMinute + ":" + msg.StartSecond;
msg.EndTime = (msg.EndYear+1900) + "-" + msg.EndMonth + "-" + msg.EndDay + " " + msg.EndHour + ":" + msg.EndMinute + ":" + msg.EndSecond;
msg.StartTime = (msg.StartYear+1900) + "-" + msg.StartMonth + "-" + msg.StartDay + " " + msg.StartHour + ":" + msg.StartMinute + ":" + msg.StartSecond;
msg.EndTime = (msg.EndYear+1900) + "-" + msg.EndMonth + "-" + msg.EndDay + " " + msg.EndHour + ":" + msg.EndMinute + ":" + msg.EndSecond;
float[] powersPeriods = new float[4] { 0, 0, 0, 0 }; //元素索引顺序代表值1234
if (msg.FlagOfTime1 >= 1 && msg.FlagOfTime1 <= 4){powersPeriods[msg.FlagOfTime1 - 1] += msg.ChargingPowerOfTime1;}
if (msg.FlagOfTime2 >= 1 && msg.FlagOfTime2 <= 4){powersPeriods[msg.FlagOfTime2 - 1] += msg.ChargingPowerOfTime2;}
if (msg.FlagOfTime3 >= 1 && msg.FlagOfTime3 <= 4){powersPeriods[msg.FlagOfTime3 - 1] += msg.ChargingPowerOfTime3;}
if (msg.FlagOfTime4 >= 1 && msg.FlagOfTime4 <= 4){powersPeriods[msg.FlagOfTime4 - 1] += msg.ChargingPowerOfTime4;}
if (msg.FlagOfTime5 >= 1 && msg.FlagOfTime5 <= 4){powersPeriods[msg.FlagOfTime5 - 1] += msg.ChargingPowerOfTime5;}
if (msg.FlagOfTime6 >= 1 && msg.FlagOfTime6 <= 4){powersPeriods[msg.FlagOfTime6 - 1] += msg.ChargingPowerOfTime6;}
if (msg.FlagOfTime7 >= 1 && msg.FlagOfTime7 <= 4){powersPeriods[msg.FlagOfTime7 - 1] += msg.ChargingPowerOfTime7;}
if (msg.FlagOfTime8 >= 1 && msg.FlagOfTime8 <= 4){powersPeriods[msg.FlagOfTime8 - 1] += msg.ChargingPowerOfTime8;}
float[] acPowersPeriods = new float[4] { 0, 0, 0, 0 }; //元素索引顺序代表值1234
if (msg.AcFlagOfTime1 >= 1 && msg.AcFlagOfTime1 <= 4){acPowersPeriods[msg.AcFlagOfTime1 - 1] += msg.AcChargingPowerOfTime1;}
if (msg.AcFlagOfTime2 >= 1 && msg.AcFlagOfTime2 <= 4){acPowersPeriods[msg.AcFlagOfTime2 - 1] += msg.AcChargingPowerOfTime2;}
if (msg.AcFlagOfTime3 >= 1 && msg.AcFlagOfTime3 <= 4){acPowersPeriods[msg.AcFlagOfTime3 - 1] += msg.AcChargingPowerOfTime3;}
if (msg.AcFlagOfTime4 >= 1 && msg.AcFlagOfTime4 <= 4){acPowersPeriods[msg.AcFlagOfTime4 - 1] += msg.AcChargingPowerOfTime4;}
if (msg.AcFlagOfTime5 >= 1 && msg.AcFlagOfTime5 <= 4){acPowersPeriods[msg.AcFlagOfTime5 - 1] += msg.AcChargingPowerOfTime5;}
if (msg.AcFlagOfTime6 >= 1 && msg.AcFlagOfTime6 <= 4){acPowersPeriods[msg.AcFlagOfTime6 - 1] += msg.AcChargingPowerOfTime6;}
if (msg.AcFlagOfTime7 >= 1 && msg.AcFlagOfTime7 <= 4){acPowersPeriods[msg.AcFlagOfTime7 - 1] += msg.AcChargingPowerOfTime7;}
if (msg.AcFlagOfTime8 >= 1 && msg.AcFlagOfTime8 <= 4){acPowersPeriods[msg.AcFlagOfTime8 - 1] += msg.AcChargingPowerOfTime8;}
client.ChargeOrderNo = msg.ChargerOrderNo;
float[] powersPeriods = new float[4] { 0, 0, 0, 0 }; //元素索引顺序代表值1234
if (msg.FlagOfTime1 >= 1 && msg.FlagOfTime1 <= 4){powersPeriods[msg.FlagOfTime1 - 1] += msg.ChargingPowerOfTime1;}
if (msg.FlagOfTime2 >= 1 && msg.FlagOfTime2 <= 4){powersPeriods[msg.FlagOfTime2 - 1] += msg.ChargingPowerOfTime2;}
if (msg.FlagOfTime3 >= 1 && msg.FlagOfTime3 <= 4){powersPeriods[msg.FlagOfTime3 - 1] += msg.ChargingPowerOfTime3;}
if (msg.FlagOfTime4 >= 1 && msg.FlagOfTime4 <= 4){powersPeriods[msg.FlagOfTime4 - 1] += msg.ChargingPowerOfTime4;}
if (msg.FlagOfTime5 >= 1 && msg.FlagOfTime5 <= 4){powersPeriods[msg.FlagOfTime5 - 1] += msg.ChargingPowerOfTime5;}
if (msg.FlagOfTime6 >= 1 && msg.FlagOfTime6 <= 4){powersPeriods[msg.FlagOfTime6 - 1] += msg.ChargingPowerOfTime6;}
if (msg.FlagOfTime7 >= 1 && msg.FlagOfTime7 <= 4){powersPeriods[msg.FlagOfTime7 - 1] += msg.ChargingPowerOfTime7;}
if (msg.FlagOfTime8 >= 1 && msg.FlagOfTime8 <= 4){powersPeriods[msg.FlagOfTime8 - 1] += msg.ChargingPowerOfTime8;}
float[] acPowersPeriods = new float[4] { 0, 0, 0, 0 }; //元素索引顺序代表值1234
if (msg.AcFlagOfTime1 >= 1 && msg.AcFlagOfTime1 <= 4){acPowersPeriods[msg.AcFlagOfTime1 - 1] += msg.AcChargingPowerOfTime1;}
if (msg.AcFlagOfTime2 >= 1 && msg.AcFlagOfTime2 <= 4){acPowersPeriods[msg.AcFlagOfTime2 - 1] += msg.AcChargingPowerOfTime2;}
if (msg.AcFlagOfTime3 >= 1 && msg.AcFlagOfTime3 <= 4){acPowersPeriods[msg.AcFlagOfTime3 - 1] += msg.AcChargingPowerOfTime3;}
if (msg.AcFlagOfTime4 >= 1 && msg.AcFlagOfTime4 <= 4){acPowersPeriods[msg.AcFlagOfTime4 - 1] += msg.AcChargingPowerOfTime4;}
if (msg.AcFlagOfTime5 >= 1 && msg.AcFlagOfTime5 <= 4){acPowersPeriods[msg.AcFlagOfTime5 - 1] += msg.AcChargingPowerOfTime5;}
if (msg.AcFlagOfTime6 >= 1 && msg.AcFlagOfTime6 <= 4){acPowersPeriods[msg.AcFlagOfTime6 - 1] += msg.AcChargingPowerOfTime6;}
if (msg.AcFlagOfTime7 >= 1 && msg.AcFlagOfTime7 <= 4){acPowersPeriods[msg.AcFlagOfTime7 - 1] += msg.AcChargingPowerOfTime7;}
if (msg.AcFlagOfTime8 >= 1 && msg.AcFlagOfTime8 <= 4){acPowersPeriods[msg.AcFlagOfTime8 - 1] += msg.AcChargingPowerOfTime8;}
RedisHelper redisHelper = AppInfo.Container.Resolve<RedisHelper>();
var hlpChannelARedis = redisHelper.GetDatabase(7);
int count = _chargeOrderRepository.GetCount(it => it.Sn == client.ChargeOrderNo);
if (count < 1)
{
ChargeOrder chargeOrder = new ChargeOrder()
{
Sn = client.ChargeOrderNo,
BatteryNo = client.BatterSn,
StartTime = new DateTime((msg.StartYear+1900) , msg.StartMonth ,msg.StartDay ,msg.StartHour, msg.StartMinute, msg.StartSecond),
EndTime = new DateTime(msg.EndYear + 1900, msg.EndMonth, msg.EndDay, msg.EndHour, msg.EndMinute, msg.EndSecond),
StartSoc = msg.SocBefore,
StopSoc = msg.SocAfter,
ChargeTimeCount= msg.ChargingTimeCount,
ElecCount = Convert.ToDecimal(msg.ChargingPower),
AcElecCount = Convert.ToDecimal(msg.AcMeterElecCount),
StartAcElec = Convert.ToDecimal(msg.AcMeterDataBefore),
StopAcElec = Convert.ToDecimal(msg.AcMeterDataAfter),
StartDcElec = Convert.ToDecimal(msg.DcMeterDataBefore),
StopDcElec = Convert.ToDecimal(msg.DcMeterDataAfter),
SharpElecCount = Convert.ToDecimal(powersPeriods[0]),
PeakElecCount = Convert.ToDecimal(powersPeriods[0]),
FlatElecCount = Convert.ToDecimal(powersPeriods[0]),
ValleyElecCount = Convert.ToDecimal(powersPeriods[0]),
AcSharpElecCount = Convert.ToDecimal(acPowersPeriods[0]),
AcPeakElecCount = Convert.ToDecimal(acPowersPeriods[0]),
AcFlatElecCount = Convert.ToDecimal(acPowersPeriods[0]),
AcValleyElecCount = Convert.ToDecimal(acPowersPeriods[0]),
ChargeMode = msg.ChargeMode,
StartMode = msg.StartMode
};
_chargeOrderRepository.Insert(chargeOrder);
}
ctx.Channel.WriteAndFlushAsync(new RecordChargeRespData());
}
}
}

@ -8,7 +8,7 @@ namespace Service.Charger.Msg.Charger.Req
public class RecordCharge : ASDU
{
/// <summary>
/// 充电开始时间-秒
/// 订单编号
/// </summary>
[Property(0, 256, PropertyReadConstant.Byte)]
public string ChargerOrderNo { get; set; }

@ -3,12 +3,12 @@
namespace Service.Charger.Msg.Host.Req
{
/// <summary>
/// 3.4.1 监控平台发送功率调节指令
/// 3.4.5 监控平台下发充电速率设置
/// </summary>
public class AdjustChargeRate : ASDU
{
/// <summary>
/// 记录类型
/// 倍率 例如0.单5C位该0值.1C为 5 ,1C 时该值为 10
/// </summary>
[Property(0, 8)]
public byte RecordType { get; set; }
@ -17,9 +17,13 @@ namespace Service.Charger.Msg.Host.Req
///期望运行 功率
/// </summary>
[Property(8, 16, scale: 0.1)]
public float ExpectedOperatingPower { get; set; }
public float ChargeRage { get; set; }
public AdjustChargeRate(float expectedOperatingPower)
/// <summary>
///
/// </summary>
/// <param name="chargeRage"></param>
public AdjustChargeRate(float chargeRage)
{
FrameTypeNo = 45;
MsgBodyCount = 1;
@ -28,7 +32,7 @@ namespace Service.Charger.Msg.Host.Req
MsgBodyAddr = new byte[] { 0, 0, 0 };
RecordType = 20;
ExpectedOperatingPower = expectedOperatingPower;
ChargeRage = chargeRage;
}
}
}

@ -3,14 +3,15 @@
namespace Service.Charger.Msg.Host.Req
{
/// <summary>
/// 3.4.7 监控平台下发站外允许充电 SOC
/// 3.4.9 监控平台下发站外允许充电 SOC
/// </summary>
public class OutSideAllowCharging : ASDU
public class OutSideAllowChargingSoc : ASDU
{
/// <summary>
/// SOC 限制值
/// </summary>
[Property(0, 8)]
public byte SocValue { get; set; }
}
}

@ -22,9 +22,9 @@ namespace Service.Charger.Msg.Host.Req
/// 期望运行功率
/// </summary>
[Property(8, 16, scale: 0.1)]
public ushort ExpectedOperatingPower { get; set; }
public float ExpectedOperatingPower { get; set; }
public PowerRegulation(ushort expectedOperatingPower)
public PowerRegulation(float expectedOperatingPower)
{
PackLen = 0;
CtlArea = 0;

@ -10,6 +10,12 @@ namespace Service.Charger.Msg.Host.Req
public RemoteStartCharging(byte socLimit, byte changePowerCmdType, float changePower,
string chargeOrderNo)
{
FrameTypeNo = 47;
MsgBodyCount = 1;
TransReason = 3;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
SocLimit = socLimit;
ChangePowerCmdType = changePowerCmdType;
ChangePower = changePower;

@ -15,6 +15,11 @@ namespace Service.Charger.Msg.Host.Req
public RemoteStopCharging(byte stopReason)
{
FrameTypeNo = 50;
MsgBodyCount = 1;
TransReason = 3;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
StopReason = stopReason;
}
}

@ -1,40 +0,0 @@
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Host.Resp
{
/// <summary>
/// 3.5.6 主动上送充电记录响应
/// </summary>
public class RecordChargRespData : ASDU
{
//保留1
[Property(0, 8)] public byte Reserve1 { get; set; }
/// <summary>
/// 充电流水号
/// </summary>
[Property(8, 16, PropertyReadConstant.Byte)]
public byte[] ChargingWater { get; set; }
/// <summary>
/// 充电流水号
/// </summary>
public string ChargingSn { get; set; }
public RecordChargRespData(string chargingWater)
{
PackLen = 0;
CtlArea = 0;
SrcAddr = 0;
FrameTypeNo = 70;
MsgBodyCount = 1;
TransReason = 3;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
Reserve1 = 0;
ChargingSn = chargingWater;
}
}
}

@ -0,0 +1,40 @@
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Host.Resp
{
/// <summary>
/// 3.5.7 主动上送充电记录响应
/// </summary>
public class RecordChargeRespData : ASDU
{
/// <summary>
///
/// </summary>
[Property(0, 8)]
public byte Reserve1 { get; set; }
/// <summary>
/// 充电流水号
/// </summary>
[Property(8, 8)]
public byte Reserve2 { get; set; }
/// <summary>
///
/// </summary>
public RecordChargeRespData()
{
PackLen = 0;
CtlArea = 0;
SrcAddr = 0;
FrameTypeNo = 43;
MsgBodyCount = 1;
TransReason = 4;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
Reserve1 = 0;
Reserve2 = 0;
}
}
}

@ -62,6 +62,10 @@ partial class Form2
this.label2 = new System.Windows.Forms.Label();
this.txtIp = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.btnRefreshData = new System.Windows.Forms.Button();
this.lblBatterNo = new System.Windows.Forms.Label();
this.lblChargeOrderNo = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.grpData.SuspendLayout();
this.grpMsg.SuspendLayout();
@ -73,6 +77,7 @@ partial class Form2
this.groupBox7.SuspendLayout();
this.grpCmd.SuspendLayout();
this.groupBox2.SuspendLayout();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
@ -91,6 +96,7 @@ partial class Form2
//
// grpData
//
this.grpData.Controls.Add(this.panel1);
this.grpData.Controls.Add(this.rTxtData);
this.grpData.Dock = System.Windows.Forms.DockStyle.Fill;
this.grpData.Location = new System.Drawing.Point(3, 718);
@ -102,10 +108,10 @@ partial class Form2
//
// rTxtData
//
this.rTxtData.Dock = System.Windows.Forms.DockStyle.Fill;
this.rTxtData.Dock = System.Windows.Forms.DockStyle.Left;
this.rTxtData.Location = new System.Drawing.Point(3, 19);
this.rTxtData.Name = "rTxtData";
this.rTxtData.Size = new System.Drawing.Size(1106, 407);
this.rTxtData.Size = new System.Drawing.Size(613, 407);
this.rTxtData.TabIndex = 0;
this.rTxtData.Text = "";
//
@ -405,6 +411,43 @@ partial class Form2
this.label1.TabIndex = 0;
this.label1.Text = "IP";
//
// panel1
//
this.panel1.Controls.Add(this.lblChargeOrderNo);
this.panel1.Controls.Add(this.lblBatterNo);
this.panel1.Controls.Add(this.btnRefreshData);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(616, 19);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(493, 407);
this.panel1.TabIndex = 1;
//
// btnRefreshData
//
this.btnRefreshData.Location = new System.Drawing.Point(28, 31);
this.btnRefreshData.Name = "btnRefreshData";
this.btnRefreshData.Size = new System.Drawing.Size(75, 23);
this.btnRefreshData.TabIndex = 19;
this.btnRefreshData.Text = "刷新数据";
this.btnRefreshData.UseVisualStyleBackColor = true;
this.btnRefreshData.Click += new System.EventHandler(this.btnRefreshData_Click);
//
// lblBatterNo
//
this.lblBatterNo.AutoSize = true;
this.lblBatterNo.Location = new System.Drawing.Point(148, 35);
this.lblBatterNo.Name = "lblBatterNo";
this.lblBatterNo.Size = new System.Drawing.Size(0, 15);
this.lblBatterNo.TabIndex = 20;
//
// lblChargeOrderNo
//
this.lblChargeOrderNo.AutoSize = true;
this.lblChargeOrderNo.Location = new System.Drawing.Point(148, 77);
this.lblChargeOrderNo.Name = "lblChargeOrderNo";
this.lblChargeOrderNo.Size = new System.Drawing.Size(0, 15);
this.lblChargeOrderNo.TabIndex = 21;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -425,6 +468,8 @@ partial class Form2
this.grpCmd.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
}
@ -462,4 +507,8 @@ partial class Form2
private RichTextBox rTxtSend;
private GroupBox grpData;
private RichTextBox rTxtData;
private Panel panel1;
private Button btnRefreshData;
private Label lblChargeOrderNo;
private Label lblBatterNo;
}

@ -3,12 +3,15 @@ using DotNetty.Handlers.Logging;
using HybirdFrameworkCore.Autofac;
using Newtonsoft.Json;
using Service.Charger.Client;
using Service.Charger.Msg.Host.Req;
using Timer = System.Windows.Forms.Timer;
namespace WinFormStarter;
public partial class Form2 : Form
{
private ChargerClient? _chargerClient;
private Timer _timer= new Timer();
public Form2()
{
@ -27,6 +30,21 @@ public partial class Form2 : Form
this.rTxtSend.Enabled = false;
this.rTxtReceive.Enabled = false;
_timer.Tick += TimerOnTick;
_timer.Enabled = true;
_timer.Interval = 500;
_timer.Start();
}
private void TimerOnTick(object? sender, EventArgs e)
{
if (_chargerClient != null)
{
SetText(this.rTxtSend, _chargerClient?.CurrentCmd?? "");
SetText(this.rTxtReceive, _chargerClient?.CurrentMsg?? "");
SetText(this.rTxtData, JsonConvert.SerializeObject(_chargerClient, Formatting.Indented));
}
}
#region ui invoke
@ -64,7 +82,7 @@ public partial class Form2 : Form
rtxt.AppendText(t);
}
}
private void SetText(Control textBox, string t)
{
if (textBox.InvokeRequired)
@ -87,10 +105,7 @@ public partial class Form2 : Form
private void DisplayData()
{
this.SetText(this.rTxtData, JsonConvert.SerializeObject(_chargerClient, Formatting.Indented));
}
private void btnChangeInOrOut_Click(object sender, EventArgs e)
{
this.lblBatterNo.Text = _chargerClient?.BatterSn;
}
private void btnConn_Click(object sender, EventArgs e)
@ -139,49 +154,117 @@ public partial class Form2 : Form
{
_chargerClient?.SendAuth();
AppendText(this.rTxtSend, _chargerClient.CurrentCmd);
DisplayData();
MessageBox.Show(@"发送成功");
}
private void btnSendBinStatus_Click(object sender, EventArgs e)
{
_chargerClient.SendBatteryHolderStatus(1, 1, 1);
MessageBox.Show(@"发送成功");
DisplayData();
}
private void btnSendAuxiliaryPower_Click(object sender, EventArgs e)
{
_chargerClient.SendAuxiliaryPower(1);
MessageBox.Show(@"发送成功");
DisplayData();
}
private void btnStartCharge_Click(object sender, EventArgs e)
{
string chargeOrderNo = _chargerClient.SendRemoteStartCharging(100);
_chargerClient.ChargeOrderNo = chargeOrderNo;
MessageBox.Show(@"发送成功");
DisplayData();
}
private void btnStopCharge_Click(object sender, EventArgs e)
{
_chargerClient.SendRemoteStopCharging(0);
MessageBox.Show(@"发送成功");
DisplayData();
}
private void btnChangePower_Click(object sender, EventArgs e)
{
_chargerClient.SendPowerRegulation(1800);
MessageBox.Show(@"发送成功");
DisplayData();
}
private void btnSetChargeRate_Click(object sender, EventArgs e)
{
_chargerClient.SendAdjustChargeRate(10);
MessageBox.Show(@"发送成功");
DisplayData();
}
private void btnOfflineStopCharge_Click(object sender, EventArgs e)
{
_chargerClient.SendOfflineStopCharging(0);
MessageBox.Show(@"发送成功");
DisplayData();
}
private void btnChangeInOrOut_Click(object sender, EventArgs e)
{
_chargerClient.SendChangeChargeMode(1);
MessageBox.Show(@"发送成功");
DisplayData();
}
private void btnSendOutEnableCharge_Click(object sender, EventArgs e)
{
}
private void btnSetPrice_Click(object sender, EventArgs e)
{
SetPeakValleyTime setPeakValleyTime = new SetPeakValleyTime()
{
NumberTime = 8,
StartHH1 = 0,
StartHH2 = 3,
StartHH3 = 6,
StartHH4 = 9,
StartHH5 = 12,
StartHH6 = 15,
StartHH7 = 18,
StartHH8 = 21,
StartMM1 = 0,
StartMM2 = 0,
StartMM3 = 0,
StartMM4 = 0,
StartMM5 = 0,
StartMM6 = 0,
StartMM7 = 0,
StartMM8 = 0,
TimePeak1 = 1,
TimePeak2 = 2,
TimePeak3 = 3,
TimePeak4 = 4,
TimePeak5 = 4,
TimePeak6 = 3,
TimePeak7 = 2,
TimePeak8 = 1
};
_chargerClient.SendSetPeakValleyTime(setPeakValleyTime);
MessageBox.Show(@"发送成功");
DisplayData();
}
private void btnReadBatteryInfo_Click(object sender, EventArgs e)
{
_chargerClient.SendQueryBattery();
MessageBox.Show(@"发送成功");
DisplayData();
}
private void btnRefreshData_Click(object sender, EventArgs e)
{
DisplayData();
}
}
Loading…
Cancel
Save