Ejemplo n.º 1
0
        /// <summary>
        /// 处理发送到设备的命令请求
        /// </summary>
        /// <returns></returns>
        private string HandleEquipmentCommandRequest()
        {
            var ret = "[]";

            try
            {
                var id = ParseInt(Utility.Decrypt(data));
                using (var bll = new EquipmentBLL())
                {
                    var obj = bll.Find(f => f.id == id && f.Deleted == false);
                    if (null != obj)
                    {
                        if ((int?)null != obj.Terminal)
                        {
                            // 查看当前设备的链接状态然后确定命令的发送方式
                            ret = HandleTerminalCommandRequest(obj.TB_Terminal);
                        }
                        else
                        {
                            ret = ResponseMessage(-1, "No terminal bond with this equipment.");
                        }
                    }
                    else
                    {
                        ret = ResponseMessage(-1, "Equipment is not exist.");
                    }
                }
            }
            catch (Exception e)
            { ret = ResponseMessage(-1, "Handle Equipment command error:" + e.Message); }
            return(ret);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 显示设备的基本信息
        /// </summary>
        private void ShowEquipmentInfo()
        {
            var n = (int?)null;

            if (!string.IsNullOrEmpty(_key))
            {
                var id = ParseInt(Utility.Decrypt(_key));
                var EquipmentInstance = new EquipmentBLL();
                var obj = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
                if (null != obj)
                {
                    functional.InnerText = ((EquipmentFunctional)obj.Functional != EquipmentFunctional.Loader ? "Excavator: " : "") +
                                           Utility.GetEquipmentFunctional(obj.Functional.Value);

                    equipment_id.InnerHtml = obj.TB_EquipmentModel.Code + obj.Number;
                    objectInfo.Rows[1].Cells[1].InnerHtml = obj.TB_EquipmentModel.TB_EquipmentType.Name;
                    objectInfo.Rows[1].Cells[3].InnerHtml = obj.TB_EquipmentModel.Code;

                    objectInfo.Rows[2].Cells[1].InnerHtml           = obj.Number;
                    objectInfo.Rows[2].Cells[3].InnerHtml           = obj.TB_EquipmentStatusName.Code;
                    objectInfo.Rows[2].Cells[3].Attributes["title"] = obj.TB_EquipmentStatusName.Name;

                    objectInfo.Rows[3].Cells[1].InnerHtml = EquipmentBLL.GetRuntime(obj.Runtime + obj.InitializedRuntime, obj.CompensatedHours.Value);
                    objectInfo.Rows[3].Cells[3].InnerHtml = EquipmentInstance.GetEngStatus(obj);

                    objectInfo.Rows[4].Cells[1].InnerText = obj.GpsAddress;

                    var StoreInstance = new StoreHistoryBLL();
                    // 入库记录
                    var _in = StoreInstance.GetStoreInfo(obj.id, obj.StoreTimes.Value, true);
                    // 出库记录
                    var _out = StoreInstance.GetStoreInfo(obj.id, obj.StoreTimes.Value, false);
                    objectInfo.Rows[6].Cells[1].InnerText           = (null == _in ? "-" : _in.Stocktime.Value.ToString("yyyy/MM/dd"));
                    objectInfo.Rows[6].Cells[3].InnerText           = StoreInstance.GetStatus(_in);
                    objectInfo.Rows[6].Cells[3].Attributes["title"] = StoreInstance.GetStatusTitle(_in);

                    objectInfo.Rows[7].Cells[1].InnerText           = (null == _out ? "-" : _out.Stocktime.Value.ToString("yyyy/MM/dd"));
                    objectInfo.Rows[7].Cells[3].InnerText           = StoreInstance.GetStatus(_out);
                    objectInfo.Rows[7].Cells[3].Attributes["title"] = StoreInstance.GetStatusTitle(_out);

                    objectInfo.Rows[8].Cells[1].InnerText = (int?)null == obj.Warehouse ? "-" : obj.TB_Warehouse.Name;

                    objectInfo.Rows[10].Cells[1].InnerText = (n == obj.Terminal ? "-" : obj.TB_Terminal.Number);
                    objectInfo.Rows[10].Cells[3].InnerHtml = Utility.GetOnlineStyle(obj.OnlineStyle, obj.OnlineTime, false);

                    objectInfo.Rows[11].Cells[1].InnerText = (n == obj.Terminal ? "-" : obj.TB_Terminal.Sim);
                    objectInfo.Rows[11].Cells[3].InnerText =
                        (n == obj.Terminal ? "-" :
                         ((int?)null == obj.TB_Terminal.Satellite ? "" : obj.TB_Terminal.TB_Satellite.CardNo));

                    //objectInfo.Rows[12].Cells[1].InnerText =
                    //    (byte?)null == obj.Signal ? "-" : obj.Signal.Value.ToString();
                    objectInfo.Rows[12].Cells[1].InnerText =
                        (DateTime?)null == obj.LastActionTime ? "-" : obj.LastActionTime.Value.ToString("yyyy/MM/dd HH:mm");
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理发送保安命令请求
        /// </summary>
        /// <returns></returns>
        private string HandleSecurityCommandRequest()
        {
            var ret = "[]";

            try
            {
                var id = ParseInt(Utility.Decrypt(data));
                using (var bll = new EquipmentBLL())
                {
                    var obj = bll.Find(f => f.id == id && f.Deleted == false);
                    if (null != obj)
                    {
                        if ((int?)null != obj.Terminal)
                        {
                            ret = "";
                            // 查看是否发送的保安命令
                            var command = CommandUtility.GetCommand(cmd);
                            if (command.Security && command.Code.Equals("6007"))
                            {
                                ret = HandleSecurityStatus(obj.LockStatus, command.Param);
                            }
                            if (string.IsNullOrEmpty(ret))
                            {
                                // 查看当前设备的链接状态然后确定命令的发送方式
                                ret = HandleTerminalCommandRequest(obj.TB_Terminal);
                            }
                        }
                        else
                        {
                            ret = ResponseMessage(-1, "No terminal bond with this equipment.");
                        }
                    }
                    else
                    {
                        ret = ResponseMessage(-1, "Equipment is not exist.");
                    }
                }
            }
            catch (Exception e) { ret = ResponseMessage(-1, "Handle Security command error:" + e.Message); }
            return(ret);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据TX300数据包更新终端和设备的在线状态
        /// </summary>
        /// <param name="tx300"></param>
        private void HandleTX300Status(TX300 tx300, AsyncUserDataBuffer data)
        {
            var sim = GetSimFromData(tx300);

            using (var ebll = new EquipmentBLL())
            {
                var equipment = ebll.Find(f => f.TB_Terminal.Sim.Equals(sim));
                var terminal  = new TerminalBLL().Find(f => f.Sim.Equals(sim));
                SaveTerminalData(null == terminal ? -1 : terminal.id, sim, data.PackageType, tx300.TotalLength, true, data.ReceiveTime);
                // 终端不存在的话,不用再继续处理数据了
                if (!IsTracker(tx300.CommandID))
                {
                    if (null == terminal)
                    {
                        return;
                    }
                }

                HandleOnline(sim, tx300.CommandID, data);

                if (tx300.CommandID != 0xAA00)
                {
                    // TX10G的数据
                    if (tx300.CommandID >= 0x7000 && tx300.CommandID <= 0x7040)
                    {
                        HandleTX10G(tx300, data);
                    }
                    else
                    {
                        SaveTX300History(tx300, data.ReceiveTime, (null == equipment ? "" : ebll.GetFullNumber(equipment)));

                        // 根据命令的不同处理各个命令详情
                        HandleCommand(tx300, equipment, terminal);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 查询命令历史记录
        /// </summary>
        /// <param name="security">是否查询保安命令</param>
        /// <returns></returns>
        private string HandleCommandHistoryRequest(bool security)
        {
            var ret = "[]";

            try
            {
                var id = ParseInt(Utility.Decrypt(data));
                using (var ebll = new EquipmentBLL())
                {
                    var obj = ebll.Find(f => f.id == id && f.Deleted == false);
                    if (null != obj)
                    {
                        // 终端不为空时才查询
                        if ((int?)null != obj.Terminal)
                        {
                            var start = DateTime.Parse(GetParamenter("start") + " 00:00:00");
                            var end   = DateTime.Parse(GetParamenter("end") + " 23:59:59");
                            var sim   = obj.TB_Terminal.Sim;
                            if (sim[0] == '8' && sim[1] == '9' && sim.Length < 11)
                            {
                                sim += "000";
                            }
                            // 查询的命令
                            //string _command = "";
                            Command command = null;
                            if (!string.IsNullOrEmpty(cmd))
                            {
                                command = CommandUtility.GetCommand(cmd);
                                //_command = command.Code;
                            }
                            using (var bll = new CommandBLL())
                            {
                                var list = bll.FindList <TB_Command>(f => f.DestinationNo.Equals(sim) &&
                                                                     f.ScheduleTime >= start && f.ScheduleTime <= end && f.Command != "0xBB0F", "ScheduleTime", true);
                                if (security)
                                {
                                    list = list.Where(w => w.Command == "0x6007" || w.Command == "0x4000" || w.Command == "0x3000" || w.Command == "0xDD02");
                                }
                                else
                                {
                                    list = list.Where(w => w.Command != "0x6007" && w.Command != "0x4000" && w.Command != "0x3000" && w.Command != "0xDD02");
                                }
                                //&&
                                //    (string.IsNullOrEmpty(_command) ? f.u_sms_command.IndexOf("0x") >= 0 : f.u_sms_command.IndexOf(_command) >= 0),
                                //    "u_sms_schedule_time", true);
                                if (null != command)
                                {
                                    list = list.Where(w => w.Command.IndexOf(command.Code) >= 0);
                                    if (security && command.Code.Equals("6007"))
                                    {
                                        list = list.Where(w => w.Content.Substring(w.Content.Length - 2) == command.Param);
                                    }
                                    else if (security && command.Code.Equals("3000"))
                                    {
                                        list = list.Where(w => w.Content.Substring(w.Content.Length - 4, 2) == command.Param);
                                    }
                                    else if (security && command.Code.Equals("4000"))
                                    {
                                        list = list.Where(w => w.Content.Substring(w.Content.Length - 4, 2) == command.Param);
                                    }
                                }
                                if (list.Count() > 0)
                                {
                                    // 将command_id替换
                                    //List<Command> commands = CommandUtility.GetCommand();
                                    foreach (var record in list)
                                    {
                                        string param = "";
                                        if (record.Command == "0x6007")
                                        {
                                            param = record.Content.Substring(record.Content.Length - 2);
                                        }
                                        if (record.Command == "0x3000")
                                        {
                                            param = record.Content.Substring(record.Content.Length - 4, 2);
                                        }
                                        if (record.Command == "0x4000")
                                        {
                                            param = record.Content.Substring(record.Content.Length - 4, 2);
                                        }
                                        if (record.Command == "0xDD02")
                                        {
                                            param = record.Content.Substring(record.Content.Length - 8, 2);
                                        }
                                        Command _cmd   = CommandUtility.GetCommand(record.Command.Replace("0x", ""), param);
                                        var     func   = (EquipmentFunctional)obj.Functional;
                                        var     called = (func == EquipmentFunctional.Mechanical || func == EquipmentFunctional.Electric) ? "Equipment" : "Loader";
                                        record.Command = (null == _cmd ? "" : _cmd.Title.Replace("Equipment", called).Replace("Loader", called));
                                        // 加入命令发送者  2015/09/18 10:36
                                        record.Content = (int?)null == record.SendUser ? "Server" : record.TB_Account.Name;
                                    }
                                }
                                ret = JsonConverter.ToJson(list);
                            }
                        }
                        else
                        {
                            ret = ResponseMessage(-1, "No terminal bond with this equipment.");
                        }
                    }
                    else
                    {
                        ret = ResponseMessage(-1, "Equipment is not exist.");
                    }
                }
            }
            catch (Exception e)
            { ret = ResponseMessage(-1, "Handle History request error:" + e.Message); }
            return(ret);
        }
        /// <summary>
        /// 导出终端列表到excel
        /// </summary>
        /// <param name="bll"></param>
        /// <param name="excel"></param>
        private void ExportTerminalsToExcel(ExcelHandlerBLL bll, TB_ExcelHandler excel)
        {
            string      source = "", data = "";
            Application app   = null;
            Workbook    book  = null;
            Worksheet   sheet = null;

            try
            {
                app         = new Application();
                book        = app.Workbooks.Open(EXCEL_PATH + EXCEL_TERMINALS);
                sheet       = (Worksheet)book.ActiveSheet;
                app.Visible = false;
                app.AlertBeforeOverwriting = false;
                app.DisplayAlerts          = false;

                using (var tbll = new TerminalBLL())
                {
                    using (var ebll = new EquipmentBLL())
                    {
                        int line = 2;
                        int cnt  = 0;
                        var n    = (int?)null;
                        var list = tbll.FindList(f => f.Delete == false);
                        foreach (var obj in list)
                        {
                            var x = line + cnt;
                            sheet.Cells[x, 1] = (cnt + 1);
                            sheet.Cells[x, 2] = obj.Number;
                            sheet.Cells[x, 3] = n == obj.Satellite ? "-" : obj.TB_Satellite.CardNo;
                            sheet.Cells[x, 4] = string.IsNullOrEmpty(obj.Firmware) ? "-" : obj.Firmware;
                            sheet.Cells[x, 5] = obj.Revision;
                            sheet.Cells[x, 6] = TerminalTypes.GetTerminalType(obj.Type.Value);
                            sheet.Cells[x, 7] = obj.ProductionDate.Value.ToString("yyyy/MM/dd");
                            var e = ebll.Find(d => d.Terminal == obj.id && d.Deleted == false);
                            sheet.Cells[x, 8] = null == e ? "-" : ebll.GetFullNumber(e);

                            var link = EverdigmUtils.GetOnlineStyle(obj.OnlineStyle, obj.OnlineTime, false);
                            link = link.Substring(link.IndexOf('>') + 1);
                            link = link.Substring(0, link.IndexOf('<'));
                            sheet.Cells[x, 9]  = string.IsNullOrEmpty(link) ? "-" : link;
                            sheet.Cells[x, 10] = null == obj.OnlineTime ? "-" : obj.OnlineTime.Value.ToString("yyyy/MM/dd HH:mm");
                            cnt++;
                        }
                    }
                }

                // 另存为别的
                var date = excel.CreateDate.Value.ToString("yyyyMMdd");
                var path = Path.Combine(WEB_PATH, "files\\xls\\", date);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                source = path + "\\Terminals2Excel_" + excel.CreateDate.Value.ToString("yyyyMMdd") + ".xlsx";
                if (File.Exists(source))
                {
                    File.Delete(source);
                }
                book.SaveAs(source);
            }
            catch (Exception e)
            {
                data = e.StackTrace;
                ShowUnhandledMessage(format("{0}Terminal to Excel handler error: {1}{2}{3}", Now, e.Message, Environment.NewLine, e.StackTrace));
            }
            finally
            {
                // 关闭book
                if (null != book)
                {
                    book.Close();
                    book = null;
                }
                // 关闭application
                if (null != app)
                {
                    app.Quit();
                    app = null;
                }
                // 释放内存
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            var target = "../" + source.Replace(WEB_PATH, "").Replace("\\", "/");

            bll.Update(f => f.id == excel.id, act =>
            {
                act.Handled = true;
                act.Status  = (byte)(string.IsNullOrEmpty(data) ? 0 : 1);
                act.Target  = target;
                act.Data    = data;
            });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 处理新版的卫星通讯协议
        /// </summary>
        /// <param name="data"></param>
        private void HandleIridiumNewProtocolPackage(IridiumData data)
        {
            if (data.Payload[0] == 0x01)
            {
                // 新版的卫星通讯协议
                uint   thisWorkTime = BitConverter.ToUInt32(data.Payload, 13);
                string locks        = CustomConvert.GetHex(data.Payload[1]);
                string alarms       = CustomConvert.IntToDigit(data.Payload[2], CustomConvert.BIN, 8) +
                                      CustomConvert.IntToDigit(data.Payload[3], CustomConvert.BIN, 8);
                IridiumLocation location = new IridiumLocation();
                location.LatLng = new byte[IridiumLocation.SIZE];
                Buffer.BlockCopy(data.Payload, 4, location.LatLng, 0, IridiumLocation.SIZE);
                location.Unpackate();

                // 通过卫星的IMEI号码查找终端
                using (var tbll = new TerminalBLL())
                {
                    using (var ebll = new EquipmentBLL())
                    {
                        var          terminal  = tbll.Find(f => f.TB_Satellite.CardNo.Equals(data.IMEI));
                        TB_Equipment equipment = null;
                        if (null != terminal)
                        {
                            // 只有第一版的终端才需要计算补偿时间
                            var compensated = terminal.Version == 1;

                            tbll.Update(f => f.id == terminal.id, act =>
                            {
                                act.OnlineStyle = (byte)LinkType.SATELLITE;
                                // 同时更新终端的最后链接时间
                                act.OnlineTime = data.Time;
                            });
                            equipment = ebll.Find(f => f.Terminal == terminal.id);
                            if (null != equipment)
                            {
                                // 旧的运转时间
                                var oldRuntime = equipment.Runtime;
                                var interval   = 0 == oldRuntime ? 0 : (thisWorkTime - oldRuntime);
                                // 粗略增加的小时数,启动时加2小时
                                var    addMin         = interval > 60 ? interval / 60 : 1 + (location.EngFlag.Equals("On") ? 1 : 0);
                                int    addHour        = (int)(interval > 60 ? interval / 60 : 1);// 显示历史记录
                                string oldCompensated = format("WorkHours {0}, UsedHours {1}, Efficiency {2}, AddHours {3}, Compensated {4}", equipment.WorkHours, equipment.UsedHours, equipment.HourWorkEfficiency, equipment.AddedHours, equipment.CompensatedHours);
                                string newCompensated = "";
                                // 更新设备的总运转时间
                                HandleEquipmentRuntime(equipment, thisWorkTime);
                                if (null != equipment)
                                {
                                    string calculated = "";
                                    ebll.Update(f => f.id == equipment.id, act =>
                                    {
                                        act.OnlineStyle = (byte)LinkType.SATELLITE;
                                        act.OnlineTime  = data.Time;
                                        // 更新设备的报警状态 2015/09/10 14:04
                                        act.Alarm = alarms;

                                        act.LastAction     = "0x1000";
                                        act.LastActionBy   = "SAT";
                                        act.LastActionTime = data.Time;
                                        // 更新定位信息 2015/09/09 23:29
                                        if (location.Available)
                                        {
                                            act.Latitude  = location.Latitude;
                                            act.Longitude = location.Longitude;
                                        }
                                        // 更新启动与否状态 2015/08/31
                                        act.Voltage = location.EngFlag.Equals("On") ? "G2400" : "G0000";

                                        // 更新总运转时间
                                        act.Runtime             = equipment.Runtime;
                                        act.AccumulativeRuntime = equipment.AccumulativeRuntime;
                                        // 更新 version 终端为1的版本的运转时间的补偿
                                        if (compensated && interval > 0)
                                        {
                                            // 实际工作小时数
                                            act.WorkHours += interval / 60.0;
                                            // 实际所用小时数
                                            act.UsedHours += addHour;
                                            // 重新计算每小时工作效率
                                            act.HourWorkEfficiency = act.WorkHours / act.UsedHours;
                                            // 补偿的小时数
                                            act.AddedHours += addMin / 60.0;
                                            // 实际补偿的小时数
                                            act.CompensatedHours = act.AddedHours * act.HourWorkEfficiency;
                                        }
                                        // 如果回来的运转时间比当前时间大则更新成为On状态  暂时  2015/09/02
                                        //if (worktime > act.Runtime)
                                        //{
                                        //    // act.Voltage = "G2400";
                                        //    act.Runtime = (int)worktime;
                                        //}
                                        //else
                                        //{
                                        //    if (worktime > 0)
                                        //    {
                                        //        // 运转时间不为零的话,更新运转时间
                                        //        act.Runtime = (int)worktime;
                                        //    }
                                        //}
                                        // 锁车状态 2015/08/14
                                        if (act.LockStatus != locks)
                                        {
                                            act.LockStatus = locks;
                                        }
                                        // 判断锁车的有效状态
                                        if (locks.Equals("40") || locks.Equals("0F") || locks.Equals("FF"))
                                        {
                                            // 锁车时还有开机状态
                                            if (location.EngFlag.Equals("On"))
                                            {
                                                // 锁车了,但未关机,还在工作中
                                                if (act.LockEffected == (byte)LockEffect.Locked)
                                                {
                                                    act.LockEffected = (byte)LockEffect.LockedAndStillWork;
                                                }
                                                else if (act.LockEffected == (byte)LockEffect.LockedAndEngineOff)
                                                {
                                                    // 锁车了且已关机了,此时再开机则需要报警(没锁住车)
                                                    act.LockEffected = (byte)LockEffect.LockedAndNoEffect;
                                                }
                                            }
                                            else
                                            {
                                                // 锁车了,且已关机了
                                                if (act.LockEffected == (byte)LockEffect.Locked)
                                                {
                                                    act.LockEffected = (byte)LockEffect.LockedAndEngineOff;
                                                }
                                            }
                                        }
                                    });
                                    if (compensated && interval > 0)
                                    {
                                        equipment      = ebll.Find(f => f.id == equipment.id);
                                        newCompensated = format("WorkHours {0}, UsedHours {1}, Efficiency {2}, AddHours {3}, Compensated {4}", equipment.WorkHours, equipment.UsedHours, equipment.HourWorkEfficiency, equipment.AddedHours, equipment.CompensatedHours);

                                        calculated = format("Compensate changed(interval: {0}){1} from {2}{3} to {4}", interval, Environment.NewLine, oldCompensated, Environment.NewLine, newCompensated);
                                    }
                                    if (!string.IsNullOrEmpty(calculated))
                                    {
                                        OnUnhandledMessage(this, new Sockets.UIEventArgs()
                                        {
                                            Message = format("{0}{1}{2}", Now, calculated, Environment.NewLine)
                                        });
                                    }
                                }
                            }
                            else
                            {
                                OnUnhandledMessage(this, new Sockets.UIEventArgs()
                                {
                                    Message = format("{0} Iridium has not bind with any equipment.", Now, Environment.NewLine)
                                });
                            }
                        }
                        else
                        {
                            OnUnhandledMessage(this, new Sockets.UIEventArgs()
                            {
                                Message = format("{0} Satellite has no terminal, data will save as terminal number: \"{1}\".{2}",
                                                 Now, data.IMEI.Substring(4), Environment.NewLine)
                            });
                        }
                        // 保存TX300历史记录
                        SaveTX300History(new TX300()
                        {
                            CommandID    = 0x1000,
                            MsgContent   = data.Payload,
                            ProtocolType = ProtocolTypes.SATELLITE,
                            // 默认装载机终端类型 2015/09/22 09:40
                            TerminalType = null == terminal ? TerminalTypes.LD : terminal.Type.Value,
                            // 没有终端时,用IMEI号码的末尾11位数字表示终端号码 2015/09/22 09:40
                            TerminalID  = null == terminal ? data.IMEI.Substring(4) : terminal.Sim,
                            TotalLength = (ushort)data.Payload.Length
                        }, data.Time, ebll.GetFullNumber(equipment));

                        try
                        {
                            long?posId = null;
                            if (location.Available)
                            {
                                using (var posbll = new PositionBLL())
                                {
                                    var pos = posbll.GetObject();
                                    pos.Latitude   = location.Latitude;
                                    pos.Longitude  = location.Longitude;
                                    pos.NS         = location.NSI;
                                    pos.EW         = location.EWI;
                                    pos.StoreTimes = null == equipment ? 0 : equipment.StoreTimes;
                                    pos.GpsTime    = data.Time;
                                    pos.Equipment  = null == equipment ? (int?)null : equipment.id;
                                    // 没有终端时,用IMEI号码的末尾11位数字表示终端号码 2015/09/22 09:40
                                    pos.Terminal = null == terminal?data.IMEI.Substring(4) : (terminal.Sim.Length < 11 ? (terminal.Sim + "000") : terminal.Sim);

                                    pos.Type = location.Report + "(Eng " + location.EngFlag + ")(SAT)";
                                    posbll.Add(pos);
                                    posId = pos.id;
                                }
                            }

                            // 处理报警信息
                            if (alarms != ALARM)
                            {
                                using (var armbll = new AlarmBLL())
                                {
                                    var arm = armbll.GetObject();
                                    arm.Code       = alarms;
                                    arm.AlarmTime  = data.Time;
                                    arm.Equipment  = null == equipment ? (int?)null : equipment.id;
                                    arm.Position   = posId;
                                    arm.StoreTimes = null == equipment ? 0 : equipment.StoreTimes;
                                    // 没有终端时,用IMEI号码的末尾11位数字表示终端号码 2015/09/22 09:40
                                    arm.Terminal = null == terminal?data.IMEI.Substring(4) : (terminal.Sim.Length < 11 ? (terminal.Sim + "000") : terminal.Sim);

                                    armbll.Add(arm);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            OnUnhandledMessage(this, new Sockets.UIEventArgs()
                            {
                                Message = format("{0}{1}{2}{3}", Now, e.Message, Environment.NewLine, e.StackTrace)
                            });
                        }
                        // 更新卫星方式的命令状态(只处理命令回复的1000,其他的命令在普通命令过程中处理)
                        if (location.ReportType == 1 && data.Payload.Length <= 17)
                        {
                            HandleIridiumCommandResponseed(data);
                        }
                        location.Dispose();
                        location = null;
                    }
                }
            }
        }