-- Data export script for Lock On version 1.2. -- Copyright (C) 2006, Eagle Dynamics. -- See http://www.lua.org for Lua script system info -- We recommend to use the LuaSocket addon (http://www.tecgraf.puc-rio.br/luasocket) -- to use standard network protocols in Lua scripts. -- LuaSocket 2.0 files (*.dll and *.lua) are supplied in the Scripts/LuaSocket folder -- and in the installation folder of the Lock On version 1.2. -- Please, set EnableExportScript = true in the Config/Export/Config.lua file -- to activate this script! -- Expand the functionality of following functions for your external application needs. -- Look into ./Temp/Error.log for this script errors, please. -- Uncomment if using Vector class from the Config/Export/Vector.lua file --[[ LUA_PATH = "?;?.lua;./Config/Export/?.lua" require 'Vector' -- See the Config/Export/Vector.lua file for Vector class details, please. --]] local default_output_file = nil function LuaExportStart() -- Works once just before mission start. -- Make initializations of your files or connections here. -- For example: -- 1) File -- default_output_file = io.open("./Temp/Export.log", "w") -- 2) Socket package.path = package.path..";.\\LuaSocket\\?.lua" package.cpath = package.cpath..";.\\LuaSocket\\?.dll" socket = require("socket") host = host or "localhost" port = port or 8080 c = socket.try(socket.connect(host, port)) -- connect to the listener socket c:setoption("tcp-nodelay",true) -- set immediate transmission mode -- -- local version = LoGetVersionInfo() --request current version info (as it showed by Windows Explorer fo DCS.exe properties) -- if version and default_output_file then -- -- default_output_file:write("ProductName: "..version.ProductName..'\n') -- default_output_file:write(string.format("FileVersion: %d.%d.%d.%d\n", -- version.FileVersion[1], -- version.FileVersion[2], -- version.FileVersion[3], -- version.FileVersion[4])) -- default_output_file:write(string.format("ProductVersion: %d.%d.%d.%d\n", -- version.ProductVersion[1], -- version.ProductVersion[2], -- version.ProductVersion[3], -- head revision (Continuously growth) -- version.ProductVersion[4])) -- build number (Continuously growth) -- end end function LuaExportBeforeNextFrame() -- Works just before every simulation frame. -- Call Lo*() functions to set data to Lock On here -- For example: -- LoSetCommand(3, 0.25) -- rudder 0.25 right -- LoSetCommand(64) -- increase thrust end function LuaExportAfterNextFrame() -- Works just after every simulation frame. -- Call Lo*() functions to get data from Lock On here. -- For example: -- local t = LoGetModelTime() -- local name = LoGetPilotName() -- local altBar = LoGetAltitudeAboveSeaLevel() -- local altRad = LoGetAltitudeAboveGroundLevel() -- local pitch, bank, yaw = LoGetADIPitchBankYaw() -- local engine = LoGetEngineInfo() -- local HSI = LoGetControlPanel_HSI() -- Then send data to your file or to your receiving program: -- 1) File -- if default_output_file then -- default_output_file:write(string.format("t = %.2f, name = %s, altBar = %.2f, altRad = %.2f, pitch = %.2f, bank = %.2f, yaw = %.2f\n", t, name, altBar, altRad, 57.3*pitch, 57.3*bank, 57.3*yaw)) -- default_output_file:write(string.format("t = %.2f ,RPM left = %f fuel_internal = %f \n",t,engine.RPM.left,engine.fuel_internal)) -- default_output_file:write(string.format("ADF = %f RMI = %f\n ",57.3*HSI.ADF,57.3*HSI.RMI)) -- end -- 2) Socket -- socket.try(c:send(string.format("t = %.2f, name = %s, altBar = %.2f, alrRad = %.2f, pitch = %.2f, bank = %.2f, yaw = %.2f\n", t, name, altRad, altBar, pitch, bank, yaw))) local t = LoGetModelTime() local altBar = LoGetAltitudeAboveSeaLevel() local altRad = LoGetAltitudeAboveGroundLevel() local pitch, bank, yaw = LoGetADIPitchBankYaw() local vel = LoGetVerticalVelocity() -- local angle = LoGetAngleOfAttack() local angle = 0 local accel = LoGetAccelerationUnits() local trueairspeed = LoGetTrueAirSpeed() local slipball = LoGetSlipBallPosition() local user1 = 1 local user2 = 2 local user3 = 3 local user4 = 4 local user5 = 5 local user6 = 6 if c then socket.try(c:send(string.format("%.3f %.2f %.2f %.2f %.2f %.2f %.2f %.0f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f \n", t, altRad, altBar, pitch*1000.0, bank*1000.0, yaw*1000.0, accel.x*1000.0, angle*1000, accel.y*1000.0, accel.z*1000.0, accel.x*1000.0, (accel.y-1)*1000.0, accel.z*1000.0, user4, user5, user6, 7))) end end function LuaExportStop() -- Works once just after mission stop. -- Close files and/or connections here. -- 1) File if default_output_file then default_output_file:close() default_output_file = nil end -- 2) Socket socket.try(c:send("quit")) -- to close the listener socket c:close() end