Board index FlightGear Support Interfacing

Can not interface(native) with Flightgear

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

Can not interface(native) with Flightgear

Postby dshetty » Fri Feb 28, 2020 4:17 am

Hi,
I am new to Flightgear. Using latest release "FlightGear 2019.1.1". Trying to communicate with the flightgear with native udp packet sent from client side using same PC where flightgear installed. But unable to communicate with flightgear.

Here is the cmd I am using
C:\Program Files\FlightGear 2019.1.1\\bin\\fgfs --aircraft=c172p --native=socket,in,10,127.0.0.1,5502,udp --fdm=external
When I start FG Run using above command line the aircraft will stand at 0 lat and 0 long and when I run my client I am getting error in my command window as below
Code: Select all
  257.23 [ALRT]:sound      AL Error (sound manager): Invalid Value at position and orientation
  257.23 [ALRT]:sound      AL Error (sound manager): Invalid Value at position and orientation
  257.23 [ALRT]:sound      AL Error (sound manager): Invalid Value at update

I am not able to figure out the issue here. For me my client code looks good.
Can anybody help me out to solve this? am I using wrong command? I also used --native-fdm=socket,in,10,127.0.0.1,5502,udp but no result
Client side code looks like
Code: Select all
#include <winsock2.h>
#include <stdio.h>
#include <time.h>
#include "FG_net_fdm.h"
#define D2R (3.14159 / 180.0)
int main(int argc, char **argv)
{
   WSADATA              wsaData;
   SOCKET               SendingSocket;
   SOCKADDR_IN          ReceiverAddr, SrcInfo;
   
   double latitude = 45.59823; // degs
   double longitude = -120.69202; // degs
   double altitude = 150.0; // meters above sea level

   float roll = 0.0; // degs
   float pitch = 0.0; // degs
   float yaw = 0.0; // degs

   float visibility = 5000.0; // meters
   int update_period = 1000;
   int                  Port = 5502;
     int len;
     int TotalByteSent;

      // Initialize Winsock version 2.2
     if( WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
     {
      printf("Client: WSAStartup failed with error %ld\n", WSAGetLastError());
          // Clean up
      WSACleanup();
          // Exit with error
      return -1;
  }
  else
  {
      printf("Client: The Winsock DLL status is %s.\n", wsaData.szSystemStatus);
  }
     // Create a new socket to receive datagrams on.
  SendingSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (SendingSocket == INVALID_SOCKET)
  {
      printf("Client: Error at socket(): %ld\n", WSAGetLastError());
          // Clean up
      WSACleanup();
          // Exit with error66
      return -1;
  }
  else
{
      printf("Client: socket() is OK!\n");
}

  ReceiverAddr.sin_family = AF_INET;
  ReceiverAddr.sin_port = htons(Port);
  ReceiverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");

  int xy = 20;
  while (xy >= 0)
  {
      Sleep(update_period);

      struct FGNetFDM fdm;

      fdm.version = htonl(FG_NET_FDM_VERSION);

      fdm.latitude = (double)htond(latitude * D2R);
      fdm.longitude = (double)htond(longitude * D2R);
      fdm.altitude = (double)htond(altitude);

      fdm.phi = (float)htonf(roll * D2R);
      fdm.theta = (float)htonf(pitch * D2R);
      fdm.psi = (float)htonf(yaw * D2R);

      fdm.num_engines = htonl(1);

      fdm.num_tanks = htonl(1);
      fdm.fuel_quantity[0] = (float)htonf(100.0);

      fdm.num_wheels = htonl(3);

      fdm.cur_time = htonl(time(0));
      fdm.warp = htonl(1);

      fdm.visibility = (float)htonf(visibility);
      printf("Client: roll Data to be sent: \"%lf\"rad\n", roll);
      printf("Client: Altitude in deg: \"%f\"deg\n", fdm.altitude);

      printf("Client: Sending datagrams...\n");

      TotalByteSent = sendto(SendingSocket, (char*)&fdm, sizeof(fdm), 0, (SOCKADDR *)&ReceiverAddr, sizeof(ReceiverAddr));

      static BOOL flag = TRUE;
      if (flag)
      {
          roll += 5.0;
      }
      else
      {
          roll -= 5.0;
      }
      flag = !flag;
      xy--;
  }
 
printf("Client: Finished sending. Closing the sending socket...\n");

if (closesocket(SendingSocket) != 0)

    printf("Client: closesocket() failed! Error code: %ld\n", WSAGetLastError());

else
    printf("Server: closesocket() is OK\n");

getchar();
return 0;

}
Last edited by Johan G on Mon Mar 09, 2020 7:37 pm, edited 1 time in total.
Reason: Adding [code] tags. They can be added manually or with the [^_ ] button.
dshetty
 
Posts: 3
Joined: Fri Feb 28, 2020 3:39 am

Re: Can not interface(native) with Flightgear

Postby wkitty42 » Fri Feb 28, 2020 2:09 pm

those sound errors have nothing to do with your problem...
are you getting any errors with your code?
which craft are you using?
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 6493
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Can not interface(native) with Flightgear

Postby dshetty » Mon Mar 02, 2020 3:27 am

Thank you for responding..
No, I am not getting any error in my code. I can see my udp data in wireshark.
I am using --aircraft=c172p
dshetty
 
Posts: 3
Joined: Fri Feb 28, 2020 3:39 am

Re: Can not interface(native) with Flightgear

Postby SurferTim » Mon Mar 02, 2020 10:24 am

What port is FG using? Looks like port 5502.
What port is your client using? Looks like port 5502.
Normally you can't bind the same ip/port twice.

Edit: I use the "--generic" udp protocol, and it works ok.
Fly low, fly slow, land on a dime. Twin Otter DHC6-300+. https://github.com/SurferTim/dhc6p
PirateAir videos at https://www.youtube.com/user/SurferTim850
User avatar
SurferTim
 
Posts: 953
Joined: Sun Dec 09, 2018 5:49 pm
Location: Miramar Beach, FL
Callsign: Pirate
Version: 2019.2.0
OS: Ubuntu 18.04

Re: Can not interface(native) with Flightgear

Postby dshetty » Tue Mar 03, 2020 3:23 am

Thank you SurferTim for showing interest on my issue.
I am trying to send data in FG_net_FDM format as a client using 5502 udp port and FG is supposed to receive data from the same port. This is the cmd I am using as input --native=socket,in,10,127.0.0.1,5502,udp
"--generic" cmd works for me as well with corresponding protocol .xml file. I would like to see data receiving in FGNetFDM format without any .xml script. Any help will be appreciated.
dshetty
 
Posts: 3
Joined: Fri Feb 28, 2020 3:39 am

Re: Can not interface(native) with Flightgear

Postby SurferTim » Tue Mar 03, 2020 8:38 am

You won't be able to bind to 127.0.0.1:5502 more than once. It will be either FG or your client app, but not both.
I recommend binding to another port on your client app, like 127.0.0.1:5503, and send the packet to 127.0.0.1:5502.

If you ran the client app on a separate computer, you could bind both to port 5502 because they would be different ip addresses.

I use a different port with Python/PyGame clients and it works well. That way you can either use the app on the same computer or a different computer.
Fly low, fly slow, land on a dime. Twin Otter DHC6-300+. https://github.com/SurferTim/dhc6p
PirateAir videos at https://www.youtube.com/user/SurferTim850
User avatar
SurferTim
 
Posts: 953
Joined: Sun Dec 09, 2018 5:49 pm
Location: Miramar Beach, FL
Callsign: Pirate
Version: 2019.2.0
OS: Ubuntu 18.04


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 1 guest