Curtis Olson wrote:

Have a look at the READM.IO <http://READM.IO> file in documentation tree for example usage of the IO system. The "native fdm" protocol is defined in src/Network/net_fdm.hxx

Thanks for pointing me to the right directions! Just for those
who might be interrested, I have attached a very simple example
program that displays certain fdm parameters.

regards

Bernhard
// g++ -I/home/kuhn/fgfs/src/FlightGear-0.9.10/src -o t main.cpp -lsgio
// fgfs --airport=edme --geometry=1536x1136 --native-fdm=socket,out,1,localhost,5500,udp

#include <stdio.h>
#include <netinet/in.h>
#include <math.h>

#include <simgear/io/sg_socket_udp.hxx>
#include "Network/net_fdm.hxx"

static void htond (double &x) {
  if ( sgIsLittleEndian() ) {
    int    *Double_Overlay;
    int     Holding_Buffer;
    
    Double_Overlay = (int *) &x;
    Holding_Buffer = Double_Overlay [0];
    
    Double_Overlay [0] = htonl (Double_Overlay [1]);
    Double_Overlay [1] = htonl (Holding_Buffer);
  } else {
    return;
  }
}

static void htonf (float &x) {
  if ( sgIsLittleEndian() ) {
    int    *Float_Overlay;
    int     Holding_Buffer;
    
    Float_Overlay = (int *) &x;
    Holding_Buffer = Float_Overlay [0];
    
    Float_Overlay [0] = htonl (Holding_Buffer);
  } else {
    return;
  }
}

int main() {

  int ret;
  SGIOChannel *io = new SGSocketUDP("localhost","5500");

  io->open(SG_IO_IN);

  while(1) {
    FGNetFDM buf;
    ret = io->read( (char*)&buf, sizeof(buf) );
    
    if(ret<0) {
      printf("error %i while receiving from socket\n",ret);
      return -2;      
    };
    
    htonf(buf.vcas);
    htonf(buf.psi);
    htonf(buf.theta);
    htond(buf.altitude);
    htonf(buf.phi);
    htonf(buf.climb_rate);
    htonf(buf.rpm[0]);
    htond(buf.latitude);
    htond(buf.longitude);
    htonf(buf.agl);
   
    printf("a=% 3.0f   ", buf.vcas);
    printf("r=% 4.0f   ", buf.phi*180/M_PI);
    printf("t=% 4.0f   ", buf.theta*180/M_PI);
    printf("a=% 7.1f   ", buf.altitude*3.28084);
    printf("h=% 4.0f   ", buf.psi*180/M_PI);
    printf("c=% 5.0f   ", buf.climb_rate*60);
    printf("m=% 4.0f   ", buf.rpm[0]);
    printf("% 10.6fN   ", buf.latitude*180/M_PI);
    printf("% 10.6fE   ",buf.longitude*180/M_PI);
    printf("% 7.1f   ", buf.agl*3.28084);
    printf("\n");
  };

};
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Flightgear-users mailing list
Flightgear-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-users

Reply via email to