Board index FlightGear Support Interfacing

UDP Input

Connecting two computers, using generic protocol, connecting with Matlab?

UDP Input

Postby legoboyvdlp » Sun Mar 24, 2019 8:42 pm

Hi,
Does anyone have any examples of a working UDP input I could look at?

I'm trying to input - I can get output no problem, but input doesn't work. I'm sending an integer - socket test shows it receives the integer fine but the property isn't updated in FlightGear and remains as ""
User avatar
legoboyvdlp
 
Posts: 7981
Joined: Sat Jul 26, 2014 2:28 am
Location: Northern Ireland
Callsign: G-LEGO
Version: next
OS: Windows 10 HP

Re: UDP Input

Postby daweed » Tue Mar 26, 2019 9:46 am

Hello Lego,
I do not use UDP , but TCP, and this is coded in python but maybe this can help u

1st my Generic Protocol File , for example :

Code: Select all
<?xml version="1.0"?>
<PropertyList>
 
<generic>
    <input>
        <binary_mode>false</binary_mode>
        <line_separator>newline</line_separator>
        <var_separator>:</var_separator>
        <chunk>
            <name>On Off RMP Switch</name>
            <node>/controls/radio/rmp[0]/on</node>
            <type>integer</type>
        </chunk>
        <chunk>
            <name>Channel Selection</name>
            <node>/systems/radio/rmp[0]/sel_chan</node>
            <type>string</type>
        </chunk>
    </input>
</generic>

</PropertyList>


My Python Code :


Opening, a connection to FG with

FGADDR : host where FG is executed
FGPORT : fgport listening

Code: Select all
sockclient = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockclient.connect((FGADDR, FGPORT))

<Code to manage Input / Ouput>

.....

Then Creating the "datastring" to be sent

Code: Select all
datastr = str(data_tree['rmp0psw'])
datastr = datastr + ':' + str(data_tree['rmp0selchan'])


Then sending to FG ... if (and only if) something have change

Code: Select all
cypher = hashlib.md5(datastr.encode('utf-8')).digest()
if cypher != oldcypher:
    #print("DATA : {} | PROPS : {}".format(datastr, props_tree)) <=== Only to debug
    sockclient.send(bytes(datastr, 'utf-8'))
    sockclient.send(bytes("\n", 'utf8'))     <== Don't forget to sent "end line" define in your generic protocol file
    oldcypher = cypher <== oldcypher is init to '' when starting the loop


I ll post later how FG is startup (option to open listening connexion), i don't have acces to my FG computer a this time
Last edited by daweed on Tue Mar 26, 2019 10:08 am, edited 1 time in total.
Windows 10 / Linux Mint 20
AMD Ryzen 7 3700X |32 Go RAM GeForce RTX 3070 Ti 8 Go
FG Interface
Lyon Saint Exupery Scenery

ATC on LFLL on Friday 19:00 UTC => 22:00 UTC
daweed
 
Posts: 398
Joined: Thu Dec 11, 2014 11:45 am
Location: LFKP LFLL
Callsign: daweed
OS: Linux Mint 20

Re: UDP Input

Postby legoboyvdlp » Tue Mar 26, 2019 10:07 am

Thank you!

I found my problem - I was missing a newline at the end of my packet (\n).

Regardless, thanks for the information!
User avatar
legoboyvdlp
 
Posts: 7981
Joined: Sat Jul 26, 2014 2:28 am
Location: Northern Ireland
Callsign: G-LEGO
Version: next
OS: Windows 10 HP


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 2 guests