Jump to content

LUA and Cockpit data


JAG

Recommended Posts

Hello, anyone could tell me where can I found info or a tutorial about getting cockpit data from the game ant handle it whit LUA?

 

Thanks

Quick guide to configure ABRIS and LCD mini monitor

Quick Countermeasure Editor v1.3.0

Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |

Link to comment
Share on other sites

Both links provides very interesting info about what I need, and now I have more questions. :lol:

 

I'll keep looking for info, because I need to learn many things to achieve the results I'm looking for.

 

I really appreciate your help, thank you very much. :thumbup:

Quick guide to configure ABRIS and LCD mini monitor

Quick Countermeasure Editor v1.3.0

Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |

Link to comment
Share on other sites

Note that the second link is a bit out of date now, as 1.0.1 changed a lot of the exporting stuff. The Wiki link is the current state of the art.

 

If it helps, my current export line is:

function LuaExportAfterNextFrame()
local t = LoGetModelTime()
local MainPanel = GetDevice(0)
local slip = MainPanel:get_argument_value(108)
local ias = MainPanel:get_argument_value(51)
local mc = MainPanel:get_argument_value(44)
local vsi = MainPanel:get_argument_value(24)
local turn = MainPanel:get_argument_value(437)
local aa = MainPanel:get_argument_value(438)
local gmt = MainPanel:get_argument_value(440)
local hoa = MainPanel:get_argument_value(439)
local rst = MainPanel:get_argument_value(441)
socket.try(c:send(string.format("t = %.2f, slip = %.2f, ias = %.2f, mc = %.2f, vsi = %.2f, turn = %.2f, aa = %.2f, gmt = %.2f, hoa = %.2f, rst = %.2f\n", t, slip, ias, mc, vsi, turn, aa, gmt, hoa, rst)))
end

 

This is sim time, the slip ball position, indicated airspeed, master caution lamp status, vertical speed, and the 5 lamps on the targeting mode control panel. And that results in the following output:

 

t = 3.16, slip = 0.31, ias = 0.47, mc = 0.00, vsi = 0.02, turn = 0.00, aa = 0.00, gmt = 0.00, hoa = 0.00, rst = 0.00
t = 3.37, slip = 0.32, ias = 0.47, mc = 0.00, vsi = 0.02, turn = 0.00, aa = 0.00, gmt = 0.00, hoa = 0.00, rst = 0.00
t = 3.59, slip = 0.33, ias = 0.47, mc = 0.00, vsi = 0.02, turn = 0.00, aa = 0.00, gmt = 0.00, hoa = 0.00, rst = 0.00
t = 3.81, slip = 0.33, ias = 0.47, mc = 0.00, vsi = 0.03, turn = 0.00, aa = 0.00, gmt = 0.00, hoa = 0.00, rst = 0.00


Edited by ruprecht

DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 |

 

Streaming DCS sometimes:

Link to comment
Share on other sites

You've come to the right place, mate. Here's some useful files:

 

Ka-50\Temp\Error.log

Enough said.

 

Ka-50\Scripts\Aircrafts\Ka-50\Cockpit\devices.lua

This has the device numbers you need for the various systems, for example:

 

MainPanel = GetDevice(0)

Weapon_System = GetDevice(12)

Helmet = GetDevice(23)

 

Ka-50\Scripts\Aircrafts\Ka-50\Cockpit\mainpanel_init.lua

 

This has the ids you need to, for example, get a lamp state:

 

MainPanel:get_argument_value(393)

or

GetDevice(0):get_argument_value(393)

 

Ka-50\Scripts\Aircrafts\Ka-50\Cockpit\clickabledata.lua

 

This has the action definitions you need to set a switch.

 

