Jump to content

Am I missing something?


algerad3

Recommended Posts

Note: I also asked this very question in Huey forums. Desperate for quick answer as I do not have a lot of time to work on the Saitek project.(Please do not be mad)

 

Does the get_frequency function still work in the Huey?

I can not get any values for any of the radios.

Ka-50 works

A-10 works

So I am sure I get a grip on how to use it:

local VHF2 = GetDevice(23)

local VHF_fm = VHF2:get_frequency()

 

I only get a nil value using device args 21,23 and 24.

 

Anyone else tried this yet?

[sIGPIC][/sIGPIC] CPIAS FOR Saitek:

Saitek Flight instrument panels and X-52 pro mfd scripts for Dcs

 

http://forums.eagle.ru/showthread.php?t=94174

Link to comment
Share on other sites

I don't have the Huey so I can't take a look myself. I would suggest using DCS Witchcraft to interactively try things with the Lua console.

 

The first three minutes of this video explain how to set up the Lua console for the DCS export environment.

 

A good approach might be to copy the dir() function from the Lua wiki into the console and evaluate it. Then you can look at the methods on a device like this:

return dir(getmetatable(GetDevice(23)))

 

Look for a device that has a get_frequency method, I doubt they have disappeared. Maybe the device numbers have shifted around. You can also look in the lua files of the Huey for the device numbers (look for "devices.lua").

 

EDIT: In the video I linked, from 6:00 on there is a walkthrough that describes the process, using the UHF radio of the A-10 as an example.

 

If you can't find the frequency but it is displayed as text in the cockpit somewhere, you could try the list_indication function.


Edited by [FSF]Ian
Link to comment
Share on other sites

Your poll is correct and should work. I even use it in Aries Radio. The only trap door is the validity of the model.There are phases, when your model is not available. This can be during mission start or a model change.I test the validity before each frame .

UH1H_GetStorageLocation = function()
   storageValid = 0
   MainPanel = GetDevice(0) or 0
   if MainPanel ~= 0 then
       storageValid = storageValid + 1
   end
   BoxOneRadio = GetDevice(20) or 0
   if BoxOneRadio ~= 0 then
       storageValid = storageValid + 1
   end
   BoxTwoRadio= GetDevice(22) or 0
   if BoxTwoRadio ~= 0 then
       storageValid = storageValid + 1
   end
   BoxThreeRadio = GetDevice(23) or 0
   if BoxThreeRadio ~= 0 then
       storageValid = storageValid + 1
   end
   Intercom = GetDevice(21) or 0
   if Intercom ~= 0 then
       storageValid = storageValid + 1
   end
end

storageValid must have the value 5 to indicate a valid Huey.

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Hi, I did some testing of the Huey radios a while back and ran into some problems, some of the lua interface functionality did not work such as set_frequency() so I used set and get _argument_value(), and some of the device id's were wrong. The ones below should be correct.

 

ELEC_INT 1

FUELSYS_INT 2

ENGINE_INT 3

HYDRO_SYS_INT 4

WEAPON_SYS 9

SYS_CONTROLLER 15

IFF 17

VHF_ARC_134 20

INTERCOM 21

UHF_ARC_51 22

VHF_ARC_131 23

ARN_82 25

ADF_ARN_83 27

XM_130 50

Link to comment
Share on other sites

Cefs,

You know I started down the path of plugging in each and every one of those values. Found another way to do the task and went with it.

You are correct on the ones confirmed as far as get freq goes.

VHF_ARC_134 20--confirmed

UHF_ARC_51 22-- confirmed

VHF_ARC_131 23--confirmed

The other ones may not put out a freq.

I just wanted to thank you for sharing your find and confirming my suspicions.

 

On a side note, I like the option I found, makes things a bit easier to work with and I am glad I had to think it through.I know have one more piece of knowledge.

Now I have to fix other things according to the finds.

Once again thanks to all for the help and suggestions.

[sIGPIC][/sIGPIC] CPIAS FOR Saitek:

Saitek Flight instrument panels and X-52 pro mfd scripts for Dcs

 

http://forums.eagle.ru/showthread.php?t=94174

Link to comment
Share on other sites

  • 4 weeks later...

