Fix logger not passed in CpuTempSensor.cs
This commit is contained in:
parent
805a132183
commit
d2134b20b6
3 changed files with 9 additions and 8 deletions
|
@ -61,7 +61,7 @@ namespace NucuCar.Domain.Telemetry
|
|||
public bool RegisterTelemeter(ITelemeter t)
|
||||
{
|
||||
if (RegisteredTelemeters.Contains(t)) return false;
|
||||
Logger.LogDebug($"Registering telemeter {t.GetIdentifier()}");
|
||||
Logger?.LogDebug($"Registering telemeter {t.GetIdentifier()}");
|
||||
RegisteredTelemeters.Add(t);
|
||||
return true;
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ namespace NucuCar.Domain.Telemetry
|
|||
public bool UnRegisterTelemeter(ITelemeter t)
|
||||
{
|
||||
if (!RegisteredTelemeters.Contains(t)) return false;
|
||||
Logger.LogDebug($"UnRegistering telemeter {t.GetIdentifier()}");
|
||||
Logger?.LogDebug($"UnRegistering telemeter {t.GetIdentifier()}");
|
||||
RegisteredTelemeters.Remove(t);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,9 @@ namespace NucuCar.Sensors.Health
|
|||
{
|
||||
}
|
||||
|
||||
public CpuTempSensor(IOptions<CpuTempConfig> options)
|
||||
public CpuTempSensor(ILogger<CpuTempSensor> logger, IOptions<CpuTempConfig> options)
|
||||
{
|
||||
Logger = logger;
|
||||
if (options.Value.Enabled)
|
||||
{
|
||||
CurrentState = SensorStateEnum.Uninitialized;
|
||||
|
@ -55,7 +56,7 @@ namespace NucuCar.Sensors.Health
|
|||
}
|
||||
}
|
||||
Logger?.LogDebug($"{DateTimeOffset.Now}:HealthSensor: reading");
|
||||
Logger.LogInformation($"CPU Temperature ${_lastTemperatureCelsius}");
|
||||
Logger?.LogInformation($"CPU Temperature ${_lastTemperatureCelsius}");
|
||||
return Task.FromResult(_lastTemperatureCelsius);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace NucuCar.Sensors
|
|||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
var sensorIdentifier = Sensor.GetIdentifier();
|
||||
Logger.LogInformation($"Starting sensor worker for {sensorIdentifier}");
|
||||
Logger?.LogInformation($"Starting sensor worker for {sensorIdentifier}");
|
||||
TelemetryPublisher?.RegisterTelemeter(Sensor);
|
||||
|
||||
Sensor.Initialize();
|
||||
|
@ -34,14 +34,14 @@ namespace NucuCar.Sensors
|
|||
/* If sensor is ok attempt to read. */
|
||||
if (sensorState == SensorStateEnum.Initialized)
|
||||
{
|
||||
Logger.LogTrace($"{sensorIdentifier} is taking a measurement!");
|
||||
Logger?.LogTrace($"{sensorIdentifier} is taking a measurement!");
|
||||
await Sensor.TakeMeasurementAsync();
|
||||
}
|
||||
/* Else attempt to re-initialize. */
|
||||
else if (sensorState == SensorStateEnum.Uninitialized ||
|
||||
sensorState == SensorStateEnum.Error)
|
||||
{
|
||||
Logger.LogWarning(
|
||||
Logger?.LogWarning(
|
||||
$"{sensorIdentifier} is in {sensorState}! Attempting to re-initialize in {_intializationDelay}ms.");
|
||||
_intializationDelay += 10000;
|
||||
await Task.Delay(_intializationDelay, stoppingToken);
|
||||
|
@ -50,7 +50,7 @@ namespace NucuCar.Sensors
|
|||
else if (sensorState == SensorStateEnum.Disabled)
|
||||
{
|
||||
// Break from while.
|
||||
Logger.LogInformation($"{sensorIdentifier} has been disabled!");
|
||||
Logger?.LogInformation($"{sensorIdentifier} has been disabled!");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue