Jump to content

Crazy question for you guys.


algerad3
 Share

Recommended Posts

Still working on the saitek thingy and I am looking at another angle. " lua sockets".

Question... once I get the socket (tcp) running and sending to the client, how do I access the received packets i.e how do I get the values and variables for further use..... Silly me; I googled and goggled and even oggled myself to death and all I got was internet , http examples.

I can get the stuff to print to lua console and that works fine , but I can not get the value for my own scripting use.

Pointer,tips or topic title for further study would be helpful. :cry:


Edited by algerad3
you would have never guessed English is supposed to be my primary language

[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 have a lua client script.. just trying to figure out how to get at the variables and values from the receive stream... I am also trying to piecemeal a client

using visual studio C++ slow going , in up to my neck and getting more deeper into the water soon to be in over my head ,if not already .

Thanks for the tip.

[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 am messing around with an example script I found in the Lua folders.

The export of course is from blackshark export, The example listener is thelittle script I found and modified.

Currently it will write the exported values to the lua console window.

I want the values to be used in the script.

As it stands , it turns the light off so I guess gear1up and gear1down has now value to work with.

How do I get the values is the question. ( as if you did not figure that out already. LOL)

your time and help is appreciated.

listeneradaptedsaitek.lua

Export.lua

[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

ok from what i see you are missing some code

 

you send the data in the export ok (i wouldnt send the light states as float formatted strings but it will work).

 

however your code doesnt actually do anything with the data once it receives it except prints it

	l, e = c:receive() 
print(e)

 

This code block will never execute

if gear1up == 1 then
		saitek.SetLed("X52P",1,1,11,true)
		else
		saitek.SetLed("X52P",1,1,11,false)
if
	gear1down == 1 then
		saitek.SetLed("X52P",1,1,12,true)
		else
		saitek.SetLed("X52P",1,1,12,false)

end

 

as gear1up isnt defined anywhere.

 

what you need to do is take "e" and parse out the values you want and assign them to a variable ...then you can act on it

 

Im still at work but will check it out and write up an example when i get home.

 

Also is there any reason why you are doing this with lua? or is it the language you are most familiar with

Link to comment
Share on other sites

oh, So I have to declare it again even though I have it in the export file ( now that I think about it some. Never mind got it. declare ,declare).

Anyways , I am using lua as I have a dll that will allow me/us to get our saitek x52 pro gear mfd working. Also helps me understand basics of programming as i really want to expand on the possibility of using the saitek flight instrument panels for gauge displays.

[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

oh, So I have to declare it again even though I have it in the export file ( now that I think about it some. Never mind got it. declare ,declare).

Anyways , I am using lua as I have a dll that will allow me/us to get our saitek x52 pro gear mfd working. Also helps me understand basics of programming as i really want to expand on the possibility of using the saitek flight instrument panels for gauge displays.

 

Yes. Remember these are two seperate programs. One doesn't know what's in the other.

When you send the data over the wire with the export you are sending it as one big string. On the client you will need to parse that strong to get the vues you are after

 

Ill give you an example in a couple of hours. Im Currently maternity cloths shopping with the wife. Oh boy.

Link to comment
Share on other sites

here is an example of how you could handle this situation. This does have the shortcoming of if the data order changes it will break.It is also not easilly maintainable for future expansion(adding a bunch of values). There are some more advanced ways to handle that and i can point you in that direction in the future if you require it

I commented out all the saitek code cause i dont have saitek gear on this computer

 

In short i added a function called StrSplit that allows you to split a string up into table based on a token.

 

Every other step i took is commented in the code. lemme know if you have any questions/problems

 

 

-----------------------------------------------------------------------------
-- TCP sample: Little program to dump lines received at a given port
-- LuaSocket sample files
-- Author: Diego Nehab
-- RCS ID: $Id: listener.lua,v 1.11 2005/01/02 22:44:00 diego Exp $
-----------------------------------------------------------------------------

function StrSplit(str, delim, maxNb)
   -- Eliminate bad cases...
   if string.find(str, delim) == nil then
       return { str }
   end
   if maxNb == nil or maxNb < 1 then
       maxNb = 0    -- No limit
   end
   local result = {}
   local pat = "(.-)" .. delim .. "()"
   local nb = 0
   local lastPos
   for part, pos in string.gfind(str, pat) do
       nb = nb + 1
       result[nb] = part
       lastPos = pos
       if nb == maxNb then break end
   end
   -- Handle the last field
   if nb ~= maxNb then
       result[nb + 1] = string.sub(str, lastPos)
   end
   return result
end

-- require "saitek"
-- saitek.AddPage("X52P",1,1, true);
		-- saitek.AddPage("X52P",1,2, false);
		-- saitek.AddPage("X52P",1,3, false);
		-- saitek.AddPage("X52P",1,4, false);
		-- saitek.AddPage("X52P",1,5, false);
		-- saitek.AddPage("X52P",1,6, false);
		-- saitek.AddPage("X52P",1,7, false);
		-- saitek.AddPage("X52P",1,8, false);
		-- saitek.AddPage("X52P",1,9, false);
		-- saitek.AddPage("X52P",1,10,false);





-- Make and verify connections.
--####################################################################
--####################################################################

local socket = require("socket")
host = host or "localhost"
port = port or 8080
if arg then
host = arg[1] or host
port = arg[2] or port
end

binding = (string.format("Binding'"))


--saitek.SetString("X52P",1,1,1, binding)
s = assert(socket.bind(host, port))
i, p   = s:getsockname()

assert(i, p)
waiting = (string.format("Waiting" ))
--saitek.SetString("X52P",1,1,2, waiting)
c = assert(s:accept())
connected = (string.format("dcs Connected"))
--saitek.SetString("X52P",1,1,3, connected)
--#####################################################################
--#####################################################################

-- Recieve info
--#####################################################################
--#####################################################################
while not e do
if gear1up == 1 then
		--saitek.SetLed("X52P",1,1,11,true)
		print("gear1up on")
		else
		--saitek.SetLed("X52P",1,1,11,false)
		print("gear1up off")
-- if
	-- gear1down == 1 then
		-- saitek.SetLed("X52P",1,1,12,true)
		-- else
		-- saitek.SetLed("X52P",1,1,12,false)

-- end

end

--print(l)
l, e = c:receive()


print(e)
data = StrSplit(e,",") -- we take the string received and split it into a table using , as the token  to split the string on
-- so  altBar = somevalue, gear1up = somevalue, gear1down = somevalue, gear2up = somevalue, gear2down = somevalue, gear3up = somevalue, gear3down = somevalue\n" will be split into a table e.g
-- gear1up is located at index 2 as lua uses 1 based indexing not 0 based indexing
value = StrSplit(data[2],"=") -- now we split data[2] which contains gear1up=somevalue on the token "="
-- we now end up with value as a table containing "gear1up" at index 1 and the value as index2 so we set our gear1up variable to the value at index2
gear1up = value[2]


end

Link to comment
Share on other sites

correct...In the example above you split the (string) data that came in over the socket using "," as the token to split on. This results in a table. Then you take each item in the table and split the string using "=" as a token. The second element in that table is the value you would want to assign to whatever vars you use in your script.

 

From a high level if you wanted to make it more robust (not sensitive to order) you could take each element in the first table and split the values into a key:value pair. This could be wrapped into a function that is completely reusable and wouldnt need to be altered when you add new variables. Then you could just look up each item you are interested in by the key and ordering would no longer be an issue. you also wouldnt need any local variables in that case as you could just use the key:values directly for example:

instead of something like

gear1up = value[2]...
if gear1up == 1 then ...

 

you could just have

if data["gear1up"]== 1 then...

Link to comment
Share on other sites

Whartsell,

Just wanted to say thanks for the help you have given me....

Still working on the example you have provided.

It seems that when I start the program....Listener and Dcs it starts off telling me the gear1 = off. After that it states that there is an error...String expected but is nil, or after some changes it will run but, the gear is always reporting "off". I will get it sorted out . the Important part is that I now know which direction to go.

[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

  • 1 month later...

me again, I can not quite figure out how to get the example to function correctly. It will not print "Gear1up on" just "gear1up off". it is like it is not receiving the change in the variable. Racking my skull on this one.

[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 was also googling to death, with no result.

 

So my project is:

 

Built a throttle for UH-1.

 

Things that i have:

One USB board with 8 GPIO/4 A-D

 

Situation:

I can write code to capture input from the board with VB .net

 

Problem:

What steps must i follow to send input data from VB program to DCS

(i would like the steps to be like first you write "this" to dcs\io\*.lua . after you do this, then this and if someone could explain theprotocol of the connection)

 

I tried to communicate the lua listener.lua with vb using socket (encoding ASCII) with no result..

 

Sorry if i am so noob, but you know.. it's confusion googling all week...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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