/// <summary> /// 处理终端OFF的信息 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0xFF00(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { // 终端没电关机 _0xFF00 xff00 = new _0xFF00(); xff00.Content = obj.MsgContent; xff00.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Voltage = "G0000"; act.OnlineStyle = (byte)LinkType.OFF; if (xff00.GPSInfo.Available) { act.Latitude = xff00.GPSInfo.Latitude; act.Longitude = xff00.GPSInfo.Longitude; act.GpsUpdated = false; } }); } } if (xff00.GPSInfo.Available) { SaveGpsInfo(xff00.GPSInfo, equipment, obj.TerminalID, "Battery OFF" + GetPackageType(obj.ProtocolType)); } }
/// <summary> /// 更新或新建Tracker的基本信息 /// </summary> private void UpdateTrackerInfo(TX300 tx300, AsyncUserDataBuffer data, TrackerBLL bll) { var sim = GetSimFromData(tx300); var tracker = bll.Find(f => f.SimCard.Equals(sim)); if (null == tracker) { // 新增一个tracker tracker = bll.GetObject(); tracker.SimCard = sim; tracker.LastActionAt = data.ReceiveTime; tracker.Socket = data.SocketHandle; tracker.State = 1; bll.Add(tracker); } else { bll.Update(f => f.id == tracker.id, act => { act.LastActionAt = data.ReceiveTime; act.Socket = data.SocketHandle; if (tx300.CommandID == 0x7020 || tx300.CommandID == 0x7030 || tx300.CommandID == 0x7040) { act.CSQ = tx300.MsgContent[0]; } }); } }
private void save(string sender, string text, string date) { DateTime dt = DateTime.Parse(date);//DateTime.ParseExact(date, "yyyyMMddHHmmss", null, System.Globalization.DateTimeStyles.None); byte[] b = Convert.FromBase64String(text); string content = Utility.GetHex(b); //try { TX300 x300 = new TX300(content); x300.package_to_msg(); x300.TerminalID = sender + "000"; //save(x300); if (x300.CommandID == 0xBB0F) { handleBB0F(sender, x300.TerminalType); } var SMSInstance = new SmsBLL(); var sms = SMSInstance.GetObject(); sms.SendTime = dt; sms.Sender = sender; sms.Data = text; // 这里接收到的都是终端汇报回来的信息 sms.Type = Common.SMSUtility.SMS_TERMINAL; SMSInstance.Add(sms); } }
/// <summary> /// 处理命令回复的定位信息 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x1000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x1000 x1000 = new _0x1000(); x1000.Content = obj.MsgContent; x1000.Unpackage(); if (null != equipment) { if (x1000.GPSInfo.Available) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Latitude = x1000.GPSInfo.Latitude; act.Longitude = x1000.GPSInfo.Longitude; act.GpsUpdated = false; }); } } } if (x1000.GPSInfo.Available) { SaveGpsInfo(x1000.GPSInfo, equipment, obj.TerminalID, "Position command" + GetPackageType(obj.ProtocolType)); } }
private void Handle0x7030(TX300 obj, TB_Tracker tracker) { _0x7030 x7030 = new _0x7030(); x7030.Content = obj.MsgContent; x7030.Unpackage(); string provider = "gps"; var bin = "0000000000000000"; if (obj.TerminalType == TerminalTypes.TX10GAPP) { bin = CustomConvert.IntToDigit(obj.PackageID, CustomConvert.BIN, 8) + CustomConvert.IntToDigit(obj.TotalPackage, CustomConvert.BIN, 8); } int cnt = 0; foreach (var pos in x7030.Positions) { if (pos.Available) { provider = GetTrackerProvider(bin[cnt]);//bin[cnt] == '0' ? "gps" : "network"; SaveTrackerPosition(obj.TerminalID, (null == tracker ? "" : tracker.CarNumber), (null == tracker ? -1 : tracker.id), provider, pos, "Tracking", tracker.LastActionAt.Value); } cnt++; } }
/// <summary> /// 处理设备的开关机信息 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x5000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { // 发动机启动/关闭信息 _0x5000 x5000 = new _0x5000(); x5000.Content = obj.MsgContent; x5000.Unpackage(); if (null != equipment) { EquipmentInstance.Update(f => f.id == equipment.id, act => { act.Voltage = string.Format("G{0}", ((int)Math.Floor(x5000.GeneratorVoltage * 10)).ToString("0000")); if (x5000.GPSInfo.Available) { act.Latitude = x5000.GPSInfo.Latitude; act.Longitude = x5000.GPSInfo.Longitude; act.GpsUpdated = false; } }); } if (x5000.GPSInfo.Available) { SaveGpsInfo(x5000.GPSInfo, equipment, obj.TerminalID, "0x5000"); } }
/// <summary> /// 处理定期报告信息 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x1001(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x1001 x1001 = new _0x1001(); x1001.Content = obj.MsgContent; x1001.Unpackage(); if (null != equipment) { EquipmentInstance.Update(f => f.id == equipment.id, act => { act.Signal = x1001.CSQ_1 > 0 ? x1001.CSQ_1 : (x1001.CSQ_2 > 0 ? x1001.CSQ_2 : byte.MinValue); if (x1001.WorkTime > 0) { act.Runtime = (int)x1001.WorkTime; } }); } var pos = GetGpsinfoFrom1001(x1001, true); pos.Equipment = null == equipment ? (int?)null : equipment.id; pos.Terminal = obj.TerminalID; pos.StoreTimes = null == equipment ? 0 : equipment.StoreTimes; PositionInstance.Add(pos); pos = GetGpsinfoFrom1001(x1001, false); pos.Equipment = null == equipment ? (int?)null : equipment.id; pos.Terminal = obj.TerminalID; pos.StoreTimes = null == equipment ? 0 : equipment.StoreTimes; PositionInstance.Add(pos); }
/// <summary> /// 处理报警信息 /// </summary> /// <param name="obj"></param> private void Handle0x2000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { // 报警 _0x2000 x2000 = new _0x2000(); x2000.Content = obj.MsgContent; x2000.Unpackage(); if (null != equipment) { EquipmentInstance.Update(f => f.id == equipment.id, act => { if (x2000.AlarmBIN[0] == '1') { // Main Power Disconnect act.Voltage = "G0000"; // 主电断报警之后进入睡眠状态 act.OnlineStyle = (byte)LinkType.SLEEP; } if (x2000.GPSInfo.Available) { act.Latitude = x2000.GPSInfo.Latitude; act.Longitude = x2000.GPSInfo.Longitude; act.GpsUpdated = false; } }); } if (x2000.GPSInfo.Available) { SaveGpsInfo(x2000.GPSInfo, equipment, obj.TerminalID, "0x2000"); } }
/// <summary> /// 根据TX300数据包更新终端和设备的在线状态 /// </summary> /// <param name="tx300"></param> private void HandleTX300Status(TX300 tx300, AsyncUserDataBuffer data) { var sim = GetSimFromData(tx300); var equipment = EquipmentInstance.Find(f => f.TB_Terminal.Sim.Equals(sim)); var terminal = TerminalInstance.Find(f => f.Sim.Equals(sim)); // 终端不存在的话,不用再继续处理数据了 if (null == terminal) { return; } HandleOnline(sim, tx300.CommandID, data); if (tx300.CommandID != 0xAA00) { SaveTX300History(tx300, data.ReceiveTime, (null == equipment ? "" : EquipmentInstance.GetFullNumber(equipment))); // TX10G的数据 if (tx300.CommandID == 0x7010 || tx300.CommandID == 0x7020 || tx300.CommandID == 0x7030) { HandleTX10G(tx300, data); } else { // 根据命令的不同处理各个命令详情 HandleCommand(tx300, equipment, terminal); } } }
/// <summary> /// 处理装载机的0x600B初始化运转时间的回复 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x600B(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x600B x600B = new _0x600B(); x600B.Content = obj.MsgContent; x600B.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { // 600B时直接重置所有的运转时间 act.Runtime = (int)x600B.Worktime; act.AccumulativeRuntime = (int)x600B.Worktime; // 装载机的总运转时间初始化时,将其特定的初始化时间设为0 if (act.InitializedRuntime > 0) { act.InitializedRuntime = 0; } // 更改运转时间时,同时清空补偿的运转时间 2017/11/24 10:40 if (act.CompensatedHours > 0) { act.CompensatedHours = 0; } }); } } }
/// <summary> /// 处理数据并更新终端和设备的状态 /// </summary> /// <param name="obj"></param> private void HandleDataStatus(TX300 obj) { var sim = GetSimFromData(obj); var terminal = TerminalInstance.Find(f => f.Sim.Equals(sim)); if (null == terminal) { return; } var equipment = EquipmentInstance.Find(f => f.TB_Terminal.Sim.Equals(sim) && f.Deleted == false); HandleOnline(sim, obj.CommandID); SaveTX300History(obj, (null == equipment ? "" : EquipmentInstance.GetFullNumber(equipment))); // 卫星数据只有0x1000和0x6007(0x6007会有0xEE00存在)两种 switch (obj.CommandID) { case 0x1000: Handle0x1000(obj, equipment); break; case 0x6007: Handle0x6007(obj, equipment); break; case 0xEE00: Handle0xEE00(obj, equipment); // 483130433130372007600140A5 // 5831304331303530076001403F break; } }
/// <summary> /// 处理运转时间消息 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x6004(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x6004DX x6004 = new _0x6004DX(); x6004.Type = obj.TerminalType; x6004.Content = obj.MsgContent; x6004.Unpackage(); HandleEquipmentRuntime(equipment, x6004.TotalWorkTime); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Runtime = equipment.Runtime; act.AccumulativeRuntime = equipment.AccumulativeRuntime; if (obj.TerminalType == Protocol.TerminalTypes.DH || obj.TerminalType == Protocol.TerminalTypes.DX) { // EPOS命令时清空报警 2015/09/24 08:00 act.Alarm = ALARM; } }); } } }
/// <summary> /// 处理终端OFF的信息 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0xFF00(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { // 终端没电关机 _0xFF00 xff00 = new _0xFF00(); xff00.Content = obj.MsgContent; xff00.Unpackage(); if (null != equipment) { EquipmentInstance.Update(f => f.id == equipment.id, act => { act.Voltage = "G0000"; act.OnlineStyle = (byte)LinkType.OFF; if (xff00.GPSInfo.Available) { act.Latitude = xff00.GPSInfo.Latitude; act.Longitude = xff00.GPSInfo.Longitude; act.GpsUpdated = false; } }); } if (xff00.GPSInfo.Available) { SaveGpsInfo(xff00.GPSInfo, equipment, obj.TerminalID, "0xFF00"); } }
private void Handle0x3000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x3000 x3000 = new _0x3000(); x3000.Content = obj.MsgContent; x3000.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.LockStatus = CustomConvert.GetHex(x3000.Type); // 存储锁车状态 act.LockEffected = (byte)((x3000.Type == 0x40 || x3000.Type == 0x0F || x3000.Type == 0xFF) ? 1 : 0); if (x3000.GPSInfo.Available) { act.Latitude = x3000.GPSInfo.Latitude; act.Longitude = x3000.GPSInfo.Longitude; act.GpsUpdated = false; } }); } } if (x3000.GPSInfo.Available) { SaveGpsInfo(x3000.GPSInfo, equipment, obj.TerminalID, ("Security: " + x3000.Flag + GetPackageType(obj.ProtocolType))); } }
/// <summary> /// 处理定期报告信息 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x1001(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x1001 x1001 = new _0x1001(); x1001.Content = obj.MsgContent; x1001.Unpackage(); HandleEquipmentRuntime(equipment, x1001.WorkTime); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Signal = (x1001.CSQ_1 > 0 && x1001.CSQ_1 <= 31) ? x1001.CSQ_1 : ((x1001.CSQ_2 > 0 && x1001.CSQ_2 <= 31) ? x1001.CSQ_2 : byte.MinValue); // 去掉 0x1001 里面的运转时间更新 //if (x1001.WorkTime > 0) //{ act.AccumulativeRuntime = equipment.AccumulativeRuntime; act.Runtime = equipment.Runtime; //} // 更新0x1001里的定位信息 2015/09/09 23:29 if (x1001.Available_2) { act.Latitude = x1001.Latitude_2; act.Longitude = x1001.Longitude_2; } else if (x1001.Available_1) { act.Latitude = x1001.Latitude_1; act.Longitude = x1001.Longitude_1; } }); } } using (var posbll = new PositionBLL()) { var pos = GetGpsinfoFrom1001(x1001, true); if ((pos.Longitude > 0 && pos.Longitude < 180) && (pos.Latitude > 0 && pos.Latitude < 90)) { pos.Equipment = null == equipment ? (int?)null : equipment.id; pos.Terminal = obj.TerminalID; pos.StoreTimes = null == equipment ? 0 : equipment.StoreTimes; pos.Type = "Period report" + GetPackageType(obj.ProtocolType); posbll.Add(pos); } pos = GetGpsinfoFrom1001(x1001, false); if ((pos.Longitude > 0 && pos.Longitude < 180) && (pos.Latitude > 0 && pos.Latitude < 90)) { pos.Equipment = null == equipment ? (int?)null : equipment.id; pos.Terminal = obj.TerminalID; pos.StoreTimes = null == equipment ? 0 : equipment.StoreTimes; pos.Type = "Period report" + GetPackageType(obj.ProtocolType); posbll.Add(pos); } } }
/// <summary> /// 处理命令回复状态 /// </summary> /// <param name="tx300"></param> private void HandleCommandResponsed(TX300 tx300) { CommandInstance.Update(f => f.DestinationNo == tx300.TerminalID && f.Command == "0x" + CustomConvert.IntToDigit(tx300.CommandID, CustomConvert.HEX, 4) && f.ScheduleTime >= DateTime.Now.AddMinutes(-3) && f.Status >= (byte)CommandStatus.SentByTCP && f.Status <= (byte)CommandStatus.SentToDest, act => { act.Status = (byte)CommandStatus.Returned; }); }
private void HandleCommand(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { switch (obj.CommandID) { case 0x1000: Handle0x1000(obj, equipment, terminal); break; case 0x1001: HandleTerminalVersion(obj, terminal); Handle0x1001(obj, equipment, terminal); break; case 0x2000: Handle0x2000(obj, equipment, terminal); break; case 0x5000: Handle0x5000(obj, equipment, terminal); break; case 0x6000: break; case 0x6001: break; case 0x6004: break; case 0x6007: Handle0x6007(obj, equipment, terminal); break; case 0xBB00: HandleTerminalVersion(obj, terminal); break; case 0xBB0F: break; case 0xCC00: HandleTerminalVersion(obj, terminal); break; case 0xDD00: HandleTerminalVersion(obj, terminal); break; case 0xDD02: break; case 0xEE00: HandleTerminalVersion(obj, terminal); break; case 0xFF00: Handle0xFF00(obj, equipment, terminal); break; } }
/// <summary> /// 处理卫星服务器发过来的通讯信息数据。type=data,cmd=destination,data=数据内容 /// </summary> /// <returns></returns> private string HandleDataRequest() { var ret = ""; TX300 x300 = new TX300(); x300.Content = CustomConvert.GetBytes(data); x300.package_to_msg(); HandleDataStatus(x300); return(ret); }
/// <summary> /// 处理设备的开关机信息 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x5000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { // 发动机启动/关闭信息 _0x5000 x5000 = new _0x5000(); x5000.Type = obj.TerminalType; x5000.Content = obj.MsgContent; x5000.Unpackage(); HandleEquipmentRuntime(equipment, x5000.WorkTime); if (null != equipment) { string vol = format("G{0}0", ((int)Math.Floor(x5000.GeneratorVoltage * 10)).ToString("000")); using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Voltage = vol; if (x5000.GeneratorVoltage > 20.0) { // 开机的时候清空报警信息 2015/09/24 08:00 act.Alarm = ALARM; } if (x5000.GeneratorVoltage < 20) { act.Rpm = 0; } act.Runtime = equipment.Runtime; act.AccumulativeRuntime = equipment.AccumulativeRuntime; //if (x5000.WorkTime > 0) //{ // // 如果总运转时间大于等于当前服务器中保存的时间则更新,否则不更新 // if (x5000.WorkTime >= act.Runtime) // { // act.Runtime = (int)x5000.WorkTime; // } //} if (x5000.GPSInfo.Available) { act.Latitude = x5000.GPSInfo.Latitude; act.Longitude = x5000.GPSInfo.Longitude; act.GpsUpdated = false; } }); } } if (x5000.GPSInfo.Available) { SaveGpsInfo(x5000.GPSInfo, equipment, obj.TerminalID, "Eng.: " + x5000.State + GetPackageType(obj.ProtocolType)); } }
/// <summary> /// 处理保安命令 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x6007(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x6007 x6007 = new _0x6007(); x6007.Content = obj.MsgContent; x6007.Unpackage(); if (null != equipment) { EquipmentInstance.Update(f => f.id == equipment.id, act => { act.LockStatus = CustomConvert.GetHex(x6007.Code); }); } }
/// <summary> /// 获取CC00的返回数据 /// </summary> /// <param name="x300"></param> /// <returns></returns> private byte[] Get0xCC00(TX300 x300) { byte[] cc00 = new byte[23]; Buffer.BlockCopy(x300.Content, 0, cc00, 0, 17); cc00[0] = 0x17; cc00[7] = 0xFF; cc00[8] = 0xFF; // 心跳时间间隔,7分钟 cc00[17] = 0x07; WbsDateTime dt = new WbsDateTime(DateTime.Now); Buffer.BlockCopy(dt.DateTimeToByte, 0, cc00, 19, 4); dt = null; return(cc00); }
/// <summary> /// 处理EE00命令 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0xEE00(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0xEE00 xee00 = new _0xEE00(); xee00.Content = obj.MsgContent; xee00.Unpackage(); // 更新终端发送命令的结果 if (null != equipment && xee00.ErrorCommand.Equals("0x6007")) { // 更新锁车状态 using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.LockStatus = xee00.ErrorParamenter; }); } } // 更新命令的发送状态 using (var bll = new CommandBLL()) { bll.Update(f => f.DestinationNo == obj.TerminalID && f.Command == xee00.ErrorCommand && f.ScheduleTime >= DateTime.Now.AddMinutes(-3) && f.Status >= (byte)CommandStatus.SentByTCP && f.Status <= (byte)CommandStatus.SentToDest, act => { byte b = 0x10; switch (xee00.Error) { case 0x20: b = (byte)CommandStatus.EposFail; break; case 0x30: b = (byte)CommandStatus.EngNotStart; break; default: b = (byte)CommandStatus.NoFunction; break; } act.Status = b; }); } }
/// <summary> /// 处理0xEE00传回来的0x6007命令 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0xEE00(TX300 obj, TB_Equipment equipment) { _0xEE00 xee00 = new _0xEE00(); xee00.Content = obj.MsgContent; xee00.Unpackage(); if (xee00.ErrorCommand == "0x6007") { if (null != equipment) { EquipmentInstance.Update(f => f.id == equipment.id && f.Deleted == false, act => { act.LockStatus = xee00.ErrorParamenter; }); } } }
/// <summary> /// 处理DD00命令 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0xDD00(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0xDD00 xdd00 = new _0xDD00(); xdd00.Content = obj.MsgContent; xdd00.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Signal = xdd00.CSQ; }); } } //if (null != terminal) //{ // TerminalInstance.Update(f => f.id == terminal.id, act => { act.Firmware = xdd00.Firmware; }); //} }
/// <summary> /// 处理仪表盘数据 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x6000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x6000 x6000 = new _0x6000(); x6000.Content = obj.MsgContent; x6000.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Rpm = (short)x6000.RPM; // EPOS命令时清空报警 2015/09/24 08:00 act.Alarm = ALARM; }); } } }
/// <summary> /// 保存数据到历史记录表 /// </summary> /// <param name="tx300"></param> private void SaveTX300History(TX300 tx300, DateTime receiveTime, string mac_id) { TB_HISTORIES obj = DataInstance.GetObject(); obj.command_id = "0x" + CustomConvert.IntToDigit(tx300.CommandID, CustomConvert.HEX, 4); obj.mac_id = mac_id; obj.message_content = CustomConvert.GetHex(tx300.MsgContent); obj.message_type = 1; obj.package_id = tx300.PackageID; obj.protocol_type = tx300.ProtocolType; obj.protocol_version = tx300.ProtocolVersion; obj.receive_time = receiveTime; obj.sequence_id = tx300.SequenceID.ToString(); obj.server_port = 31875; obj.terminal_id = tx300.TerminalID; obj.terminal_type = tx300.TerminalType; obj.total_length = (short)tx300.TotalLength; obj.total_package = tx300.TotalPackage; DataInstance.Add(obj); }
/// <summary> /// 处理终端版本的信息 /// </summary> /// <param name="obj"></param> /// <param name="terminal"></param> private void HandleTerminalVersion(TX300 obj, TB_Terminal terminal) { // 处理终端版本信息 byte[] version = new byte[7]; byte rev = 0; if (obj.CommandID == 0xDD00) { Buffer.BlockCopy(obj.MsgContent, 1, version, 0, 7); } else if (obj.CommandID == 0x1001) { Buffer.BlockCopy(obj.MsgContent, 25, version, 0, 7); // revision rev = obj.MsgContent[32]; } else { Buffer.BlockCopy(obj.MsgContent, 0, version, 0, 7); } string ver = Encoding.ASCII.GetString(version); version = null; if (obj.CommandID == 0xBB00) { // revision string s = Encoding.ASCII.GetString(obj.MsgContent, 7, 2); rev = byte.Parse(s); } using (var bll = new TerminalBLL()) { bll.Update(f => f.id == terminal.id, act => { act.Firmware = ver; if (rev > 0) { act.Revision = rev; } }); } }
/// <summary> /// 处理DD02卫星功能命令 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0xDD02(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0xDD02 xdd02 = new _0xDD02(); xdd02.Content = obj.MsgContent; xdd02.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.SatelliteStatus = xdd02.Status; }); } } if (null != terminal) { using (var bll = new TerminalBLL()) { bll.Update(f => f.id == terminal.id, act => { act.SatelliteStatus = xdd02.Status; }); } } }
/// <summary> /// 处理报警信息 /// </summary> /// <param name="obj"></param> private void Handle0x2000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { // 报警 _0x2000 x2000 = new _0x2000(); x2000.Content = obj.MsgContent; x2000.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { if (x2000.AlarmBIN[0] == '1') { // Main Power Disconnect act.Voltage = "G0000"; // 主电断报警之后进入睡眠状态 act.OnlineStyle = (byte)LinkType.SLEEP; } // 同时更新设备的报警状态 2015/09/10 14:02 act.Alarm = x2000.AlarmBIN; if (x2000.GPSInfo.Available) { act.Latitude = x2000.GPSInfo.Latitude; act.Longitude = x2000.GPSInfo.Longitude; act.GpsUpdated = false; } }); } } long gps = -1; if (x2000.GPSInfo.Available) { gps = SaveGpsInfo(x2000.GPSInfo, equipment, obj.TerminalID, "Alarm report" + GetPackageType(obj.ProtocolType)); } // 保存报警信息 SaveAlarm(equipment, obj.TerminalID, gps, x2000.AlarmBIN); }
/// <summary> /// 处理保安命令 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x6007(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x6007 x6007 = new _0x6007(); x6007.Content = obj.MsgContent; x6007.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.LockStatus = CustomConvert.GetHex(x6007.Code); if (obj.TerminalType == Protocol.TerminalTypes.DH || obj.TerminalType == Protocol.TerminalTypes.DX) { // EPOS命令时清空报警 2015/09/24 08:00 act.Alarm = ALARM; } }); } } }