You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.3 KiB

5 months ago
using log4net;
5 months ago
using Microsoft.AspNetCore.Mvc;
using Service.TBox.Server;
5 months ago
using WebStarter.Dto.Resp;
5 months ago
namespace WebStarter.Controllers;
/// <summary>
/// 车辆管理
/// </summary>
[ApiController]
[Route("[controller]")]
public class TBoxController : ControllerBase
{
private static readonly ILog Log = LogManager.GetLogger(typeof(TBoxController));
/// <summary>
5 months ago
/// 连接车辆
5 months ago
/// </summary>
/// <param name="carNo">vin码</param>
/// <returns></returns>
5 months ago
[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>
5 months ago
[HttpGet("/lock/{carNo}")]
5 months ago
public int Lock(string carNo)
5 months ago
{
Log.Info($"Lock");
5 months ago
TBoxServerMgr.Server?.StartSendLock(1);
return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus ?? 100;
5 months ago
}
/// <summary>
/// 解锁
/// </summary>
/// <param name="carNo">vin码</param>
5 months ago
/// <returns>发送状态</returns>
5 months ago
[HttpGet("/unLock/{carNo}")]
5 months ago
public int UnLock(string carNo)
5 months ago
{
Log.Info($"UnLock {carNo}");
5 months ago
TBoxServerMgr.Server?.StartSendLock(2);
return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus ?? 100;
5 months ago
}
5 months ago
5 months ago
/// <summary>
5 months ago
/// 获取车辆信息
5 months ago
/// </summary>
/// <returns></returns>
5 months ago
[HttpGet("/getCarInfo/{carNo}")]
public TBoxInfo GetCarInfo()
5 months ago
{
Log.Info($"Restart");
5 months ago
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;
5 months ago
}
5 months ago
}