3 #include <sys/socket.h>
8 #include <netinet/in.h>
16 #include "../flight_gear.h"
23 struct sockaddr_in addr;
25 unsigned int initial_time;
26 unsigned int time_offset;
52 void nps_flightgear_init(
const char *host,
unsigned int port,
unsigned int port_in,
unsigned int time_offset)
55 struct protoent *pte = getprotobyname(
"UDP");
56 flightgear.socket = socket(PF_INET, SOCK_DGRAM, pte->p_proto);
58 perror(
"nps_flightgear_init flightgear.socket socket()");
61 if ( setsockopt(
flightgear.socket, SOL_SOCKET, SO_REUSEADDR,
62 &so_reuseaddr,
sizeof(so_reuseaddr)) == -1) {
63 perror(
"nps_flightgear_init flightgear.socket setsockopt()");
69 flightgear.addr.sin_addr.s_addr = inet_addr(host);
74 struct sockaddr_in addr_in;
75 flightgear.socket_in = socket(PF_INET, SOCK_DGRAM, pte->p_proto);
77 perror(
"nps_flightgear_init flightgear.socket_in socket()");
80 if ( setsockopt(
flightgear.socket_in, SOL_SOCKET, SO_REUSEADDR,
81 &so_reuseaddr,
sizeof(so_reuseaddr)) == -1) {
82 perror(
"nps_flightgear_init flightgear.socket_in setsockopt()");
85 addr_in.sin_family = PF_INET;
86 addr_in.sin_port = htons(port_in);
87 addr_in.sin_addr.s_addr = htonl(INADDR_ANY);
89 if (bind(
flightgear.socket_in, (
struct sockaddr*)&addr_in,
sizeof(addr_in)) == -1) {
90 perror(
"nps_flightgear_init bind()");
94 printf(
"Bount to port %u to receive from\n", port_in);
102 time_t t = time(NULL);
119 memset(&fgfdm, 0,
sizeof(fgfdm));
165 if (sendto(
flightgear.socket, (
char *)(&fgfdm),
sizeof(fgfdm), 0,
167 fprintf(stderr,
"error sending to FlightGear\n");
219 if (sendto(
flightgear.socket, (
char *)(&gui),
sizeof(gui), 0,
221 fprintf(stderr,
"error sending to FlightGear\n");
238 size_t s_env =
sizeof(env);
244 memset(&env, 0, s_env);
245 bytes_read = recvfrom(
flightgear.socket_in, (
char*)(&env), s_env, MSG_WAITALL, NULL, NULL);
246 while (bytes_read != -1) {
247 if (bytes_read == (
int)s_env){
258 printf(
"WARNING : ignoring packet with size %d (%d expected)", bytes_read, (
int)s_env);
262 memset(&env, 0, s_env);
263 bytes_read = recvfrom(
flightgear.socket_in, (
char*)(&env), s_env, MSG_WAITALL, NULL, NULL);
266 if ((errno & (EAGAIN | EWOULDBLOCK)) == 0) {
267 perror(
"nps_flightgear_receive recvfrom()");
void nps_atmosphere_set_wind_ned(double wind_north, double wind_east, double wind_down)
uint32_t eng_state[FG_NET_FDM_MAX_ENGINES]
void nps_flightgear_send_fdm()
Send FlightGear FDM packet For visualization with moving surfaces (elevator, propeller etc)...
float fuel_quantity[FG_NET_FDM_MAX_TANKS]
pthread_mutex_t fdm_mutex
struct NpsFdm fdm
Holds all necessary NPS FDM state information.
double alt
in meters above WGS84 reference ellipsoid
struct DoubleEulers ltp_to_body_eulers
#define FG_NET_FDM_MAX_ENGINES
#define FG_NET_GUI_VERSION
float fuel_quantity[FG_NET_GUI_MAX_TANKS]
void nps_flightgear_init(const char *host, unsigned int port, unsigned int port_in, unsigned int time_offset)
void nps_flightgear_send()
Send FlightGear GUI packet For visualization of airplane position and attitude only start fgfs with â€...
uint32_t eng_state[FG_NET_FDM_MAX_ENGINES]
void * nps_flightgear_receive(void *data)
Receive Flight Gear environment messages.
float rpm[FG_NET_FDM_MAX_ENGINES]
static struct @328 flightgear
Atmosphere model (pressure, wind) for NPS.
float rpm[FG_NET_FDM_MAX_ENGINES]
#define FG_NET_FDM_VERSION
float course_deviation_deg