Jump to content

LUA and Cockpit data


JAG

Recommended Posts

is that patch change something in lua export

 

i dont know why this not work

 

i try to get radio state like this

 

local R_800 = GetDevice(48 )

local radio = R_800:l_get_state()

end

but i get that l_get state error nil

 

any ideas here?

 

and thanks

Link to comment
Share on other sites

  • 4 months later...
  • 2 weeks later...

inputsTable = {[10] = {TwoPositionSwitch, 60, 2, 1}} 

 

Hey Oakes reading your excellent 'tutorial' here I understand 10 is the var value you just decided to assign to that one and only swithc. I also understand this is a two position switch, hence the function above. But how did you get the values 60, 2, 1?

 

I looked at this function and it can have up to five values.

function TwoPositionSwitch(pValue, pDevice, pNumber, pOnValue, pInvert)

 

I think for your example above pValue is nil, pDevice is 60 (as shown in devices.lua the device number for this switch K041 is 60), pNumber = 2, pOnValue = 1, pInvert is nil

 

Why pValue and PInvert are nil? because by default they are so? And when they are nil you just skip them?

 

In clickabledata.lua I found K041 in two places:

 

devices.K041, action = {device_commands.Button_1,device_commands.Button_1}, arg = {222,222}, arg_value = {-direction*1.0,direction*1.0}, arg_lim = {{0, 1},{0, 1}}, use_OBB = true, updatable = true}

 

and

-- K041
elements["K-041-PTR"]   = { class = {class_type.TUMB,class_type.TUMB}, hint = LOCALIZE("K-041 Targeting-navigation system power switch"),      device = devices.K041, action = {device_commands.Button_2,device_commands.Button_2},  arg = {433,433}, arg_value = {-direction*1.0,direction*1.0}, arg_lim = {{0.0, 1.0},{0.0, 1.0}}, use_OBB = true, updatable = true}

 

pNumber is the device_commands.Button_?? value from clickabledata.lua

 

Why take the value 2 from button_2 and not 1? Because we are supposed to take from the 'elements' part?

 

I'm trying to learn how to determine all these values so that I can create my own inputTable values in the soicConfig.lua file just like your example, for other swithes.

Link to comment
Share on other sites

Hi mate

 

As you know, from SIOC we get at string like this:

 

Arn.Inicio:123=1:234=2:345=3:

 

whenever any SIOC parameter changes its value i.e. the SIOC server this string to export.lua, (the client in this case) when it registers a change in one of its parameters, this of course usually happens when we flip a physical switch.

 

The syntax of this string is quite simple 123=1 means parameter 123 now has the value of 1, 234=2 means that parameter 234 now has the value of 2 etc.

 

We handle this in the function LuaEXportBeforeNextFrame() in Export.lua.

http://code.google.com/p/dcsbsexport/source/browse/trunk/Export.lua#101

 

local [color=Magenta]inpst[/color] = c:receive()

This code read the input buffer and puts the result into inpst.

