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.

95 lines
2.5 KiB

using log4net;
using Microsoft.AspNetCore.Mvc;
using Service.Api.Resp;
using Service.TBox.Server;
using Service.TBox.Service;
namespace WebStarter.Controllers;
/// <summary>
/// 车辆管理
/// </summary>
[ApiController]
[Route("[controller]")]
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.BatteryNo()!=null;
}
/// <summary>
/// 加锁
/// </summary>
/// <param name="carNo">vin码</param>
/// <returns>"0未解锁未上锁 1解锁成功 2上锁成功 3无效数据 其他状态无效" </returns>
[HttpGet("lock/{carNo}")]
public bool Lock(string carNo)
{
Log.Info($"Lock {carNo}");
TBoxServerMgr.Server?.StartSendLock(1);
return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus==2;
}
/// <summary>
/// 解锁
/// </summary>
/// <param name="carNo">vin码</param>
/// <returns>发送状态</returns>
[HttpGet("unLock/{carNo}")]
public bool UnLock(string carNo)
{
Log.Info($"UnLock {carNo}");
TBoxServerMgr.Server?.StartSendLock(2);
return TBoxServerMgr.Server?.LockStatusMsg?.LockStatus ==1;
}
/// <summary>
/// 获取车辆信息
/// </summary>
/// <returns></returns>
[HttpGet("getCarInfo/{carNo}")]
public CarInfoResp GetCarInfo(string carNo)
{
Log.Info($"getCarInfo {carNo}");
return TBoxService.GetHnYQCarInfo(carNo);
}
/// <summary>
/// 断开连接
/// </summary>
/// <param name="carNo">vin码</param>
/// <returns>发送状态</returns>
[HttpGet("disConnect/{carNo}")]
public bool DisConnect(string carNo)
{
Log.Info($"DisConnect {carNo}");
TBoxServerMgr.Server?.StartSendLock(0);
return TBoxServerMgr.Server != null && !TBoxServerMgr.Server.Connected;
}
/// <summary>
/// Reset
/// </summary>
/// <param name="carNo">vin码</param>
/// <returns></returns>
[HttpGet("reset")]
public bool Reset()
{
Log.Info($"Reset ");
TBoxServerMgr.Server?.Reset();
return true;
}
}