根据最新协议修改msg及handler

master
ydh 3 months ago
parent f75979f355
commit 66d4f68254

@ -36,7 +36,8 @@ public class ExportDb
private readonly SqlSugarClient Db = new(new ConnectionConfig private readonly SqlSugarClient Db = new(new ConnectionConfig
{ {
ConnectionString = ConnectionString =
"server=106.12.36.89;Database=chassis_track_swap0;Uid=remote_user;Pwd=Rszn123;Charset=utf8;", // "server=106.12.36.89;Database=chassis_track_swap0;Uid=remote_user;Pwd=Rszn123;Charset=utf8;",
"server=127.0.0.1;Port=3306;Database=nhagv_dev;Uid=root;Pwd=123456;Charset=utf8;",
DbType = DbType.MySql, DbType = DbType.MySql,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute InitKeyType = InitKeyType.Attribute

@ -64,12 +64,13 @@ public class Decoder : ByteToMessageDecoder
BaseMsg msg = data[5] switch BaseMsg msg = data[5] switch
{ {
0x01 => ModelConvert.Decode<ElecMsg>(data),
0x03 => ModelConvert.Decode<HeartBeatMsg>(data), 0x03 => ModelConvert.Decode<HeartBeatMsg>(data),
0x06 => ModelConvert.Decode<LockMsgResp>(data), 0x06 => ModelConvert.Decode<LockMsgResp>(data),
0x08 => ModelConvert.Decode<UnLockMsgResp>(data), 0x08 => ModelConvert.Decode<UnLockMsgResp>(data),
0x10 => ModelConvert.Decode<SettleConfirmMsgResp>(data), 0x10 => ModelConvert.Decode<SettleConfirmMsgResp>(data),
0x12 => ModelConvert.Decode<SetParamMsgResp>(data), 0x12 => ModelConvert.Decode<SetParamMsgResp>(data),
0x51 => ModelConvert.Decode<ElecBaseMsg>(data),
0x52 => ModelConvert.Decode<ElecMsg>(data),
_ => new BaseMsg() _ => new BaseMsg()
}; };
Log.Info($"receive original ={BitUtls.BytesToHexStr(data)} , data={JsonConvert.SerializeObject(msg)}"); Log.Info($"receive original ={BitUtls.BytesToHexStr(data)} , data={JsonConvert.SerializeObject(msg)}");

@ -0,0 +1,37 @@
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;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Service.Car.Handler
{
[Order(8)]
[Scope("InstancePerDependency")]
public class ElecBaseMsgHandler : SimpleChannelInboundHandler<ElecBaseMsg>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ElecBaseMsgHandler));
/// <summary>
///
/// </summary>
/// <param name="ctx"></param>
/// <param name="msg"></param>
/// <exception cref="NotImplementedException"></exception>
protected override void ChannelRead0(IChannelHandlerContext ctx, ElecBaseMsg msg)
{
Log.Info($"receive ElecBaseMsg = {JsonConvert.SerializeObject(msg)}");
IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(msg.CarNo);
ioSession?.BusinessMap.AddOrUpdate("ElecBaseMsg", msg, ((s, o) => msg));
ioSession?.BusinessMap.AddOrUpdate("Connected", true, ((s, o) => true));
}
}
}

@ -31,11 +31,11 @@ public class ElecMsgHandler : SimpleChannelInboundHandler<ElecMsg>, IBaseHandler
ioSession?.BusinessMap.AddOrUpdate("ElecMsg", msg, ((s, o) => msg)); ioSession?.BusinessMap.AddOrUpdate("ElecMsg", msg, ((s, o) => msg));
ioSession?.BusinessMap.AddOrUpdate("Connected", true, ((s, o) => true)); ioSession?.BusinessMap.AddOrUpdate("Connected", true, ((s, o) => true));
ElecMsgResp resp = new ElecMsgResp(0) //ElecMsgResp resp = new ElecMsgResp(0)
{ //{
CarNo = msg.CarNo // CarNo = msg.CarNo
}; //};
resp.InitCurrentTime(); //resp.InitCurrentTime();
ctx.Channel.WriteAndFlushAsync(resp); //ctx.Channel.WriteAndFlushAsync(resp);
} }
} }

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Car.Msg.Car.Req
{
public class ElecBaseMsg : BaseMsg
{
/// <summary>
/// 电池编码
/// </summary>
[Property(248, 192)]
public string BatteryCode { get; set; }
/// <summary>
/// 电池编码
/// </summary>
[Property(340, 8)]
public byte BatteryManufacturer { get; set; }
/// <summary>
/// 电池类型
/// </summary>
[Property(348, 8)]
public byte BatteryType { get; set; }
/// <summary>
/// 额定能量
/// </summary>
[Property(356, 16)]
public byte RatedEnergy { get; set; }
/// <summary>
/// 额定容量
/// </summary>
[Property(372, 16)]
public byte RatedCapacity { get; set; }
/// <summary>
/// 额定电压
/// </summary>
[Property(388, 16)]
public byte RatedVoltage { get; set; }
}
}

