/// <summary> /// 判断持续未定位状态时发送重启GPS指令:暂时未用 /// </summary> /// <param name="aLongHanDataGpsData"></param> /// <param name="aDicIsGPSLocaated"></param> /// <param name="Time"></param> /// <returns></returns> public bool IsSendRsgsMessage(LongHanData aLongHanDataGpsData, Dictionary<string, DateTime> aDicIsGPSLocated, double Time) { if (aLongHanDataGpsData.BaseData.IsLocatedData) { if (aDicIsGPSLocated.ContainsKey(aLongHanDataGpsData.BaseData.GPSCode)) { aDicIsGPSLocated[aLongHanDataGpsData.BaseData.GPSCode] = aLongHanDataGpsData.BaseData.ReceiveTime; } } else { if (!aDicIsGPSLocated.ContainsKey(aLongHanDataGpsData.BaseData.GPSCode)) aDicIsGPSLocated.Add(aLongHanDataGpsData.BaseData.GPSCode, aLongHanDataGpsData.BaseData.ReceiveTime); } return false; }
/// <summary> 解析正常位置上报GPS数据 /// 解析正常位置上报GPS数据 /// </summary> /// <param name="value"></param> /// <param name="MaxSpeedMeterPerSecond"></param> /// <returns></returns> public LongHanData DecodeGPSData(byte[] value, double MaxSpeedMeterPerSecond) { LongHanData aGPSInfo = new LongHanData(); aGPSInfo = ConvertBytesToEntity(value); aGPSInfo.BaseData.IsFetchData = false; aGPSInfo.FullGpsCode = base.CodePrefix + aGPSInfo.BaseData.GPSCode; if (value.Length > 49) { int pExtensionPos = 43; while (true) { bool blnFindExtension = false; if (value[pExtensionPos + 1] == 0x05 && value[pExtensionPos + 3] == 0x01) { int pOilBegin = pExtensionPos + 4; if (value[pOilBegin] == 0xFF && value[pOilBegin + 1] == 0xFF && value[pOilBegin + 2] == 0xFF) aGPSInfo.BaseData.OilBearing = 0; else aGPSInfo.BaseData.OilBearing = (decimal)GetOilBearing(value[pOilBegin], value[pOilBegin + 1], value[pOilBegin + 2]); pExtensionPos = pExtensionPos + 7; blnFindExtension = true; } if (value[pExtensionPos + 1] == 0x0A && value[pExtensionPos + 3] == 0x03) { int pTempatureBegin = pExtensionPos + 4; aGPSInfo.BaseData.Detector1 = GetTemperature(value[pTempatureBegin], value[pTempatureBegin + 1]); aGPSInfo.BaseData.Detector2 = GetTemperature(value[pTempatureBegin + 2], value[pTempatureBegin + 3]); aGPSInfo.BaseData.Detector3 = GetTemperature(value[pTempatureBegin + 4], value[pTempatureBegin + 5]); aGPSInfo.BaseData.Detector4 = GetTemperature(value[pTempatureBegin + 6], value[pTempatureBegin + 7]); pExtensionPos = pExtensionPos + 12; blnFindExtension = true; } //Added by lixun on 2010/12/6 Ticket #2652 新协议升级后,80和8E除了主信令不一样外其它格式内容都一样,获取4字节里程 //老的补传协议不会有扩展数据固定32个字节 if (value[pExtensionPos + 1] == 0x06 && value[pExtensionPos + 3] == 0x88) { int starkMileage = pExtensionPos + 4; aGPSInfo.BaseData.StarkMileage = (decimal)GetMileage(value[starkMileage], value[starkMileage + 1], value[starkMileage + 2], value[starkMileage + 3]); pExtensionPos = pExtensionPos + 8; blnFindExtension = true; base.OnDebugDataEvent(base.TransfersType.ToString(), aGPSInfo.FullGpsCode, "-----4 bytes mileage:" + aGPSInfo.BaseData.StarkMileage.ToString()); } //判断是否扩展数据已经解析结束,因为扩展数据指令长度固定为4位 if (value.Length - pExtensionPos <= 4) { blnFindExtension = false; } if (!blnFindExtension) { break; } } } //aGPSInfo.AbsoluteMileage = 0; aGPSInfo.BaseData.IsOverflowGPSData = false; //判断停车时间是否延长发送时间 aGPSInfo.BaseData.IsStartStopCarTime = false; aGPSInfo.BaseData.IsSendLongIntervalMessage = false; aGPSInfo.BaseData.StartStopCarTime = aGPSInfo.BaseData.ReportTime; aGPSInfo.BaseData.ControlTime = System.DateTime.Now; return aGPSInfo; }
/// <summary> /// 将收到的字节数组转换为对应的实体 /// </summary> /// <param name="sourceBuffer"></param> /// <returns></returns> private LongHanData ConvertBytesToEntity(byte[] sourceBuffer) { bool hasPotTrunFunction = false; LongHanData data = new LongHanData(); GPSDataEntity entity = new GPSDataEntity(); //GPSCode byte[] destBuffer = null; destBuffer = new byte[4]; Array.Copy(sourceBuffer, 5, destBuffer, 0, 4); entity.GPSCode = GetGPSCode(destBuffer); //entity.GPSCode = LongHanInstructionSet.GetLongHanGpsCode(sourceBuffer); if (gpsFuctionDictionary != null && gpsFuctionDictionary.ContainsKey(ConstFunctionName.PotTrunFunction) && gpsFuctionDictionary[ConstFunctionName.PotTrunFunction].Contains("0013" + entity.GPSCode)) { hasPotTrunFunction = true; } //ReportTime,ReceiveTime destBuffer = new byte[6]; Array.Copy(sourceBuffer, 9, destBuffer, 0, 6); entity.ReportTime = Transfer.TransferBCDByteToDateTime(destBuffer); entity.ReceiveTime = DateTime.Now; //Latitude destBuffer = new byte[4]; Array.Copy(sourceBuffer, 15, destBuffer, 0, 4); entity.Latitude = (decimal)ReturnLatitude(GetLatitude(destBuffer), GetLatitudeMinute(destBuffer)); //Longitude destBuffer = new byte[4]; Array.Copy(sourceBuffer, 19, destBuffer, 0, 4); entity.Longitude = (decimal)ReturnLongitude(GetLongitude(destBuffer), GetLongitudeMinute(destBuffer)); //Speed destBuffer = new byte[2]; Array.Copy(sourceBuffer, 23, destBuffer, 0, 2); entity.Speed = GetSpeed(destBuffer); //Direction destBuffer = new byte[2]; Array.Copy(sourceBuffer, 25, destBuffer, 0, 2); entity.Direction = GetDirection(destBuffer); //PositionState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 27, destBuffer, 0, 1); entity.IsLocatedData = GetPositionState(destBuffer); //AntennaState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 27, destBuffer, 0, 1); entity.AntennaState = (int)GetAntennaState(destBuffer); //PowerState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 27, destBuffer, 0, 1); entity.PowerState = (int)GetPowerState(destBuffer); if (sourceBuffer.Length > 30) { //Mileage destBuffer = new byte[3]; Array.Copy(sourceBuffer, 28, destBuffer, 0, 3); entity.StarkMileage = (decimal)GetMileage(destBuffer); //ACCState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 31, destBuffer, 0, 1); entity.ACCState = GetACCState(destBuffer); //OilState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 31, destBuffer, 0, 1); entity.OilState = GetOilState(destBuffer); //updated for lixun on 2012/12/16 调整过后默认为0--关门,当低电接负线后更改为1--开门 //entity.DoorStatus = GetDoorStatus(destBuffer); if (GetDoorStatus(destBuffer) > 0) entity.DoorStatus = 0; else entity.DoorStatus = 1; //updated by lixun on 2010/11/23 for solve Ticket #2658 if (GetCoolerStatus(destBuffer) > 0) entity.CoolerStatus = 0; else entity.CoolerStatus = 1; if (sourceBuffer.Length > 32) { //PlunderState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 32, destBuffer, 0, 1); entity.PlunderState = GetPlunderState(destBuffer); //ExtensionData destBuffer = new byte[sourceBuffer.Length - 31]; Array.Copy(sourceBuffer, 31, destBuffer, 0, (sourceBuffer.Length - 31)); } //若已经关联了正反转相关外设,则解析正反转,并存到开门报警字段 if (hasPotTrunFunction && sourceBuffer.Length > 34) { destBuffer = new byte[1]; Array.Copy(sourceBuffer, 31, destBuffer, 0, 1); byte[] destBuffer1 = new byte[1]; Array.Copy(sourceBuffer, 34, destBuffer1, 0, 1); entity.DoorStatus = GetPotTrunStatus(destBuffer, destBuffer1); switch (entity.DoorStatus) { case 0: OnDebugDataEvent("------", "0013" + entity.GPSCode, "不转"); break; case 1: OnDebugDataEvent("------", "0013" + entity.GPSCode, "正转"); break; case 2: OnDebugDataEvent("------", "0013" + entity.GPSCode, "反转"); break; } } } data.BaseData = entity; return data; }
/// <summary> /// 检查异常漂移,补传数据 /// </summary> private void ComputeMileAgeAndVerifyDataForFetch(ref LongHanData aGPSInfo, double MaxSpeedMeterPerSecond) { if (aGPSInfo == null) { return; } if (aGPSInfo.BaseData.IsLocatedData) { aGPSInfo.BaseData.IsFetchData = true; } }
///// <summary> ///// 检查异常漂移 ///// </summary> ///// <param name="aGPSInfo"></param> ///// <param name="aPreviousValidGPSData"></param> ///// <param name="MaxSpeedMeterPerSecond"></param> //private void ComputeMileAgeAndVerifyData( // ref object obj, // LongHanData aPreviousValidGPSData, // double MaxSpeedMeterPerSecond) //{ // LongHanData aGPSInfo = obj as LongHanData; // if (aGPSInfo == null) // { // return; // } // if (aGPSInfo.IsGPSLocaated) // { // bool blnIsFirstGPSData = false; // if (aPreviousValidGPSData == null) // { // blnIsFirstGPSData = true; // } // System.TimeSpan dtSpan; // double dclMileage = 0; // bool blnIsGPSOverflow = false; // bool blnShoudBeStillness = false; //是否要记录里程 // bool blnIsArrivalDelayed = false; //是否前条时间超过后一条时间 // if (!blnIsFirstGPSData) // { // if (DateTime.Compare(aGPSInfo.ReportTime, aPreviousValidGPSData.ReportTime) <= 0) // { // blnIsArrivalDelayed = true; // } // double CurrentLatitude = Convert.ToDouble(aGPSInfo.Latitude);//上一点纬度 // double CurrentLongitude = Convert.ToDouble(aGPSInfo.Longitude);//上一点经度 // double LastLatitude = Convert.ToDouble(aPreviousValidGPSData.Latitude); // double LastLongitude = Convert.ToDouble(aPreviousValidGPSData.Longitude); // if ((CurrentLatitude != LastLatitude) || (CurrentLongitude != LastLongitude)) // { // dclMileage = GPSCommonFunc.GetDistance(LastLatitude, LastLongitude, CurrentLatitude, CurrentLongitude); // } // dtSpan = aGPSInfo.ReportTime - aPreviousValidGPSData.ReportTime; // double dclMaxMileage = Math.Abs(Convert.ToDouble(MaxSpeedMeterPerSecond * dtSpan.TotalSeconds)); // if (dclMileage > dclMaxMileage) // { // //异常:GPS漂移数据 // blnIsGPSOverflow = true; // aGPSInfo.IsOverflowGPSData = blnIsGPSOverflow; // } // //对速度的判断 // if (aGPSInfo.Speed > (MaxSpeedMeterPerSecond * 3.6)) // { // blnIsGPSOverflow = true; // aGPSInfo.IsOverflowGPSData = blnIsGPSOverflow; // } // //是否要记录里程 // if ((aGPSInfo.Speed == 0) && (aPreviousValidGPSData.Speed == 0) && (dtSpan.TotalMinutes < 30)) // { // blnShoudBeStillness = true; // } // #region 因停车时间延长判断 // //判断停车时间是否要重新设置上报时间 // if ((aGPSInfo.Speed == 0) && (aPreviousValidGPSData.Speed == 0) && (aGPSInfo.ACCState == 0) && (aPreviousValidGPSData.ACCState == 0)) // { // if (aPreviousValidGPSData.IsStartStopCarTime) // { // aGPSInfo.IsStartStopCarTime = true; // aGPSInfo.StartStopCarTime = aPreviousValidGPSData.StartStopCarTime; //保存上一个停车时间点 // TimeSpan StopCarTime = aGPSInfo.ReportTime - aPreviousValidGPSData.StartStopCarTime; // if (StopCarTime.TotalMinutes > LongIntervalTimes) // { // aGPSInfo.IsSendLongIntervalMessage = true; // } // } // else // { // aGPSInfo.StartStopCarTime = aPreviousValidGPSData.ReportTime; // aGPSInfo.IsStartStopCarTime = true; // } // } // else // { // aGPSInfo.StartStopCarTime = aGPSInfo.ReportTime; // aGPSInfo.IsStartStopCarTime = false; // aGPSInfo.IsSendLongIntervalMessage = false; // } // #endregion // aGPSInfo.AbsoluteMileage = aPreviousValidGPSData.AbsoluteMileage; // aGPSInfo.ControlTime = aPreviousValidGPSData.ControlTime; // } // if (((!blnIsGPSOverflow) && (!blnIsFirstGPSData) && (!blnShoudBeStillness)) && (!blnIsArrivalDelayed)) // { // aGPSInfo.Mileage = dclMileage; // aGPSInfo.AbsoluteMileage = aGPSInfo.AbsoluteMileage + aGPSInfo.Mileage; // } // } //} #endregion /// <summary> /// 检查异常漂移,正常数据 /// </summary> private void ComputeMileAgeAndVerifyData(ref LongHanData aGPSInfo, GPSDataEntity aPreviousValidGPSData, double MaxSpeedMeterPerSecond) { if (aGPSInfo == null || aGPSInfo.BaseData.IsLocatedData == false) { return; } //是否是第一个上的点 bool blnIsFirstGPSData = false; if (aPreviousValidGPSData == null) { blnIsFirstGPSData = true; } TimeSpan dtSpan; double dclMileage = 0; //是第一个点则返回,不做漂移计算 if (blnIsFirstGPSData == true) { return; } double CurrentLatitude = Convert.ToDouble(aGPSInfo.BaseData.Latitude);//上一点纬度 double CurrentLongitude = Convert.ToDouble(aGPSInfo.BaseData.Longitude);//上一点经度 double LastLatitude = Convert.ToDouble(aPreviousValidGPSData.Latitude); double LastLongitude = Convert.ToDouble(aPreviousValidGPSData.Longitude); if ((CurrentLatitude != LastLatitude) || (CurrentLongitude != LastLongitude)) { dclMileage = Transfer.GetDistance(LastLatitude, LastLongitude, CurrentLatitude, CurrentLongitude); } dtSpan = aGPSInfo.BaseData.ReportTime - aPreviousValidGPSData.ReportTime; double dclMaxMileage = Math.Abs(Convert.ToDouble(MaxSpeedMeterPerSecond * dtSpan.TotalSeconds)); if (dclMileage > dclMaxMileage) { //异常:GPS漂移数据 aGPSInfo.BaseData.IsOverflowGPSData = true; //当发生漂移,认为是补传数据 } //对速度的判断 if (aGPSInfo.BaseData.Speed > 150) { aGPSInfo.BaseData.IsOverflowGPSData = true; //当发生漂移,认为是补传数据 } #region 因停车时间延长判断 //判断停车时间是否要重新设置上报时间 if ((aGPSInfo.BaseData.Speed == 0) && (aPreviousValidGPSData.Speed == 0) && (aGPSInfo.BaseData.ACCState == 0) && (aPreviousValidGPSData.ACCState == 0)) { if (aPreviousValidGPSData.IsStartStopCarTime) { aGPSInfo.BaseData.IsStartStopCarTime = true; aGPSInfo.BaseData.StartStopCarTime = aPreviousValidGPSData.StartStopCarTime; //保存上一个停车时间点 TimeSpan StopCarTime = aGPSInfo.BaseData.ReportTime - aPreviousValidGPSData.StartStopCarTime; if (StopCarTime.TotalMinutes > LongIntervalTimes) { aGPSInfo.BaseData.IsSendLongIntervalMessage = true; } } else { aGPSInfo.BaseData.StartStopCarTime = aPreviousValidGPSData.ReportTime; aGPSInfo.BaseData.IsStartStopCarTime = true; } } else { aGPSInfo.BaseData.StartStopCarTime = aGPSInfo.BaseData.ReportTime; aGPSInfo.BaseData.IsStartStopCarTime = false; aGPSInfo.BaseData.IsSendLongIntervalMessage = false; } #endregion aGPSInfo.BaseData.Mileage = (decimal)dclMileage; }
/// <summary> 解析正常位置上报GPS数据 /// 解析正常位置上报GPS数据 /// </summary> /// <param name="value"></param> /// <param name="MaxSpeedMeterPerSecond"></param> /// <returns></returns> public LongHanData DecodeGPSData(byte[] value, double MaxSpeedMeterPerSecond,ref int NeedReply) { LongHanData aGPSInfo = new LongHanData(); aGPSInfo = ConvertBytesToEntity(value, ref NeedReply); aGPSInfo.BaseData.IsFetchData = false; aGPSInfo.FullGpsCode = base.CodePrefix + aGPSInfo.BaseData.GPSCode; if (value.Length > 49) { int pExtensionPos = 43; while (true) { bool blnFindExtension = false; if (value[pExtensionPos + 1] == 0x05) { int pOilBegin = pExtensionPos + 4; aGPSInfo.BaseData.OilBearing = (decimal)GetOilBearing(value[pOilBegin], value[pOilBegin + 1], value[pOilBegin + 2]); pExtensionPos = pExtensionPos + 7; blnFindExtension = true; } if (value[pExtensionPos + 1] == 0x0A) { int pTempatureBegin = pExtensionPos + 4; aGPSInfo.BaseData.Detector1 = GetTemperature(value[pTempatureBegin], value[pTempatureBegin + 1]); aGPSInfo.BaseData.Detector2 = GetTemperature(value[pTempatureBegin + 2], value[pTempatureBegin + 3]); aGPSInfo.BaseData.Detector3 = GetTemperature(value[pTempatureBegin + 4], value[pTempatureBegin + 5]); aGPSInfo.BaseData.Detector4 = GetTemperature(value[pTempatureBegin + 6], value[pTempatureBegin + 7]); pExtensionPos = pExtensionPos + 12; blnFindExtension = true; } //判断是否扩展数据已经解析结束 if (value.Length - pExtensionPos >= 1) { blnFindExtension = false; } if (!blnFindExtension) { break; } } } //aGPSInfo.AbsoluteMileage = 0; aGPSInfo.BaseData.IsOverflowGPSData = false; //判断停车时间是否延长发送时间 aGPSInfo.BaseData.IsStartStopCarTime = false; aGPSInfo.BaseData.IsSendLongIntervalMessage = false; aGPSInfo.BaseData.StartStopCarTime = aGPSInfo.BaseData.ReportTime; aGPSInfo.BaseData.ControlTime = System.DateTime.Now; return aGPSInfo; }
/// <summary> /// 将收到的字节数组转换为对应的实体 /// </summary> /// <param name="sourceBuffer"></param> /// <returns></returns> private LongHanData ConvertBytesToEntity(byte[] sourceBuffer,ref int NeedReply) { LongHanData data = new LongHanData(); GPSDataEntity entity = new GPSDataEntity(); //GPSCode byte[] destBuffer = null; destBuffer = new byte[4]; Array.Copy(sourceBuffer, 5, destBuffer, 0, 4); entity.GPSCode = GetGPSCode(destBuffer); //entity.GPSCode = LongHanInstructionSet.GetLongHanGpsCode(sourceBuffer); //ReportTime,ReceiveTime destBuffer = new byte[6]; Array.Copy(sourceBuffer, 9, destBuffer, 0, 6); entity.ReportTime = Transfer.TransferBCDByteToDateTime(destBuffer); entity.ReceiveTime = DateTime.Now; //Latitude destBuffer = new byte[4]; Array.Copy(sourceBuffer, 15, destBuffer, 0, 4); entity.Latitude = (decimal)ReturnLatitude(GetLatitude(destBuffer), GetLatitudeMinute(destBuffer)); //Longitude destBuffer = new byte[4]; Array.Copy(sourceBuffer, 19, destBuffer, 0, 4); entity.Longitude = (decimal)ReturnLongitude(GetLongitude(destBuffer), GetLongitudeMinute(destBuffer)); //Speed destBuffer = new byte[2]; Array.Copy(sourceBuffer, 23, destBuffer, 0, 2); entity.Speed = GetSpeed(destBuffer); //Direction destBuffer = new byte[2]; Array.Copy(sourceBuffer, 25, destBuffer, 0, 2); entity.Direction = GetDirection(destBuffer); //PositionState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 27, destBuffer, 0, 1); entity.IsLocatedData = GetPositionState(destBuffer); //AntennaState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 27, destBuffer, 0, 1); entity.AntennaState = (int)GetAntennaState(destBuffer); //PowerState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 27, destBuffer, 0, 1); entity.PowerState = (int)GetPowerState(destBuffer); //Mileage destBuffer = new byte[3]; Array.Copy(sourceBuffer, 28, destBuffer, 0, 3); //updated by lixun on 2011/7/5 #3507 [技术支持]龙翰里程问题,改由平台计算里程 //entity.StarkMileage = (decimal)GetMileage(destBuffer); //ACCState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 31, destBuffer, 0, 1); entity.ACCState = GetACCState(destBuffer); //OilState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 31, destBuffer, 0, 1); entity.OilState = GetOilState(destBuffer); //entity.DoorStatus = GetDoorStatus(destBuffer); //entity.CoolerStatus = GetCoolerStatus(destBuffer); //updated for lixun on 2012/12/16 调整过后默认为0--关门,当低电接负线后更改为1--开门 if (GetDoorStatus(destBuffer) > 0) entity.DoorStatus = 0; else entity.DoorStatus = 1; //updated by lixun on 2010/11/23 for solve Ticket #2658 if (GetCoolerStatus(destBuffer) > 0) entity.CoolerStatus = 0; else entity.CoolerStatus = 1; //PlunderState destBuffer = new byte[1]; Array.Copy(sourceBuffer, 32, destBuffer, 0, 1); entity.PlunderState = GetPlunderState(destBuffer); destBuffer = new byte[1]; Array.Copy(sourceBuffer, 33, destBuffer, 0, 1); NeedReply = Transfer.GetByteIndexValue(destBuffer[0], 6); //ExtensionData destBuffer = new byte[sourceBuffer.Length - 31]; Array.Copy(sourceBuffer, 31, destBuffer, 0, (sourceBuffer.Length - 31)); data.BaseData = entity; return data; }