The result may be nothing (since SIOC hasn't sent any data since the last time we read the buffer) -> we do a check for this with

 

if [color=Magenta]inpst[/color] then

If there is data in inpst we continue otherwise we exit the LuaEXportBeforeNextFrame() function.

 

Assuming inpst contained data (ie Arn.Inicio:123=1:234=2:345=3) we now need to parse this data to get the SIOC parameters and their respective value:

 

We do this here:

for lSIOC_Param, lSIOCValue in SIOC_Parse([color=Magenta]inpst[/color]) do

This piece of clever LUA code is not easy to read but it simply gives us for each iteration (through the SIOC_Parse() function) the parameter and its value, the parameter is put into lSIOC_Param and the value is put into lSIOCValue.

 

In our example the first iteration gives us lSIOC_Param = 123 and lSIOCValue = 1.

 

We now check that lSIOC_Param is not nil (sometimes SIOC sends an empty string):

 if inputsTable[lSIOC_Param] ~= nil then

 

If lSIOC_Param is not nil we input take lSIOC_Param and lSIOCValue input into this line:

inputsTable[[color=DarkRed]lSIOC_Param[/color]][1]([color=Blue]lSIOCValue[/color], inputsTable[lSIOC_Param][2],inputsTable[lSIOC_Param][3],inputsTable[lSIOC_Param][4],inputsTable[lSIOC_Param][5],inputsTable[lSIOC_Param][6],inputsTable[lSIOC_Param][7],inputsTable[lSIOC_Param][8],inputsTable[lSIOC_Param][9])

 

Now, this is where it gets somewhat complicated, in LUA you can store function names in variables -> you can store variables in arrays -> you can store arrays in tables -> you can store function names in arrays in tables.

 

inputsTable is such a table, for each SIOC parameter we store an array of functions and values.

 

The line below (from SIOCConfig.lua) simply stores an array containing one function (TwoPositionSwitch) and four integers (12,5,1,1) at table position 123 in the table inputsTable

 

[[color=DarkRed]123[/color]] = {TwoPositionSwitch, 12, 5, 1, 1}

The call:

inputsTable[[color=DarkRed]123[/color]][1]

will return the first array element of the array stored at table position 123, in this case it will return the function TwoPositionSwitch

 

The call:

inputsTable[[color=DarkRed]123[/color]][2]

will return the second array element of the array stored at table position 123, in this case it will return the integer 12 and so on.

 

 

Now lets get back to:

 

inputsTable[[color=DarkRed]lSIOC_Param[/color]][1]([color=Blue]lSIOCValue[/color],   inputsTable[lSIOC_Param][2],inputsTable[lSIOC_Param][3],inputsTable[lSIOC_Param][4],inputsTable[lSIOC_Param][5],inputsTable[lSIOC_Param][6],inputsTable[lSIOC_Param][7],inputsTable[lSIOC_Param][8],inputsTable[lSIOC_Param][9])

 

Remember, in our example lSIOC_Param = 123 and lSIOCValue = 1.

 

What we are really doing here is calling the first element of the array stored at table position lSIOC_Param (in this example this means stored at table position 123), this will return the function TwoPositionSwitch ->

 

inputsTable[[color=DarkRed]lSIOC_Param[/color]][1]([color=Blue]lSIOCValue[/color],   inputsTable[[color=DarkRed]lSIOC_Param[/color]][2],inputsTable[[color=DarkRed]lSIOC_Param[/color]][3],inputsTable[[color=DarkRed]lSIOC_Param[/color]][4],inputsTable[[color=DarkRed]lSIOC_Param[/color]][5],inputsTable[[color=DarkRed]lSIOC_Param[/color]][6]..............

goes to

inputsTable[[color=DarkRed]123[/color]][1]([color=Blue]lSIOCValue[/color],   inputsTable[[color=DarkRed]123[/color]][2],inputsTable[[color=DarkRed]123[/color]][3],inputsTable[[color=DarkRed]123[/color]][4],inputsTable[[color=DarkRed]123[/color]][5],inputsTable[[color=DarkRed]123[/color]][6]..............

goes to

TwoPositionSwitch([color=Blue]lSIOCValue[/color],   inputsTable[[color=DarkRed]123[/color]][2],inputsTable[[color=DarkRed]123[/color]][3],inputsTable[[color=DarkRed]123[/color]][4],inputsTable[[color=DarkRed]123[/color]][5],inputsTable[[color=DarkRed]123[/color]][6]..............

 

Remember lSIOCValue = 1 =>

TwoPositionSwitch([color=Blue]1[/color], inputsTable[[color=DarkRed]123[/color]][2],inputsTable[[color=DarkRed]123[/color]][3],inputsTable[[color=DarkRed]123[/color]][4],inputsTable[[color=DarkRed]123[/color]][5],inputsTable[[color=DarkRed]123[/color]][6]..............

and inputsTable[lSIOC_Param][2] => inputsTable[123][2] => 12

 

TwoPositionSwitch([color=Blue]1[/color], 12, inputsTable[[color=DarkRed]123[/color]][3],inputsTable[[color=DarkRed]123[/color]][4],inputsTable[[color=DarkRed]123[/color]][5],inputsTable[[color=DarkRed]123[/color]][6]..............

and inputsTable[lSIOC_Param][3] => inputsTable[123][3] => 5

 

TwoPositionSwitch([color=Blue]1[/color], 12, 5, inputsTable[[color=DarkRed]123[/color]][4],inputsTable[[color=DarkRed]123[/color]][5],inputsTable[[color=DarkRed]123[/color]][6]..............

and so on until we end up with this call

 

TwoPositionSwitch([color=Blue]1[/color], 12, 5, 1, 1)

Which means:

 

function TwoPositionSwitch(pValue, pDevice, pNumber, pOnValue, pInvert)

pValue = 1, pDevice = 12, PNumber = 5, pOnValue = 1 and pInvert = 1

 

 

A somewhat long explanation that pValue is not nil, its it in fact the value of the SIOC parameter.

 

pInvert means invert the behavior of the switch, if you leave it blank (nil) or set it to 0 then we don't invert and if you set it to 1 we invert.

 

/Oakes

 

 

 

Link to comment
Share on other sites

Thanks for your detailed explanation. I'd try to understand it.

 

In BS the device.lua file has a number assigned to each device. in the A10C beta this file exists but none of the devices are assigned any value yet. Can we assign them any number we like and put the corresponding value in the inputstable parameter or do we have to wait for an update?

Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...

Hey guys, just read through all the info in this particular thread. Please send me to another if it's been explained elsewhere.

 

I'm using a pokeys to capture key presses, switches etc. I've got that figured out and running in a C# program. My question is this:

 

I don't understand how I can use a UDP socket to get info back to the export.lua script. I understand that i create a listener socket on whatever port I choose and have my export.lua send stuff to it, but I don't get how my C# program can send stuff back? Forgive me if my socket-fu is not so strong, but I'm pretty sure that UDP is connectionless, and that I can't have a listener for the same socket in two different places on my PC. The example script I have (I think it might have been y2kiah?) has both incoming data (switches from my C# program) and outgoing data (updates from DCS) going on the same UDP socket. How does that work? Thanks for any wisdom! :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...