using System.Threading.Tasks; using Google.Protobuf.WellKnownTypes; using Grpc.Core; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using NucuCar.Sensors.Abstractions; using NucuCar.Sensors.Grpc; using NucuCarSensorsProto; namespace NucuCar.Sensors.Environment { /// /// EnvironmentSensor's gRPC service. /// It allows reading the sensor's data using remote procedure calls. /// public class Bme680GrpcService : EnvironmentSensorGrpcService.EnvironmentSensorGrpcServiceBase { private readonly ILogger _logger; private readonly IOptions _options; private readonly ISensor _bme680Sensor; public Bme680GrpcService(ILogger logger, ISensor bme680Sensor, IOptions options) { _bme680Sensor = bme680Sensor; _logger = logger; _options = options; } public override Task GetMeasurement(Empty request, ServerCallContext context) { _logger?.LogDebug($"Calling {nameof(GetMeasurement)}."); if (_options.Value.Grpc) { return Task.FromResult(_bme680Sensor.Object.GetMeasurement()); } return Task.FromResult(Responses.GrpcIsDisabledResponse); } } }