For example, Master Arm is Button_1. So then you add 1 to 3000 (don't look at me like that) to get the action:

 

Weapon_System:performClickableAction(3001,1) --master arm on

or

GetDevice(12):performClickableAction(3001,0)--master arm off

 

Hope this helps,

Colin

  • Like 2
Link to comment
Share on other sites

One more question, I have planned to use the values obtained with LUA with another program, for example VB.Net. In the info, it says that LUA generate a script file whit the values, but my doubt is, if I want to know for example the speed of the chopper, LUA will be generating a script file, every second?

 

If that the case, it's no problem, but can the values given by LUA, be readed in real time, by another program, instead or be reading script files every second.

 

Or If I'm misunderstanding how LUA works, how could the values generated by LUA, be readed for another program, in this case VB.NET, in real time?

 

 

Saludos

Quick guide to configure ABRIS and LCD mini monitor

Quick Countermeasure Editor v1.3.0

Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |

Link to comment
Share on other sites

You can either write the export to a file, or you can stream it to a TCP or UDP socket. I recommend the latter. You can then use basic socket networking in your .Net program to stream in the data.

 

As per Trigger's second link, setup using a TCP socket:

 

-- 2) Socket
dofile "lua.lua"
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


Edited by ruprecht

DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 |

 

Streaming DCS sometimes:

Link to comment
Share on other sites

You can either write the export to a file, or you can stream it to a TCP or UDP socket. I recommend the latter. You can then use basic socket networking in your .Net program to stream in the data.

 

As per Trigger's second link, setup using a TCP socket:

 

-- 2) Socket
dofile "lua.lua"
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

 

Does this mean that I can use a 2nd networked computer and have it dedicated to running my cockpit?

Intel I7 920 Std Clock - 6GB DDR3 RAM - 2 x GTX260 SLI - 10K 130GB Velociraptor Drive - Vista 64Bit - Saitek X52 Pro Hotas - Saitek Pro Rudder Pedals - TrackIR 5

Link to comment
Share on other sites

Ok, I will read a few more things about LUA and as soon as posible I'll start to work in my project.

 

If I have another doubt I will post.

 

Thanks guys

 

Un saludo (Cheers)

Quick guide to configure ABRIS and LCD mini monitor

Quick Countermeasure Editor v1.3.0

Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |

Link to comment
Share on other sites

Hi!

 

One more question, I have planned to use the values obtained with LUA with another program, for example VB.Net.

This is exactly what I do. I use a VB.Net program to read/write between the lua TCP client and a serial port.

if I want to know for example the speed of the chopper, LUA will be generating a script file, every second?

No, it just sends the value. It's totally under your control. You can send it every second (or tenth of a second) or every frame(cycle). I send it every frame, but only if it's different from the last value sent.

 

Hope this helps. Keep asking if you're stuck at any point. We've got this pretty much figured out now, but I think for all of us, not too long ago, it was all a complete bloody mystery.

 

Cheers,

Colin

Link to comment
Share on other sites

I send it every frame, but only if it's different from the last value sent.

 

Colin, would you mind awfully posting a LUA code extract on how to do this? And do you use TCP or UDP?

 

Cheers

DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 |

 

Streaming DCS sometimes:

Link to comment
Share on other sites

good stuff. So after learning all this usb programming stuff and Visual C++ and hoping to avoid TCP/IP I have to learn that too now after all. Im gonna get myself into a programming mess that Ill never be able to get out of. I was wondering that same question too tho. Feel free to post examples of TCP/IP communications lol. I dont know the first thing about its protocols or electrical characteristics.

Intel i7 990X, 6GB DDR3, Nvidia GTX 470 x2 SLI, Win 7 x64

http://picasaweb.google.com/sweinhart

Link to comment
Share on other sites

If I understand, the TCP will be used when you want to send LUA values to another pc, but in my case, I don't need to send it to another pc, instead I need to read those values in the computer that is generating them, and read them in real time with vb.net. How could those values be readed?


Edited by JAG

Quick guide to configure ABRIS and LCD mini monitor

Quick Countermeasure Editor v1.3.0

Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |

Link to comment
Share on other sites

