Board index FlightGear Support Interfacing

UDP Input

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

UDP Input

Postby legoboyvdlp » Sun Mar 24, 2019 7: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: 7077
Joined: Sat Jul 26, 2014 1:28 am
Callsign: YV-LEGO
Version: 2018.3.1
OS: Windows 10 HP

Re: UDP Input

Postby daweed » Tue Mar 26, 2019 8: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 9:08 am, edited 1 time in total.
Linux Mint 18.3
AMD FX 4300 Quad-Core Black Edition|20 Go RAMGeForce GTX 750 Ti
FG Interface
Lyon Saint Exupery Scenery

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

Re: UDP Input

Postby legoboyvdlp » Tue Mar 26, 2019 9: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: 7077
Joined: Sat Jul 26, 2014 1:28 am
Callsign: YV-LEGO
Version: 2018.3.1
OS: Windows 10 HP


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 1 guest