@ -5,80 +5,80 @@ namespace Service.Car.Msg.Car.Req;
public class ElecMsg : BaseMsg public class ElecMsg : BaseMsg
{ {
/// <summary> /// <summary>
/// 车辆累计放电量 /// 电池 SOC
/// </summary> /// </summary>
[Property(248, 24, scale: 0.01, round: 2)] [Property(248, 8)]
public double AccDischargeCount { get; set; } public byte SOC { get; set; }
/// <summary> /// <summary>
/// 车辆累计回馈电量 /// 电池 SOH
/// </summary> /// </summary>
[Property(272, 24, scale: 0.01, round: 2)] [Property(256, 8)]
public double AccFallbackCount { get; set; } public byte SOH { get; set; }
/// <summary> /// <summary>
/// 车辆累计插枪充电量 /// BMS 当前状态
/// </summary> /// </summary>
[Property(296, 24, scale: 0.01, round: 2)] [Property(264, 8)]
public double AccChargeCount { get; set; } public byte BMSStates { get; set; }
/// <summary> /// <summary>
/// 5 车辆累计综合能耗 /// 电芯温度平均值
/// </summary> /// </summary>
[Property(320, 24, scale: 0.01, round: 2)] [Property(272, 8)]
public double AccKgce { get; set; } public byte ElectricCoreTemValue { get; set; }
/// <summary> /// <summary>
/// 6 本次实时放电量 /// 电流
/// </summary> /// </summary>
[Property(344, 24, scale: 0.01, round: 2)] [Property(280, 16)]
public double ThisTimeRealDischarge { get; set; } public short Current { get; set; }
/// <summary> /// <summary>
/// 7 上一次结算放电量 /// 电压
/// </summary> /// </summary>
[Property(368, 24, scale: 0.01, round: 2)] [Property(296, 16)]
public double LastTimeBalanceDischarge { get; set; } public short Voltage { get; set; }
/// <summary> /// <summary>
/// 8 本次实时回馈电量 /// 车速
/// </summary> /// </summary>
[Property(392, 24, scale: 0.01, round: 2)] [Property(312, 16)]
public double ThisTimeRealFeedbackPower { get; set; } public short Speed { get; set; }
/// <summary> /// <summary>
/// 9 上一次结算回馈电量 /// 电芯电压平均值
/// </summary> /// </summary>
[Property(416, 24, scale: 0.01, round: 2)] [Property(328, 16)]
public double LastTimeBalanceFeedbackPower { get; set; } public short VoltageAverage { get; set; }
/// <summary> /// <summary>
/// 10 本次实时插枪充电量 /// 单次充电量
/// </summary> /// </summary>
[Property(440, 24, scale: 0.01, round: 2)] [Property(344, 16)]
public double ThisTimeRealChargeCount { get; set; } public short SingleCharge { get; set; }
/// <summary> /// <summary>
/// 11 上一次结算插枪充电量 /// 累计充电量
/// </summary> /// </summary>
[Property(464, 24, scale: 0.01, round: 2)] [Property(360, 32)]
public double LastTimeBalanceChargeCount { get; set; } public float CumulativeCharge { get; set; }
/// <summary> /// <summary>
/// 12 本次实时综合能耗 /// 累计放电量
/// </summary> /// </summary>
[Property(488, 24, scale: 0.01, round: 2)] [Property(392, 32)]
public double ThisTimeRealKgce { get; set; } public float CumulativeDischarge { get; set; }
/// <summary> ///// <summary>
/// 13 上一次结算综合能耗 ///// 13 上一次结算综合能耗
/// </summary> ///// </summary>
[Property(512, 24, scale: 0.01, round: 2)] //[Property(512, 8)]
public double LastTimeBalanceKgce { get; set; } //public double LastTimeBalanceKgce { get; set; }
/// <summary> ///// <summary>
/// 14 待结算电费电量 ///// 14 待结算电费电量
/// </summary> ///// </summary>
[Property(536, 24, scale: 0.01, round: 2)] //[Property(536, 8)]
public double ElectricityToBeSettled { get; set; } //public double ElectricityToBeSettled { get; set; }
} }

