Ejemplo n.º 1
0
        /// <summary>
        /// 华宝A5断油断电指令 H5
        /// </summary>
        /// <param name="session"></param>
        /// <param name="instruction"></param>
        public void HandleH5(AppSocketSession session, EInstruction instruction)
        {
            var deviceGpsCodeNoPrefix = session["DeviceGpsCodeNoPrefix"] as string;
            if (deviceGpsCodeNoPrefix == null)
            {
                _logger.WarnFormat("发送指令失败!车辆不在线!{0}-{1}", instruction.DeviceId, instruction.InstructionType.GetDisplayName());
            }

            List<byte> content = new List<byte>();
            switch (instruction.InstructionType)
            {
                case EnumInstructionType.BreakOilOrPower:
                    content.Add(0x01);//正常断油 必须速度小于 20km/h
                    //content.Add(0x05);//强制断油
                    break;
                case EnumInstructionType.RecoveryBreakOilOrPower:
                    content.Add(0x00);
                    break;
            }
            content.AddRange(ByteHelper.ConvertDateTimeToBytesByBcd(DateTime.Now.AddSeconds(5)));
            if (content.Count > 0)
            {
                var cmd = T808Common.CreateBytesPackage("A006", deviceGpsCodeNoPrefix, GetSerialNumber(), (bw) =>
                {
                    bw.Write(content.ToArray());
                });
                session.SendAsync(cmd);
                _logger.WarnFormat("开始执行指令{0}-{1}-{2}", instruction.DeviceId, instruction.InstructionType.GetDisplayName(), ByteHelper.ConvertBytesToStringByHex(cmd));
            }
            else
            {
                _logger.WarnFormat("发送指令失败,无效指令!{0}-{1}", instruction.DeviceId, instruction.InstructionType.GetDisplayName());
            }
        }
Ejemplo n.º 2
0
 public void Handle(AppSocketSession session, EInstruction instruction)
 {
     byte[] content = null;
     switch (instruction.InstructionType)
     {
         case EnumInstructionType.BreakOilOrPower:
             content = Encoding.ASCII.GetBytes("DYD,000000#");
             break;
         case EnumInstructionType.RecoveryBreakOilOrPower:
             content = Encoding.ASCII.GetBytes("HFYD,000000#");
             break;
     }
     if (content != null && content.Length > 0)
     {
         var cmd = KksCommon.CreateBytesPackage("80", session.GetSerialNumber(), (bw) =>
         {
             //指令长度
             bw.WriteInt(content.Length);
             //服务器标志位
             bw.WriteInt32(GetSerialNumber());
             //指令内容
             bw.Write(content);
             //语言
             bw.Write(new byte[] {0x00, 0x01});
         });
         session.SendAsync(cmd);
         _logger.WarnFormat("开始执行指令{0}-{1}-{2}", instruction.DeviceId, instruction.InstructionType.GetDisplayName(), ByteHelper.ConvertBytesToStringByHex(cmd));
     }
     else
     {
         _logger.WarnFormat("发送指令失败,无效指令!{0}-{1}", instruction.DeviceId, instruction.InstructionType.GetDisplayName());
     }
 }
