Subversion Repositories group.electronics

Rev

Rev 156 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
155 pfowler 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
 
7
using Microsoft.FlightSimulator.SimConnect;
8
using System.Runtime.InteropServices;
9
 
10
namespace NITNavComm {
11
    public class FSXObject {
12
 
13
        public SimData simdata;
14
        public SimConnect hSimConnect = null;
15
 
16
        public enum DATA_REQUESTS {
17
            AIRCRAFT,
18
            AVIONICS,
19
            NAVCOM1_REQ,
20
            NAVCOM2_REQ
21
        }
22
 
23
        public enum DEFINITIONS {
24
            AIRCRAFT,
25
            AVIONICS,
26
            NAVCOM1_DATA,
27
            NAVCOM2_DATA
28
        }
29
 
30
        public enum EVENT_ID {
31
            COM1_SWAP_FREQ,
32
            NAV1_SWAP_FREQ,
33
            COM_RADIO_WHOLE_INC,
34
            COM_RADIO_WHOLE_DEC,
35
            COM_RADIO_FRACT_INC,
36
            COM_RADIO_FRACT_DEC,
37
            NAV1_RADIO_WHOLE_INC,
38
            NAV1_RADIO_WHOLE_DEC,
39
            NAV1_RADIO_FRACT_INC,
40
            NAV1_RADIO_FRACT_DEC,
41
            COM2_SWAP_FREQ,
42
            NAV2_SWAP_FREQ,
43
            COM2_RADIO_WHOLE_INC,
44
            COM2_RADIO_WHOLE_DEC,
45
            COM2_RADIO_FRACT_INC,
46
            COM2_RADIO_FRACT_DEC,
47
            NAV2_RADIO_WHOLE_INC,
48
            NAV2_RADIO_WHOLE_DEC,
49
            NAV2_RADIO_FRACT_INC,
50
            NAV2_RADIO_FRACT_DEC,
51
        }
52
 
53
        public enum GROUP_ID {
54
            NAVCOM1,
55
            NAVCOM2
56
        }
57
 
58
        public struct SimData {
59
            public uint objectid;
60
            public Aircraft_Data aircraft;
61
        }
62
 
63
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
64
        public struct NavCom_Data {
65
            public double Freq0;
66
            public double Freq1;
67
            public double Freq2;
68
            public double Freq3;
69
        }
70
 
71
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
72
        public struct Avionics_Data {
73
            public bool avionics_master;
74
            public double com1_status;
75
            public double com2_status;
76
        }
77
 
78
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
79
        public struct Aircraft_Data {
80
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
81
            public string atc_type;
82
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
83
            public string atc_model;
84
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
85
            public string atc_id;
86
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
87
            public string title;
88
        }
89
 
90
        public FSXObject() {
91
            this.simdata = new SimData();
92
        }
93
 
94
        public void Comm1DecFract() {
95
            this.hSimConnect.TransmitClientEvent(
96
                this.simdata.objectid,
97
                FSXObject.EVENT_ID.COM_RADIO_FRACT_DEC, 1,
98
                FSXObject.GROUP_ID.NAVCOM1,
99
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
100
            );
101
        }
102
 
103
        public void Comm1DecWhole() {
104
            this.hSimConnect.TransmitClientEvent(
105
                this.simdata.objectid,
106
                FSXObject.EVENT_ID.COM_RADIO_WHOLE_DEC, 1,
107
                FSXObject.GROUP_ID.NAVCOM1,
108
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
109
            );
110
        }
111
 
112
        public void Comm1IncFract() {
113
            this.hSimConnect.TransmitClientEvent(
114
                this.simdata.objectid,
115
                FSXObject.EVENT_ID.COM_RADIO_FRACT_INC, 1,
116
                FSXObject.GROUP_ID.NAVCOM1,
117
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
118
            );
119
        }
120
 
121
        public void Comm1IncWhole() {
122
            this.hSimConnect.TransmitClientEvent(
123
                this.simdata.objectid,
124
                FSXObject.EVENT_ID.COM_RADIO_WHOLE_INC, 1,
125
                FSXObject.GROUP_ID.NAVCOM1,
126
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
127
            );
128
        }
129
 
130
        public void Comm1SwapFreq() {
131
            this.hSimConnect.TransmitClientEvent(
132
                this.simdata.objectid,
133
                FSXObject.EVENT_ID.COM1_SWAP_FREQ, 1,
134
                FSXObject.GROUP_ID.NAVCOM1,
135
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
136
            );
137
        }
138
 
139
        public void Nav1DecFract() {
140
            this.hSimConnect.TransmitClientEvent(
141
                this.simdata.objectid,
142
                FSXObject.EVENT_ID.NAV1_RADIO_FRACT_DEC, 1,
143
                FSXObject.GROUP_ID.NAVCOM1,
144
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
145
            );
146
        }
147
 
148
        public void Nav1DecWhole() {
149
            this.hSimConnect.TransmitClientEvent(
150
                this.simdata.objectid,
151
                FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_DEC, 1,
152
                FSXObject.GROUP_ID.NAVCOM1,
153
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
154
            );
155
        }
156
 
157
        public void Nav1IncFract() {
158
            this.hSimConnect.TransmitClientEvent(
159
                this.simdata.objectid,
160
                FSXObject.EVENT_ID.NAV1_RADIO_FRACT_INC, 1,
161
                FSXObject.GROUP_ID.NAVCOM1,
162
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
163
            );
164
        }
165
 
166
        public void Nav1IncWhole() {
167
            this.hSimConnect.TransmitClientEvent(
168
                this.simdata.objectid,
169
                FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_INC, 1,
170
                FSXObject.GROUP_ID.NAVCOM1,
171
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
172
            );
173
        }
174
 
175
        public void Nav1SwapFreq() {
176
            this.hSimConnect.TransmitClientEvent(
177
                this.simdata.objectid,
178
                FSXObject.EVENT_ID.NAV1_SWAP_FREQ, 1,
179
                FSXObject.GROUP_ID.NAVCOM1,
180
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
181
            );
182
        }
183
 
184
 
185
 
186
 
187
        public void Comm2DecFract() {
188
            this.hSimConnect.TransmitClientEvent(
189
                this.simdata.objectid,
190
                FSXObject.EVENT_ID.COM2_RADIO_FRACT_DEC, 1,
191
                FSXObject.GROUP_ID.NAVCOM2,
192
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
193
            );
194
        }
195
 
196
        public void Comm2DecWhole() {
197
            this.hSimConnect.TransmitClientEvent(
198
                this.simdata.objectid,
199
                FSXObject.EVENT_ID.COM2_RADIO_WHOLE_DEC, 1,
200
                FSXObject.GROUP_ID.NAVCOM2,
201
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
202
            );
203
        }
204
 
205
        public void Comm2IncFract() {
206
            this.hSimConnect.TransmitClientEvent(
207
                this.simdata.objectid,
208
                FSXObject.EVENT_ID.COM2_RADIO_FRACT_INC, 1,
209
                FSXObject.GROUP_ID.NAVCOM2,
210
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
211
            );
212
        }
213
 
214
        public void Comm2IncWhole() {
215
            this.hSimConnect.TransmitClientEvent(
216
                this.simdata.objectid,
217
                FSXObject.EVENT_ID.COM2_RADIO_WHOLE_INC, 1,
218
                FSXObject.GROUP_ID.NAVCOM2,
219
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
220
            );
221
        }
222
 
223
        public void Comm2SwapFreq() {
224
            this.hSimConnect.TransmitClientEvent(
225
                this.simdata.objectid,
226
                FSXObject.EVENT_ID.COM2_SWAP_FREQ, 1,
227
                FSXObject.GROUP_ID.NAVCOM2,
228
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
229
            );
230
        }
231
 
232
        public void Nav2DecFract() {
233
            this.hSimConnect.TransmitClientEvent(
234
                this.simdata.objectid,
235
                FSXObject.EVENT_ID.NAV2_RADIO_FRACT_DEC, 1,
236
                FSXObject.GROUP_ID.NAVCOM1,
237
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
238
            );
239
        }
240
 
241
        public void Nav2DecWhole() {
242
            this.hSimConnect.TransmitClientEvent(
243
                this.simdata.objectid,
244
                FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_DEC, 1,
245
                FSXObject.GROUP_ID.NAVCOM2,
246
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
247
            );
248
        }
249
 
250
        public void Nav2IncFract() {
251
            this.hSimConnect.TransmitClientEvent(
252
                this.simdata.objectid,
253
                FSXObject.EVENT_ID.NAV2_RADIO_FRACT_INC, 1,
254
                FSXObject.GROUP_ID.NAVCOM2,
255
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
256
            );
257
        }
258
 
259
        public void Nav2IncWhole() {
260
            this.hSimConnect.TransmitClientEvent(
261
                this.simdata.objectid,
262
                FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_INC, 1,
263
                FSXObject.GROUP_ID.NAVCOM2,
264
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
265
            );
266
        }
267
 
268
        public void Nav2SwapFreq() {
269
            this.hSimConnect.TransmitClientEvent(
270
                this.simdata.objectid,
271
                FSXObject.EVENT_ID.NAV2_SWAP_FREQ, 1,
272
                FSXObject.GROUP_ID.NAVCOM2,
273
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
274
            );
275
        }
276
    }
277
}