Merge remote-tracking branch 'origin/v1.0.2_Tboxmerge'

master
lxw 5 months ago
commit b4307d2c05

@ -0,0 +1,23 @@
namespace Service.Api.Resp
{
public class BatteryInfo
{
public string? BatteryNo { get; set; }
/// <summary>
/// 电池类型
/// </summary>
public int? BatteryType { get; set; }
/// <summary>
/// 电池包型号
/// </summary>
public int? BatteryPackageModel { get; set; }
public float? Soe { get; set; }
public float? Soc { get; set; }
public float? Soh { get; set; }
}
}

@ -0,0 +1,26 @@
namespace Service.Api.Resp;
public class CarInfo
{
public string? CarNo { get; set; }
public string? CarVin { get; set; }
/// <summary>
/// 车型数据 "0:无效值1:牵引车 2:搅拌车 3:自卸车"
/// </summary>
public byte? CarType { get; set; }
/// <summary>
/// 电池数
/// </summary>
public int BatteryNum { get; set; }
/// <summary>
/// 车辆电池数据
/// </summary>
public List<BatteryInfo> BatteryInfos { get; set; }
}

@ -0,0 +1,29 @@
using Service.Car.Msg.Car.Req;
namespace Service.Api.Resp;
/// <summary>
/// 车辆返回
/// </summary>
public class CarInfoResp
{
public bool Connected { get; set; }
public string CarNo { get; set; }
/// <summary>
/// 度电数据
/// </summary>
/// <returns></returns>
public ElecMsg? ElecMsg { get; set; }
/// <summary>
/// 车辆信息
/// </summary>
public CarInfo? CarInfo { get; set; }
/// <summary>
/// 车辆状态信息
/// </summary>
public CarStatus? CarStatus { get; set; }
}

@ -0,0 +1,28 @@
namespace Service.Api.Resp;
public class CarStatus
{
/// <summary>
/// 车辆档位 最小值:-1最大值 14 0x0F表示无效-1 代表倒档 R0 代表空挡 N大于 0 代表前进档 D
/// </summary>
public byte? Gear { get; set; }
/// <summary>
/// 刹车状态 "0:未拉手刹1已拉手刹 其它值无效"
/// </summary>
public byte? Break { get; set; }
/// <summary>
/// 钥匙状态 "0:OFF1:ACC ON 2:IG ON 其它值无效"
/// </summary>
public byte? Keys { get; set; }
/// <summary>
/// 0未解锁未上锁
/// 1解锁成功
/// 2上锁成功
/// 3无效数据
/// </summary>
public byte? LockStatus { get; set; }
}

