Skip to content

Commit

Permalink
Added message count
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Sep 23, 2023
1 parent 6d4d10e commit 981d088
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/BaseStationReader.Data/BaseStationReader.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>BaseStationReader.Data</PackageId>
<PackageVersion>1.24.0.0</PackageVersion>
<PackageVersion>1.25.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Owners>Dave Walker</Owners>
Expand All @@ -17,7 +17,7 @@
<PackageProjectUrl>https://github.com/davewalker5/ADS-B-BaseStationReader</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.24.0.0</ReleaseVersion>
<ReleaseVersion>1.25.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/BaseStationReader.Data/BaseStationReaderDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.Property(e => e.VerticalRate).HasColumnName("VerticalRate");
entity.Property(e => e.Squawk).HasColumnName("Squawk");
entity.Property(e => e.Status).HasColumnName("Status");
entity.Property(e => e.Messages).HasColumnName("Messages");

entity.Property(e => e.FirstSeen)
.IsRequired()
Expand Down

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BaseStationReader.Data.Migrations
{
/// <inheritdoc />
public partial class MessageCount : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "Messages",
table: "AIRCRAFT",
type: "INTEGER",
nullable: false,
defaultValue: 0);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Messages",
table: "AIRCRAFT");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("TEXT")
.HasColumnName("Longitude");

b.Property<int>("Messages")
.HasColumnType("INTEGER");

b.Property<string>("Squawk")
.HasColumnType("TEXT")
.HasColumnName("Squawk");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>BaseStationReader.Entities</PackageId>
<PackageVersion>1.24.0.0</PackageVersion>
<PackageVersion>1.25.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Owners>Dave Walker</Owners>
Expand All @@ -17,7 +17,7 @@
<PackageProjectUrl>https://github.com/davewalker5/ADS-B-BaseStationReader</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.24.0.0</ReleaseVersion>
<ReleaseVersion>1.25.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/BaseStationReader.Entities/Tracking/Aircraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class Aircraft : ICloneable
[Required]
public TrackingStatus Status { get; set; }

[Export("Messages", 12)]
public int Messages { get; set; }

public object Clone()
{
return MemberwiseClone();
Expand Down
4 changes: 2 additions & 2 deletions src/BaseStationReader.Logic/BaseStationReader.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>BaseStationReader.Logic</PackageId>
<PackageVersion>1.24.0.0</PackageVersion>
<PackageVersion>1.25.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Owners>Dave Walker</Owners>
Expand All @@ -17,7 +17,7 @@
<PackageProjectUrl>https://github.com/davewalker5/ADS-B-BaseStationReader</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.24.0.0</ReleaseVersion>
<ReleaseVersion>1.25.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
55 changes: 27 additions & 28 deletions src/BaseStationReader.Logic/Tracking/AircraftTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,33 +115,30 @@ private void UpdateExistingAircraft(Message msg)
var lastLatitude = aircraft.Latitude;
var lastLongitude = aircraft.Longitude;

// Determine if it's changed and update its properties
bool changed = UpdateAircraftProperties(aircraft, msg);
if (changed)
// Update the aircraft propertes
UpdateAircraftProperties(aircraft, msg);
try
{
try
// If the position's changed, construct a position instance to add to the notification event arguments
AircraftPosition? position = null;
if (aircraft.Latitude != lastLatitude || aircraft.Longitude != lastLongitude)
{
// If the position's changed, construct a position instance to add to the notification event arguments
AircraftPosition? position = null;
if (aircraft.Latitude != lastLatitude || aircraft.Longitude != lastLongitude)
{
position = CreateAircraftPosition(aircraft);
}

// Notify subscribers
AircraftUpdated?.Invoke(this, new AircraftNotificationEventArgs
{
Aircraft = aircraft,
Position = position,
NotificationType = AircraftNotificationType.Updated
});
position = CreateAircraftPosition(aircraft);
}
catch (Exception ex)

// Notify subscribers
AircraftUpdated?.Invoke(this, new AircraftNotificationEventArgs
{
// Log and sink the exception. The tracker has to be protected from errors in the
// subscriber callbacks or the application will stop updating
_logger.LogException(ex);
}
Aircraft = aircraft,
Position = position,
NotificationType = AircraftNotificationType.Updated
});
}
catch (Exception ex)
{
// Log and sink the exception. The tracker has to be protected from errors in the
// subscriber callbacks or the application will stop updating
_logger.LogException(ex);
}
}
}
Expand Down Expand Up @@ -211,27 +208,29 @@ private void AddNewAircraft(Message msg)
/// </summary>
/// <param name="aircraft"></param>
/// <param name="msg"></param>
private bool UpdateAircraftProperties(Aircraft aircraft, Message msg)
private void UpdateAircraftProperties(Aircraft aircraft, Message msg)
{
bool changed = false;
// Increment the message count
aircraft.Messages++;

// Iterate over the aircraft propertues
foreach (var aircraftProperty in _aircraftProperties)
{
// Find the corresponding message property for the current aircraft property
var messageProperty = Array.Find(_messageProperties, x => x.Name == aircraftProperty.Name);
if (messageProperty != null)
{
// See if the property has changed
var original = aircraftProperty.GetValue(aircraft);
var updated = messageProperty.GetValue(msg);
if (updated != null && original != updated)
{
// It has, so u0date it
aircraftProperty.SetValue(aircraft, updated);
aircraft.Status = TrackingStatus.Active;
changed = true;
}
}
}

return changed;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ReleaseVersion>1.24.0.0</ReleaseVersion>
<FileVersion>1.24.0.0</FileVersion>
<ProductVersion>1.24.0</ProductVersion>
<ReleaseVersion>1.25.0.0</ReleaseVersion>
<FileVersion>1.25.0.0</FileVersion>
<ProductVersion>1.25.0</ProductVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ReleaseVersion>1.24.0.0</ReleaseVersion>
<FileVersion>1.24.0.0</FileVersion>
<ProductVersion>1.24.0</ProductVersion>
<ReleaseVersion>1.25.0.0</ReleaseVersion>
<FileVersion>1.25.0.0</FileVersion>
<ProductVersion>1.25.0</ProductVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
9 changes: 7 additions & 2 deletions src/BaseStationReader.Terminal/appsettings.desktop.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ApplicationSettings": {
"Host": "192.168.0.98",
"Host": "127.0.0.1",
"Port": 30003,
"SocketReadTimeout": 60000,
"ApplicationTimeout": 600000,
Expand All @@ -13,7 +13,7 @@
"EnableSqlWriter": false,
"WriterInterval": 30000,
"WriterBatchSize": 20000,
"RefreshInterval": 5000,
"RefreshInterval": 1000,
"MaximumRows": 0,
"Columns": [
{
Expand Down Expand Up @@ -70,6 +70,11 @@
"Property": "LastSeen",
"Label": "Last Seen",
"Format": "HH:mm:ss.fff"
},
{
"Property": "Messages",
"Label": "Messages",
"Format": ""
}
]
},
Expand Down
Loading

0 comments on commit 981d088

Please sign in to comment.