充电机初始化修改

master
lxw 6 days ago
parent c63be21955
commit 83258d232f

@ -33,4 +33,15 @@ public class BinInfoRepository : BaseRepository<BinInfo>
{
return this.QueryByClause(it => it.No == binNo);
}
/// <summary>
///
/// </summary>
/// <param name="binNo"></param>
/// <returns></returns>
public BinInfo? QueryByChargeCode(string chargeNo)
{
return this.QueryByClause(it => it.ChargerNo == chargeNo);
}
}

@ -426,34 +426,7 @@ public class ChargerClient
}
/// <summary>
/// 发送鉴权----并且发送电价配置
/// </summary>
public Result<bool> SendAuth()
{
if (!Connected)
{
return Result<bool>.Fail($"charger-{BinNo} disconnect");
}
byte authCodeKey = ChargerUtils.GetByteRandomNum(); //鉴码KEY[随机数]
byte[] authCodes = ChargerUtils.GetAuthCodesResult(ChargerConst.AuthCode, authCodeKey); //鉴权码
Auth auth = new Auth(IncreAuthTimes(), authCodes, authCodeKey);
CurrentCmd = JsonConvert.SerializeObject(auth, Formatting.Indented) + "\r\n" +
BitUtls.BytesToHexStr(auth.ToBytes());
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(auth);
try
{
Log().Info("Auth after send SetPeakValleyTime");
ServerMgr.Server.SessionMgr.GetSession(Sn).Send(BulidSetPeakValleyTimeObj(StaticStationInfo.Ceid));
}
catch (Exception e)
{
Log().Info($"Auth after send SetPeakValleyTime deeor:{e}");
}
return Result<bool>.Success();
}
/// <summary>
/// 监控平台发送远程开始充电指令
@ -852,18 +825,6 @@ public class ChargerClient
#endregion
/// <summary>
///
/// </summary>
/// <param name="sn"></param>
/// <param name="destAddr"></param>
public void SessionAttr(string sn, string destAddr)
{
ChannelUtils.AddAttr(Channel, ChargerConst.ChargerSn, sn);
ChannelUtils.AddAttr(Channel, ChargerConst.EqmTypeNo, sn);
ChannelUtils.AddAttr(Channel, ChargerConst.EqmCode, sn);
ChannelUtils.AddAttr(Channel, ChargerConst.DestAddr, destAddr);
}
/// <summary>

@ -143,7 +143,7 @@ public class Decoder : ByteToMessageDecoder
11 => ModelConvert.Decode<Login>(bytes),
13 => ModelConvert.Decode<HeartBeat>(bytes),
21 => ModelConvert.Decode<AdjustChargeRateRes>(bytes),
25 => ModelConvert.Decode<AuthRes>(bytes),
24 => ModelConvert.Decode<Auth>(bytes),
34 => ModelConvert.Decode<UpgradeRequestRes>(bytes),
35 => ModelConvert.Decode<UplinkUpgrade>(bytes),
41 => ModelConvert.Decode<VehicleVIN>(bytes),

@ -20,10 +20,7 @@ public static class ChargerConst
public static readonly byte[] BatteryNo = { 0x00, 0xF8, 0x81 };
public static readonly byte[] BatteryBasicInfo = { 0x00, 0xF8, 0x82 };
/// <summary>
/// 充电机和充电枪,枪号匹配
/// </summary>
public static Dictionary<Tuple<string, int>, string> _dictionary = new Dictionary<Tuple<string, int>, string>();
/// <summary>
/// 启动方式

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -21,7 +22,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, AcMeter msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
client.AcMeter = msg;

@ -3,6 +3,7 @@ using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -19,7 +20,7 @@ namespace Service.Charger.Handler
private static readonly ILog Log = LogManager.GetLogger(typeof(AdjustChargeRateResHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, AdjustChargeRateRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
}

@ -0,0 +1,72 @@
using System.Text;
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Newtonsoft.Json;
using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Msg.Host.Resp;
namespace Service.Charger.Handler
{
/// <summary>
/// 接收到鉴权帧
/// <code>
/// 1保存日志到log
/// 2从SessionMgr中取目的地址解析后写入ChargerManager
/// 3保存鉴权状态和充电状态
/// </code>
/// </summary>
[Order(8)]
[Scope("InstancePerDependency")]
public class AuthHandler : SimpleChannelInboundHandler<Auth>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(AuthHandler));
private const String AUTH_CODE = "szhckj01";
protected override void ChannelRead0(IChannelHandlerContext ctx, Auth msg)
{
Log.Info($"收到充电机鉴权认证请求: {msg}" );
byte[] receivedAuthCodes = msg.AuthCodes;
byte authCodeKey = msg.AuthCodeKey;
// 鉴权码转换为字节数组
byte[] expectedAuthCodes = Encoding.ASCII.GetBytes(AUTH_CODE);;
// 验证鉴权码
Boolean isValid = ValidateAuthCodes(receivedAuthCodes, expectedAuthCodes, authCodeKey);
// 鉴权结果处理
byte authResult = (isValid ? (byte)0 : (byte)1);
AuthRes authRes = new AuthRes(authResult, msg.ConnSeq, authResult);
Log.Info($"鉴权码验证{JsonConvert.SerializeObject(authRes)}, isValid {authResult}");
// 返回鉴权响应
ctx.Channel.WriteAndFlushAsync(authRes);
}
private bool ValidateAuthCodes(byte[] receivedAuthCodes, byte[] expectedAuthCodes, byte authCodeKey) {
// 判断长度是否一致
if (receivedAuthCodes.Length != expectedAuthCodes.Length) {
return false;
}
// 字节异或
for (int i = 0; i < expectedAuthCodes.Length; i++) {
if ((receivedAuthCodes[i] ^ authCodeKey) != expectedAuthCodes[i]) {
return false;
}
}
return true;
}
}
}

