NUC-43: Update readme.md & rename SensorTelemetry to Telemetry.

This commit is contained in:
Denis-Cosmin Nutiu 2020-05-01 11:29:59 +03:00
parent af9e5d4bf9
commit 69c3a80d34
7 changed files with 27 additions and 14 deletions

View file

@ -5,11 +5,11 @@ namespace NucuCar.Sensors.Environment
{ {
public class Bme680Worker : SensorWorker public class Bme680Worker : SensorWorker
{ {
public Bme680Worker(ILogger<Bme680Worker> logger, SensorTelemetry sensorTelemetry, ISensor<Bme680Sensor> sensor) public Bme680Worker(ILogger<Bme680Worker> logger, Telemetry.Telemetry telemetry, ISensor<Bme680Sensor> sensor)
{ {
Logger = logger; Logger = logger;
MeasurementInterval = 3000; MeasurementInterval = 3000;
TelemetryPublisher = sensorTelemetry.Publisher; TelemetryPublisher = telemetry.Publisher;
Sensor = sensor.Object; Sensor = sensor.Object;
} }
} }

View file

@ -5,11 +5,11 @@ namespace NucuCar.Sensors.Health
{ {
public class CpuTempWorker : SensorWorker public class CpuTempWorker : SensorWorker
{ {
public CpuTempWorker(ILogger<CpuTempWorker> logger, SensorTelemetry sensorTelemetry, ISensor<CpuTempSensor> sensor) public CpuTempWorker(ILogger<CpuTempWorker> logger, Telemetry.Telemetry telemetry, ISensor<CpuTempSensor> sensor)
{ {
Logger = logger; Logger = logger;
MeasurementInterval = 3000; MeasurementInterval = 3000;
TelemetryPublisher = sensorTelemetry.Publisher; TelemetryPublisher = telemetry.Publisher;
Sensor = sensor.Object; Sensor = sensor.Object;
} }
} }

View file

@ -24,7 +24,7 @@ namespace NucuCar.Sensors
services.Configure<CpuTempConfig>(hostContext.Configuration.GetSection("HealthSensor")); services.Configure<CpuTempConfig>(hostContext.Configuration.GetSection("HealthSensor"));
// Singletons // Singletons
services.AddSingleton<SensorTelemetry>(); services.AddSingleton<Telemetry.Telemetry>();
services.AddSingleton<ISensor<Bme680Sensor>, Bme680Sensor>(); services.AddSingleton<ISensor<Bme680Sensor>, Bme680Sensor>();
services.AddSingleton<ISensor<CpuTempSensor>, CpuTempSensor>(); services.AddSingleton<ISensor<CpuTempSensor>, CpuTempSensor>();

View file

@ -6,15 +6,19 @@ using NucuCar.Domain.Telemetry;
namespace NucuCar.Telemetry namespace NucuCar.Telemetry
{ {
public class SensorTelemetry public class Telemetry
{ {
public TelemetryPublisher Publisher { get; set; } public TelemetryPublisher Publisher { get; set; }
public SensorTelemetry() /// <summary>
/// Class used together with the DI, holds a Publisher instance that's being create by options from
/// TelemetryConfig.
/// </summary>
public Telemetry()
{ {
} }
public SensorTelemetry(ILogger<SensorTelemetry> logger, IOptions<TelemetryConfig> options) public Telemetry(ILogger<Telemetry> logger, IOptions<TelemetryConfig> options)
{ {
if (options.Value.ServiceEnabled) if (options.Value.ServiceEnabled)
{ {

View file

@ -19,12 +19,12 @@ namespace NucuCar.Telemetry
private readonly TelemetryPublisher _telemetryPublisher; private readonly TelemetryPublisher _telemetryPublisher;
public TelemetryWorker(ILogger<TelemetryWorker> logger, IOptions<TelemetryConfig> options, public TelemetryWorker(ILogger<TelemetryWorker> logger, IOptions<TelemetryConfig> options,
SensorTelemetry sensorTelemetry) Telemetry telemetry)
{ {
_logger = logger; _logger = logger;
_interval = options.Value.PublishInterval; _interval = options.Value.PublishInterval;
_serviceEnabled = options.Value.ServiceEnabled; _serviceEnabled = options.Value.ServiceEnabled;
_telemetryPublisher = sensorTelemetry.Publisher; _telemetryPublisher = telemetry.Publisher;
} }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) protected override async Task ExecuteAsync(CancellationToken stoppingToken)

View file

@ -5,7 +5,6 @@ using Microsoft.Extensions.Options;
using Moq; using Moq;
using NucuCar.Sensors; using NucuCar.Sensors;
using NucuCar.Sensors.Environment; using NucuCar.Sensors.Environment;
using NucuCar.Telemetry;
using NucuCarSensorsProto; using NucuCarSensorsProto;
using Xunit; using Xunit;
@ -15,7 +14,7 @@ namespace NucuCar.UnitTests.NucuCar.Sensors.Tests.EnvironmentSensor.Tests
{ {
private readonly Mock<ILogger<Bme680Worker>> _mockLogger; private readonly Mock<ILogger<Bme680Worker>> _mockLogger;
private readonly Mock<IOptions<Bme680Config>> _mockOptions; private readonly Mock<IOptions<Bme680Config>> _mockOptions;
private readonly Mock<SensorTelemetry> _mockSensorTelemetry; private readonly Mock<global::NucuCar.Telemetry.Telemetry> _mockSensorTelemetry;
private readonly Mock<TestBme680Sensor> _mockTestBme680Sensor; private readonly Mock<TestBme680Sensor> _mockTestBme680Sensor;
private readonly Mock<ISensor<Bme680Sensor>> _mockBme680ISensor; private readonly Mock<ISensor<Bme680Sensor>> _mockBme680ISensor;
private readonly CancellationTokenSource _cts; private readonly CancellationTokenSource _cts;
@ -25,7 +24,7 @@ namespace NucuCar.UnitTests.NucuCar.Sensors.Tests.EnvironmentSensor.Tests
_cts = new CancellationTokenSource(); _cts = new CancellationTokenSource();
_mockLogger = new Mock<ILogger<Bme680Worker>>(); _mockLogger = new Mock<ILogger<Bme680Worker>>();
_mockOptions = new Mock<IOptions<Bme680Config>>(); _mockOptions = new Mock<IOptions<Bme680Config>>();
_mockSensorTelemetry = new Mock<SensorTelemetry>(); _mockSensorTelemetry = new Mock<global::NucuCar.Telemetry.Telemetry>();
_mockTestBme680Sensor = new Mock<TestBme680Sensor>(); _mockTestBme680Sensor = new Mock<TestBme680Sensor>();
_mockBme680ISensor = new Mock<ISensor<Bme680Sensor>>(); _mockBme680ISensor = new Mock<ISensor<Bme680Sensor>>();

View file

@ -11,10 +11,20 @@ https://docs.microsoft.com/en-us/dotnet/core/install/
### NucuCar.Domain ### NucuCar.Domain
Holds common classes and interfaces that are required by the other projects. Holds common classes and interfaces that are required by the projects.
It provides all the types that are generated via protocol buffers. It provides all the types that are generated via protocol buffers.
### NucuCar.Common
Contains implementations for common logic, contains wrappers.
Usually utility classes and methods that are not necessarily tied to this solution
and can be reused.
### NucuCar.Telemetry
Holds concrete implementation for telemetry publishers and workers.
### NucuCar.Sensors ### NucuCar.Sensors
Manages all the car sensors. For more info see the readme file located in the project directory. Manages all the car sensors. For more info see the readme file located in the project directory.