generated from ut-issl/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
114 lines (96 loc) · 3.65 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.IO;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using WINGS_TMTC_IF.Services;
using WINGS_TMTC_IF.Services.MOBC;
using WINGS_TMTC_IF.Services.SECONDARY_OBC;
using WINGS_TMTC_IF.Services.IsslCommon;
namespace WINGS_TMTC_IF
{
public class Program
{
public static void Main(string[] args)
{
var services = ConfigureServices();
var serviceProvider = services.BuildServiceProvider();
serviceProvider.GetService<App>().Run();
}
private static IServiceCollection ConfigureServices()
{
IServiceCollection services = new ServiceCollection();
var configuration = LoadConfiguration();
services.AddSingleton(configuration);
services.AddTransient<App>();
services.AddTransient<IOperationService, OperationService>();
services.AddTransient<TmtcPacketService>();
ConfigureUserDefinedServices(services, configuration);
return services;
}
private static IConfiguration LoadConfiguration()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
return builder.Build();
}
private static void ConfigureUserDefinedServices(IServiceCollection services, IConfiguration configuration)
{
var component = ConsoleSelectComponent(configuration);
switch (component)
{
case "MOBC_UART":
services.AddSingleton<IPortManager, SerialPortManager>();
services.AddSingleton<ITmPacketExtractor, MobcUartTmPacketExtractor>();
services.AddSingleton<ITcPacketHandler, MobcUartTcPacketHandler>();
configuration["SerialPort:BaudRate:Using"] = configuration["SerialPort:BaudRate:MOBC_UART"];
break;
case "MOBC_RF":
services.AddSingleton<IPortManager, LanPortManager>();
services.AddSingleton<ITmPacketExtractor, MobcRfTmPacketExtractor>();
services.AddSingleton<ITcPacketHandler, MobcRfTcPacketHandler>();
configuration["SerialPort:BaudRate:Using"] = configuration["SerialPort:BaudRate:MOBC_RF"];
break;
case "SECONDARY_OBC":
services.AddSingleton<IPortManager, SerialPortManager>();
services.AddSingleton<ITmPacketExtractor, SecondaryObcTmPacketExtractor>();
services.AddSingleton<ITcPacketHandler, SecondaryObcTcPacketHandler>();
configuration["SerialPort:BaudRate:Using"] = configuration["SerialPort:BaudRate:SECONDARY_OBC"];
break;
case "ISSL_COMMON":
services.AddSingleton<IPortManager, SerialPortManager>();
services.AddSingleton<ITmPacketExtractor, IsslCommonTmPacketExtractor>();
services.AddSingleton<ITcPacketHandler, IsslCommonTcPacketHandler>();
configuration["SerialPort:BaudRate:Using"] = configuration["SerialPort:BaudRate:ISSL_COMMON"];
break;
default:
throw new Exception();
}
}
private static string ConsoleSelectComponent(IConfiguration configuration)
{
int num;
var compos = configuration.GetSection("ComponentList").Get<string[]>();
Console.WriteLine("Select component and press enter");
for (int i = 0; i < compos.Length; i++)
{
Console.WriteLine("[ {0} ] : {1}", i, compos[i]);
}
while (true)
{
try
{
num = int.Parse(Console.ReadLine());
if (num < compos.Length)
{
return compos[num];
}
}
catch
{
}
Console.WriteLine("Error unexpected input");
}
}
}
}