-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
111 lines (96 loc) · 3.68 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
using System;
using System.IO;
using System.Threading;
using Newtonsoft.Json;
using SensorServer.Configuration;
using SensorServer.DepthCamera;
using SensorServer.ProjectorControl;
namespace SensorServer
{
class Program
{
private static CameraController _cameraController = null;
private static ProtobufCommunication _protobufCommunication = null;
private static bool _finished = false;
/// <summary>
/// Read configuration file, initialize data sender and depth camera controller
/// </summary>
static void Main()
{
AppConfiguration config = new();
try
{
string json = File.ReadAllText("config.json");
config = JsonConvert.DeserializeObject<AppConfiguration>(json);
}
catch
{
Console.WriteLine("Config file not found");
}
Console.CancelKeyPress += new ConsoleCancelEventHandler(ConsoleEventHandler);
_protobufCommunication = new(config.CommunicationConfiguration.Host, config.CommunicationConfiguration.Port);
while (true)
{
if (_finished) break;
_protobufCommunication.Connect();
Thread readThread = null;
switch (config.ProjectorControl)
{
case ProjectorControlType.HdmiCec:
_protobufCommunication.ProjectorController = new HdmiProjectorController();
break;
case ProjectorControlType.Pjlink:
_protobufCommunication.ProjectorController = new PjlinkProjectorController(config.PjlinkConfiguration);
break;
}
if (config.ProjectorControl != ProjectorControlType.None)
{
readThread = new(_protobufCommunication.Start);
readThread.Start();
}
if (config.DepthCamera)
{
_cameraController = new(_protobufCommunication, config.DepthCameraConfiguration);
try
{
_cameraController.Start();
}
catch(Exception e)
{
if (!_protobufCommunication.IsConnected())
{
if(readThread != null)
{
_protobufCommunication.Stop();
_protobufCommunication.Dispose();
}
continue;
}
else
{
Console.WriteLine(e.Message);
}
}
}
if (readThread != null) readThread.Join();
}
}
/// <summary>
/// Added EventHandler for stoping program
/// </summary>
public static void ConsoleEventHandler(object sender, ConsoleCancelEventArgs args)
{
if (args.SpecialKey == ConsoleSpecialKey.ControlC)
{
_finished = true;
_protobufCommunication.Stop();
_protobufCommunication.Dispose();
if (_cameraController != null)
{
_cameraController.Stop();
_cameraController.Dispose();
}
}
}
}
}