If I understand, the TCP will be used when you want to send LUA values to another pc, but in my case, I don't need to send it to another pc, instead I need to read those values in the computer that is generating them, and read them in real time with vb.net. How could those values be readed?

 

You still use a TCP or UDB socket, but you send it to and connect from 127.0.0.1 (localhost) instead.

DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 |

 

Streaming DCS sometimes:

Link to comment
Share on other sites

I dont know the first thing about its protocols or electrical characteristics.

 

You don't really need to understand the protocol, just the API that the various languages use. All the low level stuff is abstracted away by the API.

 

The data sending Lua code has already been posted and in any case is included in your Lua files in the DCS:BS directory. The other end, it's a relatively simple matter of listening on the socket and reading in the data. My example using C# .Net:

 

private void readSocket() {
           StreamReader reader;
           String data;
           TcpListener listener = new TcpListener(IPAddress.Any, 8080);
           listener.Start();
           Socket sock = listener.AcceptSocket();
           NetworkStream serverstream = new NetworkStream(sock);
           reader = new StreamReader(serverstream);

           while (true) {
               Console.WriteLine("receiving from server...");
               data = reader.ReadLine();
               Console.WriteLine(data);
           }
       }

DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 |

 

Streaming DCS sometimes:

Link to comment
Share on other sites

Colin, would you mind awfully posting a LUA code extract on how to do this? And do you use TCP or UDP?

Cheers

 
local WSCdisplaystring = "/W"..ready..loaded..weaponcode..weaponcount..cannonrounds
if lastWSCdisplaystring ~= WSCdisplaystring then
   socket.try(client:send(WSCdisplaystring))
   lastWSCdisplaystring = WSCdisplaystring
end 

 

I use TCP up til now. But I'll try UDP; I just don't know what the advantage might be.

 

Cheers,

Colin

Link to comment
Share on other sites

Makes sense, thanks.

 

In my limited understanding, the general difference between TCP and UDP is that TCP is designed for accuracy - so each packet is error checked, and can be re-requested. UDP just bangs the packets out there, and no error checking or re-requesting is possible.

 

So for something like downloading a file, or using the internet, where it's important that what ends up at your end is exactly the same as what left the other end, TCP is the go.

 

Theoretically UDP is faster and lower bandwidth because there is less overhead to do with the quality control. And for sim data, if a particular frame's data is lost, there is another frame's data right behind it. You toss each frame away and grab the next one, accuracy is less important than speed and bandwidth.

 

UDP is slightly different to implement in Lua and in your client though. I'm using TCP at the moment cause I have it working, but re-engineering for UDP is on the list.

DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 |

 

Streaming DCS sometimes:

Link to comment
Share on other sites

It's been about 15 years since I did any networking stuff but from what I vaguely remember I don't think it really matters in this application.

 

TCP establishes a virtual connection between the host ports and provides a higher guarantee of packet delivery.

 

UDP is connectionless and offers no guarantee of delivery but it is better suited to stuff like multicasting.

 

TCP probably has a higher overhead but again, we're talking about a local host or a host on the same subnet so I don't think that would have any impact on this application.

 

Cheers,

Pogo


Edited by Pogo

Intel I7 920 Std Clock - 6GB DDR3 RAM - 2 x GTX260 SLI - 10K 130GB Velociraptor Drive - Vista 64Bit - Saitek X52 Pro Hotas - Saitek Pro Rudder Pedals - TrackIR 5

Link to comment
Share on other sites

This time there are many questions guys, and this is getting better and better :smilewink:. I been programming with vb before, but I'm new with lua, so I have many doubts, for example of where to put the code for the TCP connection and how to start sending data to be received by the program created in vb, where to specify the values I need for the cockpit, how to run the script and many others, so I return to the DCS page that trigger post, and find a few answers, and looks like everything must be written in exportl.lua, so I get to the conclusion, you don't have to run the scripts or create them, they are executed by the game, the only thing you have to do is to find the script file that have the functionality you require, especify the values you need, and show or use that values the way you need.