@ -4,81 +4,78 @@ namespace Service.Car.Msg.Car.Req;
public class ElecMsg : BaseMsg
{
/// <summary>
/// 小计里程 0~16777215
/// </summary>
public double? SubMile { get; set; }
/// <summary>
/// 车辆总里程 0~16777215
/// </summary>
public double? TotalMile { get; set; }
/// <summary>
/// 车辆累计放电量
/// </summary>
[Property(248, 24, scale: 0.01, round: 2)]
public double AccDischargeCount { get; set; }
/// <summary>
/// 车辆累计回馈电量
/// </summary>
[Property(272, 24, scale: 0.01, round: 2)]
public double AccFallbackCount { get; set; }
/// <summary>
/// 车辆累计插枪充电量
/// </summary>
[Property(296, 24, scale: 0.01, round: 2)]
public double AccChargeCount { get; set; }
/// <summary>
/// 5 车辆累计综合能耗
/// </summary>
[Property(320, 24, scale: 0.01, round: 2)]
public double AccKgce { get; set; }
/// <summary>
/// 6 本次实时放电量
/// </summary>
[Property(344, 24, scale: 0.01, round: 2)]
public double ThisTimeRealDischarge { get; set; }
/// <summary>
/// 7 上一次结算放电量
/// </summary>
[Property(368, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceDischarge { get; set; }
/// <summary>
/// 8 本次实时回馈电量
/// </summary>
[Property(392, 24, scale: 0.01, round: 2)]
public double ThisTimeRealFeedbackPower { get; set; }
/// <summary>
/// 9 上一次结算回馈电量
/// </summary>
[Property(416, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceFeedbackPower { get; set; }
/// <summary>
/// 10 本次实时插枪充电量
/// </summary>
[Property(440, 24, scale: 0.01, round: 2)]
public double ThisTimeRealChargeCount { get; set; }
/// <summary>
/// 11 上一次结算插枪充电量
/// </summary>
[Property(464, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceChargeCount { get; set; }
/// <summary>
/// 12 本次实时综合能耗
/// </summary>
[Property(488, 24, scale: 0.01, round: 2)]
public double ThisTimeRealKgce { get; set; }
/// <summary>
/// 13 上一次结算综合能耗
/// </summary>
[Property(512, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceKgce { get; set; }
/// <summary>
/// 14 待结算电费电量
/// </summary>
[Property(536, 24, scale: 0.01, round: 2)]
public double ElectricityToBeSettled { get; set; }
}

@ -3,6 +3,7 @@ using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Newtonsoft.Json;
using Service.TBox.Msg.TBox;
using Service.TBox.Server;
namespace Service.TBox.Handler;
@ -15,5 +16,7 @@ public class SocMsgHandler : SimpleChannelInboundHandler<SocMsg>, IBaseHandler
protected override void ChannelRead0(IChannelHandlerContext ctx, SocMsg msg)
{
Log.Info($"receive SocMsg={JsonConvert.SerializeObject(msg)}");
var server = TBoxServerMgr.Server;
if (server != null) server.SocMsg = msg;
}
}

@ -7,41 +7,48 @@ public class StatusMsg : BaseMsg
/// <summary>
/// 车辆档位 最小值:-1最大值 14 0x0F表示无效-1 代表倒档 R0 代表空挡 N大于 0 代表前进档 D
/// </summary>
[Property(32,4)]
[Property(32, 4, offset: 1)]
public byte Gear { get; set; }
/// <summary>
/// 刹车状态 "0:未拉手刹1已拉手刹 其它值无效"
/// </summary>
[Property(36,2)]
[Property(36, 2)]
public byte Break { get; set; }
/// <summary>
/// 钥匙状态 "0:OFF1:ACC ON 2:IG ON 其它值无效"
/// </summary>
[Property(38,2)]
[Property(38, 2)]
public byte Keys { get; set; }
/// <summary>
/// 主继电器状态 "0:无效值1:开启 2:闭合"
/// </summary>
[Property(40,2)]
[Property(40, 2)]
public byte MainRelay { get; set; }
/// <summary>
/// 车型数据 "0:无效值1:牵引车 2:搅拌车 3:自卸车"
/// </summary>
[Property(42,2)]
[Property(42, 2)]
public byte CarType { get; set; }
/// <summary>
/// 电磁阀驱动状态预留默认无效发0 "0:无效值1:开启 2:闭合"
/// </summary>
[Property(44,2)]
[Property(44, 2)]
public byte Solenoid { get; set; }
/// <summary>
/// 换电车辆不在线标志位 "0不在线1在线"
/// </summary>
[Property(46,2)]
[Property(46, 2)]
public byte Online { get; set; }
/// <summary>
/// Wifi数据转换控制器电源电压故障标志位 "0无故障1电压过低 2电压过高"
/// </summary>
[Property(48,2)]
[Property(48, 2)]
public byte WifiError { get; set; }
}
}

@ -191,7 +191,9 @@ public class TBoxServer : TcpServer<IBaseHandler, Decoder, Encoder>
public string? BatteryNo()
{
byte leng = BatteryOneSn.Length;
#region MyRegion
/*byte leng = BatteryOneSn.Length;
if (leng > 8)
{
byte[] bytes = new byte[leng];
@ -229,7 +231,7 @@ public class TBoxServer : TcpServer<IBaseHandler, Decoder, Encoder>
{
bytes[i] = lstByte[i];
}
if (BatteryOneSn.Sn1 != 0 && BatteryOneSn.Sn2 != 0
&& BatteryOneSn.Sn3 != 0 && BatteryOneSn.Sn4 != 0
&& BatteryOneSn.Sn5 != 0 && BatteryOneSn.Sn6 != 0
@ -239,9 +241,45 @@ public class TBoxServer : TcpServer<IBaseHandler, Decoder, Encoder>
{
return Encoding.ASCII.GetString(bytes);
}
}
}*/
return null;
#endregion
List<byte> list = new()
{
BatteryOneSn.Sn1,
BatteryOneSn.Sn2,
BatteryOneSn.Sn3,
BatteryOneSn.Sn4,
BatteryOneSn.Sn5,
BatteryOneSn.Sn6,
BatteryTwoSn.Sn1,
BatteryTwoSn.Sn2,
BatteryTwoSn.Sn3,
BatteryTwoSn.Sn4,
BatteryTwoSn.Sn5,
BatteryTwoSn.Sn6,
};
var count = list.Where(i => i <= 0).Count();
if (count > 6)
{
return null;
}
byte[] bytes = new byte[12];
bytes[0] = BatteryOneSn.Sn1;
bytes[1] = BatteryOneSn.Sn2;
bytes[2] = BatteryOneSn.Sn3;
bytes[3] = BatteryOneSn.Sn4;
bytes[4] = BatteryOneSn.Sn5;
bytes[5] = BatteryOneSn.Sn6;
bytes[6] = BatteryTwoSn.Sn1;
bytes[7] = BatteryTwoSn.Sn2;
bytes[8] = BatteryTwoSn.Sn3;
bytes[9] = BatteryTwoSn.Sn4;
bytes[10] = BatteryTwoSn.Sn5;
bytes[11] = BatteryTwoSn.Sn6;
return Encoding.ASCII.GetString(bytes);
}
#endregion

@ -0,0 +1,108 @@
using HybirdFrameworkCore.Utils;
using HybirdFrameworkDriver.Session;
using log4net;
using Service.Api.Resp;
using Service.Car.Msg.Car.Req;
using Service.Car.Server;
using Service.TBox.Msg.TBox;
using Service.TBox.Server;
namespace Service.TBox.Service;
public class TBoxService
{
private static readonly ILog Log = LogManager.GetLogger(typeof(TBoxService));
/// <summary>
/// 焕能长治
///
/// </summary>
/// <param name="carNo"></param>
public static CarInfoResp GetHnCZCarInfo(string carNo)
{
IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(carNo);
CarInfoResp carInfoResp = new CarInfoResp()
{
Connected = CarServerMgr.CarServer != null && ioSession != null,
CarNo = carNo,
CarInfo = new()
{
CarNo = carNo,
CarVin = carNo,
BatteryNum = 1,
}
};
if (ObjUtils.IsNotNull(ioSession))
{
ioSession.BusinessMap.TryGetValue("ElecMsg", out var elecMsg);
if (elecMsg != null)
{
carInfoResp.ElecMsg = (ElecMsg)elecMsg;
}
ioSession.BusinessMap.TryGetValue("HeartBeatMsg", out var heartBeatMsg);
if (heartBeatMsg != null)
{
var beatMsg = (HeartBeatMsg)heartBeatMsg;
CarStatus carStatus = new CarStatus();
carStatus.LockStatus = beatMsg.LockStatus;
carStatus.Keys = beatMsg.KeyStatus;
carInfoResp.CarStatus = carStatus;
}
}
return carInfoResp;
}
/// <summary>
/// 焕能阳泉
/// </summary>
/// <returns></returns>
public static CarInfoResp GetHnYQCarInfo(string carNo)
{
var statusMsg = TBoxServerMgr.Server?.StatusMsg;
BatteryInfo1? batteryInfo1 = TBoxServerMgr.Server?.BatteryInfo1;
StatusMsg? serverStatusMsg = TBoxServerMgr.Server?.StatusMsg;
LockStatusMsg? lockStatusMsg = TBoxServerMgr.Server?.LockStatusMsg;
CarInfoResp carInfoResp = new CarInfoResp()
{
CarNo = carNo,
Connected = TBoxServerMgr.Server != null && TBoxServerMgr.Server.Connected,
CarInfo = new()
{
CarNo = carNo,
CarVin = TBoxServerMgr.Server?.ReadVin(),
BatteryNum = 1,
CarType = statusMsg?.CarType,
BatteryInfos = new List<BatteryInfo>()
{
new()
{
BatteryNo = TBoxServerMgr.Server?.BatteryNo(),
Soc = TBoxServerMgr.Server?.SocMsg?.Soc,
Soe = batteryInfo1?.Soe,
Soh = TBoxServerMgr.Server?.SohMsg.Soh,
BatteryType = batteryInfo1?.TypeCode,
BatteryPackageModel = batteryInfo1?.Reserved1
}
}
},
ElecMsg = new()
{
CarNo = carNo,
SubMile = TBoxServerMgr.Server?.SubMileMsg?.SubMile,
TotalMile = TBoxServerMgr.Server?.TotalMileMsg?.TotalMile,
},
CarStatus = new()
{
Keys = serverStatusMsg?.Keys,
LockStatus = lockStatusMsg?.LockStatus,
Break = serverStatusMsg?.Break,
Gear = serverStatusMsg?.Gear
}
};
return carInfoResp;
}
}

@ -5,9 +5,11 @@ using HybirdFrameworkDriver.Session;
using log4net;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Service.Api.Resp;
using Service.Car.Msg.Car.Req;
using Service.Car.Msg.Host.Req;
using Service.Car.Server;
using Service.TBox.Service;
using WebStarter.Dto.Req;
using WebStarter.Dto.Resp;
@ -18,7 +20,8 @@ namespace WebStarter.Controllers;
/// </summary>
[ApiController]
[Route("[controller]")]
public class CarController : ControllerBase{
public class CarController : ControllerBase
{
private static readonly ILog Log = LogManager.GetLogger(typeof(CarController));
/// <summary>
@ -28,30 +31,7 @@ public class CarController : ControllerBase{
[HttpGet("getCarInfo/{carNo}")]
public CarInfoResp? GetCarInfo(string carNo)
{
IoSession? ioSession = CarServerMgr.CarServer?.SessionMgr.GetSession(carNo);
CarInfoResp carInfoResp = new CarInfoResp()
{
Connected = CarServerMgr.CarServer != null && ioSession != null,
CarNo = carNo
};
if (ObjUtils.IsNotNull(ioSession))
{
ioSession.BusinessMap.TryGetValue("ElecMsg", out var elecMsg);
if (elecMsg != null)
{
carInfoResp.ElecMsg = (ElecMsg)elecMsg;
}
ioSession.BusinessMap.TryGetValue("HeartBeatMsg", out var heartBeatMsg);
if (heartBeatMsg != null)
{
carInfoResp.HeartBeatMsg = (HeartBeatMsg)heartBeatMsg;
}
}
return carInfoResp;
return TBoxService.GetHnCZCarInfo(carNo);
}
@ -66,7 +46,6 @@ public class CarController : ControllerBase{
List<IoSession> sessionList = CarServerMgr.CarServer?.SessionMgr.GetSessionList();
foreach (var ioSession in sessionList)
{
CarInfoResp carInfoResp = new CarInfoResp()
{
Connected = true,
@ -82,12 +61,16 @@ public class CarController : ControllerBase{
ioSession.BusinessMap.TryGetValue("HeartBeatMsg", out var heartBeatMsg);
if (heartBeatMsg != null)
{
carInfoResp.HeartBeatMsg = (HeartBeatMsg)heartBeatMsg;
var beatMsg = (HeartBeatMsg)heartBeatMsg;
CarStatus carStatus = new CarStatus();
carStatus.LockStatus = beatMsg.LockStatus;
carStatus.Keys = beatMsg.KeyStatus;
carInfoResp.CarStatus = carStatus;
}
result.Add(carInfoResp);
}
return result;
}
@ -202,7 +185,7 @@ public class CarController : ControllerBase{
CarServerMgr.CarServer.SetParamMsgPair.Req = setParamMsg;
ioSession.Send(setParamMsg);
return CarServerMgr.CarServer.SetParamMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result ==0;
return CarServerMgr.CarServer.SetParamMsgPair.GetResp(TimeSpan.FromSeconds(5))?.Result == 0;
}
/// <summary>
@ -229,4 +212,4 @@ public class CarController : ControllerBase{
CarServerMgr.CarServer.Clean();
return true;
}
}
}

@ -1,6 +1,8 @@
using log4net;
using Microsoft.AspNetCore.Mvc;
using Service.Api.Resp;
using Service.TBox.Server;
using Service.TBox.Service;
using WebStarter.Dto.Resp;
namespace WebStarter.Controllers;
@ -24,7 +26,7 @@ public class TBoxController : ControllerBase
{
Log.Info($"Connect {carNo}");
TBoxServerMgr.Server.StartSendVin(carNo);
return TBoxServerMgr.Server != null && TBoxServerMgr.Server.Connected;
return TBoxServerMgr.Server != null && TBoxServerMgr.Server.BatteryNo()!=null;
}
/// <summary>
@ -33,11 +35,11 @@ public class TBoxController : ControllerBase
/// <param name="carNo">vin码</param>
/// <returns>"0未解锁未上锁 1解锁成功 2上锁成功 3无效数据 其他状态无效" </returns>
[HttpGet("lock/{carNo}")]
public int Lock(string carNo)
public bool Lock(string carNo)
{
Log.Info($"Lock {carNo}");
TBoxServerMgr.Server?.StartSendLock(1);
return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus ?? 100;
return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus==2;
}
/// <summary>
@ -46,11 +48,11 @@ public class TBoxController : ControllerBase
/// <param name="carNo">vin码</param>
/// <returns>发送状态</returns>
[HttpGet("unLock/{carNo}")]
public int UnLock(string carNo)
public bool UnLock(string carNo)
{
Log.Info($"UnLock {carNo}");
TBoxServerMgr.Server?.StartSendLock(2);
return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus ?? 100;
return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus ==1;
}
/// <summary>
@ -58,30 +60,11 @@ public class TBoxController : ControllerBase
/// </summary>
/// <returns></returns>
[HttpGet("getCarInfo/{carNo}")]
public TBoxInfo GetCarInfo(string carNo)
public CarInfoResp GetCarInfo(string carNo)
{
Log.Info($"DisConnect {carNo}");
TBoxInfo result = new TBoxInfo()
{
BatteryOneSn = TBoxServerMgr.Server?.BatteryOneSn,
BatteryTwoSn = TBoxServerMgr.Server?.BatteryTwoSn,
BatteryThreeSn = TBoxServerMgr.Server?.BatteryThreeSn,
BatteryFourSn = TBoxServerMgr.Server?.BatteryFourSn,
BatteryInfo1 = TBoxServerMgr.Server?.BatteryInfo1,
LockStatusMsg = TBoxServerMgr.Server?.LockStatusMsg,
SocMsg = TBoxServerMgr.Server?.SocMsg,
SohMsg = TBoxServerMgr.Server?.SohMsg,
StatusMsg = TBoxServerMgr.Server?.StatusMsg,
SubMileMsg = TBoxServerMgr.Server?.SubMileMsg,
TotalMileMsg = TBoxServerMgr.Server?.TotalMileMsg,
VersionMsg = TBoxServerMgr.Server?.VersionMsg,
RestartMsg = TBoxServerMgr.Server?.RestartMsg,
Vin = TBoxServerMgr.Server?.ReadVin(),
BatteryNo = TBoxServerMgr.Server?.BatteryNo(),
CarConnected = TBoxServerMgr.Server != null && TBoxServerMgr.Server.Connected,
TBoxConnected = TBoxServerMgr.Server != null
};
return result;
Log.Info($"getCarInfo {carNo}");
return TBoxService.GetHnYQCarInfo(carNo);
}
@ -110,4 +93,4 @@ public class TBoxController : ControllerBase
TBoxServerMgr.Server?.Reset();
return true;
}
}
}

@ -1,29 +0,0 @@
using Service.Car.Msg.Car.Req;
namespace WebStarter.Dto.Resp;
/// <summary>
/// 车辆数据
/// </summary>
public class CarInfoResp
{
/// <summary>
/// 连接状态
/// </summary>
public bool Connected { get; set; }
/// <summary>
/// vin码
/// </summary>
public string? CarNo { get; set; }
/// <summary>
/// 度电数据
/// </summary>
public ElecMsg? ElecMsg { get; set; }
/// <summary>
/// 状态数据
/// </summary>
public HeartBeatMsg? HeartBeatMsg { get; set; }
}
Loading…
Cancel
Save