心跳、遥信、遥测Handler的添加

master
lch 6 months ago
parent b6731f95f1
commit 18ad4af3ef

@ -4,6 +4,7 @@ using HybirdFrameworkDriver.TcpClient;
using Service.Charger.Codec;
using Service.Charger.Common;
using Service.Charger.Handler;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Req;
namespace Service.Charger.Client;
@ -21,6 +22,9 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// 参考 ChargingStatus
/// </summary>
public UInt16 ChargingStatus { get; set; }
/// <summary>
/// 是否已经开始充电
/// </summary>
public bool IsCharged { get; set; } = false;
public bool IsStopped { get; set; } = false;
public bool IsCanSendStopCmd { get; set; } = true;
@ -29,6 +33,40 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
public DateTime? ChargingStopTime { get; set; }
/// <summary>
///充电机遥信数据
/// </summary>
public UploadRemoteSignalData uploadRemoteSignalData = new UploadRemoteSignalData();
/// <summary>
/// 充电机工作状态-从遥信数据包中得到。00H待机 01H工作 02H工作完成 03H充/放电暂停
/// </summary>
public byte workstate { get; set; }
/// <summary>
/// 充电机故障-遥信数据包总故障 00H正常、01H故障
/// </summary>
public bool totalError { get; set; }
/// <summary>
/// 充电机告警-遥信数据包总告警 00H正常、01H告警
/// </summary>
public bool totalWarning { get; set; }
/// <summary>
/// 充电机遥测数据
/// </summary>
public UploadTelemetryData uploadTelemetryData = new UploadTelemetryData();
/// <summary>
///充电机实时充电功率
/// </summary>
public float realTimeChargePower { get; set; } = 0;
/// <summary>
/// 心跳-桩状态
/// </summary>
public byte pileState { get; set; }
#region 发送指令

@ -0,0 +1,36 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
namespace Service.Charger.Handler
{
//TODO::心跳的Order 应该是多少
[Order(8)]
[Scope("InstancePerDependency")]
public class HeartBeatHandler : SimpleChannelInboundHandler<HeartBeat>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(HeartBeatHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, HeartBeat msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
//心跳存储日志
Log.Info($"receive {msg} from {sn}");
//心跳桩状态
client.pileState = msg.Status;
//监控平台心跳应答0-正常、1-未注册
HeartBeatRes heartBeatRes = new HeartBeatRes(0);
ctx.Channel.WriteAndFlushAsync(heartBeatRes);
}
else
{
client.ChargingStatus = (int)ChargingStatus.StartChargingFailed;
}
}
}
}

@ -0,0 +1,44 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Service.Charger.Handler
{
/// <summary>
/// 遥信数据上报Handler
/// </summary>
//TODO::Order 应该是多少
[Order(8)]
[Scope("InstancePerDependency")]
public class UploadRemoteSignalDataHandler : SimpleChannelInboundHandler<UploadRemoteSignalData>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(UploadRemoteSignalDataHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, UploadRemoteSignalData msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
//存储日志
Log.Info($"receive {msg} from {sn}");
client.workstate = msg.WorkStatus;
client.IsCharged = msg.WorkStatus == 1 ? true : false;
client.totalError = msg.TotalError;
client.totalWarning = msg.TotalWarning;
client.uploadRemoteSignalData = msg;
}
else
{
client.ChargingStatus = (int)ChargingStatus.StartChargingFailed;
}
}
}
}

@ -0,0 +1,41 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Msg.Charger.Req;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Service.Charger.Handler
{
/// <summary>
/// 遥测数据上报Handler
/// </summary>
//TODO::Order 应该是多少
[Order(8)]
[Scope("InstancePerDependency")]
public class UploadTelemetryDataHandler : SimpleChannelInboundHandler<UploadTelemetryData>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(UploadTelemetryDataHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, UploadTelemetryData msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
//存储日志
Log.Info($"receive {msg} from {sn}");
client.uploadTelemetryData = msg;
//充电机实时充电功率
client.realTimeChargePower = msg.HighVoltageAcquisitionCurrent * msg.HighVoltageAcquisitionVoltage;
}
else
{
client.ChargingStatus = (int)ChargingStatus.StartChargingFailed;
}
}
}
}

File diff suppressed because it is too large Load Diff

