Skip to content

Commit

Permalink
v1.2.0 - Added Plane On Ground. Changed yellow push-pins on detail da…
Browse files Browse the repository at this point in the history
…ta to green. meaning plane on ground, and blue, meaning plane in the air
  • Loading branch information
SAHorowitz committed Oct 26, 2020
1 parent f75959a commit e729efe
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 26 deletions.
3 changes: 2 additions & 1 deletion FS2020PlanePath/FS2020PlanePath.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>ACCFC642F9C4885DA59BF945456E3D7F3CEF9A26</ManifestCertificateThumbprint>
Expand Down
80 changes: 67 additions & 13 deletions FS2020PlanePath/FS2020_SQLLiteDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FlightPathData
public Int32 overspeed_warning;
public Int32 is_gear_retractable;
public Int32 spoiler_available;
public Int32 sim_on_ground;

[Flags]
public enum LightStates
Expand Down Expand Up @@ -172,7 +173,7 @@ class FS2020_SQLLiteDB
SQLiteConnection sqlite_conn;
private const int TblVersion_Flights = 1;
private const int TblVersion_FlightSamples = 1;
private const int TblVersion_FlightSampleDetails = 1;
private const int TblVersion_FlightSampleDetails = 2;
private const int TblVersion_FlightWaypoints = 1;
private const int TblVersion_FlightOptions = 1;

Expand Down Expand Up @@ -258,6 +259,9 @@ public void CreateTables()
// Fill in Table Versions if needed
LoadUpTableVersions();

// Check Table versions and update as needed
UpdateTablesAsNeeded();

// Load Up Table Options if needed
LoadUpTableOptions();
}
Expand Down Expand Up @@ -323,6 +327,59 @@ private void LoadUpTableVersions()
}
}

private void UpdateTablesAsNeeded()
{
int nCurTableVersion = 0;

nCurTableVersion = GetCurrentTableVersion("FlightSampleDetails");

if (nCurTableVersion < TblVersion_FlightSampleDetails)
UpdateFlightSampleDetailsTable(nCurTableVersion);
}

private int GetCurrentTableVersion(string sTable)
{
SQLiteCommand sqlite_cmd;
string Selectsql;
int nRetval = 0;

sqlite_cmd = sqlite_conn.CreateCommand();
Selectsql = "SELECT tblVersion FROM TblVersions WHERE tblName = @tblname";
sqlite_cmd.CommandText = Selectsql;
sqlite_cmd.Parameters.AddWithValue("@tblname", sTable);
SQLiteDataReader r = sqlite_cmd.ExecuteReader();
while (r.Read())
nRetval = r.GetInt32(0);

return (nRetval);
}

private void UpdateFlightSampleDetailsTable(int nCurTableVersion)
{
SQLiteCommand sqlite_cmd;
string Updatesql;

sqlite_cmd = sqlite_conn.CreateCommand();

if (nCurTableVersion == 1)
{
Updatesql = "ALTER TABLE FlightSampleDetails ADD sim_on_ground int32";
sqlite_cmd.CommandText = Updatesql;
sqlite_cmd.ExecuteNonQuery();

sqlite_cmd.Parameters.Clear();
Updatesql = "Update FlightSampleDetails SET sim_on_ground = 0";
sqlite_cmd.CommandText = Updatesql;
sqlite_cmd.ExecuteNonQuery();

sqlite_cmd.Parameters.Clear();
Updatesql = "Update TblVersions SET tblVersion = @tblversion WHERE tblName = 'FlightSampleDetails'";
sqlite_cmd.CommandText = Updatesql;
sqlite_cmd.Parameters.AddWithValue("@tblversion", nCurTableVersion + 1);
sqlite_cmd.ExecuteNonQuery();
}
}

private void LoadUpTableOptions()
{
SQLiteCommand sqlite_cmd;
Expand Down Expand Up @@ -401,22 +458,17 @@ public String GetTableOption(String optionname)
return (sRetval);
}

public String WriteTableOption(String optionname, String optionvalue)
public void WriteTableOption(String optionname, String optionvalue)
{
SQLiteCommand sqlite_cmd;
string Updatesql;
string sRetval = "";

sqlite_cmd = sqlite_conn.CreateCommand();
Updatesql = "Update FlightPathOptions SET optionvalue = @optionvalue WHERE optionname = @optionname";
sqlite_cmd.CommandText = Updatesql;
sqlite_cmd.Parameters.AddWithValue("@optionname", optionname);
sqlite_cmd.Parameters.AddWithValue("@optionvalue", optionvalue);
SQLiteDataReader r = sqlite_cmd.ExecuteReader();
while (r.Read())
sRetval = r.GetString(0);

return (sRetval);
}

