AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
InputHandle.cs
1 using System;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using Newtonsoft.Json;
5 using Newtonsoft.Json.Linq;
6 using AirControl;
7 using System.Net.Sockets;
8 using Communicator;
9 
10 namespace Communicator
11 {
15  public class InputHandle:MonoBehaviour
16  {
17  #region Builtin Methods
18  #endregion
19 
20  #region Custom Methods
21  // receive msg to unity
26  public void ParseInput(JObject inputJson)
27  {
28  string MsgType = inputJson["MsgType"].ToString();
29  #region ControlInput
30  if (MsgType=="ControlInput")
31  {
32  //input type
33  string inputControlType = inputJson["InputControlType"].ToString();
34 
35  // Airplane Properties
36  float throttle = float.Parse(inputJson["Throttle"].ToString());
37  float stickyThrottle = float.Parse(inputJson["StickyThrottle"].ToString());
38  float pitch = float.Parse(inputJson["Pitch"].ToString());
39  float roll = float.Parse(inputJson["Roll"].ToString());
40  float yaw = float.Parse(inputJson["Yaw"].ToString());
41  float brake = float.Parse(inputJson["Brake"].ToString());
42  int flaps = int.Parse(inputJson["Flaps"].ToString());
43 
44  // connection = DB_Init.GetConnection();
45  // insert in to static class
46  StaticControlSchema.InputControlType = inputControlType;
47  StaticControlSchema.MsgType = "ControlInput";
48  StaticControlSchema.InputControlType = inputControlType;
49  // Airplane properties
50  StaticControlSchema.Throttle = throttle;
51  StaticControlSchema.StickyThrottle = stickyThrottle;
52  StaticControlSchema.Pitch = pitch;
53  StaticControlSchema.Roll = roll;
54  StaticControlSchema.Yaw = yaw;
55  StaticControlSchema.Brake = brake;
56  StaticControlSchema.Flaps = flaps;
57  }
58  #endregion
59 
60  #region Camera
61  else if (MsgType=="Camera") // if operation type is transaction
62  {
63  //input type
64  bool isActive = bool.Parse(inputJson["IsActive"].ToString());
65  //Scene Camera
66  int activeCamera = int.Parse(inputJson["ActiveCamera"].ToString());
67  bool isCapture = bool.Parse(inputJson["IsCapture"].ToString());
68  int captureCamera = int.Parse(inputJson["CaptureCamera"].ToString());
69  int captureType = int.Parse(inputJson["CaptureType"].ToString());
70  int captureWidth = int.Parse(inputJson["CaptureWidth"].ToString());
71  int captureHeight = int.Parse(inputJson["CaptureHeight"].ToString());
72 
73  //primary key
74  StaticCameraSchema.MsgType = "Camera";
75  // Camrera control
76  StaticCameraSchema.IsActive = isActive;
77  StaticCameraSchema.ActiveCamera = activeCamera;
78  // which screen to capture
79  StaticCameraSchema.IsCapture = isCapture;
80  StaticCameraSchema.CaptureCamera = captureCamera;
81  StaticCameraSchema.CaptureType = captureType;
82  StaticCameraSchema.CaptureWidth = captureWidth;
83  StaticCameraSchema.CaptureHeight = captureHeight;
84 
85  }
86  #endregion
87 
88  #region Level
89  else if (MsgType=="Level") // if operation type is transaction
90  {
91  bool levelReload = bool.Parse(inputJson["LevelReload"].ToString());
92  //set sun location
93  bool isActive = bool.Parse(inputJson["IsActive"].ToString());
94 
95  //primary key
96  StaticLevelSchema.MsgType = "Level";
97  //level reset
98  StaticLevelSchema.LevelReload = levelReload;
99  StaticLevelSchema.IsActive = isActive;
100 
101  }
102  #endregion
103 
104  #region TOD
105  else if (MsgType=="TOD") // if operation type is transaction
106  {
107  //set sun location
108  float sunLatitude = float.Parse(inputJson["SunLatitude"].ToString());
109  float sunLongitude = float.Parse(inputJson["SunLongitude"].ToString());
110  int hour = int.Parse(inputJson["Hour"].ToString());
111  int minute = int.Parse(inputJson["Minute"].ToString());
112  bool isActive = bool.Parse(inputJson["IsActive"].ToString());
113 
114  //primary key
115  StaticTODSchema.MsgType = "TOD";
116  //set sun location
117  StaticTODSchema.SunLatitude = sunLatitude;
118  StaticTODSchema.SunLongitude =sunLongitude;
119  StaticTODSchema.Hour = hour;
120  StaticTODSchema.Minute = minute;
121  StaticTODSchema.IsActive = isActive;
122 
123  }
124  #endregion
125 
126  #region Weather
127  else if (MsgType=="Weather") // if operation type is transaction
128  {
129  //set sun location
130  bool isClouds = bool.Parse(inputJson["IsClouds"].ToString());
131  bool isFog = bool.Parse(inputJson["IsFog"].ToString());
132 
133  //primary key
134  StaticWeatherSchema.MsgType = "Weather";
135  //set if clouds are enabled
136  StaticWeatherSchema.IsClouds = isClouds;
137  //set if fog ia enabled
138  StaticWeatherSchema.IsFog =isFog;
139 
140  }
141  #endregion
142 
143  #region Audio
144  else if (MsgType=="Audio") // if operation type is transaction
145  {
146  //input type
147  bool isActive = bool.Parse(inputJson["IsActive"].ToString());
148  bool enableAudio = bool.Parse(inputJson["EnableAudio"].ToString());
149 
150  //primary key
151  StaticAudioSchema.MsgType = "Audio";
152  // Camrera control
153  StaticAudioSchema.IsActive = isActive;
154  //set if fog ia enabled
155  StaticAudioSchema.EnableAudio =enableAudio;
156  }
157  #endregion
158 
159  #region UI
160  else if (MsgType=="UI") // if operation type is transaction
161  {
162  //input type
163  bool isActive = bool.Parse(inputJson["IsActive"].ToString());
164  bool showUIElements = bool.Parse(inputJson["ShowUIElements"].ToString());
165 
166  //primary key
167  StaticUISchema.MsgType = "UI";
168  // Camrera control
169  StaticUISchema.IsActive = isActive;
170  //set if clouds are enabled
171  StaticUISchema.ShowUIElements = showUIElements;
172  }
173  #endregion
174 
175 
176 
177  #region Lidar
178  else if (MsgType=="Lidar") // if operation type is transaction
179  {
180  float range = float.Parse(inputJson["Range"].ToString());
181  int density = int.Parse(inputJson["Density"].ToString());
182 
183  //primary key
184  StaticLidarSchema.MsgType = "Weather";
185  //set if clouds are enabled
186  StaticLidarSchema.Range = range;
187  //set if fog ia enabled
188  StaticLidarSchema.Density =density;
189 
190  }
191  #endregion
192 
193  #region UIControls
194  // UI control like exit, reload etc
195  // Currently relaod is only supported
196  else if (MsgType=="UIControls") // if operation type is transaction
197  {
198 
199  bool ifExit = bool.Parse(inputJson["ifExit"].ToString());
200  //primary key
201  StaticUIControlsSchema.MsgType = "UIControls";
202  //set if clouds are enabled
203  StaticUIControlsSchema.ifExit = ifExit;
204 
205  }
206  #endregion
207 
208  #region ClientInfo
209  // UI control like exit, reload etc
210  // Currently relaod is only supported
211  else if (MsgType=="ClientInfo") // if operation type is transaction
212  {
213  bool isActive = bool.Parse(inputJson["IsActive"].ToString());
214  string clientIP = inputJson["clientIP"].ToString();
215  string clientPort = inputJson["clientPort"].ToString();
216  StaticClientInfo.IsActive = isActive;
217  StaticClientInfo.ClientIP = clientIP;
218  StaticClientInfo.ClientPort = clientPort;
219 
220  }
221  #endregion
222 
223  #region Fuel
224  else if (MsgType=="Fuel") // if operation type is transaction
225  {
226  // blank for now
227  }
228  #endregion
229 
230  #region StartUp
231  else if (MsgType=="StartUp") // if operation type is transaction
232  {
233  // blank for now
234  }
235  #endregion
236 
237  // gived output if called
238  #region Output
239  else if (MsgType=="Output") // if operation type is transaction
240  {
241  // Do nothing output API will receive output
242  }
243  #endregion
244 
245 
246 
247  }
248 
249  #endregion
250 
251  }
252 }
Communicator.StaticUIControlsSchema
UI control class for serialization deserialization
Definition: IOSchema.cs:508
Communicator.StaticControlSchema.MsgType
static string MsgType
Just [PrimaryKey] is added to the Id Attribute as we only want the updated value and dont want to acc...
Definition: IOSchema.cs:49
Communicator.InputHandle.ParseInput
void ParseInput(JObject inputJson)
Parse input coming from network
Definition: InputHandle.cs:26
AirControl
Definition: AirplaneSelector.cs:8
Communicator.StaticControlSchema
Input control class, acts a dictionary. This class can be accessed anywhere in the code as dict....
Definition: IOSchema.cs:41
Communicator.InputHandle
Handle inbound request from the TCP socket
Definition: InputHandle.cs:15
Communicator
Definition: InputHandle.cs:10