2020-10-24 13:06:04 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using NucuCar.Sensors.Abstractions;
|
|
|
|
|
using NucuCarSensorsProto;
|
|
|
|
|
|
|
|
|
|
namespace NucuCar.Sensors.Modules.Heartbeat
|
|
|
|
|
{
|
|
|
|
|
public class HeartbeatSensor : GenericTelemeterSensor, ISensor<HeartbeatSensor>
|
|
|
|
|
{
|
|
|
|
|
public HeartbeatSensor()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HeartbeatSensor(ILogger<HeartbeatSensor> logger, IOptions<HeartbeatConfig> options)
|
|
|
|
|
{
|
|
|
|
|
Logger = logger;
|
|
|
|
|
if (options.Value.Enabled)
|
|
|
|
|
{
|
|
|
|
|
CurrentState = SensorStateEnum.Uninitialized;
|
|
|
|
|
Object = this;
|
|
|
|
|
TelemetryEnabled = options.Value.Telemetry;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger?.LogDebug("HeartbeatSensor is disabled!");
|
|
|
|
|
CurrentState = SensorStateEnum.Disabled;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
Logger?.LogDebug("Heartbeat sensor initialized!");
|
|
|
|
|
CurrentState = SensorStateEnum.Initialized;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Task TakeMeasurementAsync()
|
|
|
|
|
{
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override NucuCarSensorResponse GetMeasurement()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override SensorStateEnum GetState()
|
|
|
|
|
{
|
|
|
|
|
return CurrentState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetIdentifier()
|
|
|
|
|
{
|
2020-11-23 19:24:01 +00:00
|
|
|
|
return "Heartbeat";
|
2020-10-24 13:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Dictionary<string, object> GetTelemetryData()
|
|
|
|
|
{
|
|
|
|
|
var returnValue = new Dictionary<string, object>
|
|
|
|
|
{
|
|
|
|
|
["sensor_state"] = CurrentState,
|
|
|
|
|
["value"] = 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsTelemetryEnabled()
|
|
|
|
|
{
|
|
|
|
|
return TelemetryEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HeartbeatSensor Object { get; }
|
|
|
|
|
}
|
|
|
|
|
}
|