You guys seem to have a lot going in regards of data shuffling with DCS.

I am slowly getting a project underway to have the Saitek Radio Panel (which I don't own at the moment) working with DCS. Sockets and DCS are new to me and I am not comfortable with Lua nor do I seem to find any good guide for available Lua API:s for DCS.

Where I am now is that I have a test listener (TCP) in C# that gets simple telemetry from DCS, which seems to be pretty straight forward not taking into account the lack of documentation for what can be done with Lua.

 

I installed witchcraft in order to test Lua code but it makes my DCS crash/hang. The mission starts but hangs after 5s.

dcs.log:

Mist version 3.3.22 loaded.
witchcraft read error: timeout

Is it wishful thinking to think it is possible to have a single program handle the radio comms for all modules? Do all modules offer the same API:s to get() and set() values for the radios (depending on what the module has of course)?

How do you find these API:s?

Link to comment
Share on other sites

I installed witchcraft in order to test Lua code but it makes my DCS crash/hang. The mission starts but hangs after 5s.

dcs.log:

Mist version 3.3.22 loaded.
witchcraft read error: timeout

The timeout error is normal, but it should not crash. What exactly did you do to set it up? What other scripts are running? Note that using it in a mission (following the setup instructions in the README) and using it for the Export.lua environment (following the video) are two mutually exclusive use cases.

 

Is it wishful thinking to think it is possible to have a single program handle the radio comms for all modules? Do all modules offer the same API:s to get() and set() values for the radios (depending on what the module has of course)?

How do you find these API:s?

 

The radios of every module should be accessible from Export.lua, but you will need different code for each module. You find the APIs by going through the Lua scripts that run the module's cockpit (e.g. Mods/aircraft/A-10C/Scripts/Cockpit/...), finding device IDs and argument numbers that look interesting and then figuring out what they mean by trial and error.

Link to comment
Share on other sites

Thank you for your help.

 

Ian;2167775']The timeout error is normal, but it should not crash. What exactly did you do to set it up? What other scripts are running? Note that using it in a mission (following the setup instructions in the README) and using it for the Export.lua environment (following the video) are two mutually exclusive use cases.

I renamed Export.lua so it won't run. Now the mission works fine. Just a client UH-1H started on the runway. Excellent!

 

The console is for MiST only functions? No access to core functions that Export.lua offers like

local t = LoGetModelTime()

etc because I get

[string "1410023021699"]:1: attempt to call global 'LoGetModelTime' (a nil value)

?

 

The template code in witchcraft works OK.


Edited by ArturDCS
Link to comment
Share on other sites

The console is for MiST only functions? No access to core functions that Export.lua offers like

local t = LoGetModelTime()

etc because I get

[string "1410023021699"]:1: attempt to call global 'LoGetModelTime' (a nil value)

?

 

You can witchcraft in two different ways.

The first (which is described in the README) is to connect it to the mission scripting environment. This allows you to use the web interface to adjust unit positions and use the Lua console to debug your mission scripts.

 

The second (which you want and which is described in this video) is to connect it to the Export.lua environment. This allows you to take a look at the Export.lua environment with the Lua console. It has nothing to do with MiST at all.

 

You cannot use both at the same time because you will end up with two pieces of Lua code fighting over the one witchcraft server process.

  • Like 1
Link to comment
Share on other sites

Ian;2167889']You can witchcraft in two different ways...

God damn. Did this witchcraft guy get the DCS Nobel prize already or not? Damn this is sweet, I have managed to get and set the frequency via the Lua console with no problems.

Like finding the holy grail of DCS & Lua.

 

Keypoints:

 

  • Install witchcraft and configure as per the video mentioned
  • Register the function dir() in the Lua environment as found here
  • Open up the devices.lua file for your airframe and look up the ID for the device you are interested in. E.g. UH-1H
    devices["UHF_ARC_51"]                 = counter() -- 23


  • Use this code to get available methods and attributes for the device:
    local dev = GetDevice(23) 
    return dir(getmetatable(dev))


  • {["__index"] = {["listen_command"] = function, ["set_frequency"] = function, ["is_on"] = function, ["get_frequency"] = function, ["performClickableAction"] = function, ["set_modulation"] = function, ["set_channel"] = function, ["listen_event"] = function, ["SetCommand"] = function}}


  • Test getting and setting the frequency:
    local dev = GetDevice(23) 
    dev:set_frequency(51000000)
    return dev:get_frequency()


dev:set_frequency(51000000) = 5 1 0 0

dev:set_frequency(32000000) = 3 2 0 0

and so on..


Edited by ArturDCS
Link to comment
Share on other sites

What character, control char do I send to make DCS execute the Lua code block that has been sent over the socket from my C# program?

Which socket? Are you trying to replace the witchcraft server process with your C# program?

 

The web-based Lua console communicates with the node.js server using socket.io. The node.js server listens on TCP port 3001, waits for DCS to connect and then communicates over newline-delimited JSON.

 

However, those are witchcraft implementation details. It is not intended to be a RPC mechanism for cockpit data export.

 

Currently everybody is doing their own thing -- most people write some Lua code that sends a UDP packet when a value has changed (and receives commands over UDP as well).

 

I hope to start a common platform for this called DCS BIOS in the next weeks, but right now there is only the first draft of the protocol specification; I have yet to publish any code.

 

You can see a simple example that somewhat resembles the planned DCS BIOS protocol in my DCS Arduino example.

Link to comment
Share on other sites

Ian;2171252']Which socket?

I have been trying to setup my own listener in Export.lua and communicate with this from my C# program (UDP listener). This hasn't worked for some reason, I am getting timeouts. I will post code later, easier to explain.

I tried sending Lua from my C# program (networkstream.write() ) to the standard Export.lua TCP socket but that didn't work, perhaps I should try it again and check the :receive() (in Export.lua) method properly to verify it is working.

Getting the data from Export.lua to my C# program worked OK, the standard export which is defined in the Export.lua template using TCP sockets.

 

The DCS BIOS sounds good. I will have a looksy at that too, probably learn something too about comm and DCS.

 

Thanks for your reply & information, much appreciated.

Link to comment
Share on other sites

  • 2 weeks later...

I am looking at the CMSPExport.lua code.

I do not understand the chaining of previous export as commented in the file. Why is it made?

 

   -- Chain previously-included export as necessary
   if PrevExport.LuaExportStart then
       PrevExport.LuaExportStart()
   end
<..>
   -- Chain previously-included export as necessary
   if PrevExport.LuaExportBeforeNextFrame then
       PrevExport.LuaExportBeforeNextFrame()
   end
<..>
   -- Chain previously-included export as necessary
   if PrevExport.LuaExportBeforeNextFrame then
       PrevExport.LuaExportBeforeNextFrame()
   end
<..>
   -- Chain previously-included export as necessary
   if PrevExport.LuaExportAfterNextFrame then
       PrevExport.LuaExportAfterNextFrame()
   end

I will try and make an exactly similar UDP listener in my Export.lua to listen for Lua code from my text application (C#).

Link to comment
Share on other sites

I am looking at the CMSPExport.lua code.

I do not understand the chaining of previous export as commented in the file. Why is it made?

 

To allow chaining of multiple Export.lua files. Say you are using CMSPExport.lua in addition to Helios. You add a dofile() call that executes CMSPExport.lua to the end of the Helios-generated Export.lua file. Normally, the hook functions in CMSPExport.lua would overwrite what Helios defined, so Helios would not work. By saving a reference to the previous hook function and calling that, we avoid that problem.

 

Because Helios is also a good citizen and calls previous hook functions, it would also work the other way around -- renaming CMSPExport.lua to Export.lua and calling the Helios-generated file from there.

 

I made some progress on DCS-BIOS in the last few days. It now supports most of the A-10C controls and I'd like to encourage you to use it instead of rolling your own Export.lua. The idea is to abstract all the DCS implementation details away and have several developers use it, so when a DCS update breaks something there are several people who can fix it and it only needs to be fixed in one place.

 

Before I "officially" announce it, I want to implement another aircraft to get the internal abstraction levels right, but the current state of affairs is available in the "experimental" branch.

Link to comment
Share on other sites

Ian;2185262']To allow chaining of multiple Export.lua files. ..

Got it, thank you. I will look at the DCS-BIOS.

 

Ian;2185262']Before I "officially" announce it' date=' I want to implement another aircraft to get the internal abstraction levels right<>[/quote']

UH-1H perhaps? For me to get going with testing just some instruments would be enough, the radios first and foremost. Besides the UH-1H any other module that is free. I only own the UH-1H..


Edited by ArturDCS
Link to comment
Share on other sites

UH-1H perhaps? For me to get going with testing just some instruments would be enough, the radios first and foremost. Besides the UH-1H any other module that is free. I only own the UH-1H..

 

I will do the UH-1H because I have it, currently fly it, and it only has about half as many switches as the A-10C. Adding support for one of the free modules is a good point, too. If there is someone who wants to add support for a module but doesn't have the A-10C or the UH-1H, I will consider adding the TF-51 so they have a working example.

Link to comment
Share on other sites

README.md

listen for UDP packets on multicast address 29.255.50.10

(multicast address?)

 

LoL!

Should be 239.255.50.10 as specified in the BIOS spec. The 29.255.50.10 was entered in README.md and I did a look up on this IP and almost sharted. (hahaha)


Edited by ArturDCS
Link to comment
Share on other sites

Receiving instrument data via DCS BIOS works just fine! :thumbup:

 

Sending instrument data, I haven't had success yet with this. Using Wireshark I have confirmed I am actually sending UDP and correct format. The message below was 16 bytes.

FORCE_TRIM_SW 1\n

Am I doing what wrong? :joystick:

2014-09-27_160545.jpg.722a729f8a09471940e553db6099c9cb.jpg

2014-09-27_160314.jpg.4eb7371343f3892f01b88df1150ccd19.jpg

Link to comment
Share on other sites

Got it working. I had problems with my code. I was sending to 239.255.50.10 instead of 127.0.0.1.

 

C# test code:

 

 

       private String _receiveFromIP = "239.255.50.10";
       private String _sendToIP = "127.0.0.1";
       private int _receivePort = 5010;
       private int _sendPort = 7778;
       private IPEndPoint _ipEndPointReceiver = null;
       private IPEndPoint _ipEndPointSender = null;

       public void InitUDP()
       {
           try
           {
               _ipEndPointReceiver = new IPEndPoint(IPAddress.Any, _receivePort);
               _udpReceiveClient = new UdpClient();
               _udpReceiveClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
               _udpReceiveClient.Client.Bind(_ipEndPointReceiver);
               _udpReceiveClient.JoinMulticastGroup(IPAddress.Parse(_receiveFromIP));
               
               _ipEndPointSender = new IPEndPoint(IPAddress.Parse(_sendToIP), _sendPort);
               _udpSendClient = new UdpClient();
               _udpSendClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
               _udpSendClient.EnableBroadcast = true;
           }
           catch (Exception e)
           {
               WriteErrors("Error: " + e);
           }
       }

       private void WriteFunction()
       {
           try
           {
               var textToSend = textBoxSend.Text + "\n";
               byte[] unicodeBytes = Encoding.Unicode.GetBytes(textToSend);
               var asciiBytes = new List<byte>(textToSend.Length);
               asciiBytes.AddRange(Encoding.Convert(Encoding.Unicode, Encoding.ASCII, unicodeBytes));
               _udpSendClient.Send(asciiBytes.ToArray(), asciiBytes.ToArray().Length, _ipEndPointSender);
               WriteData("Sent " + asciiBytes.ToArray().Length + " bytes..");
           }
           catch (Exception e)
           {
               WriteErrors(e.Message + Environment.NewLine + e.StackTrace);
           }
       }

       public void StartListener()
       {
           //threaded...
           WriteData("Waiting for a client on port " + _receivePort);
           var once = false;
           try
           {
               while (true)
               {
                   byte[] _receivedData = _udpReceiveClient.Receive(ref _ipEndPointReceiver);
                   if(!once)
                   {
                       WriteData("Message received from " + _ipEndPointReceiver);
                       once = true;
                   }
                   WriteData(Encoding.ASCII.GetString(_receivedData, 0, _receivedData.Length));
               }
           }
           catch (Exception e)
           {
               WriteErrors("Error: " + e);
           }
           Console.WriteLine("_listeningThread2 exiting");
       }

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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