public void RunKMLThread() { for (int i = 0; i < RunKML.Coords.Count(); i++) { GPS thisGPS = new GPS(); string StartDate = "01/01/1970 00:00:00"; TimeSpan nowSpan = DateTime.Now - Convert.ToDateTime(StartDate); thisGPS.Id = Math.Abs(nowSpan.Milliseconds); thisGPS.Speed = Convert.ToDouble(txtSpeed.Text); thisGPS.Lat = RunKML.Coords[i].lat; thisGPS.Lon = RunKML.Coords[i].lon; thisGPS.MaxSpd = Convert.ToDouble(txtMaxSpeed.Text); thisGPS.MLat = Convert.ToDouble(txtMLat.Text); thisGPS.MLon = Convert.ToDouble(txtMLon.Text); thisGPS.Time = Convert.ToDateTime(txtTime.Text); thisGPS.Status = "Valid"; thisGPS.DOP = 7.0; thisGPS.Alt = 5280; thisGPS.Cell = txtCell.Text; thisGPS.Head = Convert.ToInt32(txtHead.Text); XmlSerializer ser = new XmlSerializer(typeof(GPS)); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); StringWriter str = new StringWriter(); ser.Serialize(str, thisGPS, namespaces); string msg = str.ToString(); SendUDP myUDP = new SendUDP(); SendUDP playbackUdp = new SendUDP(); txtMessageStatus.Invoke(new MethodInvoker(delegate { txtMessageStatus.Text += playbackUdp.SendUDPPacket(msg, ddlServiceAddress.Text); })); if (i == RunKML.Coords.Count() - 1) { txtMessageStatus.Invoke(new MethodInvoker(delegate { txtMessageStatus.Text = "Playback finished " + DateTime.Now.ToString(); })); runKMLThread.Abort(); break; } double distBetween = 0.0; //should be miles if ((i + 1) < RunKML.Coords.Count()) { distBetween = GeoCodeCalc.CalcDistance(RunKML.Coords[i].lat, RunKML.Coords[i].lon, RunKML.Coords[i + 1].lat, RunKML.Coords[i + 1].lon); } //int Pause = Convert.ToInt32(thisGPS.Speed * distBetween); int Pause = 5; System.Threading.Thread.Sleep(Pause * 1000); } }
private void RunCSVThread() { for (int i = 0; i < RunCSV.playbackTrucks.Count; i++) { GPS thisGPS = new GPS(); string StartDate = "01/01/1970 00:00:00"; TimeSpan nowSpan = DateTime.Now - Convert.ToDateTime(StartDate); thisGPS.Id = Math.Abs(nowSpan.Milliseconds); thisGPS.Speed = RunCSV.playbackTrucks[i].Speed; thisGPS.Lat = RunCSV.playbackTrucks[i].Lat; thisGPS.Lon = RunCSV.playbackTrucks[i].Lon; thisGPS.MaxSpd = RunCSV.playbackTrucks[i].MaxSpeed; thisGPS.MLat = RunCSV.playbackTrucks[i].Lat; thisGPS.MLon = RunCSV.playbackTrucks[i].Lon; thisGPS.Time = RunCSV.playbackTrucks[i].timeStamp; thisGPS.Status = RunCSV.playbackTrucks[i].VehicleStatus; thisGPS.Cell = txtCell.Text; thisGPS.DOP = 7.0; thisGPS.Alt = 5280; thisGPS.Head = RunCSV.playbackTrucks[i].Direction; XmlSerializer ser = new XmlSerializer(typeof(GPS)); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); StringWriter str = new StringWriter(); ser.Serialize(str, thisGPS, namespaces); string msg = str.ToString(); SendUDP myUDP = new SendUDP(); SendUDP playbackUdp = new SendUDP(); txtMessageStatus.Invoke(new MethodInvoker(delegate { txtMessageStatus.Text += playbackUdp.SendUDPPacket(msg, ddlServiceAddress.Text); })); if (i == RunCSV.playbackTrucks.Count() - 1) { txtMessageStatus.Invoke(new MethodInvoker(delegate { txtMessageStatus.Text = "Playback finished " + DateTime.Now.ToString() + Environment.NewLine; })); runCSVThread.Abort(); break; } double distBetween = 0.0; //should be miles if ((i + 1) < RunCSV.playbackTrucks.Count()) { distBetween = GeoCodeCalc.CalcDistance(RunCSV.playbackTrucks[i].Lat, RunCSV.playbackTrucks[i].Lon, RunCSV.playbackTrucks[i + 1].Lat, RunCSV.playbackTrucks[i + 1].Lon); } //int Pause = Convert.ToInt32(thisGPS.Speed * distBetween); int Pause = 5; if (thisGPS.Speed >= 0) { System.Threading.Thread.Sleep(Pause * 1000); } } txtMessageStatus.Invoke(new MethodInvoker(delegate { txtMessageStatus.Text = "Restarting. Press Stop CSV to stop playback" + Environment.NewLine; runCSVThread.Abort(); runCSVThread.Start(); })); }