Select Git revision
sim_ac_flightgear.c
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
sim_ac_flightgear.c 3.03 KiB
/*
* $Id$
*
* Copyright (C) 2011 Eric Parsonage eric@eparsonage.com
* Mainly based around the equivalent file in nps
* which was written by Antoine
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <math.h>
#include "std.h"
#include <FGFDMExec.h>
#include "flight_gear.h"
#include "sim_ac_flightgear.h"
static struct
{
int socket;
struct sockaddr_in addr;
} flightgear;
void sim_ac_flightgear_init(const char* host, unsigned int port)
{
int so_reuseaddr = 1;
struct protoent * pte = getprotobyname("UDP");
flightgear.socket = socket( PF_INET, SOCK_DGRAM, pte->p_proto);
setsockopt(flightgear.socket, SOL_SOCKET, SO_REUSEADDR,
&so_reuseaddr, sizeof(so_reuseaddr));
flightgear.addr.sin_family = PF_INET;
flightgear.addr.sin_port = htons(port);
flightgear.addr.sin_addr.s_addr = inet_addr(host);
}
static inline double get_value(JSBSim::FGFDMExec* FDMExec, string name)
{
return FDMExec->GetPropertyManager()->GetNode(name)->getDoubleValue();
}
void sim_ac_flightgear_send(JSBSim::FGFDMExec* FDMExec)
{
struct FGNetGUI gui;
gui.version = FG_NET_GUI_VERSION;
gui.latitude = get_value(FDMExec, "position/lat-gc-rad");
gui.longitude = get_value(FDMExec, "position/long-gc-rad");
gui.altitude = get_value(FDMExec, "position/h-sl-meters");