public void AddMark(double in_dLongi, double in_dLati) { RunnerData oData = GetRunnerData(m_iSel); if (oData == null) return; if (oData.m_eType != RunnerData.eRunnerData.eRS200) return; Mark oLatLong = null; if (m_nMarks < m_lstMarks.Count) oLatLong = (Mark)m_lstMarks[m_nMarks]; if (oLatLong == null) { oLatLong = new Mark(); m_lstMarks.Add(oLatLong); } m_nMarks++; oLatLong.m_dLongi = in_dLongi; oLatLong.m_dLati = in_dLati; }
public string GetTrackpoint(ActivityKeymaze in_activity) { byte[] buffer = null; if (m_eMode == eMode.eDevice) buffer = RequestDevice(CMD_TP_GET_HDR, in_activity.m_iTrack, null); else buffer = ReadLog(2); if (buffer == null) return ""; MemoryStream stream = new MemoryStream(buffer); BinaryReader reader = new BinaryReader(stream); reader.ReadBytes(25); int nMarks = Swap(reader.ReadInt16()); byte[] lstReq = new byte[2]; lstReq[0] = ACK_TP_GET_NONE; lstReq[1] = CMD_TP_GET_HDR; DateTime dStart = in_activity.m_dStart; m_dProgress = 0.0; in_activity.m_lstMarks.Clear(); int iLine = 0; while (in_activity.m_lstMarks.Count < nMarks) { if (m_eMode == eMode.eDevice) buffer = RequestDevice(CMD_TP_GET_NEXT, -1, lstReq); else buffer = ReadLog(3 + iLine); iLine++; if (buffer == null) break; stream = new MemoryStream(buffer); reader = new BinaryReader(stream); reader.ReadBytes(31); Int16 iSpeed = 0; while (reader.BaseStream.Position + 15 <= reader.BaseStream.Length) { Mark oMark = new Mark(); oMark.m_dLati = Swap(reader.ReadInt32())/1000000.0; oMark.m_dLongi = Swap(reader.ReadInt32())/1000000.0; oMark.m_dElevation = Swap(reader.ReadInt16()); iSpeed = Swap(reader.ReadInt16()); if (iSpeed < 10000) oMark.m_dSpeed = iSpeed / 10.0; else oMark.m_dSpeed = (iSpeed / 1000 * 100) + iSpeed % 1000; oMark.m_dHeartRate = reader.ReadByte(); dStart = dStart.AddSeconds((double)Swap(reader.ReadInt16()) / 10.0); oMark.m_dTime = dStart; in_activity.m_lstMarks.Add(oMark); m_dProgress = 100.0 * in_activity.m_lstMarks.Count / nMarks ; } } m_dProgress = 100.0; return SaveGPX(in_activity); }
private object[] LoadTCXMarks(string in_strFileName) { if (in_strFileName == null) return null; m_lstMarks.Clear(); m_nMarks = 0; try { StreamReader file = new StreamReader(in_strFileName); string strBuffer = file.ReadToEnd(); file.Close(); strBuffer = strBuffer.Replace(" xmlns=\"http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd\"", ""); strBuffer = strBuffer.Replace("xsi:", ""); m_XmlDoc.LoadXml(strBuffer); Mark oMarkMin = new Mark(); Mark oMarkMax = new Mark(); oMarkMin.m_dLati = oMarkMin.m_dLongi = double.MaxValue; oMarkMax.m_dLati = oMarkMax.m_dLongi = double.MinValue; string strPath = "//TrainingCenterDatabase/Activities/Activity/Lap/"; DateTime dPrevTime = ReadNodeToDateTime(strPath + "@StartTime", "yyyy\\-MM\\-dd\\THH\\:mm\\:ss\\Z", true); double dPrevDist = 0.0; strPath = "//TrainingCenterDatabase/Activities/Activity/Lap/Track/Trackpoint"; XmlNodeList xmlNodes = m_XmlDoc.DocumentElement.SelectNodes(strPath); if (xmlNodes == null) return null; int nNodes = xmlNodes.Count; for (int iNode = 0; iNode < nNodes; iNode++) { Mark oMark = new Mark(); oMark.m_dLongi = ReadNodeToDouble(xmlNodes[iNode], "Position/LongitudeDegrees"); if (oMark.m_dLongi == 0.0) continue; oMark.m_dLati = ReadNodeToDouble(xmlNodes[iNode], "Position/LatitudeDegrees"); if (oMark.m_dLati == 0.0) continue; oMark.m_dElevation = ReadNodeToDouble(xmlNodes[iNode], "AltitudeMeters"); string strTime = ReadNode(xmlNodes[iNode], "Time"); oMark.m_dTime = ParseToDateTime(strTime, "yyyy\\-MM\\-dd\\THH\\:mm\\:ss\\Z", true); oMark.m_dHeartRate = ReadNodeToDouble(xmlNodes[iNode], "HeartRateBpm/Value"); double dDistance = ReadNodeToDouble(xmlNodes[iNode], "DistanceMeters") / 1000.0; TimeSpan oTimeSpan = oMark.m_dTime - dPrevTime; if (oTimeSpan.TotalHours > 0) oMark.m_dSpeed = (dDistance - dPrevDist) / (oTimeSpan.TotalHours); dPrevTime = oMark.m_dTime; dPrevDist = dDistance; m_lstMarks.Add(oMark); if (oMark.m_dLongi < oMarkMin.m_dLongi) oMarkMin.m_dLongi = oMark.m_dLongi; if (oMark.m_dLati < oMarkMin.m_dLati) oMarkMin.m_dLati = oMark.m_dLati; if (oMark.m_dLongi > oMarkMax.m_dLongi) oMarkMax.m_dLongi = oMark.m_dLongi; if (oMark.m_dLati > oMarkMax.m_dLati) oMarkMax.m_dLati = oMark.m_dLati; m_nMarks++; } if (nNodes > 1) { object[] oCoordinates = new object[2]; oCoordinates[0] = (oMarkMax.m_dLongi + oMarkMin.m_dLongi) / 2.0; oCoordinates[1] = (oMarkMax.m_dLati + oMarkMin.m_dLati) / 2.0; return oCoordinates; } } catch (Exception e) { Debug.WriteLine(e.ToString()); } return null; }
private object[] LoadKMLMarks(string in_strFileName) { if (in_strFileName == null) return null; string strFileName = in_strFileName.Replace(".xml", ".kml"); m_lstMarks.Clear(); m_nMarks = 0; string strBuffer = ""; try { StreamReader file = new StreamReader(strFileName); strBuffer = file.ReadToEnd(); file.Close(); } catch (Exception e) { Debug.WriteLine(e.ToString()); } string strStart = "<coordinates>"; string strEnd = "</coordinates>"; int iStart = strBuffer.IndexOf(strStart); int iEnd = strBuffer.IndexOf(strEnd); if (iStart < 0 || iEnd < 0) return null; iStart += strStart.Length; string strPts = strBuffer.Substring(iStart, iEnd - iStart); string[] lstSep = { ",0 " }; string[] lstMarks = strPts.Split(lstSep, StringSplitOptions.None); Mark oMarkMin = new Mark(); Mark oMarkMax = new Mark(); oMarkMin.m_dLati = oMarkMin.m_dLongi = double.MaxValue; oMarkMax.m_dLati = oMarkMax.m_dLongi = double.MinValue; for (int iPt = 0; iPt < lstMarks.Length; iPt++) { string[] lstPts = lstMarks[iPt].Split(','); if (lstPts.Length != 2) continue; m_nMarks++; Mark oMark = new Mark(); oMark.m_dLongi = ParseToDouble(lstPts[0]); oMark.m_dLati = ParseToDouble(lstPts[1]); m_lstMarks.Add(oMark); if (oMark.m_dLongi < oMarkMin.m_dLongi) oMarkMin.m_dLongi = oMark.m_dLongi; if (oMark.m_dLati < oMarkMin.m_dLati) oMarkMin.m_dLati = oMark.m_dLati; if (oMark.m_dLongi > oMarkMax.m_dLongi) oMarkMax.m_dLongi = oMark.m_dLongi; if (oMark.m_dLati > oMarkMax.m_dLati) oMarkMax.m_dLati = oMark.m_dLati; } if (lstMarks.Length > 1) { object[] oCoordinates = new object[2]; oCoordinates[0] = (oMarkMax.m_dLongi + oMarkMin.m_dLongi) / 2.0; oCoordinates[1] = (oMarkMax.m_dLati + oMarkMin.m_dLati) / 2.0; return oCoordinates; } return null; }
private object[] LoadGPXMarks(string in_strFileName) { if (in_strFileName == null) return null; m_lstMarks.Clear(); m_nMarks = 0; try { StreamReader file = new StreamReader(in_strFileName); string strBuffer = file.ReadToEnd(); file.Close(); strBuffer = strBuffer.Replace(" version=\"1.0\" creator=\"KeyMaze 500-700 PC Software\" xmlns:st=\"urn:uuid:D0EB2ED5-49B6-44e3-B13C-CF15BE7DD7DD\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/0\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\"", ""); strBuffer = strBuffer.Replace("st:", ""); m_XmlDoc.LoadXml(strBuffer); Mark oMarkMin = new Mark(); Mark oMarkMax = new Mark(); oMarkMin.m_dLati = oMarkMin.m_dLongi = double.MaxValue; oMarkMax.m_dLati = oMarkMax.m_dLongi = double.MinValue; string strPath = "//gpx/trk/trkseg/trkpt"; XmlNodeList xmlNodes = m_XmlDoc.DocumentElement.SelectNodes(strPath); if (xmlNodes == null) return null; string[] lstHR = ReadNodes("//gpx/extensions/activity/heartRateTrack/heartRate/@bpm"); int nNodes = xmlNodes.Count; for (int iNode = 0; iNode < nNodes; iNode++) { m_nMarks++; Mark oMark = new Mark(); oMark.m_dLongi = ReadNodeToDouble(xmlNodes[iNode], "@lon"); oMark.m_dLati = ReadNodeToDouble(xmlNodes[iNode], "@lat"); oMark.m_dElevation = ReadNodeToDouble(xmlNodes[iNode], "ele"); oMark.m_dSpeed = ReadNodeToDouble(xmlNodes[iNode], "speed") / 10.0; string strTime = ReadNode(xmlNodes[iNode], "time"); oMark.m_dTime = ParseToDateTime(strTime, "yyyy\\-MM\\-dd\\THH\\:mm\\:ss\\Z", true); oMark.m_dHeartRate = ParseToDouble(lstHR[iNode]); m_lstMarks.Add(oMark); if (oMark.m_dLongi < oMarkMin.m_dLongi) oMarkMin.m_dLongi = oMark.m_dLongi; if (oMark.m_dLati < oMarkMin.m_dLati) oMarkMin.m_dLati = oMark.m_dLati; if (oMark.m_dLongi > oMarkMax.m_dLongi) oMarkMax.m_dLongi = oMark.m_dLongi; if (oMark.m_dLati > oMarkMax.m_dLati) oMarkMax.m_dLati = oMark.m_dLati; } if (nNodes > 1) { object[] oCoordinates = new object[2]; oCoordinates[0] = (oMarkMax.m_dLongi + oMarkMin.m_dLongi) / 2.0; oCoordinates[1] = (oMarkMax.m_dLati + oMarkMin.m_dLati) / 2.0; return oCoordinates; } } catch (Exception e) { Debug.WriteLine(e.ToString()); } return null; }