@ -5,7 +5,7 @@ namespace Service.Car.Msg.Car.Resp;
public class LockMsgResp : BaseMsg public class LockMsgResp : BaseMsg
{ {
/// <summary> /// <summary>
/// 0、加锁成功1、加锁失败2、车架号不匹配FF、 异常 /// 0、加锁成功其他加锁失败
/// </summary> /// </summary>
[Property(248, 8)] [Property(248, 8)]
public byte Result { get; set; } public byte Result { get; set; }

@ -5,7 +5,7 @@ namespace Service.Car.Msg.Car.Resp;
public class UnLockMsgResp : BaseMsg public class UnLockMsgResp : BaseMsg
{ {
/// <summary> /// <summary>
/// 0、解锁成功1、非 ACC OFF 状态2、车架号不匹配3、 解锁失败FF、异常 /// 0、解锁成功其他解锁失败
/// </summary> /// </summary>
[Property(248, 8)] [Property(248, 8)]
public byte Result { get; set; } public byte Result { get; set; }

@ -5,7 +5,7 @@ namespace Service.Car.Msg.Host.Resp;
public class HeartBeatMsgResp : BaseMsg public class HeartBeatMsgResp : BaseMsg
{ {
/// <summary> /// <summary>
/// 锁止状态 1 待机 2 换电 /// 后台状态 1 待机 2 换电
/// </summary> /// </summary>
[Property(248, 8)] [Property(248, 8)]
public byte HostStatus { get; set; } public byte HostStatus { get; set; }

@ -22,11 +22,14 @@ public class VinTask : ITask
public void Handle() public void Handle()
{ {
foreach (var vinMsg in TBoxServerMgr.Server?.SendVinMsg) if (TBoxServerMgr.Server?.SendVinMsg != null)
{ {
if (vinMsg != null) foreach (var vinMsg in TBoxServerMgr.Server?.SendVinMsg)
{ {
TBoxServerMgr.Server?.SessionMgr.Broadcast(vinMsg); if (vinMsg != null)
{
TBoxServerMgr.Server?.SessionMgr.Broadcast(vinMsg);
}
} }
} }
} }

@ -37,6 +37,12 @@ public class CarController : ControllerBase{
if (ObjUtils.IsNotNull(ioSession)) if (ObjUtils.IsNotNull(ioSession))
{ {
ioSession.BusinessMap.TryGetValue("ElecBaseMsg", out var elecBaseMsg);
if (elecBaseMsg != null)
{
carInfoResp.ElecBaseMsg = (ElecBaseMsg)elecBaseMsg;
}
ioSession.BusinessMap.TryGetValue("ElecMsg", out var elecMsg); ioSession.BusinessMap.TryGetValue("ElecMsg", out var elecMsg);
if (elecMsg != null) if (elecMsg != null)
{ {
@ -66,13 +72,18 @@ public class CarController : ControllerBase{
List<IoSession> sessionList = CarServerMgr.CarServer?.SessionMgr.GetSessionList(); List<IoSession> sessionList = CarServerMgr.CarServer?.SessionMgr.GetSessionList();
foreach (var ioSession in sessionList) foreach (var ioSession in sessionList)
{ {
CarInfoResp carInfoResp = new CarInfoResp() CarInfoResp carInfoResp = new CarInfoResp()
{ {
Connected = true, Connected = true,
CarNo = ioSession.Key, CarNo = ioSession.Key,
}; };
ioSession.BusinessMap.TryGetValue("ElecBaseMsg", out var elecBaseMsg);
if (elecBaseMsg != null)
{
carInfoResp.ElecBaseMsg = (ElecBaseMsg)elecBaseMsg;
}
ioSession.BusinessMap.TryGetValue("ElecMsg", out var elecMsg); ioSession.BusinessMap.TryGetValue("ElecMsg", out var elecMsg);
if (elecMsg != null) if (elecMsg != null)
{ {

@ -18,7 +18,12 @@ public class CarInfoResp
public string? CarNo { get; set; } public string? CarNo { get; set; }
/// <summary> /// <summary>
/// 度电数据 /// 电池基本信息
/// </summary>
public ElecBaseMsg? ElecBaseMsg { get; set; }
/// <summary>
/// 电池实时信息
/// </summary> /// </summary>
public ElecMsg? ElecMsg { get; set; } public ElecMsg? ElecMsg { get; set; }

@ -2,7 +2,7 @@
"ConnectionStrings": { "ConnectionStrings": {
"ConfigId": "master", "ConfigId": "master",
"DbType": "MySql", "DbType": "MySql",
"SqlConnection": "server=192.168.2.2;Port=3306;Database=huanneng_dev;Uid=root;Pwd=Rszn123;Charset=utf8;" "SqlConnection": "server=127.0.0.1;Port=3306;Database=nhagv_dev;Uid=root;Pwd=123456;Charset=utf8;"
}, },
"Update": { "Update": {
"AutoUpdate": "false", "AutoUpdate": "false",

Loading…
Cancel
Save