private bool CheckValidPoint(GPSTrackPoint point) { if (point.GPSfix != 1 && point.GPSfix != 2) { SetStatusText("GPS not fixed."); point.SoftError = true; return false; } double L = Util.CalcDistance(prevLat, prevLon, point.Latitude, point.Longitude); if (L > 3000 && prevLat == 0 && prevLon == 0) { // 初期値 L = 0; prevDateTime = point.time; prevLat = point.Latitude; prevLon = point.Longitude; } // if ((L / (point.time - prevDateTime).TotalSeconds) > Util.GetMaxVelocity(cbIcon.SelectedIndex)) if (point.Velocity > Util.GetMaxVelocity(iconIndex)) { SetStatusText("速度が速すぎます"); point.SoftError = true; } else { if (point.Latitude != 0 && point.Longitude != 0 && L >= 10) { // 移動距離10m以上のデータなら移動中とみなして、累積移動距離を加算する distance += L; totalDistance += L; prevLat = point.Latitude; prevLon = point.Longitude; SetStatusText(""); } } return !point.SoftError; }
private void CheckInNoPostArea(GPSTrackPoint point) { inNoPost = false; noPostPointIndex = 0; if (point.Velocity >= 50) { // 時速50km以上なら非送信地帯無視 return; } Double radius; try { radius = Double.Parse(GetRadius()); } catch (Exception /* e */) { // 安全装置。非送信半径がおかしかったら1kmに設定する radius = 1000; } foreach (GPSPoint p in noPostPoint) { if (Util.CalcDistance(p.Latitude, p.Longitude, point.Latitude, point.Longitude) < radius) { inNoPost = true; break; } noPostPointIndex++; } }
private GPSTrackPoint SetupGpsData() { try { int idx = gpsLat.IndexOf("."); string min = gpsLat.Substring(idx - 2); string deg = gpsLat.Substring(0, idx - 2); Lat = Double.Parse(min) / 60 + Double.Parse(deg); } catch (Exception /*e*/) { Lat = 0; } if (latNS == "S") { Lat = -Lat; } try { int idx = gpsLon.IndexOf("."); Lon = Double.Parse(gpsLon.Substring(idx - 2)) / 60 + Double.Parse(gpsLon.Substring(0, idx - 2)); } catch (Exception /*e*/) { Lon = 0; } if (lonEW == "W") { Lon = -Lon; } Double.TryParse(gpsHDOP, out hdop); if (chkDebug.Checked) { // デバッグモード時、データを上書き valid = "A"; gpsLat = GetRandomGPSLat(); gpsLon = GetGPSLon(); Double.TryParse(gpsLat, out Lat); Double.TryParse(gpsLon, out Lon); gpsD = GetGPSDirection(); gpsStatus = "1"; } DateTime datetime; try { int dd = int.Parse(gpsDate.Substring(0, 2)); int mm = int.Parse(gpsDate.Substring(2, 2)); int yy = 2000 + int.Parse(gpsDate.Substring(4, 2)); int hh = int.Parse(gpsTime.Substring(0, 2)); int mi = int.Parse(gpsTime.Substring(2, 2)); int ss = int.Parse(gpsTime.Substring(4, 2)); int msec = int.Parse(gpsTime.Substring(7, 3)); datetime = new DateTime(yy, mm, dd, hh, mi, ss, msec, DateTimeKind.Utc).ToLocalTime(); } catch (Exception /*e*/) { datetime = DateTime.Now; } gpsTime = datetime.ToString("yyyy-MM-dd'T'HH:mm:ss.Fzzz"); Double.TryParse(gpsV, out Velocity); Velocity = Math.Round(Velocity * 1.852, 1); // 1knot = 1.852km/h GPSTrackPoint position = new GPSTrackPoint(); position.Latitude = Lat; position.Longitude = Lon; Double.TryParse(gpsH, out position.Height); position.time = datetime; position.Velocity = Velocity; int.TryParse(gpsStatus, out position.GPSfix); int.TryParse(gpsC, out position.SateliteCount); Double.TryParse(gpsD, out position.Direction); position.Valid = valid; position.SoftError = false; if (lastNMEATime == new DateTime()) { acc = 0.0D; } else { acc = (position.Velocity - prevVelocity) / (lastNMEATime - position.time).TotalSeconds; } lastNMEATime = position.time; prevVelocity = position.Velocity; return position; }
void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e) { switch (e.Mode) { case Microsoft.Win32.PowerModes.StatusChange: case Microsoft.Win32.PowerModes.Suspend: break; case Microsoft.Win32.PowerModes.Resume: lastPosition = null; lastValidPosition = null; userLocation = null; prevLocation = null; myLocation = null; lastPostTime = new DateTime(); lastNMEATime = new DateTime(); break; } }
private void parseNMEA(string TextRcv) { try { ++nmeaCount; if (!Util.IsValidSentense(TextRcv)) { // チェックサムが合わなかったらエラー SetStatusText("NMEA sentense CheckSum error"); ++sentenseErrorCount; SetCounterText(); return; } if (chkSaveLog.Checked) { swCommLog.WriteLine(TextRcv); } string data_tmp = TextRcv.Substring(0, 7); // 2009.09.19 Added by y3sei if (data_tmp == "$GPRMC," || data_tmp == "$GPGGA,") // 2009.09.19 Added by y3sei { // 2009.09.19 Added by y3sei string[] data = TextRcv.Split(','); if (data[0] == "$GPGGA") { gpsTime = data[1]; gpsLat = data[2]; latNS = data[3]; gpsLon = data[4]; lonEW = data[5]; gpsStatus = data[6]; gpsC = data[7]; gpsHDOP = data[8]; gpsH = data[9]; // data[10] = 高度の単位(M) // data[11] = WGS-84楕円体から平均海水面の高度差 // data[12] = 高度の単位(M) // data[13] = DGPSデータのエイジ // data[14] = DGPS基準局のID // data[15] = チェックサム } else if (data[0] == "$GPRMC") { // data[1] = 測位時刻 valid = data[2]; // data[3] = 緯度 // data[4] = 北緯(N)/南緯(S) // data[5] = 経度 // data[6] = 東経(E)/西経(W) gpsV = data[7]; // 対地速度(knot) gpsD = data[8]; // 進行方向(度) gpsDate = data[9]; // 測位日付ddmmyy // data[10] = 磁気偏差量 // data[11] = 磁気偏差方向 // data[12] = チェックサム GPSTrackPoint position = SetupGpsData(); SetGPSText(); if (!CheckValidPoint(position)) { // 無効データ // SetStatusText("無効データ"); if (chkAutoPost.Checked && lastPostTime.AddSeconds(MaximumPostInterval) < DateTime.Now && !inNoPost) { if (lastValidPosition != null) { lastPosition = lastValidPosition; // 位置を維持 autoPostEvent.Set(); } lastPostTime = DateTime.Now; distance = 0; } } else { //trackPoints.Add(position.time, position); CheckInNoPostArea(position); //各パラメータを表示 lastPosition = position; SetStLblNoPost(); if (!inNoPost) { lastValidPosition = position; AutoSend(); } // プラグインの呼び出し foreach (PluginBase p in pluginManager.LoadedPlugins) { ImacocoNowPlugin plugin = (ImacocoNowPlugin)p; ThreadStart ts = () => { plugin.OnLocationChanged(position); }; Thread t = new Thread(ts); t.IsBackground = true; t.Start(); } } } // 2009.09.19 Added by y3sei else // 2009.09.19 Added by y3sei { // 2009.09.19 Added by y3sei SetStatusText("other error"); // 2009.09.19 Added by y3sei ++sentenseErrorCount; // 2009.09.19 Added by y3sei SetCounterText(); // 2009.09.19 Added by y3sei return; // 2009.09.19 Added by y3sei } // 2009.09.19 Added by y3sei } SetCounterText(); } catch (Exception Ex) { SetStatusText("parseNMEA: " + Ex.Message); // MessageBox.Show(Ex.Message, "Error"); ++sentenseErrorCount; // 2009.09.19 Added by y3sei SetCounterText(); // 2009.09.19 Added by y3sei } }