充电机测试工件

zw
smartwyy 8 months ago
parent bd401e20fd
commit 1d9492a4fa

@ -12,6 +12,7 @@ using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using LogLevel = DotNetty.Handlers.Logging.LogLevel;
namespace HybirdFrameworkDriver.TcpClient;
@ -20,10 +21,14 @@ public class TcpClient<TH, TD, TE> : IDisposable where TH : IChannelHandler
where TD : ByteToMessageDecoder, new()
where TE : ChannelHandlerAdapter, new()
{
[JsonIgnore]
private static readonly ILog Log = LogManager.GetLogger(typeof(TcpClient<TH, TD, TE>));
[JsonIgnore]
private Bootstrap? _bootstrap;
[JsonIgnore]
private IEventLoopGroup? _eventLoopGroup;
[JsonIgnore]
public IChannel? Channel { get; set; }
public bool Connected { get; set; }

@ -9,6 +9,7 @@ using Service.Charger.Handler;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Msg.Host.Req;
using Service.Charger.Msg.Host.Req.Bms;
namespace Service.Charger.Client;
@ -179,17 +180,6 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
this.Channel.WriteAndFlushAsync(remoteStopCharging);
}
public bool Connect()
{
base.BaseConnect();
if (Connected)
{
SendAuth();
}
return Connected;
}
/// <summary>
/// 监控平台发送功率调节指令
/// </summary>
@ -250,8 +240,39 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
this.Channel.WriteAndFlushAsync(upgradeRequest);
}
/// <summary>
///
/// </summary>
public void SendQueryBattery()
{
QueryBattery queryBattery = new QueryBattery(ChargerConst.BatteryNo);
CurrentCmd = JsonConvert.SerializeObject(queryBattery)+ "\r\n" + BitUtls.BytesToHexStr(queryBattery.ToBytes());
this.Channel.WriteAndFlushAsync(queryBattery);
}
#endregion
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool Connect()
{
base.BaseConnect();
if (Connected)
{
SendAuth();
}
return Connected;
}
/// <summary>
///
/// </summary>
/// <param name="sn"></param>
/// <param name="destAddr"></param>
public void SessionAttr(string sn, string destAddr)
{
ChannelUtils.AddAttr(Channel, ChargerConst.ChargerSn, sn);

@ -1,48 +0,0 @@
using DotNetty.Codecs.Mqtt.Packets;
using HybirdFrameworkCore.Autofac.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Service.Charger.Msg.Host.Req
{
/// <summary>
/// 3.5.16 站控下发 VIN 鉴权的结果
/// </summary>
public class AuthenticationVIN:ASDU
{
/// <summary>
/// 记录类型
/// </summary>
[Property(0, 8)]
public byte RecordType { get; set; }
/// <summary>
/// VIN 鉴权结果 1:通过 2 不通过
/// </summary>
[Property(8, 8)]
public byte VINResult { get; set; }
/// <summary>
/// 站控下发 VIN 鉴权的结果
/// </summary>
/// <param name="vinresult">VIN 鉴权结果 1:通过 2 不通过</param>
public AuthenticationVIN(byte vinresult)
{
PackLen = 0;
CtlArea = 0;
SrcAddr = 0;
FrameTypeNo = 45;
MsgBodyCount = 1;
TransReason = 3;
PublicAddr = 4;
MsgBodyAddr = new byte[] { 0, 0, 0 };
RecordType = 51;
VINResult = vinresult;
}
}
}

@ -1,62 +0,0 @@
using DotNetty.Codecs.Mqtt.Packets;
using HybirdFrameworkCore.Autofac.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Service.Charger.Msg.Host.Req
{
/// <summary>
/// 3.5.5 监控平台下发电池仓的状态
/// </summary>
public class BatteryHolderStatus:ASDU
{
/// <summary>
/// 记录类型
/// </summary>
[Property(0, 8)]
public byte RecordType { get; set; }
/// <summary>
/// 是否有电池 0:无电池 1有电池
/// </summary>
[Property(8, 8)]
public byte Battery { get; set; }
/// <summary>
/// 电接头连接状态 0:未连接 1: 已连接
/// </summary>
[Property(16, 8)]
public byte ConnectionState { get; set; }
/// <summary>
/// 水接头状态 0:未连接 1: 已连接
/// </summary>
[Property(24, 8)]
public byte WaterCondition { get; set; }
/// <summary>
///
/// </summary>
/// <param name="battery">是否有电池 0:无电池 1有电池</param>
/// <param name="connectionState">电接头连接状态 0:未连接 1: 已连接</param>
/// <param name="waterCondition">水接头状态 0:未连接 1: 已连接</param>
public BatteryHolderStatus(byte battery, byte connectionState, byte waterCondition)
{
PackLen = 0;
CtlArea = 0;
SrcAddr = 0;
FrameTypeNo = 45;
MsgBodyCount = 1;
TransReason = 3;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
RecordType = 15;
Battery = battery;
ConnectionState = connectionState;
WaterCondition = waterCondition;
}
}
}

@ -0,0 +1,44 @@
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Host.Req.Bms
{
/// <summary>
/// 3.4.1 监控平台发送功率调节指令
/// </summary>
public class QueryBattery : ASDU
{
/// <summary>
/// 记录类型
/// </summary>
[Property(0, 8)]
public byte RecordType { get; set; }
/// <summary>
/// 记录类型
/// </summary>
[Property(8, 3, PropertyReadConstant.Byte)]
public byte[] Pgn { get; set; } = { 0x00, 0xf8, 0x2c };
/// <summary>
/// 记录类型
/// </summary>
[Property(32, 3, PropertyReadConstant.Byte)]
public byte[] QueryPgn { get; set; }
/// <summary>
///
/// </summary>
/// <param name="queryPgn"></param>
public QueryBattery(byte[] queryPgn)
{
FrameTypeNo = 46;
MsgBodyCount = 1;
TransReason = 3;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
RecordType = 80;
QueryPgn = queryPgn;
}
}
}

@ -1,6 +1,7 @@
using Autofac;
using DotNetty.Handlers.Logging;
using HybirdFrameworkCore.Autofac;
using Newtonsoft.Json;
using Service.Charger.Client;
namespace WinFormStarter;
@ -63,8 +64,8 @@ public partial class Form2 : Form
rtxt.AppendText(t);
}
}
private void SetText(TextBox textBox, string t)
private void SetText(Control textBox, string t)
{
if (textBox.InvokeRequired)
{
@ -81,42 +82,13 @@ public partial class Form2 : Form
}
}
private void SetText(Button button, string t)
{
if (button.InvokeRequired)
{
void Mi()
{
button.Text = t;
}
button.Invoke((MethodInvoker)Mi);
}
else
{
button.Text = t;
}
}
#endregion
private void SetText(Label label, string t)
private void DisplayData()
{
if (label.InvokeRequired)
{
void Mi()
{
label.Text = t;
}
label.Invoke((MethodInvoker)Mi);
}
else
{
label.Text = t;
}
this.SetText(this.rTxtData, JsonConvert.SerializeObject(_chargerClient, Formatting.Indented));
}
#endregion
private void btnChangeInOrOut_Click(object sender, EventArgs e)
{
}
@ -167,6 +139,8 @@ public partial class Form2 : Form
{
_chargerClient?.SendAuth();
AppendText(this.rTxtSend, _chargerClient.CurrentCmd);
DisplayData();
}
private void btnSendBinStatus_Click(object sender, EventArgs e)
@ -205,11 +179,9 @@ public partial class Form2 : Form
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void btnReadBatteryInfo_Click(object sender, EventArgs e)
{
_chargerClient.SendQueryBattery();
DisplayData();
}
}

@ -1,6 +1,7 @@
using Autofac;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using log4net;
using log4net.Config;
using SqlSugar;
using SqlSugar.IOC;
@ -12,6 +13,7 @@ namespace WinFormStarter
internal static class Program
{
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
public static IContainer Container { get; private set; }
/// <summary>
@ -55,6 +57,7 @@ internal static class Program
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs ex)
{
Log.Error($"system error {ex.Exception}");
var result = MessageBox.Show("系统发生错误,您需要退出系统吗?", "异常", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) Application.Exit();
}

Loading…
Cancel
Save