diff --git a/NucuCar.Domain/Sensors/GenericSensor.cs b/NucuCar.Domain/Sensors/GenericSensor.cs index b1bdb1f..64ac641 100644 --- a/NucuCar.Domain/Sensors/GenericSensor.cs +++ b/NucuCar.Domain/Sensors/GenericSensor.cs @@ -9,7 +9,6 @@ namespace NucuCar.Domain.Sensors /// public abstract class GenericSensor { - protected bool TelemetryEnabled; protected ILogger Logger; protected SensorStateEnum CurrentState; diff --git a/NucuCar.Domain/Sensors/GenericTelemeterSensor.cs b/NucuCar.Domain/Sensors/GenericTelemeterSensor.cs index 52c2fff..ba5930b 100644 --- a/NucuCar.Domain/Sensors/GenericTelemeterSensor.cs +++ b/NucuCar.Domain/Sensors/GenericTelemeterSensor.cs @@ -11,7 +11,9 @@ namespace NucuCar.Domain.Sensors /// public abstract class GenericTelemeterSensor : GenericSensor, ITelemeter { + protected bool TelemetryEnabled; public abstract string GetIdentifier(); public abstract Dictionary GetTelemetryData(); + public abstract bool IsTelemetryEnabled(); } } \ No newline at end of file diff --git a/NucuCar.Domain/Telemetry/ITelemeter.cs b/NucuCar.Domain/Telemetry/ITelemeter.cs index 5ecae45..6ddfcaa 100644 --- a/NucuCar.Domain/Telemetry/ITelemeter.cs +++ b/NucuCar.Domain/Telemetry/ITelemeter.cs @@ -16,8 +16,18 @@ namespace NucuCar.Domain.Telemetry /// /// This function should return a dictionary containing the telemetry data. + /// When implementing this function you should return null if the telemetry is disabled. + /// See: /// /// The telemetry data. It should be JSON serializable. Dictionary GetTelemetryData(); + + /// + /// This function should return whether the sensor has telemetry enabled or not. + /// A value of true indicates that the sensor has enabled telemetry, and a value of false indicates + /// that telemetry is not enabled. + /// + /// A boolean indicating if the sensor has enabled telemetry. + bool IsTelemetryEnabled(); } } \ No newline at end of file diff --git a/NucuCar.Domain/Telemetry/TelemetryPublisher.cs b/NucuCar.Domain/Telemetry/TelemetryPublisher.cs index 68c906c..4b66135 100644 --- a/NucuCar.Domain/Telemetry/TelemetryPublisher.cs +++ b/NucuCar.Domain/Telemetry/TelemetryPublisher.cs @@ -60,7 +60,7 @@ namespace NucuCar.Domain.Telemetry /// Returns true if the telemeter has registered successfully and false otherwise. public bool RegisterTelemeter(ITelemeter t) { - if (RegisteredTelemeters.Contains(t)) return false; + if (RegisteredTelemeters.Contains(t) || !t.IsTelemetryEnabled()) return false; Logger?.LogDebug($"Registering telemeter {t.GetIdentifier()}"); RegisteredTelemeters.Add(t); return true; diff --git a/NucuCar.Sensors/Environment/Bme680Sensor.cs b/NucuCar.Sensors/Environment/Bme680Sensor.cs index 2fad57f..edb2ac5 100644 --- a/NucuCar.Sensors/Environment/Bme680Sensor.cs +++ b/NucuCar.Sensors/Environment/Bme680Sensor.cs @@ -149,6 +149,11 @@ namespace NucuCar.Sensors.Environment return returnValue; } + public override bool IsTelemetryEnabled() + { + return TelemetryEnabled; + } + public Bme680Sensor Object { get; } } } \ No newline at end of file diff --git a/NucuCar.Sensors/Health/CpuTempSensor.cs b/NucuCar.Sensors/Health/CpuTempSensor.cs index b9dd085..823ad8e 100644 --- a/NucuCar.Sensors/Health/CpuTempSensor.cs +++ b/NucuCar.Sensors/Health/CpuTempSensor.cs @@ -98,6 +98,11 @@ namespace NucuCar.Sensors.Health return returnValue; } + public override bool IsTelemetryEnabled() + { + return TelemetryEnabled; + } + public CpuTempSensor Object { get; } } } \ No newline at end of file diff --git a/NucuCar.TestClient/Telemetry/AzureTelemetryPublishCmd.cs b/NucuCar.TestClient/Telemetry/AzureTelemetryPublishCmd.cs index f08584d..a967e0c 100644 --- a/NucuCar.TestClient/Telemetry/AzureTelemetryPublishCmd.cs +++ b/NucuCar.TestClient/Telemetry/AzureTelemetryPublishCmd.cs @@ -41,6 +41,11 @@ namespace NucuCar.TestClient.Telemetry { return _dummyTelemeterData; } + + public bool IsTelemetryEnabled() + { + return true; + } } public static async Task RunAzurePublisherTelemetryTest(AzureTelemetryPublishOptions opts)