Board index FlightGear Support Interfacing

Is there a way for a bidirectional connections over TCP/UDP?

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

Is there a way for a bidirectional connections over TCP/UDP?

Postby www2 » Sun Jun 02, 2019 1:09 pm

Xpost from the mailing list with the subject of:
How can i handling bidirectional connections over TCP/UDP sockets?

Hi i play with the Generic protocol over TCP/UDP sockets.
I have the problem that i can not handle bidirectional data streams over TCP/UDP sockes using this setting: --generic=socket,out,10,localhost,65432,tcp,test (fg as the client to a server)

How can i do bidirectional data streams over one tcp/udp port that do the in/out trick.:
--generic=socket,out,10,localhost,65432,tcp,test
--generic=socket,in,10,localhost,65433,tcp,test
Or like to see a option that flight gear force as a server or client for handling bidirectional data streams.

www2

P.S. The code that i use for testing this:

test.py
Code: Select all
#!/usr/bin/env python3

from time import time
import socket

HOST = '127.0.0.1'  # Standard loopback interface address (localhost)
PORT = 65432        # Port to listen on (non-privileged ports are > 1023)

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print('Connected by', addr)
        while True:
            data = conn.recv(1024)
            if not data:
                break
            print(data.decode('ascii').strip())
            t = time()
            conn.send(b"%i\n"%5000)


text.xml:
Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
 <output>
 <line_separator>newline</line_separator>
 <var_separator>tab</var_separator>

 <chunk>
  <name>altitude-ft</name>
  <type>float</type>
  <format>%f</format>
  <node>/position/altitude-ft</node>
 </chunk>
 <chunk>
     <name>airspeed-kt</name>
     <type>float</type>
     <format>%f</format>
     <node>/velocities/airspeed-kt</node>
 </chunk>

</output>
<input>
    <chunk>
     <name>test time</name>
     <type>float</type>
     <node>/position/altitude-ft</node>
    </chunk>
</input>
 </generic>
</PropertyList>
www2
 
Posts: 260
Joined: Thu Apr 16, 2009 1:58 pm

Re: Is there a way for a bidirectional connections over TCP/

Postby daweed » Mon Jun 03, 2019 11:22 am

Code: Select all
--generic=socket,out,10,localhost,65432,tcp,test
--generic=socket,in,10,localhost,65433,tcp,test


Your protocol settings configures an output via port 64432 AND an entry on port 64433.
Your Python code only seems to handle communication via port 64432 .... and Flightgear is waiting input on port 65433

According to the I / O documentation

Either you set up a connection in your code that will connect to FG on port 64433 to send input , or according to the documentation https://sourceforge.net/p/flightgear/fg ... /README.IO , you should try with the parameter 'bi'

"FlightGear has a fairly flexible IO subsystem that allows you to "speak" any supported protocol over any supported medium. The IO options are configured at runtime via command line options. You can specify multiple entries if you like, one per command line option."

The general form of the command line is as follows:

--protocol = medium, direction, hz, medium_options ...

protocol = {native, nmea, garmin, fgfs, rul, pve, ray, etc. }
medium = {serial, socket, file, etc. }
direction = {in, out, bi}
hz = number of times to process channel for second (floating point values are ok)
Regards

Daweed

PS : Here how i am managing the things (using 2 protocol files and 2 parameters as you did)
I am using 2 machine, one running Flightgear instance (the one with ip addr 192.168.0.185) and one running the python code which is a Raspebrry Pi as Hardware interface

Code: Select all
#!/usr/bin/env python3
# -*-coding:Utf-8 -*

# System Module Import
import socket
import os
import sys
import operator
import time
import struct
import hashlib

....

FGINTADDR = '192.168.0.30' # Flightgear IP Machine
FGINTPORT = 7800 # Flightgear Input Protocol Port
FGADDR = '192.168.0.185' # Interface IP Machine
FGPORT = 7850 # Ouput port for Interface Machine
loop = True
oldcypher = ''

...

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to the port
server_address = (FGINTADDR, FGINTPORT)
print('starting up on {} port {}'.format(*server_address))
sock.bind(server_address)

# Listen for incoming connections
sock.listen(1)

while loop == True:
    # Wait for a connection
    print('waiting for a connection')
    connection, client_address = sock.accept()  # This connexion will be use to get data from FG

    sockclient = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # This connexion will be use to send data to FG
    sockclient.connect((FGADDR, FGPORT))

    data = connection.recv(BUFFERSIZE).strip().decode('utf-8')

    ....

    DATA ARE PROCESSED in this BLOCK

    ....

    ########################################
    # DATA SENDING PROCESS
    ########################################
    # Checksum is calcuted to check if data to be sent have change since last time (avoiding sending something if it is not needed)
    cypher = hashlib.md5(datastr.encode('utf-8')).digest()
   
    if cypher != oldcypher:
        print("DATA : {} | PROPS : {}".format(datastr, props_tree))
        sockclient.send(bytes(datastr, 'utf-8'))
        sockclient.send(bytes("\n", 'utf8'))
        oldcypher = cypher


I will post in the evening my protocol files
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: 328
Joined: Thu Dec 11, 2014 10:45 am
Location: LFKP LFLL
Callsign: daweed
OS: Linux Mint 19.2

Re: Is there a way for a bidirectional connections over TCP/

Postby www2 » Mon Jun 03, 2019 7:43 pm

@daweed
I ask more a option for forcing flightgear in a server/client mode than the current one e.g.:
--generic=server,bi,10,localhost,65432,tcp,test
--generic=client,bi,10,localhost,65432,tcp,test

As in the current behave for socket,in is that flight gear behave as a server and socket,out behave as a client
www2
 
Posts: 260
Joined: Thu Apr 16, 2009 1:58 pm

Re: Is there a way for a bidirectional connections over TCP/

Postby daweed » Tue Jun 04, 2019 9:07 am

Not sure to understand what u want, as i said in my previous message, i manage In and Out with 2 parameters (will post my FG parameter tonight) and can handle In and Out without any problem with my python code.

When u setup a 'bi' parameter, FG should handle In and Out throught the same port ....
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: 328
Joined: Thu Dec 11, 2014 10:45 am
Location: LFKP LFLL
Callsign: daweed
OS: Linux Mint 19.2

Re: Is there a way for a bidirectional connections over TCP/

Postby www2 » Thu Jun 06, 2019 12:22 am

@daweed I like to see that flightgear can be force act like a server or a client than the current situation that "--generic=socket,in" flight gear act like server that only reserve and "--generic=socket,out" flight gear act like as a client that only send.
www2
 
Posts: 260
Joined: Thu Apr 16, 2009 1:58 pm


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 2 guests