-- This is the SimRacingStudio Export.lua Script for Digital Combat Simulator -- Please place this file in "C:\Users\YOUR_USER_NAME\Saved Games\DCS\Scripts\Hooks\SRSExport.lua -- Data export script for DCS, version 1.2. -- Copyright (C) 2006-2014, 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 DCS. local SRS_Callbacks = {} local log_file = nil local spool_debug = false local engine_map = {} engine_map["Mi-8MT"] = {panel_idx = 42, factor = 100} engine_map["A-10C"] = {panel_idx = 78, factor = 100} engine_map["UH-1H"] = {panel_idx = 123, factor = 100} engine_map["Ka-50"] = {panel_idx = 52, factor = 100} engine_map["SA342M"] = {panel_idx = 52, factor = 100} engine_map["SA342L"] = {panel_idx = 52, factor = 100} engine_map["SA342Mistral"] = {panel_idx = 52, factor = 100} engine_map["SA342Minigun"] = {panel_idx = 52, factor = 100} engine_map["P-51D"] = {panel_idx = 23, factor = 151} engine_map["P-51D-30-NA"] = {panel_idx = 23, factor = 151} engine_map["TF-51D"] = {panel_idx = 23, factor = 151} engine_map["FW-190D9"] = {panel_idx = 47, factor = 1} engine_map["Bf-109K-4"] = {panel_idx = 29, factor = 1} engine_map["SpitfireLFMkIX"] = {panel_idx = 37, factor = 1} engine_map["SpitfireLFMkIXCW"] = {panel_idx = 37, factor = 1} engine_map["F-86F Sabre"] = {panel_idx = 16, factor = 100} engine_map["A-10C"] = {panel_idx = 78, factor = 100} engine_map["MiG-21Bis"] = {panel_idx = 50, factor = 100} engine_map["MiG-15bis"] = {panel_idx = 42, factor = 100} engine_map["L-39C"] = {panel_idx = 84, factor = 100} engine_map["L-39ZA"] = {panel_idx = 84, factor = 100} engine_map["F-5E"] = {panel_idx = 16, factor = 100} engine_map["F-5E-3"] = {panel_idx = 16, factor = 100} engine_map["AJS37"] = {panel_idx = 139, factor = 100} function SRS_Callbacks.onSimulationStart() package.path = package.path..";"..lfs.currentdir().."/LuaSocket/?.lua" package.cpath = package.cpath..";"..lfs.currentdir().."/LuaSocket/?.dll" socket = require("socket") host = "127.0.0.1" port = tonumber("9800") c = socket.udp() if spool_debug then log_file = io.open(lfs.writedir().."/Logs/srsdebug.txt", "w") end end function get_engine_rpm(airplane, engine, MainPanel) if engine_map[airplane] then return MainPanel:get_argument_value(engine_map[airplane]["panel_idx"]) * engine_map[airplane]["factor"]; else if engine ~= nil then return engine.RPM.left; else return 0; end end end function SRS_Callbacks.onSimulationFrame() local protocol = 1 local engine = Export.LoGetEngineInfo() local rpm = 0 local ay = 0 local az = 0 local ax = 0 local canopy = 0 local landing_gear = 0 local cannon_shells = 0 local airSpeed = Export.LoGetIndicatedAirSpeed() local trueAirSpeed = Export.LoGetTrueAirSpeed() local acceleration = Export.LoGetAccelerationUnits() local pitch, bank, yaw = Export.LoGetADIPitchBankYaw() local angVelocity = Export.LoGetAngularVelocity() local airCraftInfo = Export.LoGetSelfData() local aircraft_name = airCraftInfo.Name local mechInfo = Export.LoGetMechInfo() local snares = Export.LoGetSnares() local payload = Export.LoGetPayloadInfo() local MainPanel = Export.GetDevice(0) if mechInfo ~= nil then canopy = mechInfo.canopy.value landing_gear = mechInfo.gear.value end if payload ~= nil then cannon_shells = payload.Cannon.shells end if acceleration ~= nil then ay = acceleration.y az = acceleration.z ax = acceleration.x end rpm = get_engine_rpm(aircraft_name, engine, MainPanel) if spool_debug then log_file:write(string.format("%.2f", rpm)) log_file:write(string.format("name = %s\n", aircraft_name)) end socket.try(c:sendto(string.format("%.2f,%.2f,%.2f,%.5f,%.5f,%.5f,%.5f,%.5f,%.5f,%.5f,%.5f,%.5f,%s,%s,%s,%.5f", protocol, rpm, trueAirSpeed, ax, ay, az, pitch, bank, yaw, angVelocity.z, angVelocity.x, angVelocity.y, aircraft_name, canopy, landing_gear, cannon_shells), host, port)) end function SRS_Callbacks.onSimulationStop() c:close() if spool_debug then log_file:write(string.format("exit")) if log_file then log_file:close() log_file = nil end end end DCS.setUserCallbacks(SRS_Callbacks)