diff --git a/Service/Charger/Client/ChargerClient.cs b/Service/Charger/Client/ChargerClient.cs index 90d906f..4d76746 100644 --- a/Service/Charger/Client/ChargerClient.cs +++ b/Service/Charger/Client/ChargerClient.cs @@ -1,6 +1,7 @@ using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkDriver.Session; using HybirdFrameworkDriver.TcpClient; +using HybirdFrameworkServices.Charger.Handler; using Service.Charger.Codec; using Service.Charger.Common; using Service.Charger.Handler; @@ -28,11 +29,35 @@ public class ChargerClient : TcpClient 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; } + /// + /// 电池包实时数据 + /// + public BatteryPackData? BatteryPackData { get; set; } + /// + /// 电池包实时单体温度&单体电压数据 + /// + public BatteryPackDataVoltage? BatteryPackDataVoltage { get; set; } + /// + /// 电池包上报累计充放电电量 + /// + public BatteryPackTotalElectricity? BatteryPackTotalElectricity { get; set; } + /// + /// 电池包上报充放电口温度 + /// + public BatteryPackPortTemperature? BatteryPackPortTemperature { get; set; } + /// + /// 电池包内部接触器状态和故障上报 + /// + public BatteryPackStateAndFault? BatteryPackStateAndFault { get; set; } + + + + /// ///充电机遥信数据 /// diff --git a/Service/Charger/Codec/Decoder.cs b/Service/Charger/Codec/Decoder.cs index 496f329..9d97f7a 100644 --- a/Service/Charger/Codec/Decoder.cs +++ b/Service/Charger/Codec/Decoder.cs @@ -124,12 +124,20 @@ public class Decoder : ByteToMessageDecoder 48 => ModelConvert.Decode(bytes), 50 => ModelConvert.Decode(bytes), 75 => ModelConvert.Decode(bytes), - 83 => ModelConvert.Decode(bytes), + + 82 => ModelConvert.Decode(bytes), + 83 => ModelConvert.Decode(bytes), + 84 => ModelConvert.Decode(bytes), + 85 => ModelConvert.Decode(bytes), + 86 => ModelConvert.Decode(bytes), + + + //83 => ModelConvert.Decode(bytes), 87 => ModelConvert.Decode(bytes), 49 => ModelConvert.Decode(bytes), 47 => ModelConvert.Decode(bytes), - 86 => ModelConvert.Decode(bytes), + // 86 => ModelConvert.Decode(bytes), _ => throw new InvalidOperationException("This should never be reached"), }, #endregion diff --git a/Service/Charger/Handler/BatteryPackDataHandler.cs b/Service/Charger/Handler/BatteryPackDataHandler.cs new file mode 100644 index 0000000..004811d --- /dev/null +++ b/Service/Charger/Handler/BatteryPackDataHandler.cs @@ -0,0 +1,35 @@ +using System.Text; +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Service.Charger.Client; +using Service.Charger.Handler; +using Service.Charger.Msg.Charger.Req; +using Service.Charger.Msg.Host.Resp; + +namespace HybirdFrameworkServices.Charger.Handler +{ + /// + /// 3.5.9 电池包实时数据上报(站内充电模式有电池包时周期性上传) + /// + /// 1,保存电池包实时数据 + /// 2,保存日志到log + /// + /// + [Order(8)] + [Scope("InstancePerDependency")] + public class BatteryPackDataHandler : SimpleChannelInboundHandler, IBaseHandler + { + private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackDataHandler)); + protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackData msg) + { + if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + { + Log.Info($"receive {msg} from {sn}"); + + client.BatteryPackData = msg; + } + + } + } +} diff --git a/Service/Charger/Handler/BatteryPackDataVoltageHandler.cs b/Service/Charger/Handler/BatteryPackDataVoltageHandler.cs new file mode 100644 index 0000000..ce46250 --- /dev/null +++ b/Service/Charger/Handler/BatteryPackDataVoltageHandler.cs @@ -0,0 +1,35 @@ +using System.Text; +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Service.Charger.Client; +using Service.Charger.Handler; +using Service.Charger.Msg.Charger.Req; +using Service.Charger.Msg.Host.Resp; + +namespace HybirdFrameworkServices.Charger.Handler +{ + /// + /// 3.5.10 电池包实时单体温度&单体电压数据(站内充电模式有电池包时周期性上传) + /// + /// 1,电池包实时单体温度&单体电压数据 + /// 2,保存日志到log + /// + /// + [Order(8)] + [Scope("InstancePerDependency")] + public class BatteryPackDataVoltageHandler : SimpleChannelInboundHandler, IBaseHandler + { + private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackDataVoltageHandler)); + protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackDataVoltage msg) + { + if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + { + Log.Info($"receive {msg} from {sn}"); + + client.BatteryPackDataVoltage = msg; + } + + } + } +} diff --git a/Service/Charger/Handler/BatteryPackPortTemperatureHandler.cs b/Service/Charger/Handler/BatteryPackPortTemperatureHandler.cs new file mode 100644 index 0000000..c9425e2 --- /dev/null +++ b/Service/Charger/Handler/BatteryPackPortTemperatureHandler.cs @@ -0,0 +1,35 @@ +using System.Text; +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Service.Charger.Client; +using Service.Charger.Handler; +using Service.Charger.Msg.Charger.Req; +using Service.Charger.Msg.Host.Resp; + +namespace HybirdFrameworkServices.Charger.Handler +{ + /// + /// 3.5.12 电池包上报充放电口温度(站内充电模式有电池包时周期性上传) + /// + /// 1,保存电池包上报充放电口温度 + /// 2,保存日志到log + /// + /// + [Order(8)] + [Scope("InstancePerDependency")] + public class BatteryPackPortTemperatureHandler : SimpleChannelInboundHandler, IBaseHandler + { + private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackPortTemperatureHandler)); + protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackPortTemperature msg) + { + if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + { + Log.Info($"receive {msg} from {sn}"); + + client.BatteryPackPortTemperature = msg; + } + + } + } +} diff --git a/Service/Charger/Handler/BatteryPackStateAndFaultHandler.cs b/Service/Charger/Handler/BatteryPackStateAndFaultHandler.cs new file mode 100644 index 0000000..8369d68 --- /dev/null +++ b/Service/Charger/Handler/BatteryPackStateAndFaultHandler.cs @@ -0,0 +1,35 @@ +using System.Text; +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Service.Charger.Client; +using Service.Charger.Handler; +using Service.Charger.Msg.Charger.Req; +using Service.Charger.Msg.Host.Resp; + +namespace HybirdFrameworkServices.Charger.Handler +{ + /// + /// 3.5.13 电池包内部接触器状态和故障上报(站内充电模式有电池包时周期性上传) + /// + /// 1,保存电池包内部接触器状态和故障上报 + /// 2,保存日志到log + /// + /// + [Order(8)] + [Scope("InstancePerDependency")] + public class BatteryPackStateAndFaultHandler : SimpleChannelInboundHandler, IBaseHandler + { + private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackStateAndFaultHandler)); + protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackStateAndFault msg) + { + if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + { + Log.Info($"receive {msg} from {sn}"); + + client.BatteryPackStateAndFault = msg; + } + + } + } +} diff --git a/Service/Charger/Handler/BatteryPackTotalElectricityHandler.cs b/Service/Charger/Handler/BatteryPackTotalElectricityHandler.cs new file mode 100644 index 0000000..9cf104e --- /dev/null +++ b/Service/Charger/Handler/BatteryPackTotalElectricityHandler.cs @@ -0,0 +1,35 @@ +using System.Text; +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Service.Charger.Client; +using Service.Charger.Handler; +using Service.Charger.Msg.Charger.Req; +using Service.Charger.Msg.Host.Resp; + +namespace HybirdFrameworkServices.Charger.Handler +{ + /// + /// 3.5.11 电池包上报累计充放电电量(站内充电模式有电池包时周期性上传 + /// + /// 1,保存电池包上报累计充放电电量数据 + /// 2,保存日志到log + /// + /// + [Order(8)] + [Scope("InstancePerDependency")] + public class BatteryPackTotalElectricityHandler : SimpleChannelInboundHandler, IBaseHandler + { + private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryPackTotalElectricityHandler)); + protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryPackTotalElectricity msg) + { + if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) + { + Log.Info($"receive {msg} from {sn}"); + + client.BatteryPackTotalElectricity = msg; + } + + } + } +} diff --git a/Service/Charger/Msg/Charger/Req/BatteryPackData.cs b/Service/Charger/Msg/Charger/Req/BatteryPackData.cs new file mode 100644 index 0000000..809cb0a --- /dev/null +++ b/Service/Charger/Msg/Charger/Req/BatteryPackData.cs @@ -0,0 +1,63 @@ +using HybirdFrameworkCore.Autofac.Attribute; + +namespace Service.Charger.Msg.Charger.Req +{ + /// + /// 3.5.9 电池包实时数据上报(站内充电模式有电池包时周期性上传) + /// + public class BatteryPackData : ASDU + { + /// + /// 记录类型 + /// + [Property(0, 8)] + public byte RecordType { get; set; } + /// + /// 电池包 SOC + /// + [Property(8, 8, PropertyReadConstant.Bit, 0.4, 1)] + public float SOC { get; set; } + /// + /// 电池包 SOH + /// + [Property(16, 8, PropertyReadConstant.Bit, 0.4, 1)] + public float SOH { get; set; } + /// + /// 电池包总电流,充电为负值,放电为正 + /// + [Property(24, 16, PropertyReadConstant.Bit, 0.1, 1, 1000)] + public float TotalCurrent { get; set; } + /// + /// 电池包允许最大回充电电流值(脉冲) + /// + [Property(40, 16, PropertyReadConstant.Bit, 0.1, 1)] + public float AllowableMaxBackCurrent { get; set; } + + /// + /// 电池包允许最大放电电流值(脉冲) + /// + [Property(56, 16, PropertyReadConstant.Bit, 0.1, 1)] + public float AllowableMaxPutCurrent { get; set; } + /// + /// 电池包正极绝缘值 + /// + [Property(72, 16)] + public UInt16 PositiveInsulationValue { get; set; } + /// + /// 电池包负极绝缘值 + /// + [Property(88, 16)] + public UInt16 NegativeInsulationValue { get; set; } + /// + /// 电池端高压(主继电器内侧) + /// + [Property(104, 16)] + public UInt16 BatteryHighVoltage { get; set; } + /// + /// 母线端高压(主继电器外侧) Busbar + /// + [Property(120, 16)] + public UInt16 BusbarHighVoltage { get; set; } + + } +} \ No newline at end of file diff --git a/Service/Charger/Msg/Charger/Req/BatteryPackDataVoltage.cs b/Service/Charger/Msg/Charger/Req/BatteryPackDataVoltage.cs new file mode 100644 index 0000000..1c93f68 --- /dev/null +++ b/Service/Charger/Msg/Charger/Req/BatteryPackDataVoltage.cs @@ -0,0 +1,89 @@ +using HybirdFrameworkCore.Autofac.Attribute; + +namespace Service.Charger.Msg.Charger.Req +{ + /// + /// 3.5.10 电池包实时单体温度&单体电压数据(站内充电模式有电池包时周期性上传) + /// + public class BatteryPackDataVoltage : ASDU + { + /// + /// 记录类型 + /// + [Property(0, 8)] + public byte RecordType { get; set; } + /// + /// 电芯温度最大值 + /// + [Property(8, 8, PropertyReadConstant.Bit, 1, 0, 50)] + public Int16 CellTemperatureMax { get; set; } + /// + /// 电芯温度最小值 + /// + [Property(16, 8, PropertyReadConstant.Bit, 1, 0, 50)] + public Int16 CellTemperatureMin { get; set; } + /// + /// 电芯温度平均值 + /// + [Property(24, 8, PropertyReadConstant.Bit, 1, 0, 50)] + public Int16 CellTemperatureAverage { get; set; } + /// + /// 电芯温度最大值所在 CSC 编号 + /// + [Property(32, 8 )] + public byte CellTemperatureCSCNumber { get; set; } + /// + /// 电芯温度最大值所在 CSC 内温度探针编号 + /// + [Property(40, 8 )] + public byte CellTemperatureCSCProbeNumber { get; set; } + /// + /// 电芯温度最小值所在 CSC 编号 + /// + [Property(48, 8)] + public byte CellTemperatureMinCSCNumber { get; set; } + /// + /// 电芯温度最小值所在 CSC 内温度探针编号 + /// + [Property(56, 8)] + public byte CellTemperatureMinCSCProbeNumber { get; set; } + + /// + /// 电芯电压最大值 + /// + [Property(64, 16, PropertyReadConstant.Bit, 0.001, 3)] + public float CellVoltageMax { get; set; } + /// + /// 电芯电压最大值所在 CSC 编号 + /// + [Property(80, 8)] + public byte CellVoltageCSCNumber { get; set; } + /// + /// 电芯电压最大值所在 CSC 内的单体编号 + /// + [Property(88, 8)] + public byte CellVoltageCSCProbeNumber { get; set; } + /// + /// 电芯电压平均值 + /// + [Property(96, 16, PropertyReadConstant.Bit, 0.001, 3)] + public float CellVoltageAverage { get; set; } + /// + /// 电芯电压最小值 + /// + [Property(112, 8, PropertyReadConstant.Bit, 0.001, 3)] + public float CellVoltageMin { get; set; } + /// + /// 电芯电压最小值所在 CSC 编号 + /// + [Property(128, 8)] + public byte CellVoltageMinCSCNumber { get; set; } + /// + /// 电芯电压最小值所在 CSC 内的单体编号 + /// + [Property(136, 8)] + public byte CellVoltageMinCSCProbeNumber { get; set; } + + + } +} \ No newline at end of file diff --git a/Service/Charger/Msg/Charger/Req/BatteryPackPortTemperature.cs b/Service/Charger/Msg/Charger/Req/BatteryPackPortTemperature.cs new file mode 100644 index 0000000..14011f4 --- /dev/null +++ b/Service/Charger/Msg/Charger/Req/BatteryPackPortTemperature.cs @@ -0,0 +1,38 @@ +using HybirdFrameworkCore.Autofac.Attribute; + +namespace Service.Charger.Msg.Charger.Req +{ + /// + /// 3.5.12 电池包上报充放电口温度(站内充电模式有电池包时周期性上传) + /// + public class BatteryPackPortTemperature : ASDU + { + /// + /// 记录类型 + /// + [Property(0, 8)] + public byte RecordType { get; set; } + /// + /// A 枪温度 1/充电连接器1 温度 1 + /// + [Property(8, 8, PropertyReadConstant.Bit, 1, 0, 50)] + public Int16 AGunTemperature1 { get; set; } + /// + /// A 枪温度 2/充电连接器1 温度2 + /// + [Property(16, 8, PropertyReadConstant.Bit, 1, 0, 50)] + public Int16 AGunTemperature2 { get; set; } + /// + /// B 枪温度 1/充电连接器2 温度 1 + /// + [Property(24, 8, PropertyReadConstant.Bit, 1, 0, 50)] + public Int16 BGunTemperature1 { get; set; } + /// + /// B 枪温度 2/充电连接器2 温度2 + /// + [Property(32, 8, PropertyReadConstant.Bit, 1, 0, 50)] + public Int16 BGunTemperature2 { get; set; } + + + } +} \ No newline at end of file diff --git a/Service/Charger/Msg/Charger/Req/BatteryPackStateAndFault.cs b/Service/Charger/Msg/Charger/Req/BatteryPackStateAndFault.cs new file mode 100644 index 0000000..bfc6113 --- /dev/null +++ b/Service/Charger/Msg/Charger/Req/BatteryPackStateAndFault.cs @@ -0,0 +1,178 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using SqlSugar.DistributedSystem.Snowflake; + +namespace Service.Charger.Msg.Charger.Req +{ + /// + /// 3.5.13 电池包内部接触器状态和故障上报(站内充电模式有电池包时周期性上传) + /// + public class BatteryPackStateAndFault : ASDU + { + /// + /// 记录类型 + /// + [Property(0, 8)] + public byte RecordType { get; set; } + /// + /// 充负 1 继电器粘连故障 + /// + [Property(8, 8)] + public byte ChargingNegativeOneAdhesionFault { get; set; } + /// + /// 充正 1 继电器粘连故 障 + /// + [Property(16, 8)] + public byte ChargingCorrectOneAdhesionFault { get; set; } + /// + /// 主负继电器粘连故障 + /// + [Property(24, 8)] + public byte MainNegativeAdhesionFault { get; set; } + /// + /// 主正继电器粘连故障 + /// + [Property(32, 8)] + public byte MainCorrectAdhesionFault { get; set; } + /// + /// 主负继电器状态(如继 电器状态由 BMS检测) + /// + [Property(40, 8)] + public byte MainNegativeState { get; set; } + /// + /// 主正继电器状态(如继 电器状态由 BMS检测) + /// + [Property(48, 8)] + public byte MainCorrectState { get; set; } + /// + /// 加热 2 继电器粘连故障 + /// + [Property(56, 8)] + public byte HeatingTwoAdhesionFault { get; set; } + /// + /// 加热 1 继电器粘连故障 + /// + [Property(64, 8)] + public byte HeatingOneAdhesionFault { get; set; } + /// + /// 充负 2 继电器粘连故障 + /// + [Property(72, 8)] + public byte ChargingNegativeTwoAdhesionFault { get; set; } + /// + /// 充正 2 继电器粘连故障 + /// + [Property(80, 8)] + public byte ChargingCorrectTwoAdhesionFault { get; set; } + /// + /// 充正继电器 2状态(如 继电器状态由 BMS检测) + /// + [Property(88, 8)] + public byte ChargingCorrectTwoState { get; set; } + /// + /// 充负继电器 2状态(如 继电器状态由 BMS检 测) + /// + [Property(96, 8)] + public byte ChargingNegativeTwoState { get; set; } + /// + /// 充负继电器 1状态(如 继电器状态由 BMS检 测) + /// + [Property(104, 8)] + public byte ChargingNegativeOneState { get; set; } + /// + /// 充正继电器 1状态(如 继电器状态由 BMS检 测 + /// + [Property(112, 8)] + public byte ChargingCorrectOneState { get; set; } + /// + /// 预充继电器状态(如继电器状态由 BMS 检测) + /// + [Property(120, 8)] + public byte PreChargingState { get; set; } + /// + /// 主负继电器无法闭合 报警 + /// + [Property(128, 8)] + public byte MainNegativeNotCloseFault { get; set; } + /// + /// 主正继电器无法闭合 报警 + /// + [Property(136, 8)] + public byte MainCorrectNotCloseFault { get; set; } + /// + /// 支路断路故障 + /// + [Property(144, 8)] + public byte BranchBrokenFault { get; set; } + /// + /// 附件继电器粘连故障(保留) + /// + [Property(152, 8)] + public byte AnnexAdhesionFault { get; set; } + /// + /// BMS 24V 供电异常报 警 + /// + [Property(160, 8)] + public byte BMSPowerSupplyFault { get; set; } + /// + /// BMS 24V 供电异常报 警 + /// + [Property(168, 8)] + public byte BMSPowerSupplyFault2 { get; set; }//协议里两个字段一样 + /// + /// 热管理系统故障 + /// + [Property(176, 8)] + public byte ThermalManagementFault { get; set; } + /// + /// 加热膜或 TMS接触器 无法闭合故障 + /// + [Property(184, 8)] + public byte HeatingFilmNotCloseFault { get; set; } + /// + /// 加热膜或 TMS接触器 无法闭合故障 + /// + [Property(192, 8)] + public byte HeatingFilmNotCloseFault2 { get; set; }////协议里两个字段一样 + /// + /// 加热膜或 TMS接触器 无法断开报警 + /// + [Property(200, 8)] + public byte HeatingFilmNotDisconnectFault { get; set; } + /// + /// 直流充电 2 负继电器 无法闭合报警 + /// + [Property(208, 8)] + public byte DcTwoNegativeNotCloseFault { get; set; } + + /// + /// 直流充电 2 正继电器 无法闭合报警 + /// + [Property(216, 8)] + public byte DcTwoCorrectNotCloseFault { get; set; } + /// + /// 直流充电 1 负继电器 无法闭合报警 + /// + [Property(224, 8)] + public byte DcOneNegativeNotCloseFault { get; set; } + /// + /// 直流充电 1 正继电器 无法闭合报警 + /// + [Property(232, 8)] + public byte DcOneCorrectNotCloseFault { get; set; } + /// + /// 充电插座过温报警 + /// + [Property(240, 8)] + public byte ChargingSocketOverheatedFault { get; set; } + /// + /// 电池包自保护报警 + /// + [Property(248, 8)] + public byte SelfProtectionFault { get; set; } + /// + /// 电池系统故障码 + /// + [Property(256, 8)] + public byte BatterySystemFaultCode { get; set; } + } +} \ No newline at end of file diff --git a/Service/Charger/Msg/Charger/Req/BatteryPackTotalElectricity.cs b/Service/Charger/Msg/Charger/Req/BatteryPackTotalElectricity.cs new file mode 100644 index 0000000..a5f293d --- /dev/null +++ b/Service/Charger/Msg/Charger/Req/BatteryPackTotalElectricity.cs @@ -0,0 +1,48 @@ +using HybirdFrameworkCore.Autofac.Attribute; + +namespace Service.Charger.Msg.Charger.Req +{ + /// + /// 3.5.11 电池包上报累计充放电电量(站内充电模式有电池包时周期性上传 + /// + public class BatteryPackTotalElectricity : ASDU + { + /// + /// 记录类型 + /// + [Property(0, 8)] + public byte RecordType { get; set; } + /// + /// 累计充电电量 + /// + [Property(8, 32, PropertyReadConstant.Bit, 0.1, 1, 0)] + public float TotalElectricCharge { get; set; } + /// + /// 累计放电电量 + /// + [Property(40, 32, PropertyReadConstant.Bit, 0.1, 1, 0)] + public float TotalElectricDischarge { get; set; } + /// + /// 单次充电电量 + /// + [Property(72, 32, PropertyReadConstant.Bit, 0.1, 1, 0)] + public float OnceElectricCharge { get; set; } + /// + /// 累计动能回馈充电电量 + /// + [Property(88, 32, PropertyReadConstant.Bit, 0.1, 1, 0)] + public float TotalFeedbackElectricCharge { get; set; } + /// + /// 累计换电电量 + /// + [Property(120, 32, PropertyReadConstant.Bit, 0.1, 1, 0)] + public float TotalElectricSwap { get; set; } + /// + /// 累计插枪充电电量 + /// + [Property(152, 32, PropertyReadConstant.Bit, 0.1, 1, 0)] + public float TotalElectricInsertCharge { get; set; } + + + } +} \ No newline at end of file