2019-11-10 12:38:40 +00:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2019-11-09 13:34:49 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2020-08-01 15:07:13 +00:00
|
|
|
using NucuCar.Sensors.Abstractions;
|
2020-02-02 14:19:53 +00:00
|
|
|
using NucuCar.Sensors.Grpc;
|
2020-08-01 15:22:38 +00:00
|
|
|
using NucuCar.Sensors.Modules.Environment;
|
|
|
|
using NucuCar.Sensors.Modules.Health;
|
2020-10-24 13:06:04 +00:00
|
|
|
using NucuCar.Sensors.Modules.Heartbeat;
|
2020-04-17 15:11:07 +00:00
|
|
|
using NucuCar.Telemetry;
|
2019-11-09 13:34:49 +00:00
|
|
|
|
2019-11-09 17:23:07 +00:00
|
|
|
namespace NucuCar.Sensors
|
2019-11-09 13:34:49 +00:00
|
|
|
{
|
|
|
|
public class Program
|
|
|
|
{
|
|
|
|
public static void Main(string[] args)
|
|
|
|
{
|
|
|
|
CreateHostBuilder(args).Build().Run();
|
|
|
|
}
|
2019-11-10 12:38:40 +00:00
|
|
|
|
2019-11-09 13:34:49 +00:00
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
|
|
Host.CreateDefaultBuilder(args)
|
2019-11-11 11:28:52 +00:00
|
|
|
.ConfigureServices((hostContext, services) =>
|
|
|
|
{
|
2019-11-26 18:24:27 +00:00
|
|
|
services.Configure<TelemetryConfig>(hostContext.Configuration.GetSection("Telemetry"));
|
|
|
|
services.Configure<Bme680Config>(hostContext.Configuration.GetSection("EnvironmentSensor"));
|
2019-12-29 12:10:58 +00:00
|
|
|
services.Configure<CpuTempConfig>(hostContext.Configuration.GetSection("HealthSensor"));
|
2020-10-24 13:06:04 +00:00
|
|
|
services.Configure<HeartbeatConfig>(hostContext.Configuration.GetSection("HeartbeatSensor"));
|
2019-11-26 18:24:27 +00:00
|
|
|
|
2019-11-24 15:47:17 +00:00
|
|
|
// Singletons
|
2020-05-01 08:29:59 +00:00
|
|
|
services.AddSingleton<Telemetry.Telemetry>();
|
2019-11-30 16:55:55 +00:00
|
|
|
services.AddSingleton<ISensor<Bme680Sensor>, Bme680Sensor>();
|
2019-12-29 12:08:18 +00:00
|
|
|
services.AddSingleton<ISensor<CpuTempSensor>, CpuTempSensor>();
|
2020-10-24 13:06:04 +00:00
|
|
|
services.AddSingleton<ISensor<HeartbeatSensor>, HeartbeatSensor>();
|
2020-10-25 13:31:54 +00:00
|
|
|
|
2019-11-24 15:47:17 +00:00
|
|
|
// Workers
|
2020-10-25 13:31:54 +00:00
|
|
|
// Telemetry
|
2019-11-24 16:40:42 +00:00
|
|
|
services.AddHostedService<TelemetryWorker>();
|
2020-10-25 13:31:54 +00:00
|
|
|
// Sensors
|
2019-11-24 16:40:42 +00:00
|
|
|
services.AddHostedService<Bme680Worker>();
|
2019-12-29 12:08:18 +00:00
|
|
|
services.AddHostedService<CpuTempWorker>();
|
2020-10-24 13:06:04 +00:00
|
|
|
services.AddHostedService<HeartbeatWorker>();
|
2019-11-11 11:28:52 +00:00
|
|
|
})
|
2019-11-26 18:24:27 +00:00
|
|
|
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<GrpcStartup>(); });
|
2019-11-09 13:34:49 +00:00
|
|
|
}
|
|
|
|
}
|