private bool ParseText(string info, float offsetX, float offsetY) { try { _info = info; string[] parts = info.Split(new[] { ',' }); int length = parts.Length; if (length <= 1) { return(false); //心跳包回拨 } Code = parts[0]; //if (Code.StartsWith("1")) //{ // LogEvent.Info("RealPos,", "Code.StartsWith(1):" + info); //} if (parts[1] == "-1.#IND0") { parts[1] = "-1.0"; } if (parts[2] == "-1.#IND0") { parts[2] = "-1.0"; } float x = parts[1].ToFloat() * AppSetting.PositionPower; float y = parts[2].ToFloat() * AppSetting.PositionPower; if (x < offsetX) { X = x + offsetX; //平面位置 Z = y + offsetY; //平面位置 } else //模拟数据是可以没有偏移量的 看模拟程序的版本 { X = x; Z = y; } Y = parts[3].ToFloat() * AppSetting.PositionPower;//高度位置,为了和Unity坐标信息一致,Y为高度轴 DateTimeStamp = parts[4].ToLong(); DateTime = TimeConvert.ToDateTime(DateTimeStamp); //TimeSpan time1 = DateTime.Now - DateTime; //long DateTimeStamp2 = TimeConvert.DateTimeToTimeStamp(DateTime); if (length > 5) { Power = parts[5].ToInt(); if (Power >= AppSetting.LowPowerFlag) { PowerState = 0; } else { PowerState = 1; } } if (length > 6) { Number = parts[6].ToInt(); } if (length > 7) { Flag = parts[7]; } if (length > 8) { ArchorsText = parts[8]; Archors = ArchorsText.Split(new[] { '@' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (Archors.Count > 1) { Console.Write("Archors.Count > 1"); } IsSimulate = ArchorsText == "@0000" || string.IsNullOrEmpty(ArchorsText); } //if (Code == "092D" && (ArchorsText == null || Archors == null)) //{ // int i = 0; //} if (length > 8) { } //else if(length == 8) //{ //} else { LogEvent.Info("位置信息数据可能被截断!!!!:" + info); //return false; } return(true); } catch (Exception ex) { LogEvent.Info("定位数据解析失败:" + info + "\n" + ex.ToString()); return(false); } }
/// <summary> /// 解析位置信息 /// </summary> /// <param name="info"></param> /// <param name="offsetX">偏移量X 和定位引擎约定好具体偏移数值</param> /// <param name="offsetY">偏移量Y 和定位引擎约定好具体偏移数值</param> /// <returns></returns> public bool Parse(string info, float offsetX, float offsetY) { try { _info = info; string[] parts = info.Split(new[] { ',' }); int length = parts.Length; if (length <= 1) { return(false); //心跳包回拨 } Code = parts[0]; if (Code.StartsWith("1")) { LogEvent.Info("Code.StartsWith(1):" + info); } if (parts[1] == "-1.#IND0") { parts[1] = "-1.0"; } if (parts[2] == "-1.#IND0") { parts[2] = "-1.0"; } float x = parts[1].ToFloat(); float y = parts[2].ToFloat(); if (x < offsetX) { X = x + offsetX; //平面位置 Z = y + offsetY; //平面位置 } else //模拟数据是可以没有偏移量的 看模拟程序的版本 { X = x; Z = y; } Y = parts[3].ToFloat();//高度位置,为了和Unity坐标信息一致,Y为高度轴 DateTimeStamp = parts[4].ToLong(); DateTime = TimeConvert.TimeStampToDateTime(DateTimeStamp); //TimeSpan time1 = DateTime.Now - DateTime; //long DateTimeStamp2 = TimeConvert.DateTimeToTimeStamp(DateTime); if (length > 5) { Power = parts[5].ToInt(); } if (length > 6) { Number = parts[6].ToInt(); } if (length > 7) { Flag = parts[7]; } if (length > 8) { ArchorsText = parts[8]; Archors = ArchorsText.Split(new [] { '@' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (Archors.Count > 1) { Console.Write("Archors.Count > 1"); } IsSimulate = ArchorsText == "@0000" || string.IsNullOrEmpty(ArchorsText); } if (Power >= 400) { PowerState = 0; } else { PowerState = 1; } return(true); } catch (Exception ex) { LogEvent.Info(ex.ToString()); return(false); } }