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.

151 lines
3.6 KiB

using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.AutoTask;
using HybirdFrameworkDriver.TcpServer;
using log4net;
using Service.TBox.Codec;
using Service.TBox.Handler;
using Service.TBox.Msg.Host;
using Service.TBox.Msg.TBox;
using Service.TBox.MyTask;
using VinMsg = Service.TBox.Msg.Host.VinMsg;
namespace Service.TBox.Server;
[Scope]
public class TBoxServer : TcpServer<IBaseHandler, Decoder, Encoder>
{
private static readonly ILog Log = LogManager.GetLogger(typeof(TBoxServer));
#region HostMsg
public LockMsg LockMsg = new LockMsg(3);
public VinMsg[] SendVinMsg = new VinMsg[3];
public string SendVin { get; set; }
#endregion
#region TBoxMsg
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 Msg.TBox.VinMsg VinMsg { get; set; }
#endregion
#region func
/// <summary>
///
/// </summary>
/// <param name="@lock">0断开连接 1加锁 2解锁 3无效</param>
public void StartSendLock(byte @lock)
{
LockMsg.Lock = @lock;
if (TaskInit.TaskMap.TryGetValue(LockTask.TaskName, out var task))
{
task.Start();
}
}
/// <summary>
///
/// </summary>
public void StopSendLock()
{
if (TaskInit.TaskMap.TryGetValue(LockTask.TaskName, out var task))
{
task.Stop();
}
}
/// <summary>
///
/// </summary>
/// <param name="vin"></param>
public void StartSendVin(string vin)
{
SendVin = vin;
EncodeVin(vin);
if (TaskInit.TaskMap.TryGetValue(VinTask.TaskName, out var task))
{
task.Start();
}
}
/// <summary>
///
/// </summary>
/// <param name="vin"></param>
private void EncodeVin(string vin)
{
if (vin.Length != 17)
{
Log.Info("vin length is not 17");
return;
}
SendVinMsg[0] = new VinMsg()
{
Seq = 1,
B2 = (byte)vin[0],
B3 = (byte)vin[1],
B4 = (byte)vin[2],
B5 = (byte)vin[3],
B6 = (byte)vin[4],
B7 = (byte)vin[5],
B8 = (byte)vin[6],
};
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],
};
SendVinMsg[2] = new VinMsg()
{
Seq = 3,
B2 = (byte)vin[14+0],
B3 = (byte)vin[14+1],
B4 = (byte)vin[14+2],
};
}
/// <summary>
///
/// </summary>
public void StopSendVin()
{
if (TaskInit.TaskMap.TryGetValue(VinTask.TaskName, out var task))
{
task.Stop();
}
}
/// <summary>
/// "0无指令 1重启指令"
/// </summary>
/// <param name="restart"></param>
public void SendRestart(byte restart)
{
TBoxServerMgr.Server?.SessionMgr.Broadcast(new RestartMsg(restart));
}
#endregion
}