Ejemplo n.º 3
0
        public void Handle(AppSocketSession session, EInstruction instruction)
        {
            var deviceGpsCodeNoPrefix = session["DeviceGpsCodeNoPrefix"] as string;
            if (deviceGpsCodeNoPrefix == null)
            {
                _logger.WarnFormat("发送指令失败!车辆不在线!{0}-{1}", instruction.DeviceId, instruction.InstructionType.GetDisplayName());
            }
            
            var cmd = new List<string>();
            switch (instruction.InstructionType)
            {
                case EnumInstructionType.BreakOilOrPower:
                    cmd.Add("#1:{0}:1:*".GetFormat(deviceGpsCodeNoPrefix));
                    cmd.Add(ByteHelper.ConvertUInt32ToHexString(GetSerialNumber()));
                    cmd.Add("CC");
                    cmd.Add(ByteHelper.ConvertDateToHexString(DateTime.Now));
                    cmd.Add(ByteHelper.ConvertTimeToHexString(DateTime.Now));
                    cmd.Add("Y1L1#");
                    session.SendAsync(Encoding.UTF8.GetBytes(string.Join(",", cmd)));
                    break;
                case EnumInstructionType.RecoveryBreakOilOrPower:
                    cmd.Add("#1:{0}:1:*".GetFormat(deviceGpsCodeNoPrefix));
                    cmd.Add(ByteHelper.ConvertUInt32ToHexString(GetSerialNumber()));
                    cmd.Add("CC");
                    cmd.Add(ByteHelper.ConvertDateToHexString(DateTime.Now));
                    cmd.Add(ByteHelper.ConvertTimeToHexString(DateTime.Now));
                    cmd.Add("Y2L2#");
                    
                    break;
            }

            if (cmd.Count > 0)
            {
                session.SendAsync(Encoding.UTF8.GetBytes(string.Join(",", cmd)));
                _logger.WarnFormat("开始执行指令{0}-{1}-{2}", instruction.DeviceId,instruction.InstructionType.GetDisplayName(), string.Join(",", cmd));
            }
            else
            {
                _logger.WarnFormat("发送指令失败,无效指令!{0}-{1}", instruction.DeviceId, instruction.InstructionType.GetDisplayName());
            }

        }
Ejemplo n.º 4
0
 private void OnReceived(object sender, EInstruction instruction)
 {
     try
     {
         _logger.WarnFormat("接收到指令{0}-{1}", instruction.DeviceId, instruction.InstructionType.GetDisplayName());
         var session = _appSocketSessionManager.GetByIdentity(instruction.DeviceId.ToString());
         if (session != null)
         {
             _instructionHandler.Handle(session, instruction);
         }
         else
         {
             _logger.WarnFormat("发送指令失败!车辆不在线或者车辆不在当前服务器!{0}-{1}",instruction.DeviceId,instruction.InstructionType.GetDisplayName());
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
     }
 }
Ejemplo n.º 5
0
        public void Handle(AppSocketSession session, EInstruction instruction)
        {
            //开油:*HQ,0000,S20,095517,1,0#
            //断油:*HQ,0000,S20,095517,1,1#"

            var deviceGpsCodeNoPrefix = session["DeviceGpsCodeNoPrefix"] as string;
            if (deviceGpsCodeNoPrefix == null)
            {
                _logger.WarnFormat("发送指令失败!车辆不在线!{0}-{1}", instruction.DeviceId, instruction.InstructionType.GetDisplayName());
            }

            var cmd = $"*HQ,0000,S20,{DateTime.Now.ToString("HHmmss")},1,{(instruction.InstructionType==EnumInstructionType.BreakOilOrPower ? "1" : "0")}#";
            if (cmd.Length > 0)
            {
                session.SendAsync(Encoding.ASCII.GetBytes(string.Join(",", cmd)));
                _logger.WarnFormat("开始执行指令{0}-{1}-{2}", instruction.DeviceId, instruction.InstructionType.GetDisplayName(), string.Join(",", cmd));
            }
            else
            {
                _logger.WarnFormat("发送指令失败,无效指令!{0}-{1}", instruction.DeviceId, instruction.InstructionType.GetDisplayName());
            }

        }
Ejemplo n.º 6
0
 public void Handle(AppSocketSession session, EInstruction instruction)
 {
     
 }
Ejemplo n.º 7
0
        public void Handle(AppSocketSession session, EInstruction instruction)
        {
            var deviceGpsTypeName = session["DeviceGpsTypeName"] as string;
            if(!deviceGpsTypeName.HasValue()) return;

            switch (deviceGpsTypeName)
            {
                case "H1"://沃达孚
                    HandleH1(session,instruction);
                    break;
                case "H5"://华宝A5
                    HandleH5(session, instruction);
                    break;
            }
        }