-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExportScript.lua
173 lines (139 loc) · 5.16 KB
/
ExportScript.lua
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
-- Ikarus and D.A.C. Export Script
--
-- Copyright by Michael aka McMicha 2014 - 2018
-- Contact [email protected]
-- Main Table
ExportScript = {}
ExportScript.Version = {}
ExportScript.Version.ExportScript = "1.2.1"
-- Simulation id
ExportScript.SimID = string.format("%08x*",os.time())
-- State data for export
ExportScript.PacketSize = 0
ExportScript.SendStrings = {}
ExportScript.LastData = {}
ExportScript.PacketSizeDAC = {}
ExportScript.SendStringsDAC = {}
ExportScript.LastDataDAC = {}
ExportScript.lastExportTimeHI = 0
ExportScript.lastExportTimeLI = 0
ExportScript.NoLuaExportBeforeNextFrame = false
local PrevExport = {}
PrevExport.LuaExportStart = LuaExportStart
PrevExport.LuaExportStop = LuaExportStop
PrevExport.LuaExportBeforeNextFrame = LuaExportBeforeNextFrame
PrevExport.LuaExportAfterNextFrame = LuaExportAfterNextFrame
dofile(lfs.writedir()..[[Scripts\DCS-ExportScript\Config.lua]])
ExportScript.utf8 = dofile(lfs.writedir()..[[Scripts\DCS-ExportScript\lib\utf8.lua]])
dofile(lfs.writedir()..[[Scripts\DCS-ExportScript\lib\Tools.lua]])
dofile(lfs.writedir()..[[Scripts\DCS-ExportScript\lib\genericRadio.lua]])
dofile(lfs.writedir()..[[Scripts\DCS-ExportScript\lib\Maps.lua]])
for i = 1, #ExportScript.Config.DAC, 1 do
ExportScript.PacketSizeDAC[i] = 0
ExportScript.SendStringsDAC[i] = {}
ExportScript.LastDataDAC[i] = {}
end
-- Found DCS or FC Module
ExportScript.FoundDCSModule = false
ExportScript.FoundFCModule = false
ExportScript.FoundNoModul = true
---------------------------------------------
-- DCS Export API Function Implementations --
---------------------------------------------
function LuaExportStart()
-- Works once just before mission start.
-- (and before player selects their aircraft, if there is a choice!)
-- 2) Setup udp sockets to talk to GlassCockpit
package.path = package.path..";.\\LuaSocket\\?.lua"
package.cpath = package.cpath..";.\\LuaSocket\\?.dll"
--local lrename1, lrename2 = os.rename(ExportScript.Config.LogPath, ExportScript.Config.LogPath..".old")
ExportScript.logFile = io.open(ExportScript.Config.LogPath, "wa") -- "W+"
if ExportScript.logFile then
ExportScript.logFile:write('\239\187\191') -- create a UTF-8 BOM
ExportScript.logFile:write("ExportScript Version: "..ExportScript.Version.ExportScript.."\r\n")
end
--if lrenmae1 == nil then
-- ExportScript.Tools.WriteToLog("Rename Error: "..lrename2)
--end
ExportScript.Tools.createUDPSender()
ExportScript.Tools.createUDPListner()
ExportScript.AF = {} -- Table for Auxiliary functions
ExportScript.NoLuaExportBeforeNextFrame = false
ExportScript.Tools.SelectModule() -- point globals to Module functions and data.
-- Chain previously-included export as necessary
if PrevExport.LuaExportStart then
PrevExport.LuaExportStart()
end
end
function LuaExportBeforeNextFrame()
--[[ if ExportScript.Config.Debug then
ExportScript.Tools.ProcessInput()
else
ExportScript.coProcessArguments_BeforeNextFrame = coroutine.create(ExportScript.Tools.ProcessInput)
coStatus = coroutine.resume(ExportScript.coProcessArguments_BeforeNextFrame)
end
if ExportScript.NoLuaExportBeforeNextFrame == false then
ExportScript.Tools.ProcessOutput()
end
]]
-- Chain previously-included export as necessary
if PrevExport.LuaExportBeforeNextFrame then
PrevExport.LuaExportBeforeNextFrame()
end
end
function LuaExportAfterNextFrame()
if ExportScript.NoLuaExportBeforeNextFrame then
ExportScript.Tools.ProcessOutput()
end
-- Chain previously-included export as necessary
if PrevExport.LuaExportAfterNextFrame then
PrevExport.LuaExportAfterNextFrame()
end
end
function LuaExportActivityNextEvent(t)
local tNext = t
-- Put your event code here and increase tNext for the next event
-- so this function will be called automatically at your custom
-- model times.
-- If tNext == t then the activity will be terminated.
if ExportScript.Config.Debug then
ExportScript.Tools.ProcessInput()
else
ExportScript.coProcessArguments_BeforeNextFrame = coroutine.create(ExportScript.Tools.ProcessInput)
coStatus = coroutine.resume(ExportScript.coProcessArguments_BeforeNextFrame)
end
if ExportScript.NoLuaExportBeforeNextFrame == false then
ExportScript.Tools.ProcessOutput()
end
tNext = tNext + ExportScript.Config.ExportInterval
return tNext
end
function LuaExportStop()
-- Works once just after mission stop.
if ExportScript.Config.DACExport then
ExportScript.Tools.SendDataDAC("DAC", "stop")
for i=1, #ExportScript.Config.DAC, 1 do
ExportScript.Tools.FlushDataDAC(i)
end
end
if ExportScript.Config.IkarusExport then
ExportScript.Tools.SendData("Ikarus", "stop")
ExportScript.Tools.FlushData()
end
ExportScript.UDPsender:close()
if ExportScript.Config.Listener then
ExportScript.UDPListener:close()
end
ExportScript.ModuleName = nil
ExportScript.FoundNoModul = false
if ExportScript.logFile then
ExportScript.Tools.WriteToLog("====== Logfile close ======")
ExportScript.logFile:flush()
ExportScript.logFile:close()
ExportScript.logFile = nil
end
-- Chain previously-included export as necessary
if PrevExport.LuaExportStop then
PrevExport.LuaExportStop()
end
end