2019-11-10 12:38:40 +00:00
|
|
|
using System.Threading.Tasks;
|
2019-11-10 14:02:50 +00:00
|
|
|
using Google.Protobuf.WellKnownTypes;
|
2019-11-10 12:38:40 +00:00
|
|
|
using Grpc.Core;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2019-11-11 11:28:52 +00:00
|
|
|
using NucuCarSensorsProto;
|
2019-11-10 12:38:40 +00:00
|
|
|
|
|
|
|
namespace NucuCar.Sensors.EnvironmentSensor
|
|
|
|
{
|
2019-11-24 13:12:12 +00:00
|
|
|
/// <summary>
|
|
|
|
/// EnvironmentSensor's gRPC service.
|
|
|
|
/// It allows reading the sensor's data using remote procedure calls.
|
|
|
|
/// </summary>
|
2019-11-24 16:03:46 +00:00
|
|
|
public class Bme680GrpcService : EnvironmentSensorGrpcService.EnvironmentSensorGrpcServiceBase
|
2019-11-10 12:38:40 +00:00
|
|
|
{
|
2019-11-24 16:03:46 +00:00
|
|
|
private readonly ILogger<Bme680GrpcService> _logger;
|
2019-11-30 15:44:54 +00:00
|
|
|
private readonly ISensor<Bme680Sensor> _bme680Sensor;
|
2019-11-10 12:38:40 +00:00
|
|
|
|
2019-11-30 15:44:54 +00:00
|
|
|
public Bme680GrpcService(ILogger<Bme680GrpcService> logger, ISensor<Bme680Sensor> bme680Sensor)
|
2019-11-10 12:38:40 +00:00
|
|
|
{
|
2019-11-24 16:03:46 +00:00
|
|
|
_bme680Sensor = bme680Sensor;
|
2019-11-10 12:38:40 +00:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2019-12-06 22:31:28 +00:00
|
|
|
public override Task<NucuCarSensorState> GetState(Empty request, ServerCallContext context)
|
2019-11-10 12:38:40 +00:00
|
|
|
{
|
2019-12-06 22:31:28 +00:00
|
|
|
_logger?.LogDebug($"Calling {nameof(GetState)}.");
|
2019-11-10 14:02:50 +00:00
|
|
|
return Task.FromResult(new NucuCarSensorState()
|
2019-11-10 12:38:40 +00:00
|
|
|
{
|
2019-11-30 15:44:54 +00:00
|
|
|
State = _bme680Sensor.Object.GetState()
|
2019-11-10 14:02:50 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-06 22:31:28 +00:00
|
|
|
public override Task<NucuCarSensorResponse> GetMeasurement(Empty request,
|
2019-11-24 13:12:12 +00:00
|
|
|
ServerCallContext context)
|
2019-11-10 14:02:50 +00:00
|
|
|
{
|
2019-12-06 22:31:28 +00:00
|
|
|
_logger?.LogDebug($"Calling {nameof(GetMeasurement)}.");
|
2019-12-19 20:59:17 +00:00
|
|
|
return Task.FromResult(_bme680Sensor.Object.GetMeasurement());
|
2019-11-10 12:38:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|