diff --git a/Service/Api/Resp/BatteryInfo.cs b/Service/Api/Resp/BatteryInfo.cs
new file mode 100644
index 0000000..e8bce52
--- /dev/null
+++ b/Service/Api/Resp/BatteryInfo.cs
@@ -0,0 +1,23 @@
+namespace Service.Api.Resp
+{
+ public class BatteryInfo
+ {
+ public string? BatteryNo { get; set; }
+
+ ///
+ /// 电池类型
+ ///
+ public int? BatteryType { get; set; }
+
+ ///
+ /// 电池包型号
+ ///
+ public int? BatteryPackageModel { get; set; }
+
+ public float? Soe { get; set; }
+
+ public float? Soc { get; set; }
+
+ public float? Soh { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Service/Api/Resp/CarInfo.cs b/Service/Api/Resp/CarInfo.cs
new file mode 100644
index 0000000..f06a184
--- /dev/null
+++ b/Service/Api/Resp/CarInfo.cs
@@ -0,0 +1,26 @@
+namespace Service.Api.Resp;
+
+public class CarInfo
+{
+ public string? CarNo { get; set; }
+
+
+ public string? CarVin { get; set; }
+
+
+ ///
+ /// 车型数据 "0:无效值1:牵引车 2:搅拌车 3:自卸车"
+ ///
+ public byte? CarType { get; set; }
+
+ ///
+ /// 电池数
+ ///
+ public int BatteryNum { get; set; }
+
+
+ ///
+ /// 车辆电池数据
+ ///
+ public List BatteryInfos { get; set; }
+}
\ No newline at end of file
diff --git a/Service/Api/Resp/CarInfoResp.cs b/Service/Api/Resp/CarInfoResp.cs
new file mode 100644
index 0000000..736a39e
--- /dev/null
+++ b/Service/Api/Resp/CarInfoResp.cs
@@ -0,0 +1,29 @@
+using Service.Car.Msg.Car.Req;
+
+namespace Service.Api.Resp;
+
+///
+/// 车辆返回
+///
+public class CarInfoResp
+{
+ public bool Connected { get; set; }
+
+ public string CarNo { get; set; }
+
+ ///
+ /// 度电数据
+ ///
+ ///
+ public ElecMsg? ElecMsg { get; set; }
+
+ ///
+ /// 车辆信息
+ ///
+ public CarInfo? CarInfo { get; set; }
+
+ ///
+ /// 车辆状态信息
+ ///
+ public CarStatus? CarStatus { get; set; }
+}
\ No newline at end of file
diff --git a/Service/Api/Resp/CarStatus.cs b/Service/Api/Resp/CarStatus.cs
new file mode 100644
index 0000000..49da968
--- /dev/null
+++ b/Service/Api/Resp/CarStatus.cs
@@ -0,0 +1,28 @@
+namespace Service.Api.Resp;
+
+public class CarStatus
+{
+ ///
+ /// 车辆档位 最小值:-1,最大值 14 ,0x0F表示无效,-1 代表倒档 R;0 代表空挡 N;大于 0 代表前进档 D;
+ ///
+ public byte? Gear { get; set; }
+
+ ///
+ /// 刹车状态 "0:未拉手刹1:已拉手刹 其它值无效"
+ ///
+ public byte? Break { get; set; }
+
+ ///
+ /// 钥匙状态 "0:OFF1:ACC ON 2:IG ON 其它值无效"
+ ///
+ public byte? Keys { get; set; }
+
+
+ ///
+ /// 0:未解锁未上锁
+ /// 1:解锁成功
+ /// 2:上锁成功
+ /// 3:无效数据
+ ///
+ public byte? LockStatus { get; set; }
+}
\ No newline at end of file
diff --git a/Service/Car/Msg/Car/Req/ElecMsg.cs b/Service/Car/Msg/Car/Req/ElecMsg.cs
index 89e8d5a..1756518 100644
--- a/Service/Car/Msg/Car/Req/ElecMsg.cs
+++ b/Service/Car/Msg/Car/Req/ElecMsg.cs
@@ -4,81 +4,78 @@ namespace Service.Car.Msg.Car.Req;
public class ElecMsg : BaseMsg
{
+ ///
+ /// 小计里程 0~16777215
+ ///
+ public double? SubMile { get; set; }
+
+ ///
+ /// 车辆总里程 0~16777215
+ ///
+ public double? TotalMile { get; set; }
+
///
/// 车辆累计放电量
///
- [Property(248, 24, scale: 0.01, round: 2)]
public double AccDischargeCount { get; set; }
///
/// 车辆累计回馈电量
///
- [Property(272, 24, scale: 0.01, round: 2)]
public double AccFallbackCount { get; set; }
///
/// 车辆累计插枪充电量
///
- [Property(296, 24, scale: 0.01, round: 2)]
public double AccChargeCount { get; set; }
///
/// 5 车辆累计综合能耗
///
- [Property(320, 24, scale: 0.01, round: 2)]
public double AccKgce { get; set; }
///
/// 6 本次实时放电量
///
- [Property(344, 24, scale: 0.01, round: 2)]
public double ThisTimeRealDischarge { get; set; }
///
/// 7 上一次结算放电量
///
- [Property(368, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceDischarge { get; set; }
///
/// 8 本次实时回馈电量
///
- [Property(392, 24, scale: 0.01, round: 2)]
public double ThisTimeRealFeedbackPower { get; set; }
///
/// 9 上一次结算回馈电量
///
- [Property(416, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceFeedbackPower { get; set; }
///
/// 10 本次实时插枪充电量
///
- [Property(440, 24, scale: 0.01, round: 2)]
public double ThisTimeRealChargeCount { get; set; }
///
/// 11 上一次结算插枪充电量
///
- [Property(464, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceChargeCount { get; set; }
///
/// 12 本次实时综合能耗
///
- [Property(488, 24, scale: 0.01, round: 2)]
public double ThisTimeRealKgce { get; set; }
///
/// 13 上一次结算综合能耗
///
- [Property(512, 24, scale: 0.01, round: 2)]
public double LastTimeBalanceKgce { get; set; }
///
/// 14 待结算电费电量
///
- [Property(536, 24, scale: 0.01, round: 2)]
public double ElectricityToBeSettled { get; set; }
}
\ No newline at end of file
diff --git a/Service/TBox/Handler/SocMsgHandler.cs b/Service/TBox/Handler/SocMsgHandler.cs
index 54fc968..bdb3b3c 100644
--- a/Service/TBox/Handler/SocMsgHandler.cs
+++ b/Service/TBox/Handler/SocMsgHandler.cs
@@ -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, 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;
}
}
diff --git a/Service/TBox/Msg/TBox/StatusMsg.cs b/Service/TBox/Msg/TBox/StatusMsg.cs
index 7f2beba..52126ae 100644
--- a/Service/TBox/Msg/TBox/StatusMsg.cs
+++ b/Service/TBox/Msg/TBox/StatusMsg.cs
@@ -7,41 +7,48 @@ public class StatusMsg : BaseMsg
///
/// 车辆档位 最小值:-1,最大值 14 ,0x0F表示无效,-1 代表倒档 R;0 代表空挡 N;大于 0 代表前进档 D;
///
- [Property(32,4)]
+ [Property(32, 4, offset: 1)]
public byte Gear { get; set; }
+
///
/// 刹车状态 "0:未拉手刹1:已拉手刹 其它值无效"
///
- [Property(36,2)]
+ [Property(36, 2)]
public byte Break { get; set; }
+
///
/// 钥匙状态 "0:OFF1:ACC ON 2:IG ON 其它值无效"
///
- [Property(38,2)]
+ [Property(38, 2)]
public byte Keys { get; set; }
+
///
/// 主继电器状态 "0:无效值1:开启 2:闭合"
///
- [Property(40,2)]
+ [Property(40, 2)]
public byte MainRelay { get; set; }
+
///
/// 车型数据 "0:无效值1:牵引车 2:搅拌车 3:自卸车"
///
- [Property(42,2)]
+ [Property(42, 2)]
public byte CarType { get; set; }
+
///
/// 电磁阀驱动状态(预留,默认无效发0) "0:无效值1:开启 2:闭合"
///
- [Property(44,2)]
+ [Property(44, 2)]
public byte Solenoid { get; set; }
+
///
/// 换电车辆不在线标志位 "0:不在线1:在线"
///
- [Property(46,2)]
+ [Property(46, 2)]
public byte Online { get; set; }
+
///
/// Wifi数据转换控制器电源电压故障标志位 "0:无故障1:电压过低 2:电压过高"
///
- [Property(48,2)]
+ [Property(48, 2)]
public byte WifiError { get; set; }
-}
+}
\ No newline at end of file
diff --git a/Service/TBox/Server/TBoxServer.cs b/Service/TBox/Server/TBoxServer.cs
index fb3cb5b..c8d2395 100644
--- a/Service/TBox/Server/TBoxServer.cs
+++ b/Service/TBox/Server/TBoxServer.cs
@@ -191,7 +191,9 @@ public class TBoxServer : TcpServer
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
{
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
{
return Encoding.ASCII.GetString(bytes);
}
- }
+ }*/
- return null;
+ #endregion
+
+ List 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
diff --git a/Service/TBox/Service/TBoxService.cs b/Service/TBox/Service/TBoxService.cs
new file mode 100644
index 0000000..9ac7071
--- /dev/null
+++ b/Service/TBox/Service/TBoxService.cs
@@ -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));
+
+
+ ///
+ /// 焕能长治
+ ///
+ ///
+ ///
+ 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;
+ }
+
+ ///
+ /// 焕能阳泉
+ ///
+ ///
+ 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()
+ {
+ 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;
+ }
+}
\ No newline at end of file
diff --git a/WebStarter/Controllers/CarController.cs b/WebStarter/Controllers/CarController.cs
index f21993b..f0f4730 100644
--- a/WebStarter/Controllers/CarController.cs
+++ b/WebStarter/Controllers/CarController.cs
@@ -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;
///
[ApiController]
[Route("[controller]")]
-public class CarController : ControllerBase{
+public class CarController : ControllerBase
+{
private static readonly ILog Log = LogManager.GetLogger(typeof(CarController));
///
@@ -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 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;
}
///
@@ -229,4 +212,4 @@ public class CarController : ControllerBase{
CarServerMgr.CarServer.Clean();
return true;
}
-}
+}
\ No newline at end of file
diff --git a/WebStarter/Controllers/TBoxController.cs b/WebStarter/Controllers/TBoxController.cs
index e2ef006..c5b2f1d 100644
--- a/WebStarter/Controllers/TBoxController.cs
+++ b/WebStarter/Controllers/TBoxController.cs
@@ -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;
}
///
@@ -33,11 +35,11 @@ public class TBoxController : ControllerBase
/// vin码
/// "0:未解锁未上锁 1:解锁成功 2:上锁成功 3:无效数据 其他状态无效"
[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;
}
///
@@ -46,11 +48,11 @@ public class TBoxController : ControllerBase
/// vin码
/// 发送状态
[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;
}
///
@@ -58,30 +60,11 @@ public class TBoxController : ControllerBase
///
///
[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;
}
-}
+}
\ No newline at end of file
diff --git a/WebStarter/Dto/Resp/CarInfoResp.cs b/WebStarter/Dto/Resp/CarInfoResp.cs
deleted file mode 100644
index b92b8d9..0000000
--- a/WebStarter/Dto/Resp/CarInfoResp.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using Service.Car.Msg.Car.Req;
-
-namespace WebStarter.Dto.Resp;
-
-///
-/// 车辆数据
-///
-public class CarInfoResp
-{
- ///
- /// 连接状态
- ///
- public bool Connected { get; set; }
-
- ///
- /// vin码
- ///
- public string? CarNo { get; set; }
-
- ///
- /// 度电数据
- ///
- public ElecMsg? ElecMsg { get; set; }
-
- ///
- /// 状态数据
- ///
- public HeartBeatMsg? HeartBeatMsg { get; set; }
-}
\ No newline at end of file