private bool CheckTableExists(String tblName)
Expand Down Expand Up @@ -484,18 +536,18 @@ public void WriteFlightPointDetails(long pk, Int32 altitude_above_ground, Int32
double plane_airspeed_indicated, double airspeed_true, double vertical_speed, double heading_indicator,
Int32 flaps_handle_position, Int32 spoilers_handle_position, Int32 gear_handle_position,
double ambient_wind_velocity, double ambient_wind_direction, double ambient_temperature, Int32 stall_warning,
Int32 overspeed_warning, Int32 is_gear_retractable, Int32 spoiler_available)
Int32 overspeed_warning, Int32 is_gear_retractable, Int32 spoiler_available, Int32 sim_on_ground)
{
SQLiteCommand sqlite_cmd;
string Insertsql;

sqlite_cmd = sqlite_conn.CreateCommand();
Insertsql = "Insert into FlightSampleDetails (FlightSamplesID, alitutdeaboveground, engine1rpm, engine2rpm, engine3rpm, engine4rpm, lightsmask, ground_velocity, plane_pitch, plane_bank, plane_heading_true, ";
Insertsql += "plane_heading_magnetic, plane_airspeed_indicated, airspeed_true, vertical_speed, heading_indicator, flaps_handle_position, spoilers_handle_position, gear_handle_position, ambient_wind_velocity, ";
Insertsql += "ambient_wind_direction, ambient_temperature, stall_warning, overspeed_warning, is_gear_retractable, spoiler_available) VALUES (@FlightSamplesID, @alitutdeaboveground, @engine1rpm, @engine2rpm, ";
Insertsql += "@engine3rpm, @engine4rpm, @lightsmask, @ground_velocity, @plane_pitch, @plane_bank, @plane_heading_true, @plane_heading_magnetic, @plane_airspeed_indicated, @airspeed_true, @vertical_speed, ";
Insertsql += "@heading_indicator, @flaps_handle_position, @spoilers_handle_position, @gear_handle_position, @ambient_wind_velocity, @ambient_wind_direction, @ambient_temperature, @stall_warning, ";
Insertsql += "@overspeed_warning, @is_gear_retractable, @spoiler_available)";
Insertsql += "ambient_wind_direction, ambient_temperature, stall_warning, overspeed_warning, is_gear_retractable, spoiler_available, sim_on_ground) VALUES (@FlightSamplesID, @alitutdeaboveground, @engine1rpm, ";
Insertsql += "@engine2rpm, @engine3rpm, @engine4rpm, @lightsmask, @ground_velocity, @plane_pitch, @plane_bank, @plane_heading_true, @plane_heading_magnetic, @plane_airspeed_indicated, @airspeed_true, ";
Insertsql += "@vertical_speed, @heading_indicator, @flaps_handle_position, @spoilers_handle_position, @gear_handle_position, @ambient_wind_velocity, @ambient_wind_direction, @ambient_temperature, @stall_warning, ";
Insertsql += "@overspeed_warning, @is_gear_retractable, @spoiler_available, @sim_on_ground)";
sqlite_cmd.CommandText = Insertsql;
sqlite_cmd.Parameters.AddWithValue("@FlightSamplesID", pk);
sqlite_cmd.Parameters.AddWithValue("@alitutdeaboveground", altitude_above_ground);
Expand Down Expand Up @@ -523,6 +575,7 @@ public void WriteFlightPointDetails(long pk, Int32 altitude_above_ground, Int32
sqlite_cmd.Parameters.AddWithValue("@overspeed_warning", overspeed_warning);
sqlite_cmd.Parameters.AddWithValue("@is_gear_retractable", is_gear_retractable);
sqlite_cmd.Parameters.AddWithValue("@spoiler_available", spoiler_available);
sqlite_cmd.Parameters.AddWithValue("@sim_on_ground", sim_on_ground);
sqlite_cmd.ExecuteNonQuery();
}

Expand Down Expand Up @@ -583,7 +636,7 @@ public List<FlightPathData> GetFlightPathData(int pk)
Selectsql += "cast (ground_velocity as double), cast (plane_pitch as double), cast (plane_bank as double), cast (plane_heading_true as double), cast (plane_heading_magnetic as double), ";
Selectsql += "cast (plane_airspeed_indicated as double), cast (airspeed_true as double), cast (vertical_speed as double), cast (heading_indicator as double), flaps_handle_position, ";
Selectsql += "spoilers_handle_position, gear_handle_position, cast (ambient_wind_velocity as double), cast (ambient_wind_direction as double), cast (ambient_temperature as double),";
Selectsql += "stall_warning, overspeed_warning, is_gear_retractable, spoiler_available ";
Selectsql += "stall_warning, overspeed_warning, is_gear_retractable, spoiler_available, sim_on_ground ";
Selectsql += "FROM FlightSamples, FlightSampleDetails WHERE FlightSampleDetails.FlightSamplesID = FlightSamples.FlightSamplesID AND FlightID = @FlightID";
sqlite_cmd.CommandText = Selectsql;
sqlite_cmd.Parameters.AddWithValue("@FlightID", pk);
Expand Down Expand Up @@ -620,6 +673,7 @@ public List<FlightPathData> GetFlightPathData(int pk)
data.overspeed_warning = r.GetInt32(26);
data.is_gear_retractable = r.GetInt32(27);
data.spoiler_available = r.GetInt32(28);
data.sim_on_ground = r.GetInt32(29);

FlightPath.Add(data);
}
Expand Down
4 changes: 3 additions & 1 deletion FS2020PlanePath/MSFS2020_SimConnectIntergration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct DataStructure
public string gps_wp_next_id;
public Int32 gps_flight_plan_wp_index;
public Int32 gps_flight_plan_wp_count;
public Int32 sim_on_ground;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
Expand Down Expand Up @@ -172,6 +173,7 @@ private void SetupEvents()
simConnect.AddToDataDefinition(DEFINITIONS.DataStructure, "GPS WP NEXT ID", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simConnect.AddToDataDefinition(DEFINITIONS.DataStructure, "GPS Flight Plan WP Index", "number", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simConnect.AddToDataDefinition(DEFINITIONS.DataStructure, "GPS Flight Plan WP Count", "number", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simConnect.AddToDataDefinition(DEFINITIONS.DataStructure, "Sim On Ground", "bool", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);

SimConnect.AddToDataDefinition(DEFINITIONS.SimEnvironmentDataStructure, "TITLE", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);

Expand Down Expand Up @@ -272,7 +274,7 @@ void SimConnect_OnRecvSimobjectData(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT
s1.gear_handle_position, s1.ambient_wind_velocity, s1.ambient_wind_direction, s1.ambient_temperature,
s1.stall_warning, s1.overspeed_warning, s1.is_gear_retractable, s1.spoiler_avaialable, s1.gps_wp_prev_latitude, s1.gps_wp_prev_longitude,
s1.gps_wp_prev_altitude, s1.gps_wp_prev_id, s1.gps_wp_next_latitude, s1.gps_wp_next_longitude, s1.gps_wp_next_altitude, s1.gps_wp_next_id,
s1.gps_flight_plan_wp_index, s1.gps_flight_plan_wp_count);
s1.gps_flight_plan_wp_index, s1.gps_flight_plan_wp_count, s1.sim_on_ground);
break;

case DATA_REQUESTS.SimEnvironmentReq:
Expand Down
2 changes: 1 addition & 1 deletion FS2020PlanePath/MainPage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 31 additions & 10 deletions FS2020PlanePath/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void UseData(double latitude, double longitude, Int32 altitude, Int32 alt
Int32 overspeed_warning, Int32 is_gear_retractable, Int32 spoiler_available, double gps_wp_prev_latitude,
double gps_wp_prev_longitude, Int32 gps_wp_prev_altitude, string gps_wp_prev_id, double gps_wp_next_latitude,
double gps_wp_next_longitude, Int32 gps_wp_next_altitude, string gps_wp_next_id, Int32 gps_flight_plan_wp_index,
Int32 gps_flight_plan_wp_count)
Int32 gps_flight_plan_wp_count, Int32 sim_on_ground)
{
if (bLoggingEnabled == true)
{
Expand All @@ -180,7 +180,7 @@ public void UseData(double latitude, double longitude, Int32 altitude, Int32 alt
plane_heading_magnetic, plane_airspeed_indicated, airspeed_true, vertical_speed,
heading_indicator, flaps_handle_position, spoilers_handle_position,
gear_handle_position, ambient_wind_velocity, ambient_wind_direction, ambient_temperature,
stall_warning, overspeed_warning, is_gear_retractable, spoiler_available);
stall_warning, overspeed_warning, is_gear_retractable, spoiler_available, sim_on_ground);
dtLastDataRecord = DateTime.Now;
}
flightPlan.AddFlightPlanWaypoint(new FlightWaypointData(gps_wp_prev_latitude, gps_wp_prev_longitude, gps_wp_prev_altitude, gps_wp_prev_id),
Expand Down Expand Up @@ -255,13 +255,25 @@ private void CreateKMLButton_Click(object sender, EventArgs e)
flightStyle.Line = lineStyle;
linestring.Extrude = false;
mainFolder.AddStyle(flightStyle);

SharpKml.Dom.Style waypointStyle = new SharpKml.Dom.Style();
waypointStyle.Id = "WaypointStyle";
waypointStyle.Icon = new SharpKml.Dom.IconStyle();
waypointStyle.Icon.Icon = new SharpKml.Dom.IconStyle.IconLink(new System.Uri("https://maps.google.com/mapfiles/kml/paddle/grn-square.png"));
mainFolder.AddStyle(waypointStyle);

SharpKml.Dom.Style pushpinblueStyle = new SharpKml.Dom.Style();
pushpinblueStyle.Id = "PushPinBlueStyle";
pushpinblueStyle.Icon = new SharpKml.Dom.IconStyle();
pushpinblueStyle.Icon.Icon = new SharpKml.Dom.IconStyle.IconLink(new System.Uri("https://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png"));
mainFolder.AddStyle(pushpinblueStyle);

SharpKml.Dom.Style pushpingreenStyle = new SharpKml.Dom.Style();
pushpingreenStyle.Id = "PushPinGreenStyle";
pushpingreenStyle.Icon = new SharpKml.Dom.IconStyle();
pushpingreenStyle.Icon.Icon = new SharpKml.Dom.IconStyle.IconLink(new System.Uri("https://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png"));
mainFolder.AddStyle(pushpingreenStyle);

placemarkLine.StyleUrl = new Uri("#FlightStyle", UriKind.Relative);

List<FlightPathData> FlightPath = new List<FlightPathData>();
Expand Down Expand Up @@ -330,7 +342,9 @@ private void CreateKMLButton_Click(object sender, EventArgs e)
descriptioncard += String.Format("<br>Temperature: {0:0.00}C / {1:0.00}F", fpd.ambient_temperature, fpd.ambient_temperature * 9 / 5 + 32);
descriptioncard += String.Format("<br>Wind: {0:0.00} knts from {1:0.00} degrees", fpd.ambient_wind_velocity, fpd.ambient_wind_direction);
descriptioncard += String.Format("<br>Altitude Above Ground: {0} feet", fpd.altitudeaboveground);

if (fpd.sim_on_ground == 1)
descriptioncard += String.Format("<br>Plane Is On The Ground");

descriptioncard += String.Format("<br><br>Heading Indicator: {0:0.00} degrees", fpd.heading_indicator);
descriptioncard += String.Format("<br>True Heading: {0:0.00} degrees", fpd.plane_heading_true);
descriptioncard += String.Format("<br>Magnetic Heading {0:0.00} degrees", fpd.plane_heading_magnetic);
Expand Down Expand Up @@ -432,6 +446,11 @@ private void CreateKMLButton_Click(object sender, EventArgs e)
{
When = new DateTime(fpd.timestamp)
};*/
if (fpd.sim_on_ground == 1)
placemarkPoint.StyleUrl = new System.Uri("#PushPinGreenStyle", UriKind.Relative);
else
placemarkPoint.StyleUrl = new System.Uri("#PushPinBlueStyle", UriKind.Relative);

placemarkPoint.Geometry = new SharpKml.Dom.Point
{
Coordinate = new Vector(fpd.latitude, fpd.longitude, (double) fpd.altitude * 0.3048),
Expand All @@ -452,14 +471,16 @@ private void CreateKMLButton_Click(object sender, EventArgs e)
{
SharpKml.Dom.GX.FlyTo flyto = new SharpKml.Dom.GX.FlyTo();

// if first time thru loop and don't have old time or
// user wants to speed up video playback above threshold
// then set duration to 1 else base it on previous timestamp
// assume duration will be based on difference between timestamps
// if first time thru loop and don't have old time or user wants to speed up video playback above threshold
// then set duration to 1 if it is greater than 1 else leave as-is
flyto.Duration = (new DateTime(fpd.timestamp) - new DateTime(lprevTimestamp)).TotalMilliseconds / 1000;
if ((lprevTimestamp == 0) ||
(SpeedUpVideoPlaybackCB.Checked == true))
flyto.Duration = 1;
else
flyto.Duration = (new DateTime(fpd.timestamp) - new DateTime(lprevTimestamp)).TotalMilliseconds / 1000;
{
if (flyto.Duration > 1)
flyto.Duration = 1;
}

lprevTimestamp = fpd.timestamp;
flyto.Mode = SharpKml.Dom.GX.FlyToMode.Smooth;
Expand Down

0 comments on commit e729efe

Please sign in to comment.