private string SaveGPX(ActivityKeymaze in_activity) { if (in_activity == null) return ""; string strFileName = m_strDirectory + "\\" + in_activity.m_dStart.ToString("yyyyMMdd") + ".gpx"; NumberFormatInfo nfi = new NumberFormatInfo(); nfi.NumberDecimalSeparator = "."; string strData = ""; try { StreamWriter file = new StreamWriter(strFileName); file.WriteLine("<?xml version=\"1.0\"?>\n"); file.WriteLine("<gpx 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\">\n"); file.WriteLine("<extensions>\n"); strData = "<st:activity id=\""; strData += in_activity.m_iID.ToString(); strData += "\" created=\""; strData += in_activity.m_dStart.ToString("yyyy-MM-ddTHH:mm:ssZ"); strData += "\" startTime=\""; strData += in_activity.m_dStart.ToString("yyyy-MM-ddTHH:mm:ssZ"); strData += "\" hasStartTime=\"true\" distanceEntered=\""; strData += in_activity.m_dDistance.ToString("F06", nfi); strData += "\" timeEntered=\""; strData += in_activity.m_dTime.ToString("HH:mm:ss"); strData += "\" calories=\""; strData += in_activity.m_iCalories.ToString(); strData += "\">\n"; file.WriteLine(strData); file.WriteLine(" <st:heartRateTrack>\n"); int nMarks = in_activity.m_lstMarks.Count; for (int iMark = 0; iMark < nMarks; iMark++) { Mark oMark = (Mark)in_activity.m_lstMarks[iMark]; if (oMark == null) continue; int iBpm = (int)oMark.m_dHeartRate; strData = " <st:heartRate time=\""; strData += oMark.m_dTime.ToString("yyyy-MM-ddTHH:mm:ssZ"); strData += "\" bpm=\""; strData += iBpm.ToString(); strData += "\" />\n"; file.WriteLine(strData); } file.WriteLine(" </st:heartRateTrack>\n"); file.WriteLine(" </st:activity>\n"); file.WriteLine(" </extensions>\n"); file.WriteLine("<trk>\n"); strData = "<name>"; strData += in_activity.m_iID.ToString("D3"); strData += "-"; strData += in_activity.m_dStart.ToString("yyyy/MM/dd-HH:mm:ss"); strData += "</name>\n"; file.WriteLine(strData); file.WriteLine("<number>1</number>\n"); file.WriteLine("<trkseg>\n"); for (int iMark = 0; iMark < nMarks; iMark++) { Mark oMark = (Mark)in_activity.m_lstMarks[iMark]; if (oMark == null) continue; strData = "<trkpt lat=\""; strData += oMark.m_dLati.ToString("F06", nfi); strData += "\" lon=\""; strData += oMark.m_dLongi.ToString("F06", nfi); strData += "\"><ele>"; strData += oMark.m_dElevation.ToString("F01", nfi); strData += "</ele><speed>"; strData += oMark.m_dSpeed.ToString("F01", nfi); strData += "</speed><time>"; strData += oMark.m_dTime.ToString("yyyy-MM-ddTHH:mm:ssZ"); strData += "</time>\n"; file.WriteLine(strData); file.WriteLine("</trkpt>\n"); } file.WriteLine("</trkseg>\n"); file.WriteLine("</trk>\n"); file.WriteLine("</gpx>"); file.Close(); } catch (Exception e) { Debug.WriteLine(e.ToString()); } return strFileName; }
public ArrayList GetActivities() { byte[] buffer = null; if (m_eMode == eMode.eDevice) buffer = RequestDevice(CMD_TP_DIR, -1, null); else buffer = ReadLog(1); if (buffer == null) return null; MemoryStream stream = new MemoryStream(buffer); BinaryReader reader = new BinaryReader(stream); ArrayList lstActivities = new ArrayList(); while (reader.BaseStream.Position + 31 <= reader.BaseStream.Length) { ActivityKeymaze activity = new ActivityKeymaze(); int y = 2000 + (int)reader.ReadByte(); int m = reader.ReadByte(); int d = reader.ReadByte(); int h = reader.ReadByte(); int min = reader.ReadByte(); int s = reader.ReadByte(); reader.ReadByte(); double dTime = (double)Swap(reader.ReadInt32()) / 10.0; activity.m_dDistance = Swap(reader.ReadInt32()); activity.m_iCalories = Swap(reader.ReadInt16()); activity.m_dMaxSpeed = Swap(reader.ReadInt16()); activity.m_dMaxHeart = reader.ReadByte(); activity.m_dAvgHeart = reader.ReadByte(); reader.ReadBytes(6); activity.m_iTrack = Swap(reader.ReadInt16()); activity.m_iID = Swap(reader.ReadInt16()); TimeZone timeZone = TimeZone.CurrentTimeZone; activity.m_dStart = timeZone.ToUniversalTime(new DateTime(y, m, d, h, min, s)); activity.m_dTime = new DateTime(y, m, d, 0, 0, 0); activity.m_dTime = activity.m_dTime.AddSeconds(dTime); lstActivities.Add(activity); } return lstActivities; }
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); }