@ -1,44 +0,0 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Msg.Charger.Resp;
namespace Service.Charger.Handler
{
/// <summary>
/// 接收到鉴权帧
/// <code>
/// 1保存日志到log
/// 2从SessionMgr中取目的地址解析后写入ChargerManager
/// 3保存鉴权状态和充电状态
/// </code>
/// </summary>
[Order(8)]
[Scope("InstancePerDependency")]
public class AuthResHandler : SimpleChannelInboundHandler<AuthRes>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(AuthResHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, AuthRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
if (msg.ConnSeq == client.AuthTimes)
{
if (msg.AuthResult == 0)
{
client.IsAuthed = true;
client.ChargingStatus = (int)ChargingStatus.Authed;
}
else
{
client.IsAuthed = false;
client.ChargingStatus = (int)ChargingStatus.AuthFailed;
}
}
}
}
}
}

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -22,7 +23,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, AuthVINRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -3,6 +3,7 @@ using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -17,7 +18,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, AuxiliaryPowerRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
client.AuxiliaryPowerRes = msg;

@ -6,6 +6,7 @@ using Service.Charger.Client;
using Service.Charger.Handler;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
namespace HybirdFrameworkServices.Charger.Handler
{
@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler
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))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -6,6 +6,7 @@ using Service.Charger.Client;
using Service.Charger.Handler;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
namespace HybirdFrameworkServices.Charger.Handler
{
@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler
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))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -6,6 +6,7 @@ using Service.Charger.Client;
using Service.Charger.Handler;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
namespace HybirdFrameworkServices.Charger.Handler
{
@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler
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))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -6,6 +6,7 @@ using Service.Charger.Client;
using Service.Charger.Handler;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
namespace HybirdFrameworkServices.Charger.Handler
{
@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler
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))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -6,6 +6,7 @@ using Service.Charger.Client;
using Service.Charger.Handler;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
namespace HybirdFrameworkServices.Charger.Handler
{
@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler
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))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -3,6 +3,7 @@ using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -20,7 +21,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, ChangeChargeModeRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
}

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -19,7 +20,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, Detectionpointextremumdata msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
}