Am I right?

 

 

Then I keep reading the content of the file, I found something interesting:

 

1- It says, that this file starts to work before the simulation begin. If that's true, that answer my question of how to start the script.

 

2- It says also, that the TCP connection must be started there, in the same file, export.lua, hey more good news.

 

3- At the begining of the file it talks about LockOn, and I remember that ruprecht said, this information is a little bit outdated. Is this file still used to send data?

 

4- In the same page, mention that a value in the Config.lua file, must be set to true, to enable the export.lua file, to work. If this true, because I did it?

 

5- If the TCP connection must be specified in export.lua, can I use the code written there, and what about this two lines of code?

-- package.path = package.path..";.\\LuaSocket\\?.lua"

-- package.cpath = package.cpath..";.\\LuaSocket\\?.dll"

 

Must be enabled, or modify it's route, pointing to some file?

 

It looks like all must be done in export.lua, then start the external program that listen the TCP port, the game and finally look at the values received.

 

Is this how things must be done?

 

It's there a way to test the tcp connection from export.lua, sending data without starting the game?

 

Thanks :thumbup:


Edited by JAG

Quick guide to configure ABRIS and LCD mini monitor

Quick Countermeasure Editor v1.3.0

Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |

Link to comment
Share on other sites

where to put the code for the TCP connection and how to start sending data to be received by the program created in vb, where to specify the values I need for the cockpit,

 

In Export.lua: in the LuaExportStart() and LuaExportAfterNextFrame() methods.

 

My current LuaExportAfterNextFrame() was posted earlier, my current LuaExportStart() is as follows:

 

function LuaExportStart()
package.path  = package.path..";.\\LuaSocket\\?.lua"
package.cpath = package.cpath..";.\\LuaSocket\\?.dll"
socket = require("socket")
host = "192.168.2.104"
port = 8080
c = socket.try(socket.connect(host, port)) -- connect to the listener socket
c:setoption("tcp-nodelay",true) -- set immediate transmission mode
end

 

Note also this:

 

-- Please, set EnableExportScript = true in the Config/Export/Config.lua file
-- to activate this script!

 

you don't have to run the scripts or create them, they are executed by the game, the only thing you have to do is to find the script file that have the functionality you require, especify the values you need, and show or use that values the way you need.

Am I right?

 

Yes, the Export.lua is executed by the game if (any only if) EnableExportScript = true in Config.lua.

 

 

3- At the begining of the file it talks about LockOn, and I remember that ruprecht said, this information is a little bit outdated. Is this file still used to send data?

 

Yes it's still in use, but the data hooks are slightly different now in BS 1.0.1. Much of the example code in the Export.lua file as it relates to getting data out of the sim is obsolete in 1.0.1 as described on the wiki.

 

For example the old call:

 

ias = LoGetIndicatedAirSpeed()

 

Now looks like this in 1.0.1:

 

local MainPanel = GetDevice(0)
local ias = MainPanel:get_argument_value(51)

 

4- In the same page, mention that a value in the Config.lua file, must be set to true, to enable the export.lua file, to work. If this true, because I did it?

 

Yes

 

5- If the TCP connection must be specified in export.lua, can I use the code written there, and what about this two lines of code?

-- package.path = package.path..";.\\LuaSocket\\?.lua"

-- package.cpath = package.cpath..";.\\LuaSocket\\?.dll"

Must be enabled, or modify it's route, pointing to some file?

 

See my config posted above.

 

It looks like all must be done in export.lua, then start the external program that listen the TCP port, the game and finally look at the values received.

Is this how things must be done?

 

Yes

 

It's there a way to test the tcp connection from export.lua, sending data without starting the game?

 

Not as far as I know. The sim has to be running to drive the scripts. I use instant action for testing.

DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 |

 

Streaming DCS sometimes:

Link to comment
Share on other sites

  • Recently Browsing   0 members

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