Skip to content
Snippets Groups Projects
Select Git revision
  • v4.0.1_stable
  • master default protected
  • thesis
  • fmics-2021
  • vanadium
  • afadl-2021
  • functional-verification
  • v5.17_devel
  • v5.16.0_stable
  • v5.15_devel
  • v5.14.0_stable
  • v5.13.0_testing
  • v5.13_devel
  • v5.12_stable
  • v5.11_devel
  • v5.10_stable
  • v5.9.0_testing
  • v5.8.2_stable
  • v5.8.1_stable
  • v5.9_devel
  • v5.8.0_stable
  • v5.7.1_testing
  • v5.7.0_testing
  • v5.7_devel
  • v5.6.0_stable
  • v5.5.2_testing
  • v5.5.1_testing
27 results

sim_ac_flightgear.c

Blame
  • 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");