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-11 10:59:07 +00:00
|
|
|
public class GrpcService : EnvironmentSensorGrpcService.EnvironmentSensorGrpcServiceBase
|
2019-11-10 12:38:40 +00:00
|
|
|
{
|
2019-11-11 10:59:07 +00:00
|
|
|
private readonly ILogger<GrpcService> _logger;
|
2019-11-23 21:06:01 +00:00
|
|
|
private readonly Bme680Sensor _bme680Sensor;
|
2019-11-10 12:38:40 +00:00
|
|
|
|
2019-11-11 10:59:07 +00:00
|
|
|
public GrpcService(ILogger<GrpcService> logger)
|
2019-11-10 12:38:40 +00:00
|
|
|
{
|
2019-11-23 21:06:01 +00:00
|
|
|
_bme680Sensor = Bme680Sensor.Instance;
|
2019-11-10 12:38:40 +00:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2019-11-10 14:02:50 +00:00
|
|
|
public override Task<NucuCarSensorState> GetSensorState(Empty request, ServerCallContext context)
|
2019-11-10 12:38:40 +00:00
|
|
|
{
|
2019-11-23 21:06:01 +00:00
|
|
|
_logger?.LogDebug($"Calling {nameof(GetSensorState)}.");
|
2019-11-10 14:02:50 +00:00
|
|
|
return Task.FromResult(new NucuCarSensorState()
|
2019-11-10 12:38:40 +00:00
|
|
|
{
|
2019-11-23 21:06:01 +00:00
|
|
|
State = _bme680Sensor.GetState()
|
2019-11-10 14:02:50 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<EnvironmentSensorMeasurement> GetSensorMeasurement(Empty request, ServerCallContext context)
|
|
|
|
{
|
2019-11-23 21:06:01 +00:00
|
|
|
_logger?.LogDebug($"Calling {nameof(GetSensorMeasurement)}.");
|
|
|
|
var sensorMeasurement = _bme680Sensor.GetMeasurement();
|
2019-11-11 10:59:07 +00:00
|
|
|
return Task.FromResult(sensorMeasurement);
|
2019-11-10 12:38:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|