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 { 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 /// /// /// /// 0:断开连接 1:加锁 2:解锁 3:无效 public void StartSendLock(byte @lock) { LockMsg.Lock = @lock; if (TaskInit.TaskMap.TryGetValue(LockTask.TaskName, out var task)) { task.Start(); } } /// /// /// public void StopSendLock() { if (TaskInit.TaskMap.TryGetValue(LockTask.TaskName, out var task)) { task.Stop(); } } /// /// /// /// public void StartSendVin(string vin) { SendVin = vin; EncodeVin(vin); if (TaskInit.TaskMap.TryGetValue(VinTask.TaskName, out var task)) { task.Start(); } } /// /// /// /// 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], }; } /// /// /// public void StopSendVin() { if (TaskInit.TaskMap.TryGetValue(VinTask.TaskName, out var task)) { task.Stop(); } } /// /// "0:无指令 1:重启指令" /// /// public void SendRestart(byte restart) { TBoxServerMgr.Server?.SessionMgr.Broadcast(new RestartMsg(restart)); } #endregion }