Le script d’exportation de DCS est simple. Son travail consiste à envoyer des trames IP de type UDP vers l’hôte local, c’est à dire le PC du simulateur lui-même, sur le port UDP 10400, ici choisi.

Le code LUA ci-dessous, non commenté, permet l’envoi des informations du panneau du train d’atterrissage. L’élément exportable DCS A-10C 653 est donc considéré. On peut retrouver ces identifiants depuis cette liste.

Les trames envoyées sont formatées pour être écoutées, lues par le programme GetExportDCSA10C_win32.exe.

 

export.lua

package.path = package.path..”;.\\LuaSocket\\?.lua”
package.cpath = package.cpath..”;.\\LuaSocket\\?.dll”

socket = require(“socket”)

log.info ( “TW(c) A10C export v0.4” );

sTW_A10CMainFunc=
{
TW_LOtime = 0;
TW_udp = socket.udp();
Tacno_NextTime =0;
Tacno_UpdatePeriod = 0.25;

StartFunc=function(self)
self.tacno_cockipt_socket = socket.udp();
self.tacno_cockipt_socket:setpeername( “127.0.0.1” , 10400);

self.TW_udp:setsockname(“*”, 10401)
self.TW_udp:setoption(‘broadcast’, true)
self.TW_udp:settimeout(.001)
end,

–TRANSMIT DATA TO EXTERNAL on UDP 10400
— read clickabledata.lua and devices.lua
AfterNextFrameFunc=function(self)
local tsend = LoGetModelTime()

local MyPlane = LoGetSelfData ()
if ( MyPlane ~= nil ) then
— ———–
— A 1 0 C
if ( MyPlane.Name == “A-10C” ) then
— is it time to read data and send them ?
local lDevice = GetDevice(0)
if ( ( tsend >= self.Tacno_NextTime) and ( lDevice ~= nil ) ) then
self.Tacno_NextTime = tsend + self.Tacno_UpdatePeriod;
— GEAR
–Flap level
socket.try(self.tacno_cockipt_socket:send( string.format(“%f”, lDevice:get_argument_value(653) ) ) )
end
end — A-10C
end –MyPlane
end,

— RECEIVE DATA FROM EXTERNAL on UDP 10401
— FORMAT GADROC’S HELIOS : C43,3007,1 where 43 is this device, 3007 -> 7 is the command and 1 the value
— read clickabledata.lua and devices.lua
— /!\ DO NOT ADD THIS FUNCTION IS YOU USE GADROC’s HELIOS (in UDP will be 9089)
BeforeNextFrameFunc=function(self)
local lInput = self.TW_udp:receive()
local lCommand , lDevice, sp2, sp3 , ep3 , arg1, arg2 , arg3

if ( lInput ) then
lCommand = string.sub(lInput,1,1)
if (lCommand == “C”) then
sp2= string.find ( lInput , ‘,’ , 1 )
sp3= string.find ( lInput , ‘,’ , sp2+1 )
ep3= string.len ( lInput )

arg1 = string.sub ( lInput , 2 , sp2-1 )
arg2 = string.sub ( lInput , sp2+1 , sp3-1 )
arg3 = string.sub ( lInput , sp3+1 , ep3 )

lDevice = GetDevice(arg1)
if type(lDevice) == “table” then
lDevice:performClickableAction(arg2,arg3)
end
end
end
end,
}

— ******************************************************************************************************

— Works just after every simulation frame.
do
local PrevLuaExportAfterNextFrame=LuaExportAfterNextFrame;

LuaExportAfterNextFrame=function()
sTW_A10CMainFunc:AfterNextFrameFunc()

if PrevLuaExportAfterNextFrame then
PrevLuaExportAfterNextFrame()
end
end
end
do
local PrevLuaExportBeforeNextFrame=LuaExportBeforeNextFrame;

LuaExportBeforeNextFrame=function()
sTW_A10CMainFunc:BeforeNextFrameFunc()

if PrevLuaExportBeforeNextFrame then
PrevLuaExportBeforeNextFrame()
end
end
end
do
local PrevLuaExportStart=LuaExportStart;

LuaExportStart=function()
sTW_A10CMainFunc:StartFunc()

if PrevLuaExportStart then
PrevLuaExportStart()
end
end
end

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.