From 115c9246f7919589f9f2fe0bca180c5a107b2e35 Mon Sep 17 00:00:00 2001 From: CZ Date: Sat, 25 May 2024 22:40:09 +0800 Subject: [PATCH] =?UTF-8?q?5.25=E5=91=A8=E5=85=AD=E7=8E=B0=E5=9C=BA?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HybirdFrameworkCore/Utils/BitUtls.cs | 11 +++++++++-- Service/Charger/Client/ClientMgr.cs | 14 +++++++------- Service/Charger/Codec/Decoder.cs | 3 +++ Service/Charger/Handler/StopChargingHandler.cs | 3 ++- .../Handler/UploadRemoteSignalDataHandler.cs | 4 ---- .../Charger/Handler/UploadTelemetryDataHandler.cs | 4 ---- .../Charger/Msg/Charger/Req/UploadTelemetryData.cs | 6 +++--- Service/Charger/Msg/Test.cs | 12 ++++++++++++ WebStarter/appsettings.json | 2 +- 9 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 Service/Charger/Msg/Test.cs diff --git a/HybirdFrameworkCore/Utils/BitUtls.cs b/HybirdFrameworkCore/Utils/BitUtls.cs index 2f60c4a..eaf751b 100644 --- a/HybirdFrameworkCore/Utils/BitUtls.cs +++ b/HybirdFrameworkCore/Utils/BitUtls.cs @@ -242,17 +242,24 @@ public static class BitUtls public static ushort Byte2UInt16(byte[] bytes, int startBit, int length) { - if (length < 9 || length > 16) throw new ArgumentException("length should be less then 17 and greater then 8"); var sub = Sub(bytes, startBit, length); + if (sub.Length == 1) + { + return Convert.ToUInt16(sub[0]); + } return BitConverter.ToUInt16(sub, 0); } public static short Byte2Int16(byte[] bytes, int startBit, int length) { - if (length < 9 || length > 16) throw new ArgumentException("length should be less then 17 and greater then 8"); + var sub = Sub(bytes, startBit, length); + if (sub.Length == 1) + { + return Convert.ToInt16(sub[0]); + } return BitConverter.ToInt16(sub, 0); } diff --git a/Service/Charger/Client/ClientMgr.cs b/Service/Charger/Client/ClientMgr.cs index 2aaa134..054e9df 100644 --- a/Service/Charger/Client/ClientMgr.cs +++ b/Service/Charger/Client/ClientMgr.cs @@ -20,9 +20,9 @@ public static class ClientMgr { private static readonly ILog Log = LogManager.GetLogger(typeof(ClientMgr)); - + private static readonly Dictionary Dictionary = new(); - + private static bool AutoChargeWorking { get; set; } public static ChargerClient? GetBySn(string sn) @@ -64,7 +64,7 @@ public static class ClientMgr List equipInfos = equipInfoRepository.QueryListByClause(it => it.TypeCode == (int)EquipmentType.Charger); if (equipInfos.Count > 0) { - Dictionary set = equipInfos.ToDictionary(it => it.Code, it => it); + Dictionary set = equipInfos.ToDictionary(it => it.Code, it => it); List equipNetInfos = netInfoRepository.QueryListByClause(it => set.Keys.Contains(it.Code)); foreach (EquipNetInfo netInfo in equipNetInfos) { @@ -100,10 +100,10 @@ public static class ClientMgr { ElecPriceModelVersionRepository elecPriceModelVersionRepository = AppInfo.Container.Resolve(); - + ElecPriceModelVersionDetailRepository elecPriceModelVersionDetailRepository = AppInfo.Container.Resolve(); - + while (true) { Thread.Sleep(1000 * 30); @@ -130,7 +130,7 @@ public static class ClientMgr //int batteryCount = elecPriceModelVersionDetail.BatteryCount; - foreach (KeyValuePair pair in Dictionary) + foreach (KeyValuePair pair in Dictionary) { Result result = pair.Value.StartCharge(); Log.Info($"start {pair.Key} charge {result.IsSuccess}:{result.Msg}"); @@ -149,7 +149,7 @@ public static class ClientMgr ChargerClient client = AppInfo.Container.Resolve(); client.InitBootstrap(netInfo.NetAddr, int.Parse(netInfo.NetPort)); client.Connect(); - client.SessionAttr(netInfo.Code, netInfo.NetAddr); + client.SessionAttr(netInfo.Code, netInfo.DestAddr); AddBySn(netInfo.Code, client); Log.Info($"connected {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}"); } diff --git a/Service/Charger/Codec/Decoder.cs b/Service/Charger/Codec/Decoder.cs index 841690e..71b64c0 100644 --- a/Service/Charger/Codec/Decoder.cs +++ b/Service/Charger/Codec/Decoder.cs @@ -11,6 +11,7 @@ using Service.Charger.Msg.Bms; using Service.Charger.Msg.Charger.Req; using Service.Charger.Msg.Charger.Resp; using Service.Charger.Msg.Host.Req; +using static System.Net.Mime.MediaTypeNames; namespace Service.Charger.Codec; @@ -140,6 +141,7 @@ public class Decoder : ByteToMessageDecoder 50 => ModelConvert.Decode(bytes), 52 => ModelConvert.Decode(bytes), 75 => ModelConvert.Decode(bytes), + 80 => new Test(), 81 => ModelConvert.Decode(bytes), 82 => ModelConvert.Decode(bytes), 83 => ModelConvert.Decode(bytes), @@ -212,6 +214,7 @@ public class Decoder : ByteToMessageDecoder 57 => ModelConvert.Decode(bytes), 58 => ModelConvert.Decode(bytes), 59 => ModelConvert.Decode(bytes), + 62 => new Test(), 81 => ModelConvert.Decode(bytes), 142 => ModelConvert.Decode(bytes), 143 => ModelConvert.Decode(bytes), diff --git a/Service/Charger/Handler/StopChargingHandler.cs b/Service/Charger/Handler/StopChargingHandler.cs index 101144f..a765414 100644 --- a/Service/Charger/Handler/StopChargingHandler.cs +++ b/Service/Charger/Handler/StopChargingHandler.cs @@ -22,7 +22,8 @@ namespace Service.Charger.Handler protected override void ChannelRead0(IChannelHandlerContext ctx, StopCharging msg) { if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client)) - {Log.Info($"receive {msg} from {sn}"); + { + Log.Info($"receive {msg} from {sn}"); client.IsCanSendStopCmd = false; ChargingStopFsdRes stopFsdRes = new ChargingStopFsdRes(0); ctx.Channel.WriteAndFlushAsync(stopFsdRes); diff --git a/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs b/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs index e8c485f..3a2fe94 100644 --- a/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs +++ b/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs @@ -35,10 +35,6 @@ namespace Service.Charger.Handler client.TotalWarning = msg.TotalWarning; client.UploadRemoteSignalData = msg; } - else - { - client.ChargingStatus = (int)ChargingStatus.StartChargingFailed; - } } } } diff --git a/Service/Charger/Handler/UploadTelemetryDataHandler.cs b/Service/Charger/Handler/UploadTelemetryDataHandler.cs index 94373dd..02909ce 100644 --- a/Service/Charger/Handler/UploadTelemetryDataHandler.cs +++ b/Service/Charger/Handler/UploadTelemetryDataHandler.cs @@ -32,10 +32,6 @@ namespace Service.Charger.Handler //充电机实时充电功率 client.RealTimeChargePower = msg.HighVoltageAcquisitionCurrent * msg.HighVoltageAcquisitionVoltage; } - else - { - client.ChargingStatus = (int)ChargingStatus.StartChargingFailed; - } } } } diff --git a/Service/Charger/Msg/Charger/Req/UploadTelemetryData.cs b/Service/Charger/Msg/Charger/Req/UploadTelemetryData.cs index b2ee1c2..4f8dd78 100644 --- a/Service/Charger/Msg/Charger/Req/UploadTelemetryData.cs +++ b/Service/Charger/Msg/Charger/Req/UploadTelemetryData.cs @@ -16,14 +16,14 @@ namespace Service.Charger.Msg.Charger.Req /// /// 最高蓄电池温度 /// - [Property(8, 2, PropertyReadConstant.Byte, 1, 0, 50)] + [Property(8, 16, offset: 50)] public Int16 MaxBatteryTemp { get; set; } /// /// 最高温度检测点编号 /// [Property(24, 16)] - public byte MaxTempDetectionPointNo { get; set; } + public ushort MaxTempDetectionPointNo { get; set; } /// /// 最低蓄电池温度 @@ -35,7 +35,7 @@ namespace Service.Charger.Msg.Charger.Req /// 最低温度检测点编号 /// [Property(56, 16)] - public byte MinTempDetectionPointNo { get; set; } + public ushort MinTempDetectionPointNo { get; set; } /// /// 单体电池最高电压 diff --git a/Service/Charger/Msg/Test.cs b/Service/Charger/Msg/Test.cs new file mode 100644 index 0000000..7e30b44 --- /dev/null +++ b/Service/Charger/Msg/Test.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Service.Charger.Msg +{ + public class Test : ASDU + { + } +} diff --git a/WebStarter/appsettings.json b/WebStarter/appsettings.json index d84dfdd..f8ca381 100644 --- a/WebStarter/appsettings.json +++ b/WebStarter/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",