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;
|
2021-08-02 18:13:59 +00:00
|
|
|
using NucuCar.Sensors.Modules.BME680;
|
|
|
|
using NucuCar.Sensors.Modules.CpuTemperature;
|
2020-10-24 13:06:04 +00:00
|
|
|
using NucuCar.Sensors.Modules.Heartbeat;
|
2021-04-25 15:40:56 +00:00
|
|
|
using NucuCar.Sensors.Modules.PMS5003;
|
2020-04-17 15:11:07 +00:00
|
|
|
using NucuCar.Telemetry;
|
2021-08-02 18:28:02 +00:00
|
|
|
using NucuCar.Telemetry.Abstractions;
|
2021-10-03 20:37:53 +00:00
|
|
|
using NucuCar.Telemetry.Publishers;
|
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) =>
|
|
|
|
{
|
2021-10-03 20:37:53 +00:00
|
|
|
services.Configure<Config>(hostContext.Configuration.GetSection("Telemetry"));
|
2021-08-02 18:13:59 +00:00
|
|
|
services.Configure<Bme680Config>(hostContext.Configuration.GetSection("Bme680Sensor"));
|
|
|
|
services.Configure<CpuTempConfig>(hostContext.Configuration.GetSection("CpuTemperatureSensor"));
|
2020-10-24 13:06:04 +00:00
|
|
|
services.Configure<HeartbeatConfig>(hostContext.Configuration.GetSection("HeartbeatSensor"));
|
2021-04-25 15:40:56 +00:00
|
|
|
services.Configure<Pms5003Config>(hostContext.Configuration.GetSection("Pms5003Sensor"));
|
2019-11-26 18:24:27 +00:00
|
|
|
|
2019-11-24 15:47:17 +00:00
|
|
|
// Singletons
|
2021-10-03 20:37:53 +00:00
|
|
|
services.AddSingleton<ITelemetryPublisher, PublisherProxy>();
|
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>();
|
2021-04-25 15:40:56 +00:00
|
|
|
services.AddSingleton<ISensor<Pms5003Sensor>, Pms5003Sensor>();
|
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>();
|
2021-04-25 15:40:56 +00:00
|
|
|
services.AddHostedService<Pms5003Worker>();
|
2021-08-01 17:35:54 +00:00
|
|
|
});
|
2019-11-09 13:34:49 +00:00
|
|
|
}
|
|
|
|
}
|