tbox接口开发

master
rszn 5 months ago
parent adca1401eb
commit 394b18c72e

@ -15,7 +15,14 @@ public class StatusMsgHandler : SimpleChannelInboundHandler<StatusMsg>, 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;
}
}
}
}

@ -18,6 +18,8 @@ public class TBoxServer : TcpServer<IBaseHandler, Decoder, Encoder>
{
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<IBaseHandler, Decoder, Encoder>
#region Send
/// <summary>
///
/// </summary>
@ -115,22 +116,21 @@ public class TBoxServer : TcpServer<IBaseHandler, Decoder, Encoder>
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],
};
}
/// <summary>
@ -152,6 +152,7 @@ public class TBoxServer : TcpServer<IBaseHandler, Decoder, Encoder>
{
TBoxServerMgr.Server?.SessionMgr.Broadcast(new RestartMsg(restart));
}
#endregion
#region Read
@ -189,5 +190,37 @@ public class TBoxServer : TcpServer<IBaseHandler, Decoder, Encoder>
}
#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
}

@ -13,7 +13,6 @@ public class TBoxServerMgr
if (Server == null)
{
Server = AppInfo.Container.Resolve<TBoxServer>();
Server.LogLevel = LogLevel.TRACE;
Server.Start(port);
}
}

@ -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));
/// <summary>
/// 加锁
/// 连接车辆
/// </summary>
/// <param name="carNo">vin码</param>
/// <returns></returns>
[HttpGet("/connect/{carNo}")]
public bool Connect(string carNo)
{
Log.Info($"Connect-{carNo}");
TBoxServerMgr.Server.StartSendVin(carNo);
return TBoxServerMgr.Server != null && TBoxServerMgr.Server.Connected;
}
/// <summary>
/// 加锁
/// </summary>
/// <param name="carNo">vin码</param>
/// <returns>"0未解锁未上锁 1解锁成功 2上锁成功 3无效数据 其他状态无效" </returns>
[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;
}
/// <summary>
/// 解锁
/// </summary>
/// <param name="carNo">vin码</param>
/// <returns></returns>
/// <returns>发送状态</returns>
[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;
}
/// <summary>
/// 重启
/// 获取车辆信息
/// </summary>
/// <returns></returns>
[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;
}
/// <summary>
/// 断开连接
/// </summary>
/// <param name="carNo">vin码</param>
/// <returns>发送状态</returns>
[HttpGet("/disConnect/{carNo}")]
public bool DisConnect(string carNo)
{
TBoxServerMgr.Server?.StartSendLock(0);
return true;
}
/// <summary>
/// Reset
/// </summary>
/// <param name="carNo">vin码</param>
/// <returns></returns>
[HttpGet("/reset")]
public bool Reset()
{
TBoxServerMgr.Server?.Reset();
return true;
}
}
}

@ -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; }
}
Loading…
Cancel
Save