From 3c0a52b2f9beff4f3149fa828f7e907c03df757c Mon Sep 17 00:00:00 2001 From: CZ Date: Sun, 26 May 2024 09:32:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=BC=8F=E7=9A=842=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=B8=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Autofac/Attribute/PropertyAttribute.cs | 10 +- Service/Charger/Codec/Decoder.cs | 4 +- Service/Charger/Handler/ModuleStateHandler.cs | 34 +++ .../Handler/VoltageCurrentSocHandler.cs | 33 +++ .../Msg/Charger/Req/AcMeter.cs~handler | 57 ---- .../Charger/Msg/Charger/Req/ModuleState.cs | 57 ++++ .../Charger/Req/RemoteSignaling.cs~handler | 252 ------------------ Service/Charger/Msg/Charger/Req/VehicleVIN.cs | 2 +- .../Msg/Charger/Req/VehicleVIN.cs~handler | 26 -- .../Msg/Charger/Req/VoltageCurrentSoc.cs | 42 +++ .../Resp/PowerRegulationRes.cs~handler | 35 --- WebStarter/bin/Debug/net6.0/appsettings.json | 2 +- 12 files changed, 179 insertions(+), 375 deletions(-) create mode 100644 Service/Charger/Handler/ModuleStateHandler.cs create mode 100644 Service/Charger/Handler/VoltageCurrentSocHandler.cs delete mode 100644 Service/Charger/Msg/Charger/Req/AcMeter.cs~handler create mode 100644 Service/Charger/Msg/Charger/Req/ModuleState.cs delete mode 100644 Service/Charger/Msg/Charger/Req/RemoteSignaling.cs~handler delete mode 100644 Service/Charger/Msg/Charger/Req/VehicleVIN.cs~handler create mode 100644 Service/Charger/Msg/Charger/Req/VoltageCurrentSoc.cs delete mode 100644 Service/Charger/Msg/Charger/Resp/PowerRegulationRes.cs~handler diff --git a/HybirdFrameworkCore/Autofac/Attribute/PropertyAttribute.cs b/HybirdFrameworkCore/Autofac/Attribute/PropertyAttribute.cs index d1a6ab4..bca041d 100644 --- a/HybirdFrameworkCore/Autofac/Attribute/PropertyAttribute.cs +++ b/HybirdFrameworkCore/Autofac/Attribute/PropertyAttribute.cs @@ -8,7 +8,15 @@ public class PropertyAttribute : System.Attribute public readonly double Scale; public readonly int Start; public readonly PropertyReadConstant Type; - + /// + /// + /// + /// + /// + /// + /// 缩放 + /// 舍入方式,用于处理浮点数的精度问题 + /// 偏移量 public PropertyAttribute(int start, int length, PropertyReadConstant type = PropertyReadConstant.Bit, double scale = 1, int round = 0, double offset = 0) { diff --git a/Service/Charger/Codec/Decoder.cs b/Service/Charger/Codec/Decoder.cs index 71b64c0..3709a4a 100644 --- a/Service/Charger/Codec/Decoder.cs +++ b/Service/Charger/Codec/Decoder.cs @@ -141,7 +141,7 @@ public class Decoder : ByteToMessageDecoder 50 => ModelConvert.Decode(bytes), 52 => ModelConvert.Decode(bytes), 75 => ModelConvert.Decode(bytes), - 80 => new Test(), + 80 => ModelConvert.Decode(bytes), 81 => ModelConvert.Decode(bytes), 82 => ModelConvert.Decode(bytes), 83 => ModelConvert.Decode(bytes), @@ -214,7 +214,7 @@ public class Decoder : ByteToMessageDecoder 57 => ModelConvert.Decode(bytes), 58 => ModelConvert.Decode(bytes), 59 => ModelConvert.Decode(bytes), - 62 => new Test(), + 62 => ModelConvert.Decode(bytes), 81 => ModelConvert.Decode(bytes), 142 => ModelConvert.Decode(bytes), 143 => ModelConvert.Decode(bytes), diff --git a/Service/Charger/Handler/ModuleStateHandler.cs b/Service/Charger/Handler/ModuleStateHandler.cs new file mode 100644 index 0000000..818f28f --- /dev/null +++ b/Service/Charger/Handler/ModuleStateHandler.cs @@ -0,0 +1,34 @@ +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Service.Charger.Client; +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 +{ + /// + /// 3.5.18 充放电机上报模块状态消息名称 充放电机上 + /// + [Order(8)] + [Scope("InstancePerDependency")] + public class ModuleStateHandler : SimpleChannelInboundHandler, IBaseHandler + { + private readonly ILog Log = LogManager.GetLogger(typeof(ModuleStateHandler)); + + protected override void ChannelRead0(IChannelHandlerContext ctx, ModuleState msg) + { + + if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + { + Log.Info($"receive {msg} from {sn}"); + + } + } + } +} diff --git a/Service/Charger/Handler/VoltageCurrentSocHandler.cs b/Service/Charger/Handler/VoltageCurrentSocHandler.cs new file mode 100644 index 0000000..4f22c6e --- /dev/null +++ b/Service/Charger/Handler/VoltageCurrentSocHandler.cs @@ -0,0 +1,33 @@ +using DotNetty.Transport.Channels; +using HybirdFrameworkCore.Autofac.Attribute; +using log4net; +using Service.Charger.Client; +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 +{ + /// + /// 3.6.1.3 充放电机上传电压电流 SOC 数据(PGN:0x00F812) + /// + [Order(8)] + [Scope("InstancePerDependency")] + public class VoltageCurrentSocHandler : SimpleChannelInboundHandler, IBaseHandler + { + private readonly ILog Log = LogManager.GetLogger(typeof(VoltageCurrentSocHandler)); + + protected override void ChannelRead0(IChannelHandlerContext ctx, VoltageCurrentSoc msg) + { + + if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) + { + Log.Info($"receive {msg} from {sn}"); + + } + } + } +} diff --git a/Service/Charger/Msg/Charger/Req/AcMeter.cs~handler b/Service/Charger/Msg/Charger/Req/AcMeter.cs~handler deleted file mode 100644 index 519721e..0000000 --- a/Service/Charger/Msg/Charger/Req/AcMeter.cs~handler +++ /dev/null @@ -1,57 +0,0 @@ -using HybirdFrameworkCore.Autofac.Attribute; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static System.Formats.Asn1.AsnWriter; - -namespace Service.Charger.Msg.Charger.Req -{ - /// - /// 3.5.19 充放电上报交流电表数据(交流电表接到充电机上的情况) - /// - public class AcMeter : ASDU - { - /// - /// 记录类型 - /// - [Property(0, 8)] - public byte RecordType { get; set; } - /// - /// 交流进线 A 相电压 - /// - [Property(8, 16, scale: 0.1)] - public float PhaseVoltageA { get; set; } - /// - /// 交流进线 B 相电压 - /// - [Property(24, 16, scale: 0.1)] - public float PhaseVoltageB { get; set; } - /// - /// 交流进线 C 相电压 - /// - [Property(40, 16, scale: 0.1)] - public float PhaseVoltageC { get; set; } - /// - /// 交流进线 A 相电流 - /// - [Property(56, 16, scale: 0.1)] - public float PhaseCurrentA { get; set; } - /// - /// 交流进线 B 相电流 - /// - [Property(72, 16, scale: 0.1)] - public float PhaseCurrentB { get; set; } - /// - /// 交流进线 C 相电流 - /// - [Property(88, 16, scale: 0.1)] - public float PhaseCurrentC { get; set; } - /// - /// 交流表总电量 - /// - [Property(104, 32, scale: 0.1)] - public float AcMeterTotalPower { get; set; } - } -} diff --git a/Service/Charger/Msg/Charger/Req/ModuleState.cs b/Service/Charger/Msg/Charger/Req/ModuleState.cs new file mode 100644 index 0000000..1e61dac --- /dev/null +++ b/Service/Charger/Msg/Charger/Req/ModuleState.cs @@ -0,0 +1,57 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Service.Charger.Msg.Charger.Req +{ + /// + /// 3.5.18 充放电机上报模块状态 + /// + public class ModuleState : ASDU + { + + /// + /// 模块总数量 + /// + [Property(0, 8)] + public byte ModelCount { get; set; } + /// + /// 模块状态 + /// + [Property(8, 8)] + public byte ModelState1 { get; set; } + /// + /// 模块状态 + /// + [Property(16, 8)] + public byte ModelState2 { get; set; } + /// + /// 模块状态 + /// + [Property(24, 8)] + public byte ModelState3 { get; set; } + /// + /// 模块状态 + /// + [Property(32, 8)] + public byte ModelState4 { get; set; } + /// + /// 模块状态 + /// + [Property(40, 8)] + public byte ModelState5 { get; set; } + /// + /// 模块状态 + /// + [Property(48, 8)] + public byte ModelState6 { get; set; } + /// + /// 模块状态 + /// + [Property(56, 8)] + public byte ModelState7 { get; set; } + } +} diff --git a/Service/Charger/Msg/Charger/Req/RemoteSignaling.cs~handler b/Service/Charger/Msg/Charger/Req/RemoteSignaling.cs~handler deleted file mode 100644 index b0e7bb2..0000000 --- a/Service/Charger/Msg/Charger/Req/RemoteSignaling.cs~handler +++ /dev/null @@ -1,252 +0,0 @@ -using HybirdFrameworkCore.Autofac.Attribute; -using Service.Charger.Common; -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static StackExchange.Redis.LCSMatchResult; - -namespace Service.Charger.Msg.Charger.Req -{ - /// - /// 3.5.8 电池包实时遥信上报(站内充电模式有电池包时周期性上传) - /// - public class RemoteSignaling : ASDU - { - /// - /// 记录类型 - /// - [Property(0, 8)] - public byte RecordType { get; set; } - /// - /// BMS 当前均衡状态 0:不平衡 1:平衡 - /// - [Property(15, 1)] - public byte CurrentBMS { get; set; } - /// - /// 附件继电器状态 0:开启 1:闭合 - /// - [Property(14, 1)] - public byte AttachmentRelayStatus { get; set; } - /// - /// BMS 当前状态 - /// 0:高压开启 - /// 1:预先充电 - /// 2 高压关断 - /// 3 高压上电故障 - /// - [Property(12, 2)] - public byte CurrentStatusBMS { get; set; } - /// - /// B2V_ST1 的生命信 0~14 循环,15:信号无效 - /// - [Property(8, 4)] - public byte B2VST1Msg { get; set; } - /// - /// 保留 - /// - [Property(23, 1)] - public byte Hold { get; set; } - /// - /// 最高报警等级 - /// 0:无故障 - /// 1:一级报警故障 - /// 2: 二级普通故障 - /// 3:三级严重故障 - /// - /// - [Property(21, 2)] - public byte MaximumAlarmLevel { get; set; } - /// - /// 充电状态 - /// 0:可以充电 - /// 1:正在充电 - /// 2:充电结束 - /// 3:充电故障 - /// - [Property(19, 2)] - public byte ChargingState { get; set; } - /// - /// 充电模式 - /// 0:预留 - /// 1:直流充电 - /// 2:交流充电 - /// 3:其他充电 - /// - [Property(17, 2)] - public byte ChargingMode { get; set; } - /// - /// 充电枪连接状态 0: 未连接 1:连接 - /// - [Property(16, 1)] - public byte ConnectionStatus { get; set; } - /// - /// PACK 欠压报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(30, 2)] - public byte PackUndervoltage { get; set; } - /// - /// PACK 过压报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(28, 2)] - public byte PackOvervoltage { get; set; } - /// - /// 电芯温度过高报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(26, 2)] - public byte ExcessiveTemperature { get; set; } - /// - /// 电芯温差异常报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(24, 2)] - public byte AbnormalTemperatureDifference { get; set; } - /// - /// 绝缘报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(38, 2)] - public byte InsulationAlarm { get; set; } - /// - /// 单体电压欠压报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(36, 2)] - public byte UndervoltageAlarm { get; set; } - /// - /// 单体电压过高报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(34, 2)] - public byte VoltageTooHigh { get; set; } - /// - /// SOC过低报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(32, 2)] - public byte LowSOCAlarm { get; set; } - /// - /// 电芯温度过低报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(46, 2)] - public byte LowTemperature { get; set; } - /// - /// 放电电流过大报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(44, 2)] - public byte ExcessiveDischargeCurrent { get; set; } - /// - /// 充电电流过大报警 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(42, 2)] - public byte ExcessiveChargingCurrent { get; set; } - /// - /// 单体压差过大 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(40, 2)] - public byte IndividualPressureDifference { get; set; } - /// - /// BMS 系统不匹配报警 0:正 常 1:故障 - /// - [Property(55, 1)] - public byte BMSSystemMismatchAlarm { get; set; } - /// - /// BMS 内部通讯故障 0:正 常 1:故障 - /// - [Property(54, 1)] - public byte BMSCommunicationFailure { get; set; } - /// - /// SOC 跳变报警 0:正 常 1:故障 - /// - [Property(53, 1)] - public byte SOCJumpAlarm { get; set; } - /// - /// SOC 过高报警 - /// - [Property(52, 1)] - public byte SOCHighAlarm { get; set; } - /// - /// BMS 硬件故障 - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(50, 2)] - public byte BMSHardwareFailure { get; set; } - /// - /// 支路压差过大报警(存在并联支路的系统) - /// 0:无故障 - /// 1:一级报警故障 - /// 2:二级普通故障 - /// 3:三级严重故障 - /// - [Property(48, 2)] - public byte BranchPressureDifference { get; set; } - /// - /// GBT32960.3 中规定的故障数目(当前时刻发生的) 0:正常 1:故障 - /// - [Property(59, 5)] - public byte CurrentTimeOccurrence { get; set; } - /// - /// 火灾报警 0:正常 1:故障 - /// - [Property(58, 1)] - public byte FireAlarm { get; set; } - /// - /// 烟雾报警 0:正常 1:故障 - /// - [Property(57, 1)] - public byte SmokeAlarm { get; set; } - /// - /// 高压互锁报警 0:正常 1:故障 - /// - [Property(56, 1)] - public byte HighVoltageInterlockAlarm { get; set; } - } -} diff --git a/Service/Charger/Msg/Charger/Req/VehicleVIN.cs b/Service/Charger/Msg/Charger/Req/VehicleVIN.cs index db95860..bf10f62 100644 --- a/Service/Charger/Msg/Charger/Req/VehicleVIN.cs +++ b/Service/Charger/Msg/Charger/Req/VehicleVIN.cs @@ -21,6 +21,6 @@ namespace Service.Charger.Msg.Charger.Req /// VIN /// [Property(8, 17, type: PropertyReadConstant.Byte)] - public string vin { get; set; } + public string Vin { get; set; } } } diff --git a/Service/Charger/Msg/Charger/Req/VehicleVIN.cs~handler b/Service/Charger/Msg/Charger/Req/VehicleVIN.cs~handler deleted file mode 100644 index db95860..0000000 --- a/Service/Charger/Msg/Charger/Req/VehicleVIN.cs~handler +++ /dev/null @@ -1,26 +0,0 @@ -using HybirdFrameworkCore.Autofac.Attribute; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Service.Charger.Msg.Charger.Req -{ - /// - /// 3.5.14 充电机上报车辆 VIN - /// - public class VehicleVIN : ASDU - { - /// - /// 记录类型 - /// - [Property(0, 8)] - public byte RecordType { get; set; } - /// - /// VIN - /// - [Property(8, 17, type: PropertyReadConstant.Byte)] - public string vin { get; set; } - } -} diff --git a/Service/Charger/Msg/Charger/Req/VoltageCurrentSoc.cs b/Service/Charger/Msg/Charger/Req/VoltageCurrentSoc.cs new file mode 100644 index 0000000..305072f --- /dev/null +++ b/Service/Charger/Msg/Charger/Req/VoltageCurrentSoc.cs @@ -0,0 +1,42 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Service.Charger.Msg.Charger.Req +{ + /// + /// 3.6.1.3 充放电机上传电压电流 SOC 数据(PGN:0x00F812) + /// + public class VoltageCurrentSoc : ASDU + { + /// + /// 电压测量值 分辨率:0.1V/位,偏移量:0V,数值范围:0V ~750V + /// + [Property(0, 16, scale: 0.1)] + public float Voltage { get; set; } + /// + /// 电流测量值 分辨率:0.05A/位,偏移量:-1600A,数值范围:-1600A~1612.75A + /// + [Property(16, 16, scale: 0.05, offset: 1600)] + public float Current { get; set; } + /// + /// 当前SOC 分辨率:0.1%/位,偏移量:0%,数值范围 0%~100% + /// + [Property(32, 16, scale: 0.01)] + public float SOC { get; set; } + /// + /// 当前SOH 分辨率:1%/位,偏移量:0%,数值范围 0%~100% + /// + [Property(48, 8, scale: 0.01)] + public float SOH { get; set; } + /// + /// 保留 + /// + [Property(56, 8)] + public byte Reserve { get; set; } + + } +} diff --git a/Service/Charger/Msg/Charger/Resp/PowerRegulationRes.cs~handler b/Service/Charger/Msg/Charger/Resp/PowerRegulationRes.cs~handler deleted file mode 100644 index 7383e2a..0000000 --- a/Service/Charger/Msg/Charger/Resp/PowerRegulationRes.cs~handler +++ /dev/null @@ -1,35 +0,0 @@ -using HybirdFrameworkCore.Autofac.Attribute; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Service.Charger.Msg.Charger.Resp -{ - /// - /// 3.4.2 充放电设备应答站功率调节指令 - /// - public class PowerRegulationRes : ASDU - { - /// - /// 记录类型 - /// - [Property(0, 8)] - public byte RecordType { get; set; } - /// - /// 应答结果 0: 成功 1:失败 - /// - [Property(8, 8)] - public byte ResponseResult { get; set; } - /// - /// 失败原因 - /// 0:正常 - /// 1:参数非法 - /// 2:双向充电设备放电中 - /// 0xFF:其他原因 - /// - [Property(16, 8)] - public ushort CauseFailure { get; set; } - } -} diff --git a/WebStarter/bin/Debug/net6.0/appsettings.json b/WebStarter/bin/Debug/net6.0/appsettings.json index d84dfdd..f8ca381 100644 --- a/WebStarter/bin/Debug/net6.0/appsettings.json +++ b/WebStarter/bin/Debug/net6.0/appsettings.json @@ -2,7 +2,7 @@ "ConnectionStrings": { "ConfigId": "master", "DbType": "MySql", - "SqlConnection": "server=180.76.133.253;Port=16306;Database=huanneng_dev;Uid=root;Pwd=Rszn123;Charset=utf8" + "SqlConnection": "server=127.0.0.1;Port=3306;Database=huanneng_dev;Uid=root;Pwd=anyixing2023!@#;Charset=utf8" }, "Update": { "AutoUpdate": "false",