@ -10,6 +10,7 @@ using Service.Charger.Common;
using Service.Charger.Handler;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
namespace HybirdFrameworkServices.Charger.Handler
{
@ -33,7 +34,7 @@ namespace HybirdFrameworkServices.Charger.Handler
private static readonly ILog Log = LogManager.GetLogger(typeof(FinishStartChargingHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, FinishStartCharging msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
msg.VehIdeNum = Encoding.ASCII.GetString(msg.Vin);

@ -7,6 +7,7 @@ using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
using Service.Init;
namespace Service.Charger.Handler
@ -30,7 +31,7 @@ namespace Service.Charger.Handler
private static readonly ILog Log = LogManager.GetLogger(typeof(FinishStopChargingHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, FinishStopCharging msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
client.IsCanSendStopCmd = false;

@ -5,6 +5,7 @@ using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -16,7 +17,7 @@ namespace Service.Charger.Handler
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))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
//心跳存储日志
Log.Info($"receive {msg} from {sn}");

@ -1,9 +1,14 @@
using DotNetty.Transport.Channels;
using Autofac;
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Newtonsoft.Json;
using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -22,18 +27,29 @@ namespace Service.Charger.Handler
{
private readonly ILog Log = LogManager.GetLogger(typeof(LoginHandler));
public BinInfoRepository BinInfoRepository { get; set; }
protected override void ChannelRead0(IChannelHandlerContext ctx, Login msg)
{
ServerMgr.SessionAttr(ctx.Channel, msg.ChargerSn, "0,0,0,0");
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
msg.ConnProtocolVersion = msg.ConnProtocolVersion0 + "." + msg.ConnProtocolVersion1 + "." + msg.ConnProtocolVersion2;
msg.ControllerHardwareVersion = msg.ControllerHardwareVersion0 + "." + msg.ControllerHardwareVersion1 + "." + msg.ControllerHardwareVersion2;
msg.ControllerSoftwareVersion = msg.ControllerSoftwareVersion0 + "." + msg.ControllerSoftwareVersion1 + "." + msg.ControllerSoftwareVersion2;
Log.Info($"receive {JsonConvert.SerializeObject(msg)} from {msg.ChargerSn}");
}
var binInfo = BinInfoRepository.QueryByChargeCode(msg.ChargerSn);
ChargerClient client = AppInfo.Container.Resolve<ChargerClient>();
client.Channel = ctx.Channel;
client.Sn = msg.ChargerSn;
client.Connected = true;
client.BinNo = binInfo.No;
ServerMgr.AddBySn(msg.ChargerSn,client);
LogSignMessage logSignMessage = new LogSignMessage(0);
ctx.Channel.WriteAndFlushAsync(logSignMessage);
}

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -24,7 +25,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, ModuleState msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -3,6 +3,7 @@ using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -20,7 +21,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, OfflineStopChargingRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
}

@ -2,6 +2,7 @@
using log4net;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.OutCharger.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler.OutCharger;
/// <summary>
@ -14,7 +15,7 @@ public class PileAdjustPowerHandler : SimpleChannelInboundHandler<PileAdjustPowe
protected override void ChannelRead0(IChannelHandlerContext ctx, PileAdjustPowerRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
}

@ -6,6 +6,7 @@ using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.OutCharger.Req;
using Service.Charger.Msg.Host.Resp.OutCharger;
using Service.Charger.Server;
namespace Service.Charger.Handler.OutCharger;
@ -22,7 +23,7 @@ public class PileChargeCompleteHandler : SimpleChannelInboundHandler<PileChargeC
protected override void ChannelRead0(IChannelHandlerContext ctx, PileChargeCompleteReq msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -4,6 +4,7 @@ using log4net;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.OutCharger.Req;
using Service.Charger.Msg.Host.Resp.OutCharger;
using Service.Charger.Server;
namespace Service.Charger.Handler.OutCharger;
/// <summary>
@ -17,7 +18,7 @@ public class PileStartChargeCompleteHandler : SimpleChannelInboundHandler<PileSt
protected override void ChannelRead0(IChannelHandlerContext ctx, PileStartChargeCompleteReq msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -9,6 +9,7 @@ using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.OutCharger.Resp;
using Service.Charger.Msg.Http.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler.OutCharger;
@ -25,7 +26,7 @@ public class PileStartChargeResHandler : SimpleChannelInboundHandler<PileStartCh
protected override void ChannelRead0(IChannelHandlerContext ctx, PileStartChargeRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -7,6 +7,7 @@ using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.OutCharger.Resp;
using Service.Charger.Msg.Http.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler.OutCharger;
/// <summary>
@ -23,7 +24,7 @@ public class PileStopChargeResHandler : SimpleChannelInboundHandler<PileStopChar
protected override void ChannelRead0(IChannelHandlerContext ctx, PileStopChargeRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
string chargeNo = sn.Substring(4);

@ -9,6 +9,7 @@ using Service.Charger.Common;
using Service.Charger.Msg.Charger.OutCharger.Req;
using Service.Charger.Msg.Host.Resp.OutCharger;
using Service.Charger.Msg.Http.Req;
using Service.Charger.Server;
using Service.Init;
namespace Service.Charger.Handler.OutCharger;
@ -27,7 +28,7 @@ public class PileUploadChargeRecordHandler : SimpleChannelInboundHandler<PileUpl
protected override void ChannelRead0(IChannelHandlerContext ctx, PileUploadChargeRecord msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
ctx.Channel.WriteAndFlushAsync(new PileUploadChargeRecordRes(msg.Pn));
if (client == null)
@ -97,7 +98,7 @@ public class PileUploadChargeRecordHandler : SimpleChannelInboundHandler<PileUpl
req.fp = powersPeriods[2];
req.vp = powersPeriods[3];
UploadChargeRecord(msg, client, req, sn, startTime, endTime, chargingPower, socBefore, socAfter,chargeOrder);
// UploadChargeRecord(msg, client, req, sn, startTime, endTime, chargingPower, socBefore, socAfter,chargeOrder);
}
else
{
@ -116,14 +117,14 @@ public class PileUploadChargeRecordHandler : SimpleChannelInboundHandler<PileUpl
req.fp = powersPeriods[2];
req.vp = powersPeriods[3];
// 充电完成上报云平台
UploadChargeRecord(msg, client, req, sn, startTime, endTime, chargingPower, socBefore, socAfter,chargeOrder);
// UploadChargeRecord(msg, client, req, sn, startTime, endTime, chargingPower, socBefore, socAfter,chargeOrder);
}
}
}
private static void UploadChargeRecord(PileUploadChargeRecord msg, ChargerClient client, PileEndChargeReq req,
/*private static void UploadChargeRecord(PileUploadChargeRecord msg, ChargerClient client, PileEndChargeReq req,
string sn, DateTime startTime, DateTime endTime, float chargingPower, byte socBefore, byte socAfter,ChargeOrder chargeOrder)
{
if (chargeOrder != null)
@ -160,7 +161,7 @@ public class PileUploadChargeRecordHandler : SimpleChannelInboundHandler<PileUpl
HttpUtil.SendPostRequest(req, "http://127.0.0.1:5034/api/OutCharger/SendPileEndCharge");
}
}*/
private static float[] PeaksAndValleys(PileUploadChargeRecord msg, float[] powersPeriods)
{

@ -6,6 +6,7 @@ using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Handler;
using Service.Charger.Msg.Charger.OutCharger.Req;
using Service.Charger.Server;
namespace Service.Charger.Handler.OutCharger;
/// <summary>
@ -25,7 +26,7 @@ public class PileUploadRemoteSignalHandler: SimpleChannelInboundHandler<PileUplo
}
protected override void ChannelRead0(IChannelHandlerContext ctx, PileUploadRemoteSignal msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
//存储日志
Log.Info($"receive {msg} from {sn}");

@ -4,6 +4,7 @@ using log4net;
using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.OutCharger.Req;
using Service.Charger.Server;
namespace Service.Charger.Handler.OutCharger;
@ -23,7 +24,7 @@ public class PileUploadTelemetryHandler : SimpleChannelInboundHandler<PileUpload
}
protected override void ChannelRead0(IChannelHandlerContext ctx, PileUploadTelemetry msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -24,7 +25,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, PowerRegulationRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
client.PowerRegulationRes = msg;

@ -5,6 +5,7 @@ using log4net;
using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -29,7 +30,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, QueryBatterySnRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
StringBuilder sb = new StringBuilder(msg.BatterSnLength);
for (int i = 0; i < msg.BatterSnLength; i++)

@ -6,6 +6,7 @@ using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -39,7 +40,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, RecordCharge msg)
{
if(ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if(ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{

@ -17,6 +17,7 @@ using Common.Util;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkCore.Redis;
using Service.Charger.Server;
using Service.Init;
namespace Service.Charger.Handler
@ -32,7 +33,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, RemoteSignaling msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
client.RemoteSignaling = msg;
@ -113,7 +114,7 @@ namespace Service.Charger.Handler
if (msg.SmokeAlarm==1) { lstAlarm.Add("103"); }
if (msg.HighVoltageInterlockAlarm==1) { lstAlarm.Add("104"); }
new FaultHandling().SaveAlarmInfo(lstAlarm, EquipmentType.Charger, "0", false, "2");
new FaultHandling().SaveAlarmInfo(lstAlarm, EquipmentType.Charger, client.Sn, false, "2");
}
}
}

@ -6,6 +6,7 @@ using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -26,7 +27,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, RemoteStartChargingRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
if (msg.Result == 0)

@ -5,6 +5,7 @@ using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Handler;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Server;
namespace HybirdFrameworkServices.Charger.Handler
{
@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, RemoteStopChargingRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
if (msg.Result != 0xff)

@ -7,6 +7,7 @@ using Service.Charger.Handler;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Msg.Host.Resp;
using Service.Charger.Server;
namespace HybirdFrameworkServices.Charger.Handler
{
@ -23,7 +24,7 @@ namespace HybirdFrameworkServices.Charger.Handler
private static readonly ILog Log = LogManager.GetLogger(typeof(ResponseSettingHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, ResponseSetting msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");

@ -3,6 +3,7 @@ using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -20,7 +21,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, SetPeakVallyTimeRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
}

@ -12,6 +12,7 @@ using System.Threading.Tasks;
using Common.Const;
using Entity.DbModel.Station;
using Repository.Station;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -91,7 +92,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, UpAlarm msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
client.UpAlarm = msg;

@ -2,6 +2,7 @@
using log4net;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Resp;
using Service.Charger.Server;
namespace Service.Charger.Handler;
@ -11,7 +12,7 @@ public class UpBmsHandler: SimpleChannelInboundHandler<UpBms>, IBaseHandler
protected override void ChannelRead0(IChannelHandlerContext ctx, UpBms msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
client.UpBms = msg;

@ -11,6 +11,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -25,7 +26,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, UpgradeRequestRes msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
}

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -24,7 +25,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, UplinkUpgrade msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
client.UplinkUpgrade = msg;

@ -14,6 +14,7 @@ using Common.Const;
using Entity.DbModel.Station;
using Repository;
using Repository.Station;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -43,7 +44,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, UploadRemoteSignalData msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
//存储日志
Log.Info($"receive {msg} from {sn}");

@ -6,6 +6,7 @@ using log4net;
using Newtonsoft.Json;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -22,7 +23,7 @@ namespace Service.Charger.Handler
public RedisHelper RedisHelper { get; set; }
protected override void ChannelRead0(IChannelHandlerContext ctx, UploadTelemetryData msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out var sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out var sn, out var client))
{
msg.ChargerNo = sn;
Log.Info($"receive {msg} from {sn}");

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -23,7 +24,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, VehicleVIN msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
client.VehicleVIN = msg;

@ -5,6 +5,7 @@ using log4net;
using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -25,7 +26,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, VoltageCurrentSoc msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
bool update = _binInfoRepository.Update(it => new BinInfo()

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service.Charger.Server;
namespace Service.Charger.Handler
{
@ -20,7 +21,7 @@ namespace Service.Charger.Handler
protected override void ChannelRead0(IChannelHandlerContext ctx, VoltageExtremumStatistics msg)
{
if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client))
if (ServerMgr.TryGetClient(ctx.Channel, out string sn, out var client))
{
Log.Info($"receive {msg} from {sn}");
client.VoltageExtremumStatistics = msg;

@ -1,6 +1,6 @@
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Host.Req
namespace Service.Charger.Msg.Charger.Req
{
/// <summary>
/// 3.3.1 监控平台鉴权认证
@ -37,7 +37,7 @@ namespace Service.Charger.Msg.Host.Req
[Property(96, 8)]
public byte AuthCodeKey { get; set; }
public Auth(ushort connseq, byte[] authcodes, byte authcodekey)
/*public Auth(ushort connseq, byte[] authcodes, byte authcodekey)
{
FrameTypeNo = 45;
MsgBodyCount = 1;
@ -50,6 +50,6 @@ namespace Service.Charger.Msg.Host.Req
ConnSeq = connseq;
AuthCodes = authcodes;
AuthCodeKey = authcodekey;
}
}*/
}
}

@ -14,10 +14,10 @@ namespace Service.Charger.Msg.Charger.Req
public byte RecordType { get; set; }
/// <summary>
/// 监控网关编号
/// 充电机编号
/// </summary>
[Property(8, 8*16)]
public String GatewayNo { get; set; }
public String ChargerSn { get; set; }
/// <summary>
/// 设备属性

@ -1,6 +1,6 @@
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Charger.Resp
namespace Service.Charger.Msg.Host.Resp
{
/// <summary>
/// 3.3.2 充放电机应答鉴权认证
@ -31,5 +31,23 @@ namespace Service.Charger.Msg.Charger.Resp
/// </summary>
[Property(32, 8)]
public byte FailReason { get; set; }
public AuthRes(byte result,ushort conSeq,byte failReason)
{
ConnSeq = conSeq;
AuthResult = result;
FailReason = failReason;
CtlArea = 0;
SrcAddr = 0;
FrameTypeNo = 45;
MsgBodyCount = 1;
TransReason = 4;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
RecordType = 25;
}
}
}

@ -8,6 +8,7 @@ using log4net;
using Newtonsoft.Json;
using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Server;
using Service.Init;
namespace Service.Charger.MyTask;
@ -200,7 +201,7 @@ public class AutoChargeTask : ITask
if (binInfo.ChargeStatus != 1)
{
//没有充电时候在充电
Result<bool>? result = ClientMgr.GetBySn(binInfo.ChargerNo)
Result<bool>? result = ServerMgr.GetBySn(binInfo.ChargerNo)
?.StartCharge(chargeSoc, (float)power, 0);
if (result is { IsSuccess: true })
{
@ -229,7 +230,7 @@ public class AutoChargeTask : ITask
if (ch.Soc < StaticStationInfo.ChargeSoc)
{
Log.Info($"auto stop charge by more charging bin {ch.No} soc:{ch.Soc}");
ClientMgr.GetBySn(ch.ChargerNo)?.SendRemoteStopCharging();
ServerMgr.GetBySn(ch.ChargerNo)?.SendRemoteStopCharging();
count++;
if (count == stopCount)
{
@ -249,7 +250,7 @@ public class AutoChargeTask : ITask
foreach (var binInfo in stopList)
{
Log.Info($"auto stop charge {binInfo.No} soc:{binInfo.Soc}");
ClientMgr.GetBySn(binInfo.ChargerNo)?.SendRemoteStopCharging();
ServerMgr.GetBySn(binInfo.ChargerNo)?.SendRemoteStopCharging();
}
#endregion

@ -7,6 +7,7 @@ using HybirdFrameworkCore.Utils;
using log4net;
using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Server;
using Service.Init;
namespace Service.Charger.MyTask;
@ -41,7 +42,7 @@ public class EmeterEnergyRecordTask : ITask
EmeterEnergyRepository.Delete(i=>i.UploadTime<time);
EmeterEnergyChangeRepository.Delete(i=>i.UploadTime<time);
foreach (var keyValuePair in ClientMgr.Dictionary)
foreach (var keyValuePair in ServerMgr.Dictionary)
{
var chargerClient = keyValuePair.Value;
if (chargerClient.Connected)

@ -1,4 +1,4 @@
using System.Collections.Concurrent;
/*using System.Collections.Concurrent;
using Common.Util;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.AutoTask;
@ -7,6 +7,7 @@ using Service.Charger.Client;
using Service.Charger.Msg.Charger.OutCharger.Req;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Http.Req;
using Service.Charger.Server;
using Service.Init;
namespace Service.Charger.MyTask;
@ -33,7 +34,7 @@ public class PileChargeRealtimeTask : ITask
public void Handle()
{
ConcurrentDictionary<string, ChargerClient> chargerClients = ClientMgr.Dictionary;
ConcurrentDictionary<string, ChargerClient> chargerClients = ServerMgr.Dictionary;
if (chargerClients.Values.Count <= 0)
{
@ -100,4 +101,4 @@ public class PileChargeRealtimeTask : ITask
{
_stop = false;
}
}
}*/

@ -1,4 +1,4 @@
using System.Collections.Concurrent;
/*using System.Collections.Concurrent;
using Common.Util;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.AutoTask;
@ -8,6 +8,7 @@ using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Msg.Charger.OutCharger.Req;
using Service.Charger.Msg.Http.Req;
using Service.Charger.Server;
using Service.Init;
namespace Service.Charger.MyTask;
@ -48,7 +49,7 @@ public class PileRealtimeTask : ITask
}
} if (ChargerConst._dictionary.Count <= 0)return;
ConcurrentDictionary<string, ChargerClient> chargerClients = ClientMgr.Dictionary;
ConcurrentDictionary<string, ChargerClient> chargerClients = ServerMgr.Dictionary;
if (chargerClients.Values.Count <= 0)
{
@ -117,4 +118,4 @@ public class PileRealtimeTask : ITask
}
}
}*/

@ -2,6 +2,7 @@
using HybirdFrameworkCore.AutoTask;
using log4net;
using Service.Charger.Client;
using Service.Charger.Server;
namespace Service.Charger.MyTask;
@ -25,7 +26,7 @@ public class QueryBatteryInfoTask : ITask
{
try
{
foreach (var (key, client) in ClientMgr.Dictionary)
foreach (var (key, client) in ServerMgr.Dictionary)
{
client.SendQueryBattery();
}

@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Threading.Channels;
using Autofac;
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac;
@ -69,4 +70,18 @@ public class ServerMgr
return o;
}
/// <summary>
///
/// </summary>
/// <param name="sn"></param>
/// <param name="destAddr"></param>
public static void SessionAttr(IChannel channel,string sn, string destAddr)
{
ChannelUtils.AddAttr(channel, ChargerConst.ChargerSn, sn);
ChannelUtils.AddAttr(channel, ChargerConst.EqmTypeNo, sn);
ChannelUtils.AddAttr(channel, ChargerConst.EqmCode, sn);
ChannelUtils.AddAttr(channel, ChargerConst.DestAddr, destAddr);
}
}

@ -8,6 +8,7 @@ using log4net;
using Newtonsoft.Json;
using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Server;
using Service.Init;
using Service.Swap.Dto;
using SqlSugar;
@ -41,7 +42,7 @@ public class BatteryInfoUploadTask : ITask
List<SingleBatInfo> batInfos = binInfos.Where(it => it.Exists == 1).Select(it =>
{
Log.Info("start BatteryInfoUploadTask uoload bininfo select");
ChargerClient? client = ClientMgr.GetBySn(it.ChargerNo);
ChargerClient? client = ServerMgr.GetBySn(it.ChargerNo);
SingleBatInfo batInfo = new SingleBatInfo()
{
bn = it.BatteryNo,

@ -83,7 +83,7 @@ public class BinInfoService : BaseServices<BinInfo>
// 功率赋值
foreach (var binInfoResp in binInfoList)
{
ChargerClient? chargerClient = ClientMgr.GetBySn(binInfoResp.ChargerNo);
ChargerClient? chargerClient = ServerMgr.GetBySn(binInfoResp.ChargerNo);
if (chargerClient != null)
{
binInfoResp.ChargeConnectFlag = chargerClient.Connected;

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
using Repository.Station;
using Service.Charger;
using Service.Charger.Client;
using Service.Charger.Server;
using Service.Station;
namespace WebStarter.Controllers;
@ -38,30 +39,11 @@ public class ChargeController : ControllerBase
[Route("GetChargerCodeList")]
public async Task<Result<List<string>>> GetChargerCodeList()
{
List<string> keysList = new List<string>(ClientMgr.Dictionary.Keys);
List<string> keysList = new List<string>(ServerMgr.Dictionary.Keys);
return Result<List<string>>.Success(keysList);
}
/// <summary>
/// 给充电机发鉴权
/// </summary>
/// <param name="code">充电机编码</param>
/// <returns>发送结果</returns>
[HttpGet]
[Route("ChargerSendAuth/{code}")]
public Result<bool> ChargerSendAuth(string code)
{
ChargerClient? chargerClient = ClientMgr.GetBySn(code);
if (chargerClient != null)
{
chargerClient.SendAuth();
return Result<bool>.Success(true);
}
return Result<bool>.Fail("充电机未连接");
}
/// <summary>
/// 给充电机发送功率调节指令
@ -78,7 +60,7 @@ public class ChargeController : ControllerBase
}
string _code = _binInfoService.QueryByClause(i => i.Code == code).ChargerNo;
ChargerClient? chargerClient = ClientMgr.GetBySn(_code);
ChargerClient? chargerClient = ServerMgr.GetBySn(_code);
if (chargerClient != null)
{
@ -133,7 +115,7 @@ public class ChargeController : ControllerBase
[Route("GetBinPowers")]
public Result<float[]> GetBinPowers()
{
float[] results = ClientMgr.Dictionary.Values
float[] results = ServerMgr.Dictionary.Values
.Select(chargerClient => chargerClient.RealTimeChargePower)
.ToArray();
return Result<float[]>.Success(results);

@ -5,6 +5,7 @@ using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Common;
using Service.Charger.Msg.Http.Req;
using Service.Charger.Server;
using Service.Init;
using Service.Station;
@ -42,7 +43,7 @@ public class OutChargerController
byte chargerGunCode = ChargerUtils.GetTheGun(httpReq.pn);
ChargerClient? chargerClient = ClientMgr.GetBySn(chargerCode);
ChargerClient? chargerClient = ServerMgr.GetBySn(chargerCode);
if (chargerClient == null)
{
@ -94,7 +95,7 @@ public class OutChargerController
byte chargerGunCode = ChargerUtils.GetTheGun(httpReq.pn);
ChargerClient? chargerClient = ClientMgr.GetBySn(chargerCode);
ChargerClient? chargerClient = ServerMgr.GetBySn(chargerCode);
if (chargerClient == null)
{
@ -127,7 +128,7 @@ public class OutChargerController
}
string _code = _binInfoService.QueryByClause(i => i.Code == code).ChargerNo;
ChargerClient? chargerClient = ClientMgr.GetBySn(_code);
ChargerClient? chargerClient = ServerMgr.GetBySn(_code);
if (chargerClient != null)
{
@ -146,7 +147,7 @@ public class OutChargerController
[Route("GetChargerPile")]
public Result<List<ChargerPileResp>> GetChargerPile()
{
var chargerClients = ClientMgr.Dictionary;
var chargerClients = ServerMgr.Dictionary;
if (chargerClients.IsEmpty)
{
return Result<List<ChargerPileResp>>.Fail("没有充电机连接");

@ -8,6 +8,7 @@ using HybirdFrameworkCore.Job;
using HybirdFrameworkCore.Redis;
using log4net;
using Service.Charger.Client;
using Service.Charger.Server;
using Service.RealTime;
using SqlSugar;
using SqlSugar.IOC;
@ -101,9 +102,9 @@ foreach (var s in list.Split(";"))
AppInfo.Container = app.Services.GetAutofacRoot();
ClientMgr.InitClient();
ServerMgr.InitServer(2408);
TaskInit.Init();
//TaskInit.Init();
QuartzSchedulerFactory.Init();
app.Lifetime.ApplicationStopping.Register(QuartzSchedulerFactory.Shutdown);

@ -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=localhost;Port=3306;Database=eaxing_back_africa_dev;Uid=root;Pwd=lxw123;Charset=utf8;"
},
"Update": {
"AutoUpdate": "false",
@ -10,7 +10,7 @@
"Url": "http://121.4.95.243:8090/Updates/AutoUpdaterStarter.xml"
},
"Redis": {
"Connection": "106.12.36.89:6379,password=123456",
"Connection": "localhost:6379,password=123456",
"InstanceName": "local",
"DefaultDB": "8"
},
@ -35,5 +35,6 @@
"Job": {
"Enabled": false
},
"AllowedHosts": "*"
}

@ -26,11 +26,11 @@
</layout>
</appender>
<logger name="ChargerC2001" additivity="false">
<logger name="EAX000100000001" additivity="false">
<level value="ALL" />
<appender-ref ref="ChargerC2001" />
<appender-ref ref="EAX000100000001" />
</logger>
<appender name="ChargerC2001" type="log4net.Appender.RollingFileAppender">
<appender name="EAX000100000001" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logs\Charger\" />
<param name="AppendToFile" value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
@ -44,11 +44,11 @@
<conversionPattern value="%date %level %thread %logger - %message%newline" />
</layout>
</appender>
<logger name="ChargerC2002" additivity="false">
<logger name="EAX000100000002" additivity="false">
<level value="ALL" />
<appender-ref ref="ChargerC2002" />
<appender-ref ref="EAX000100000002" />
</logger>
<appender name="ChargerC2002" type="log4net.Appender.RollingFileAppender">
<appender name="EAX000100000002" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logs\Charger\" />
<param name="AppendToFile" value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
@ -62,11 +62,11 @@
<conversionPattern value="%date %level %thread %logger - %message%newline" />
</layout>
</appender>
<logger name="ChargerC2003" additivity="false">
<logger name="EAX000100000003" additivity="false">
<level value="ALL" />
<appender-ref ref="ChargerC2003" />
<appender-ref ref="EAX000100000003" />
</logger>
<appender name="ChargerC2003" type="log4net.Appender.RollingFileAppender">
<appender name="EAX000100000003" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logs\Charger\" />
<param name="AppendToFile" value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
@ -80,96 +80,7 @@
<conversionPattern value="%date %level %thread %logger - %message%newline" />
</layout>
</appender>
<logger name="ChargerC2004" additivity="false">
<level value="ALL" />
<appender-ref ref="ChargerC2004" />
</logger>
<appender name="ChargerC2004" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logs\Charger\" />
<param name="AppendToFile" value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<Encoding value="UTF-8" />
<param name="StaticLogFileName" value="false" />
<param name="RollingStyle" value="Composite" />
<param name="DatePattern" value="yyyyMMdd/HH&quot;ChargerC2004.log&quot;" />
<param name="maximumFileSize" value="200MB" />
<param name="MaxSizeRollBackups" value="5" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %thread %logger - %message%newline" />
</layout>
</appender>
<logger name="ChargerC2005" additivity="false">
<level value="ALL" />
<appender-ref ref="ChargerC2005" />
</logger>
<appender name="ChargerC2005" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logs\Charger\" />
<param name="AppendToFile" value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<Encoding value="UTF-8" />
<param name="StaticLogFileName" value="false" />
<param name="RollingStyle" value="Composite" />
<param name="DatePattern" value="yyyyMMdd/HH&quot;ChargerC2005.log&quot;" />
<param name="maximumFileSize" value="200MB" />
<param name="MaxSizeRollBackups" value="5" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %thread %logger - %message%newline" />
</layout>
</appender>
<logger name="ChargerC2006" additivity="false">
<level value="ALL" />
<appender-ref ref="ChargerC2006" />
</logger>
<appender name="ChargerC2006" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logs\Charger\" />
<param name="AppendToFile" value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<Encoding value="UTF-8" />
<param name="StaticLogFileName" value="false" />
<param name="RollingStyle" value="Composite" />
<param name="DatePattern" value="yyyyMMdd/HH&quot;ChargerC2006.log&quot;" />
<param name="maximumFileSize" value="200MB" />
<param name="MaxSizeRollBackups" value="5" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %thread %logger - %message%newline" />
</layout>
</appender>
<logger name="ChargerC2007" additivity="false">
<level value="ALL" />
<appender-ref ref="ChargerC2007" />
</logger>
<appender name="ChargerC2007" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logs\Charger\" />
<param name="AppendToFile" value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<Encoding value="UTF-8" />
<param name="StaticLogFileName" value="false" />
<param name="RollingStyle" value="Composite" />
<param name="DatePattern" value="yyyyMMdd/HH&quot;ChargerC2007.log&quot;" />
<param name="maximumFileSize" value="200MB" />
<param name="MaxSizeRollBackups" value="5" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %thread %logger - %message%newline" />
</layout>
</appender>
<logger name="ChargerC2008" additivity="false">
<level value="ALL" />
<appender-ref ref="ChargerC2008" />
</logger>
<appender name="ChargerC2008" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logs\Charger\" />
<param name="AppendToFile" value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<Encoding value="UTF-8" />
<param name="StaticLogFileName" value="false" />
<param name="RollingStyle" value="Composite" />
<param name="DatePattern" value="yyyyMMdd/HH&quot;ChargerC2008.log&quot;" />
<param name="maximumFileSize" value="200MB" />
<param name="MaxSizeRollBackups" value="5" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %thread %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />

@ -111,7 +111,7 @@ public partial class Form2 : Form
private void btnConn_Click(object sender, EventArgs e)
{
string ip = txtIp.Text;
/*string ip = txtIp.Text;
var port = int.Parse(txtPort.Text);
string destAddr = txtDestAddr.Text;
@ -148,12 +148,12 @@ public partial class Form2 : Form
EnableUi(this.rTxtSend, false);
EnableUi(this.rTxtReceive, false);
}
});
});*/
}
private void btnAuth_Click(object sender, EventArgs e)
{
_chargerClient?.SendAuth();
//_chargerClient?.SendAuth();
AppendText(this.rTxtSend, _chargerClient.CurrentCmd);
DisplayData();
MessageBox.Show(@"发送成功");

Loading…
Cancel
Save