@ -16,195 +16,177 @@ namespace Service.Charger.Msg.Charger.Req
/// <summary>
/// 最高蓄电池温度
/// </summary>
[Property(8, 8, PropertyReadConstant.Bit, 1, 0, -50)]
[Property(8, 2, PropertyReadConstant.Byte, 1, 0, -50)]
public Int16 MaxBatteryTemp { get; set; }
/// <summary>
/// 最高温度检测点编号
/// </summary>
[Property(16, 8)]
[Property(24, 16)]
public byte MaxTempDetectionPointNo { get; set; }
/// <summary>
/// 最低蓄电池温度
/// </summary>
[Property(24, 8, PropertyReadConstant.Bit, 1, 0, -50)]
[Property(40, 16, PropertyReadConstant.Bit, 1, 0, -50)]
public Int16 MinBatteryTemp { get; set; }
/// <summary>
/// 最低温度检测点编号
/// </summary>
[Property(32, 8)]
[Property(56, 16)]
public byte MinTempDetectionPointNo { get; set; }
/// <summary>
/// 单体电池最高电压
/// </summary>
[Property(40, 16, PropertyReadConstant.Bit, 0.01, 2, 0)]
[Property(72, 16, PropertyReadConstant.Bit, 0.01, 2, 0)]
public float SingleBatteryMaxVoltage { get; set; }
/// <summary>
/// 单体电池最低压
/// </summary>
[Property(56, 16, PropertyReadConstant.Bit, 0.01, 2, 0)]
[Property(88, 16, PropertyReadConstant.Bit, 0.01, 2, 0)]
public float SingleBatteryMinVoltage { get; set; }
/// <summary>
/// 充电机环境温度
/// </summary>
[Property(72, 8, PropertyReadConstant.Bit, 1, 0, -50)]
[Property(104, 8, PropertyReadConstant.Bit, 1, 0, -50)]
public Int16 ChargerEnvTemp { get; set; }
/// <summary>
/// 充电导引电压
/// </summary>
[Property(80, 16, PropertyReadConstant.Bit, 0.01, 2, 0)]
[Property(112, 16, PropertyReadConstant.Bit, 0.01, 2, 0)]
public float ChargingPilotVoltage { get; set; }
/// <summary>
/// BMS 需求电压
/// </summary>
[Property(96, 16, PropertyReadConstant.Bit, 0.1, 1, 0)]
[Property(128, 16, PropertyReadConstant.Bit, 0.1, 1, 0)]
public float BmsNeedVoltage { get; set; }
/// <summary>
/// BMS 需求电流
/// </summary>
[Property(112, 16, PropertyReadConstant.Bit, 0.1, 1, -400)]
[Property(144, 16, PropertyReadConstant.Bit, 0.1, 1, -400)]
public float BmsNeedCurrent { get; set; }
/// <summary>
/// 充电模式
/// 充电模式 01H:恒压充电、02H恒流充电
/// </summary>
[Property(128, 8)]
[Property(160, 8)]
public byte ChargeMode { get; set; }
/// <summary>
/// BMS 充电电压测量值
/// </summary>
[Property(136, 16, PropertyReadConstant.Bit, 0.1, 1, 0)]
[Property(168, 16, PropertyReadConstant.Bit, 0.1, 1, 0)]
public float BmsChargingVoltage { get; set; }
/// <summary>
/// BMS 充电电流测量值
/// </summary>
[Property(152, 16, PropertyReadConstant.Bit, 0.1, 1, -400)]
[Property(184, 16, PropertyReadConstant.Bit, 0.1, 1, -400)]
public float BmsChargingCurrent { get; set; }
/// <summary>
/// 估算剩余充电时间
/// </summary>
[Property(168, 16, PropertyReadConstant.Bit, 1, 0, 0)]
[Property(200, 16, PropertyReadConstant.Bit, 1, 0, 0)]
public ushort EstimatedRemainingTime { get; set; }
/// <summary>
/// 充电接口温度探头 1
/// </summary>
[Property(184, 8, PropertyReadConstant.Bit, 1, 0, -50)]
[Property(216, 8, PropertyReadConstant.Bit, 1, 0, -50)]
public Int16 ChargingInterfaceDetectionOneTemp { get; set; }
/// <summary>
/// 充电接口温度探头 2
/// </summary>
[Property(192, 8, PropertyReadConstant.Bit, 1, 0, -50)]
[Property(224, 8, PropertyReadConstant.Bit, 1, 0, -50)]
public Int16 ChargingInterfaceDetectionTwoTemp { get; set; }
/// <summary>
/// 充电接口温度探头 3
/// </summary>
[Property(200, 8, PropertyReadConstant.Bit, 1, 0, -50)]
public Int16 ChargingInterfaceDetectionThreeTemp { get; set; }
/// <summary>
/// 充电接口温度探头 4
/// </summary>
[Property(208, 8, PropertyReadConstant.Bit, 1, 0, -50)]
[Property(232, 8, PropertyReadConstant.Bit, 1, 0, -50)]
public Int16 ChargingInterfaceDetectionFourTemp { get; set; }
/// <summary>
/// A 枪直流电表当前电量
/// 直流电表当前电量
/// </summary>
[Property(216, 32, PropertyReadConstant.Bit, 0.01, 2)]
public float AGunDcMeterCurrentPower { get; set; }
[Property(240, 32, PropertyReadConstant.Bit, 0.01, 2)]
public float DcMeterCurrentPower { get; set; }
/// <summary>
/// A 枪充电电压(直流电表电压)
/// 充电电压(直流电表电压)
/// </summary>
[Property(248, 16, PropertyReadConstant.Bit, 0.1, 1)]
public float AGunDcMeterVoltage { get; set; }
[Property(272, 16, PropertyReadConstant.Bit, 0.1, 1)]
public float DcMeterVoltage { get; set; }
/// <summary>
/// A 枪充电电流(直流电表电流)
/// 充电电流(直流电表电流)
/// </summary>
[Property(264, 16, PropertyReadConstant.Bit, 0.1, 1)]
public float AGunDcMeterCurrent { get; set; }
[Property(288, 16, PropertyReadConstant.Bit, 0.1, 1)]
public float DcMeterCurrent { get; set; }
/// <summary>
/// 高压采集电压
/// </summary>
[Property(280, 16, PropertyReadConstant.Bit, 0.1, 1)]
[Property(304, 16, PropertyReadConstant.Bit, 0.1, 1)]
public float HighVoltageAcquisitionVoltage { get; set; }
/// <summary>
/// 高压采集电流
/// </summary>
[Property(296, 16, PropertyReadConstant.Bit, 0.1, 1)]
[Property(320, 16, PropertyReadConstant.Bit, 0.1, 1)]
public float HighVoltageAcquisitionCurrent { get; set; }
/// <summary>
/// 桩内部温度
/// </summary>
[Property(312, 8, PropertyReadConstant.Bit, 1, 0)]
[Property(336, 8, PropertyReadConstant.Bit, 1, 0)]
public byte ChargerInsideTemp { get; set; }
/// <summary>
/// 本次充电时间
/// </summary>
[Property(320, 16)]
[Property(344, 16)]
public ushort ChargingTime { get; set; }
/// <summary>
/// 模块进风口温度
/// </summary>
[Property(336, 8)]
[Property(360, 8)]
public byte ModuleOneAirInletTemp { get; set; }
/// <summary>
/// 模块出风口温度
/// </summary>
[Property(344, 8)]
[Property(368, 8)]
public byte ModuleTwoAirInletTemp { get; set; }
/// <summary>
/// B 枪直流电表当前电量
/// 充电模式 0站内充电 1站外充电
/// </summary>
[Property(352, 32, PropertyReadConstant.Bit, 0.01, 2)]
public float BGunDcMeterCurrentPower { get; set; }
[Property(376, 8)]
public byte ChargeModel { get; set; }
/// <summary>
/// B 枪充电电压(直流电表电压)
/// 充电启动方式 1站控启动 2本地充电
/// </summary>
[Property(384, 16, PropertyReadConstant.Bit, 0.1, 1)]
public float BGunDcMeterVoltage { get; set; }
[Property(384, 8)]
public byte ChargingStartMethod { get; set; }
/// <summary>
/// A 枪充电电流(直流电表电流)
/// 交流电表当前电量
/// </summary>
[Property(392, 32, PropertyReadConstant.Bit, 0.01, 2)]
public float ACMeterCurrentBatteryValue { get; set; }
[Property(400, 16, PropertyReadConstant.Bit, 0.1, 1)]
public float BGunDcMeterCurrent { get; set; }
/// <summary>
/// 交流电表值1
/// </summary>
[Property(416, 32, PropertyReadConstant.Bit, 0.01, 2)]
public float ACMeterValue1 { get; set; }
/// <summary>
/// 交流电表值2
/// </summary>
[Property(448, 32, PropertyReadConstant.Bit, 0.01, 2)]
public float ACMeterValue2 { get; set; }
}
}

@ -16,7 +16,7 @@ namespace Service.Charger.Msg.Host.Resp
/// <summary>
/// 结果 0 正常 1 未注册
/// </summary>
[Property(0, 8)]
[Property(8, 8)]
public byte Result { get; set; }
public HeartBeatRes(byte result)

Loading…
Cancel
Save