拓展帧添加

master
xjl 4 weeks ago
parent 5c5e6177b8
commit 1018f44854

@ -69,6 +69,7 @@ public class Decoder : ByteToMessageDecoder
0x08 => ModelConvert.Decode<UnLockMsgResp>(data),
0x10 => ModelConvert.Decode<SettleConfirmMsgResp>(data),
0x12 => ModelConvert.Decode<SetParamMsgResp>(data),
0x13 => ModelConvert.Decode<HeartExpandBeatMsg>(data),
0x51 => ModelConvert.Decode<ElecBaseMsg>(data),
0x52 => ModelConvert.Decode<ElecMsg>(data),
_ => new BaseMsg()

@ -30,6 +30,7 @@ namespace Service.Car.Handler
Log.Info($"receive ElecBaseMsg = {JsonConvert.SerializeObject(msg)}");
IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(msg.CarNo);
msg.BatteryCode = msg.BatteryCode.Replace("\u0000", "");
ioSession?.BusinessMap.AddOrUpdate("ElecBaseMsg", msg, ((s, o) => msg));
ioSession?.BusinessMap.AddOrUpdate("Connected", true, ((s, o) => true));
}

@ -0,0 +1,46 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.Session;
using log4net;
using Newtonsoft.Json;
using Service.Car.Msg.Car.Req;
using Service.Car.Msg.Host.Resp;
using Service.Car.Server;
namespace Service.Car.Handler;
/// <summary>
///
/// </summary>
[Order(8)]
[Scope("InstancePerDependency")]
public class HeartExpandBeatMsgHandler : SimpleChannelInboundHandler<HeartExpandBeatMsg>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(HeartExpandBeatMsgHandler));
/// <summary>
///
/// </summary>
/// <param name="ctx"></param>
/// <param name="msg"></param>
/// <exception cref="NotImplementedException"></exception>
protected override void ChannelRead0(IChannelHandlerContext ctx, HeartExpandBeatMsg msg)
{
Log.Info($"receive HeartBeatMsg = {JsonConvert.SerializeObject(msg)}");
IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(ctx.Channel.Id.ToString());
if (ioSession != null && ioSession.Key != msg.CarNo)
{
CarServerMgr.CarServer?.SessionMgr.ChangeSessionKey(ioSession, msg.CarNo);
}
if (ioSession == null)
{
ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(msg.CarNo);
}
ioSession.BusinessMap.AddOrUpdate("HeartExpandBeatMsg", msg, ((s, o) => msg));
ioSession?.BusinessMap.AddOrUpdate("Connected", true, ((s, o) => true));
}
}

@ -0,0 +1,27 @@
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Car.Msg.Car.Req;
public class HeartExpandBeatMsg : BaseMsg
{
/// <summary>
/// 锁止IO状态1
/// </summary>
[Property(248, 8)]
public byte LockIOStatus01 { get; set; }
/// <summary>
/// 锁止IO状态2
/// </summary>
[Property(256, 8)]
public byte LockIOStatus02 { get; set; }
/// <summary>
/// 充电连接器状态1 0 断开1 连接
/// </summary>
[Property(264, 8)]
public byte ChargingConnectorStatus01 { get; set; }
/// <summary>
/// 充电连接器状态1 0 断开1 连接
/// </summary>
[Property(272, 8)]
public byte ChargingConnectorStatus02 { get; set; }
}

@ -24,7 +24,7 @@ public class CarServer : TcpServer<IBaseHandler, Decoder, Encoder>
/// 1 待机 2 换电
/// </summary>
public byte StationStatus { get; set; } = 1;
public string VIN { get; set; };
public string VIN { get; set; }
public CarServer() : base()

@ -54,6 +54,12 @@ public class CarController : ControllerBase{
{
carInfoResp.HeartBeatMsg = (HeartBeatMsg)heartBeatMsg;
}
ioSession.BusinessMap.TryGetValue("HeartExpandBeatMsg", out var heartExpandBeatMsg);
if (heartExpandBeatMsg != null)
{
carInfoResp.HeartExpandBeatMsg = (HeartExpandBeatMsg)heartExpandBeatMsg;
}
}
@ -95,6 +101,11 @@ public class CarController : ControllerBase{
{
carInfoResp.HeartBeatMsg = (HeartBeatMsg)heartBeatMsg;
}
ioSession.BusinessMap.TryGetValue("HeartExpandBeatMsg", out var heartExpandBeatMsg);
if (heartExpandBeatMsg != null)
{
carInfoResp.HeartExpandBeatMsg = (HeartExpandBeatMsg)heartExpandBeatMsg;
}
result.Add(carInfoResp);

@ -31,4 +31,9 @@ public class CarInfoResp
/// 状态数据
/// </summary>
public HeartBeatMsg? HeartBeatMsg { get; set; }
/// <summary>
/// 状态拓展数据
/// </summary>
public HeartExpandBeatMsg? HeartExpandBeatMsg { get; set; }
}
Loading…
Cancel
Save