public string BindingDataGps(int id) { Context.DataTruck dbtruck = RepoDataTruck.FindByPK(id); List <DataGPS> ListModel = new List <DataGPS>(); foreach (Context.DataTruckGPSHistory item in dbtruck.DataTruckGPSHistory.OrderByDescending(d => d.Id)) { if (ListModel.Count == 0) { ListModel.Add(new DataGPS(item)); } else { if (ListModel.Last().NoGPS == item.NoGPS) { var data = ListModel.Last(); data = new DataGPS(item); } else { ListModel.Add(new DataGPS(item)); } } } return(new JavaScriptSerializer().Serialize(new { data = ListModel })); }
public ActionResult Edit(DataGPS model) { if (ModelState.IsValid) { if (RepoDataGps.IsBoxExist(model.IdDataTruck.Value, model.Id)) { ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang gps, harap ganti dengan truck yang lain"); return(View("Form", model)); } Context.DataGPS dbitem = RepoDataGps.FindByPK(model.Id); model.SetDb(dbitem); Context.DataGPSHistory dbitemHistory = new Context.DataGPSHistory(); model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); dbitem.DataGPSHistory.Add(dbitemHistory); Context.DataTruckGPSHistory dbtruckHistory = new Context.DataTruckGPSHistory(); model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); RepoDataGps.save(dbitem, UserPrincipal.id, dbitemHistory); Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value); dbtruck.DataTruckGPSHistory.Add(dbtruckHistory); RepoDataTruck.save(dbtruck, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }
public void save(DataGPS dbitem, int id, DataGPSHistory dgh) { var hstq = "INSERT INTO dbo.\"DataGPSHistory\" (\"IdDataGPS\", \"NoGPS\", \"Vehicle\", \"strVendor\", \"ModelGps\", \"NoDevice\", \"SensorSuhu\", \"SensorPintu\", \"Tahun\", \"TanggalPasang\", " + "\"TanggalGaransi\", \"Tanggal\", \"Username\") VALUES (" + dgh.IdDataGPS + ", " + dgh.NoGPS + ", " + dgh.Vehicle + ", " + dgh.strVendor + ", " + dgh.ModelGps + ", " + dgh.NoDevice + ", " + dgh.SensorSuhu + ", " + dgh.SensorPintu + ", " + dgh.Tahun + ", " + dgh.TanggalPasang + ", " + dgh.TanggalGaransi + ", " + dgh.Tanggal + ", " + dgh.Username + ");"; if (dbitem.Id == 0) //create { context.DataGPS.Add(dbitem); var query = "INSERT INTO dbo.\"DataGPS\" (\"NoGPS\", \"IdDataTruck\", \"IdVendor\", \"ModelGps\", \"NoDevice\", \"SensorSuhu\", \"SensorPintu\", \"Tahun\", \"TanggalPasang\", \"TanggalGaransi\", urutan) " + "VALUES (" + dbitem.NoGPS + "," + dbitem.IdDataTruck + "," + dbitem.IdVendor + "," + dbitem.ModelGps + "," + dbitem.NoDevice + "," + dbitem.SensorSuhu + "," + dbitem.SensorPintu + "," + dbitem.Tahun + "," + dbitem.TanggalPasang + "," + dbitem.TanggalGaransi + "," + dbitem.urutan + ");"; var auditrail = new Auditrail { Actionnya = "Add", EventDate = DateTime.Now, Modulenya = "Data GPS", QueryDetail = query + hstq, RemoteAddress = AppHelper.GetIPAddress(), IdUser = id }; context.Auditrail.Add(auditrail); } else //edit { context.DataGPS.Attach(dbitem); var query = "UPDATE dbo.\"DataGPS\" SET \"NoGPS\" = " + dbitem.NoGPS + ", \"IdDataTruck\" = " + dbitem.IdDataTruck + ", \"IdVendor\" = " + dbitem.IdVendor + ", \"ModelGps\" = " + dbitem.ModelGps + ", \"NoDevice\" = " + dbitem.NoDevice + ", \"SensorSuhu\" = " + dbitem.SensorSuhu + ", \"SensorPintu\" = " + dbitem.SensorPintu + ", \"Tahun\" = " + dbitem.Tahun + ", \"TanggalPasang\" = " + dbitem.TanggalPasang + ", \"TanggalGaransi\" = " + dbitem.TanggalGaransi + ", urutan = " + dbitem.urutan + " WHERE \"Id\" = " + dbitem.Id + ";"; var auditrail = new Auditrail { Actionnya = "Edit", EventDate = DateTime.Now, Modulenya = "Data GPS", QueryDetail = query + hstq, RemoteAddress = AppHelper.GetIPAddress(), IdUser = id }; context.Auditrail.Add(auditrail); var entry = context.Entry(dbitem); entry.State = EntityState.Modified; } context.SaveChanges(); }
/// <summary> /// Busca un GPS Activo en una empresa /// </summary> /// <param name="imei"></param> /// <returns></returns> public DataGPS BuscarSiExisteGps(string imei) { try { DataGPS aux = new DataGPS(); if (!imei.Equals("")) { aux = (from g in db.GPS join eg in db.EmpresaGPS on g.IMEI equals eg.imei where g.IMEI == imei && eg.estado == true select new DataGPS { ID = g.ID, IMEI = g.IMEI, Modelo = g.Modelo, NroTelefono = g.NroTelefono.ToString() }).FirstOrDefault(); } return(aux); } catch (Exception ex) { return(null); } }
public ActionResult Edit(int id) { Context.DataGPS dbitem = RepoDataGps.FindByPK(id); DataGPS model = new DataGPS(dbitem); ViewBag.name = model.NoGPS; return(View("Form", model)); }
public void delete(DataGPS dbitem, int id) { context.DataGPS.Remove(dbitem); var query = "DELETE FROM dbo.\"DataGPS\" WHERE \"Id\" = " + dbitem.Id + ";"; var auditrail = new Auditrail { Actionnya = "Delete", EventDate = DateTime.Now, Modulenya = "Data GPS", QueryDetail = query, RemoteAddress = AppHelper.GetIPAddress(), IdUser = id }; context.Auditrail.Add(auditrail); context.SaveChanges(); }
public string BuscarSiExisteGPS(string imei) { string data = string.Empty; DataGPS g = gpsCtrl.BuscarSiExisteGps(imei); if (g != null) { data = "1"; } else { data = "0"; } return(data); }
private LatLng PredictPayloadDropLoc(DataGPS gpsData) { DropPrediction.Vector3 windSpeed = new DropPrediction.Vector3(panelWindInput.getWindX(), panelWindInput.getWindY()); Console.WriteLine("Wind: " + windSpeed.x + ", " + windSpeed.y); // Return if there are no items in the default data list if (MainDataMaster.DefaultDataList.Count == 0) { return(null); } // Get the aircraft altitude in Meters from the latest default data object double aircraftAlt = MainDataMaster.DefaultDataList[MainDataMaster.DefaultDataList.Count - 1].alt_bar_ft; aircraftAlt /= ConversionFactors.METERS_TO_FEET; // Get the initial position based on altitude DropPrediction.Vector3 landingPos = new DropPrediction.Vector3(0, 0, aircraftAlt); // Calculate the x and y velocities from heading double velX = gpsData.gps_speed_ft_s * Math.Sin(gpsData.gps_course * ConversionFactors.DEG_TO_RAD) / ConversionFactors.METERS_SECONDS_TO_FEET_SECONDS; double velY = gpsData.gps_speed_ft_s * Math.Cos(gpsData.gps_course * ConversionFactors.DEG_TO_RAD) / ConversionFactors.METERS_SECONDS_TO_FEET_SECONDS; DropPrediction.Vector3 vel = new DropPrediction.Vector3(velX, velY, 0); // Get the resulting delta-location from the aircraft DropPrediction.Vector3 result = DropPrediction.PredictionAlgorithmEuler.PredictionIntegrationFunction(landingPos, vel, windSpeed); // Find dx and dy in feet from the aircraft. double dx = result.x * ConversionFactors.METERS_TO_FEET; double dy = result.y * ConversionFactors.METERS_TO_FEET; // Find the latitude and longitude of the paylaod LatLng res = new LatLng(); res.lat = gpsData.gps_lat + dy / PhysicsConstants.EARTH_RADIUS_FT * ConversionFactors.RAD_TO_DEG; double lonRadius = PhysicsConstants.EARTH_RADIUS_FT * Math.Cos(res.lat * ConversionFactors.DEG_TO_RAD); res.lon = gpsData.gps_lon + dx / lonRadius * ConversionFactors.RAD_TO_DEG; // Return the latitude and longitude return(res); }
public void UpdateDefaultPlayback(DataDefault indata) { panelAltitudePlot.UpdateAltitude(indata.time_seconds, indata.alt_bar_ft); panelInstruments.UpdateInstruments(indata.airspeed_ft_s, indata.alt_bar_ft); // Check for a drop in the playback (hasDroppedPlayback should be reset in playToolback function) if (!hasDroppedPlayback && indata.dropTime_seconds > 0) { // Update altitude with drop panelAltitudePlot.UpdateAltitudeDrop(indata.time_seconds, indata.dropAlt_ft); // Check for a GPS drop, if it exists update the panel DataGPS lastGps = PlaybackController.GetGPSBeforeTime(indata.time_seconds); if (lastGps != null) { panelGPSPlot.UpdateLatLonDrop(lastGps.gps_lat, lastGps.gps_lon); } // Set hasDroppedPlayback to true hasDroppedPlayback = true; } }
public ActionResult Add(DataGPS model) { if (ModelState.IsValid) { if (RepoDataGps.IsBoxExist(model.IdDataTruck.Value)) { ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang gps, harap ganti dengan truck yang lain"); return(View("Form", model)); } Context.DataGPS dbitem = new Context.DataGPS(); model.SetDb(dbitem); //generate code dbitem.urutan = RepoDataGps.getUrutan() + 1; dbitem.NoGPS = RepoDataGps.generateCode(dbitem.urutan); Context.DataGPSHistory dbitemHistory = new Context.DataGPSHistory(); model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); dbitemHistory.Vehicle = RepoDataTruck.FindByPK(dbitem.IdDataTruck.Value).VehicleNo; dbitemHistory.NoGPS = dbitem.NoGPS; dbitemHistory.strVendor = dbitem.IdVendor.HasValue ? RepoVendorGPS.FindByPK(dbitem.IdVendor.Value).Nama : ""; dbitem.DataGPSHistory.Add(dbitemHistory); Context.DataTruckGPSHistory dbtruckHistory = new Context.DataTruckGPSHistory(); model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); RepoDataGps.save(dbitem, UserPrincipal.id, dbitemHistory); Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value); dbtruckHistory.Vehicle = dbtruck.VehicleNo; dbtruckHistory.NoGPS = dbitem.NoGPS; dbtruckHistory.strVendor = dbitem.IdVendor.HasValue ? RepoVendorGPS.FindByPK(dbitem.IdVendor.Value).Nama : ""; dbtruck.DataTruckGPSHistory.Add(dbtruckHistory); RepoDataTruck.save(dbtruck, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }
// Delegate Function to Facilitate Playback of GPS Data // REQUIRES: Not-Null DataGPS object // EFFECTS: Adds point to panelGPSPlot // MODIFIES: Nothing public void UpdateGPSPlayback(DataGPS indata) { panelGPSPlot.UpdateLatLon(indata.gps_lat, indata.gps_lon); }
// TODO: Verify that length of data (number of terms) is correct -> validate message // Parses data into a List public void ParseData(string InputString) { rawDataFile.WriteLine(InputString); if (InputString.Length < 2) { return; } // Divide data by each comma string[] DataString = InputString.Split(','); // Ensure that there are at least 2 data objects in the string if (DataString.Length < 2) { return; } // Initialize the start time (if necessary) and get the total seconds from the start time if (startTime > DateTime.Now) { startTime = DateTime.Now; } double dataSeconds = DateTime.Now.Subtract(startTime).TotalSeconds; // Checks for the "MX" tag. If no tag, we are not receiving data from MX vehicle if (!DataString[1].Equals("MX")) { Console.WriteLine("Not Reading MX"); } // Checks for 'A', 'B', or 'C' messages. If none, sends an error message // 'A' message delivers time in milliseconds, barometric altitude (meters), // airspeed, payload drop time, and payload drop altitude (meters) if (DataString[0].Equals("A")) { // A,MX,MILLIS,ALT_BARO,ANALOG_PITOT,PRESS,TEMP,DROP_TIME,DROP_ALT // Ignore data string if the lengths are not equal if (DataString.Length < A_MSG_LEN) { return; } // Parse Data from String DataDefault inDefault = new DataDefault(); inDefault.time_seconds = dataSeconds; inDefault.alt_bar_ft = Convert.ToDouble(DataString[3]) * ConversionFactors.METERS_TO_FEET; int AnalogPitotValue = (int)Convert.ToDouble(DataString[4]); inDefault.pressure_pa = Convert.ToDouble(DataString[5]); inDefault.temperature_c = Convert.ToDouble(DataString[6]); inDefault.dropTime_seconds = Convert.ToDouble(DataString[7]) * ConversionFactors.MILLIS_TO_SECONDS; inDefault.dropAlt_ft = Convert.ToDouble(DataString[8]) * ConversionFactors.METERS_TO_FEET; // Calculate Airspeed from Analog Value inDefault.airspeed_ft_s = PitotLibrary.GetAirspeedFeetSeconds(AnalogPitotValue, inDefault.temperature_c, inDefault.pressure_pa); // Write Data to File dataFile.WriteLine(inDefault.ToString()); // Add data object to data master list MainDataMaster.DefaultDataList.Add(inDefault); // Update the standard altitude plot and instruments panelAltitudePlot.UpdateAltitude(inDefault.time_seconds, inDefault.alt_bar_ft); //panelInstruments.UpdateInstruments(inDefault.airspeed_ft_s, inDefault.alt_bar_ft); //panelInstruments.UpdateInstrumentsAir(inDefault.alt_bar_ft); panelInstruments.UpdateInstrumentsAir(inDefault.airspeed_ft_s); //panelInstruments.UpdateInstrumentsAlt(inDefault.alt_bar_ft); // Check if a payload has been dropped if (!PayloadDropped && inDefault.dropTime_seconds > 0) { panelDropStatus.UpdateDrop(inDefault.time_seconds, inDefault.alt_bar_ft); panelAltitudePlot.UpdateAltitudeDrop(inDefault.time_seconds, inDefault.dropAlt_ft); // Get the last GPS coordinate to plot drop on the GPS panel // Sends aircraft and predicted drop GPS coordinates to DropPredictionStatus panel // -> Will not show if GPS list is empty, no GPS position information int gpsCount = MainDataMaster.GpsDataList.Count; if (gpsCount > 0) { DataGPS lastGpsData = MainDataMaster.GpsDataList[gpsCount - 1]; panelGPSPlot.UpdateLatLonDrop(lastGpsData.gps_lat, lastGpsData.gps_lon); panelDropPredictionStatus.UpdatePlaneLatLon(lastGpsData.gps_lat, lastGpsData.gps_lon); LatLng predictedLatLng = PredictPayloadDropLoc(lastGpsData); if (predictedLatLng != null) { panelDropPredictionStatus.UpdatePredictLatLon(predictedLatLng.lat, predictedLatLng.lon); } } // Set PayloadDropped to true PayloadDropped = true; } } // 'B' message delivers time in milliseconds, the gps system, the gps latitude, // the gps longitude, the gps measurement for groundspeed in knots, // gps course (degrees), gps altitude (meters), // gps hdop, and gps fixtime (milliseconds) // Converts meters to feet, and knots to ft/s // Divide some variables to restore proper values else if (DataString[0].Equals("B")) { // B,MX,MILLIS,GPS_SYSTEM,LAT,LON,GPS_SPEED,GPS_COURSE,GPS_ALT,GPS_HDOP // Ignore data string if the lengths are not equal if (DataString.Length < B_MSG_LEN) { return; } // Parse GPS Data DataGPS gpsData = new DataGPS(); gpsData.time_seconds = dataSeconds; gpsData.gps_system = DataString[3]; gpsData.gps_lat = (Convert.ToDouble(DataString[4])) / 1000000; //degrees gpsData.gps_lon = (Convert.ToDouble(DataString[5])) / 1000000; //degrees gpsData.gps_speed_ft_s = ((Convert.ToDouble(DataString[6])) / 1000) * ConversionFactors.KNOTS_TO_FPS; //Converts Speed from Knots to ft/s gpsData.gps_course = (Convert.ToDouble(DataString[7])) / 1000; //degrees gpsData.gps_alt_ft = ((Convert.ToDouble(DataString[8])) / 1000) * ConversionFactors.METERS_TO_FEET; gpsData.gps_hdop = (Convert.ToDouble(DataString[9])) / 10; // Write data to file dataFile.WriteLine(gpsData.ToString()); // Add data object to DataMaster MainDataMaster.GpsDataList.Add(gpsData); // Check if if latitude is within USA if (((gpsData.gps_lat >= 20) && (gpsData.gps_lat <= 50)) && ((gpsData.gps_lon <= -65) && (gpsData.gps_lon >= -127))) { // Update GPS Panel with new location panelGPSPlot.UpdateLatLon(gpsData.gps_lat, gpsData.gps_lon); // Add tangent line between target and MX vehicle if (TARGET_ON) { panelGPSPlot.UpdateLatLonTangent_Target(gpsData.gps_lat, gpsData.gps_lon, targetLocation.lat, targetLocation.lon); } // Update GPS altitude plot //panelAltitudePlot.UpdateAltitudeGPS(gpsData.time_seconds, gpsData.gps_alt_ft); // Predict payload drop location and display location on screen if it exists LatLng predictedLatLng = PredictPayloadDropLoc(gpsData); if (predictedLatLng != null) { panelGPSPlot.UpdateLatLonPredict(predictedLatLng.lat, predictedLatLng.lon); panelGPSPlot.UpdateLatLonTangent_Predict(gpsData.gps_lat, gpsData.gps_lon, predictedLatLng.lat, predictedLatLng.lon); } } } // 'C' message delivers gyro data. Gives time in milliseconds; x, y, and z gyro values; // and x, y, and z acceleration values. // Gyro in radians/s // Acceleration in m/s^2 else if (DataString[0].Equals("C")) { // C,MX,MILLIS,GYROX,GYROY,GYROZ,ACCELX,ACCELY,ACCELZ // Ignore data string if the lengths are not equal if (DataString.Length < C_MSG_LEN) { return; } // Parse incoming data DataAccelGyro gyroData = new DataAccelGyro(); gyroData.time_seconds = dataSeconds; gyroData.gyro_x = Convert.ToDouble(DataString[3]); gyroData.gyro_y = Convert.ToDouble(DataString[4]); gyroData.gyro_z = Convert.ToDouble(DataString[5]); gyroData.accel_x = Convert.ToDouble(DataString[6]); gyroData.accel_y = Convert.ToDouble(DataString[7]); gyroData.accel_z = Convert.ToDouble(DataString[8]); // Write data to file dataFile.WriteLine(gyroData.ToString()); // Add data object to DataMaster MainDataMaster.GryoAccelDataList.Add(gyroData); } // 'D' message delivers extra data. As of 2017-2018, delivers additional altitude data else if (DataString[0].Equals("D")) { // D,MX,MILLIS,BAROALT // Ignore string if length is not equal if (DataString.Length < D_MSG_LEN) { return; } //Parse incoming data DataD extraData = new DataD(); extraData.time_seconds = dataSeconds; extraData.alt = Convert.ToDouble(DataString[3]) * ConversionFactors.METERS_TO_FEET; // Write data to file dataFile.WriteLine(extraData.ToString()); // Add data object to DataMaster MainDataMaster.DataDList.Add(extraData); // Update altitude plot with additional altitude panelAltitudePlot.UpdateAltitudeBarometer(extraData.time_seconds, extraData.alt); // Update altitude in instruments panel panelInstruments.UpdateInstrumentsAlt(extraData.alt); } else { // If unknown message, write information to console dataFile.WriteLine("Unknown Message: " + InputString); } }
public ActionResult Add() { DataGPS model = new DataGPS(); return(View("Form", model)); }