根据最新协议修改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
{
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,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute

@ -64,12 +64,13 @@ public class Decoder : ByteToMessageDecoder
BaseMsg msg = data[5] switch
{
0x01 => ModelConvert.Decode<ElecMsg>(data),
0x03 => ModelConvert.Decode<HeartBeatMsg>(data),
0x06 => ModelConvert.Decode<LockMsgResp>(data),
0x08 => ModelConvert.Decode<UnLockMsgResp>(data),
0x10 => ModelConvert.Decode<SettleConfirmMsgResp>(data),
0x12 => ModelConvert.Decode<SetParamMsgResp>(data),
0x51 => ModelConvert.Decode<ElecBaseMsg>(data),
0x52 => ModelConvert.Decode<ElecMsg>(data),
_ => new BaseMsg()
};
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("Connected", true, ((s, o) => true));
ElecMsgResp resp = new ElecMsgResp(0)
{
CarNo = msg.CarNo
};
resp.InitCurrentTime();
ctx.Channel.WriteAndFlushAsync(resp);
//ElecMsgResp resp = new ElecMsgResp(0)
//{
// CarNo = msg.CarNo
//};
//resp.InitCurrentTime();
//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
{
/// <summary>
/// 车辆累计放电量
/// 电池 SOC
/// </summary>
[Property(248, 24, scale: 0.01, round: 2)]
public double AccDischargeCount { get; set; }
[Property(248, 8)]
public byte SOC { get; set; }
/// <summary>
/// 车辆累计回馈电量
/// 电池 SOH
/// </summary>
[Property(272, 24, scale: 0.01, round: 2)]
public double AccFallbackCount { get; set; }
[Property(256, 8)]
public byte SOH { get; set; }
/// <summary>
/// 车辆累计插枪充电量
/// BMS 当前状态
/// </summary>
[Property(296, 24, scale: 0.01, round: 2)]
public double AccChargeCount { get; set; }
[Property(264, 8)]
public byte BMSStates { get; set; }
/// <summary>
/// 5 车辆累计综合能耗
/// 电芯温度平均值
/// </summary>
[Property(320, 24, scale: 0.01, round: 2)]
public double AccKgce { get; set; }
[Property(272, 8)]
public byte ElectricCoreTemValue { get; set; }
/// <summary>
/// 6 本次实时放电量
/// 电流
/// </summary>
[Property(344, 24, scale: 0.01, round: 2)]
public double ThisTimeRealDischarge { get; set; }
[Property(280, 16)]
public short Current { get; set; }
/// <summary>
/// 7 上一次结算放电量
/// 电压
/// </summary>
[Property(368, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceDischarge { get; set; }
[Property(296, 16)]
public short Voltage { get; set; }
/// <summary>
/// 8 本次实时回馈电量
/// 车速
/// </summary>
[Property(392, 24, scale: 0.01, round: 2)]
public double ThisTimeRealFeedbackPower { get; set; }
[Property(312, 16)]
public short Speed { get; set; }
/// <summary>
/// 9 上一次结算回馈电量
/// 电芯电压平均值
/// </summary>
[Property(416, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceFeedbackPower { get; set; }
[Property(328, 16)]
public short VoltageAverage { get; set; }
/// <summary>
/// 10 本次实时插枪充电量
/// 单次充电量
/// </summary>
[Property(440, 24, scale: 0.01, round: 2)]
public double ThisTimeRealChargeCount { get; set; }
[Property(344, 16)]
public short SingleCharge { get; set; }
/// <summary>
/// 11 上一次结算插枪充电量
/// 累计充电量
/// </summary>
[Property(464, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceChargeCount { get; set; }
[Property(360, 32)]
public float CumulativeCharge { get; set; }
/// <summary>
/// 12 本次实时综合能耗
/// 累计放电量
/// </summary>
[Property(488, 24, scale: 0.01, round: 2)]
public double ThisTimeRealKgce { get; set; }
[Property(392, 32)]
public float CumulativeDischarge { get; set; }
/// <summary>
/// 13 上一次结算综合能耗
/// </summary>
[Property(512, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceKgce { get; set; }
///// <summary>
///// 13 上一次结算综合能耗
///// </summary>
//[Property(512, 8)]
//public double LastTimeBalanceKgce { get; set; }
/// <summary>
/// 14 待结算电费电量
/// </summary>
[Property(536, 24, scale: 0.01, round: 2)]
public double ElectricityToBeSettled { get; set; }
///// <summary>
///// 14 待结算电费电量
///// </summary>
//[Property(536, 8)]
//public double ElectricityToBeSettled { get; set; }
}

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

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

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

@ -21,6 +21,8 @@ public class VinTask : ITask
}
public void Handle()
{
if (TBoxServerMgr.Server?.SendVinMsg != null)
{
foreach (var vinMsg in TBoxServerMgr.Server?.SendVinMsg)
{
@ -30,6 +32,7 @@ public class VinTask : ITask
}
}
}
}
public bool Stoped()
{

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

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

@ -2,7 +2,7 @@
"ConnectionStrings": {
"ConfigId": "master",
"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": {
"AutoUpdate": "false",

Loading…
Cancel
Save