Skip to content

Commit

Permalink
Merge pull request #33 from davewalker5/BSR-55-Message-Count
Browse files Browse the repository at this point in the history
Added message count
  • Loading branch information
davewalker5 committed Sep 23, 2023
2 parents 6d4d10e + 88a1628 commit cb5c237
Show file tree
Hide file tree
Showing 25 changed files with 249 additions and 62 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
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System.Diagnostics.CodeAnalysis;

#nullable disable

namespace BaseStationReader.Data.Migrations
{
/// <inheritdoc />
[ExcludeFromCodeCoverage]
public partial class AircraftStatus : Migration
{
/// <inheritdoc />
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,31 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System.Diagnostics.CodeAnalysis;

#nullable disable

namespace BaseStationReader.Data.Migrations
{
/// <inheritdoc />
[ExcludeFromCodeCoverage]
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
@@ -1,5 +1,6 @@
// <auto-generated />
using System;
using System.Diagnostics.CodeAnalysis;
using BaseStationReader.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand All @@ -10,6 +11,7 @@
namespace BaseStationReader.Data.Migrations
{
[DbContext(typeof(BaseStationReaderDbContext))]
[ExcludeFromCodeCoverage]
partial class BaseStationReaderDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
Expand Down Expand Up @@ -57,6 +59,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
2 changes: 1 addition & 1 deletion src/BaseStationReader.Entities/Messages/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void AppendField(StringBuilder builder, object? value)
/// <param name="value"></param>
private void AppendBooleanFiled(StringBuilder builder, bool value)
{
var append = value == true ? "1" : "0";
var append = value ? "1" : "0";
AppendField(builder, append);
}
}
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
2 changes: 1 addition & 1 deletion src/BaseStationReader.Simulator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace BaseStationReader.Simulator
{
internal class Program
internal static class Program
{
static void Main(string[] args)
{
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
Loading

0 comments on commit cb5c237

Please sign in to comment.