From 394b18c72e624ca0f34af61170d14b087c1cd2e2 Mon Sep 17 00:00:00 2001 From: rszn <645583145@qq.com> Date: Tue, 18 Jun 2024 12:05:32 +0800 Subject: [PATCH] =?UTF-8?q?tbox=E6=8E=A5=E5=8F=A3=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/TBox/Handler/StatusMsgHandler.cs | 13 +++- Service/TBox/Server/TBoxServer.cs | 57 +++++++++++---- Service/TBox/Server/TBoxServerMgr.cs | 1 - WebStarter/Controllers/TBoxController.cs | 88 ++++++++++++++++++++---- WebStarter/Dto/Resp/TBoxInfo.cs | 24 +++++++ 5 files changed, 152 insertions(+), 31 deletions(-) create mode 100644 WebStarter/Dto/Resp/TBoxInfo.cs diff --git a/Service/TBox/Handler/StatusMsgHandler.cs b/Service/TBox/Handler/StatusMsgHandler.cs index dd79583..230147a 100644 --- a/Service/TBox/Handler/StatusMsgHandler.cs +++ b/Service/TBox/Handler/StatusMsgHandler.cs @@ -15,7 +15,14 @@ public class StatusMsgHandler : SimpleChannelInboundHandler, IBaseHan protected override void ChannelRead0(IChannelHandlerContext ctx, StatusMsg msg) { Log.Info($"receive OtherMsg={msg}"); - var server = TBoxServerMgr.Server; - if (server != null) server.StatusMsg = msg; + TBoxServerMgr.Server.StatusMsg = msg; + if (msg.Online == 1) + { + TBoxServerMgr.Server.Connected = true; + } + else + { + TBoxServerMgr.Server.Connected = false; + } } -} \ No newline at end of file +} diff --git a/Service/TBox/Server/TBoxServer.cs b/Service/TBox/Server/TBoxServer.cs index fbee9b6..0c22fbc 100644 --- a/Service/TBox/Server/TBoxServer.cs +++ b/Service/TBox/Server/TBoxServer.cs @@ -18,6 +18,8 @@ public class TBoxServer : TcpServer { private static readonly ILog Log = LogManager.GetLogger(typeof(TBoxServer)); + public bool Connected { get; set; } + #region HostMsg public LockMsg LockMsg = new LockMsg(3); @@ -49,7 +51,6 @@ public class TBoxServer : TcpServer #region Send - /// /// /// @@ -115,22 +116,21 @@ public class TBoxServer : TcpServer SendVinMsg[1] = new VinMsg() { Seq = 2, - B2 = (byte)vin[7+0], - B3 = (byte)vin[7+1], - B4 = (byte)vin[7+2], - B5 = (byte)vin[7+3], - B6 = (byte)vin[7+4], - B7 = (byte)vin[7+5], - B8 = (byte)vin[7+6], + B2 = (byte)vin[7 + 0], + B3 = (byte)vin[7 + 1], + B4 = (byte)vin[7 + 2], + B5 = (byte)vin[7 + 3], + B6 = (byte)vin[7 + 4], + B7 = (byte)vin[7 + 5], + B8 = (byte)vin[7 + 6], }; SendVinMsg[2] = new VinMsg() { Seq = 3, - B2 = (byte)vin[14+0], - B3 = (byte)vin[14+1], - B4 = (byte)vin[14+2], + B2 = (byte)vin[14 + 0], + B3 = (byte)vin[14 + 1], + B4 = (byte)vin[14 + 2], }; - } /// @@ -152,6 +152,7 @@ public class TBoxServer : TcpServer { TBoxServerMgr.Server?.SessionMgr.Broadcast(new RestartMsg(restart)); } + #endregion #region Read @@ -189,5 +190,37 @@ public class TBoxServer : TcpServer } #endregion + + public void Reset() + { + + StopSendLock(); + StopSendVin(); + + LockMsg.Lock = 3; + SendVin = null; + SendVinMsg[0] = null; + SendVinMsg[1] = null; + SendVinMsg[2] = null; + VinMsgs[0] = null; + VinMsgs[1] = null; + VinMsgs[2] = null; + + BatteryOneSn = null; + BatteryTwoSn = null; + BatteryThreeSn = null; + BatteryFourSn = null; + BatteryInfo1 = null; + LockStatusMsg = null; + SocMsg = null; + SohMsg = null; + StatusMsg = null; + SubMileMsg = null; + TotalMileMsg = null; + VersionMsg = null; + RestartMsg = null; + Connected = false; + } + #endregion } diff --git a/Service/TBox/Server/TBoxServerMgr.cs b/Service/TBox/Server/TBoxServerMgr.cs index c5162b5..58955ab 100644 --- a/Service/TBox/Server/TBoxServerMgr.cs +++ b/Service/TBox/Server/TBoxServerMgr.cs @@ -13,7 +13,6 @@ public class TBoxServerMgr if (Server == null) { Server = AppInfo.Container.Resolve(); - Server.LogLevel = LogLevel.TRACE; Server.Start(port); } } diff --git a/WebStarter/Controllers/TBoxController.cs b/WebStarter/Controllers/TBoxController.cs index 7ac0ede..c62d436 100644 --- a/WebStarter/Controllers/TBoxController.cs +++ b/WebStarter/Controllers/TBoxController.cs @@ -1,9 +1,7 @@ -using HybirdFrameworkDriver.Session; -using log4net; +using log4net; using Microsoft.AspNetCore.Mvc; -using Service.Car.Server; -using Service.TBox.Msg.Host; using Service.TBox.Server; +using WebStarter.Dto.Resp; namespace WebStarter.Controllers; @@ -17,36 +15,96 @@ public class TBoxController : ControllerBase private static readonly ILog Log = LogManager.GetLogger(typeof(TBoxController)); /// - /// 加锁 + /// 连接车辆 /// /// vin码 /// + [HttpGet("/connect/{carNo}")] + public bool Connect(string carNo) + { + Log.Info($"Connect-{carNo}"); + TBoxServerMgr.Server.StartSendVin(carNo); + return TBoxServerMgr.Server != null && TBoxServerMgr.Server.Connected; + } + + /// + /// 加锁 + /// + /// vin码 + /// "0:未解锁未上锁 1:解锁成功 2:上锁成功 3:无效数据 其他状态无效" [HttpGet("/lock/{carNo}")] - public bool Lock() + public int Lock(string carNo) { Log.Info($"Lock"); - return false; + TBoxServerMgr.Server?.StartSendLock(1); + return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus ?? 100; } /// /// 解锁 /// /// vin码 - /// + /// 发送状态 [HttpGet("/unLock/{carNo}")] - public bool UnLock(string carNo) + public int UnLock(string carNo) { Log.Info($"UnLock {carNo}"); - return false; + TBoxServerMgr.Server?.StartSendLock(2); + return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus ?? 100; } + /// - /// 重启 + /// 获取车辆信息 /// /// - [HttpGet("/Restart")] - public bool Restart() + [HttpGet("/getCarInfo/{carNo}")] + public TBoxInfo GetCarInfo() { Log.Info($"Restart"); - return false; + 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(), + CarConnected = TBoxServerMgr.Server != null && TBoxServerMgr.Server.Connected, + TBoxConnected = TBoxServerMgr.Server != null + }; + return result; + } + + + /// + /// 断开连接 + /// + /// vin码 + /// 发送状态 + [HttpGet("/disConnect/{carNo}")] + public bool DisConnect(string carNo) + { + TBoxServerMgr.Server?.StartSendLock(0); + return true; + } + + /// + /// Reset + /// + /// vin码 + /// + [HttpGet("/reset")] + public bool Reset() + { + TBoxServerMgr.Server?.Reset(); + return true; } -} \ No newline at end of file +} diff --git a/WebStarter/Dto/Resp/TBoxInfo.cs b/WebStarter/Dto/Resp/TBoxInfo.cs new file mode 100644 index 0000000..5b43d45 --- /dev/null +++ b/WebStarter/Dto/Resp/TBoxInfo.cs @@ -0,0 +1,24 @@ +using Service.TBox.Msg.Host; +using Service.TBox.Msg.TBox; + +namespace WebStarter.Dto.Resp; + +public class TBoxInfo +{ + public BatteryOneSn? BatteryOneSn { get; set; } + public BatteryTwoSn? BatteryTwoSn { get; set; } + public BatteryThreeSn BatteryThreeSn { get; set; } + public BatteryFourSn BatteryFourSn { get; set; } + public BatteryInfo1 BatteryInfo1 { get; set; } + public LockStatusMsg LockStatusMsg { get; set; } + public SocMsg SocMsg { get; set; } + public SohMsg SohMsg { get; set; } + public StatusMsg StatusMsg { get; set; } + public SubMileMsg SubMileMsg { get; set; } + public TotalMileMsg TotalMileMsg { get; set; } + public VersionMsg VersionMsg { get; set; } + public RestartMsg RestartMsg { get; set; } + public String Vin { get; set; } + public bool CarConnected { get; set; } + public bool TBoxConnected { get; set; } +}