3 #include <sys/socket.h>
8 #include <netinet/in.h>
16 #include "../flight_gear.h"
22 struct sockaddr_in addr;
24 unsigned int initial_time;
25 unsigned int time_offset;
48 void nps_flightgear_init(
const char *host,
unsigned int port,
unsigned int port_in,
unsigned int time_offset)
51 struct protoent *pte = getprotobyname(
"UDP");
52 flightgear.socket = socket(PF_INET, SOCK_DGRAM, pte->p_proto);
54 perror(
"nps_flightgear_init flightgear.socket socket()");
57 if ( setsockopt(
flightgear.socket, SOL_SOCKET, SO_REUSEADDR,
58 &so_reuseaddr,
sizeof(so_reuseaddr)) == -1) {
59 perror(
"nps_flightgear_init flightgear.socket setsockopt()");
65 flightgear.addr.sin_addr.s_addr = inet_addr(host);
70 struct sockaddr_in addr_in;
71 flightgear.socket_in = socket(PF_INET, SOCK_DGRAM, pte->p_proto);
73 perror(
"nps_flightgear_init flightgear.socket_in socket()");
76 if ( setsockopt(
flightgear.socket_in, SOL_SOCKET, SO_REUSEADDR,
77 &so_reuseaddr,
sizeof(so_reuseaddr)) == -1) {
78 perror(
"nps_flightgear_init flightgear.socket_in setsockopt()");
81 addr_in.sin_family = PF_INET;
82 addr_in.sin_port = htons(port_in);
83 addr_in.sin_addr.s_addr = htonl(INADDR_ANY);
85 if (bind(
flightgear.socket_in, (
struct sockaddr*)&addr_in,
sizeof(addr_in)) == -1) {
86 perror(
"nps_flightgear_init bind()");
90 printf(
"Bount to port %u to receive from\n", port_in);
98 time_t t = time(NULL);
112 memset(&fgfdm, 0,
sizeof(fgfdm));
158 if (sendto(
flightgear.socket, (
char *)(&fgfdm),
sizeof(fgfdm), 0,
160 fprintf(stderr,
"error sending to FlightGear\n");
212 if (sendto(
flightgear.socket, (
char *)(&gui),
sizeof(gui), 0,
214 fprintf(stderr,
"error sending to FlightGear\n");
230 size_t s_env =
sizeof(env);
234 memset(&env, 0, s_env);
235 bytes_read = recvfrom(
flightgear.socket_in, (
char*)(&env), s_env, MSG_DONTWAIT, NULL, NULL);
236 while (bytes_read != -1) {
237 if (bytes_read == (
int)s_env){
246 printf(
"WARNING : ignoring packet with size %d (%d expected)", bytes_read, (
int)s_env);
250 memset(&env, 0, s_env);
251 bytes_read = recvfrom(
flightgear.socket_in, (
char*)(&env), s_env, MSG_DONTWAIT, NULL, NULL);
254 if ((errno & (EAGAIN | EWOULDBLOCK)) == 0) {
255 perror(
"nps_flightgear_receive recvfrom()");
void nps_atmosphere_set_wind_ned(double wind_north, double wind_east, double wind_down)
static struct @327 flightgear
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]
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()
Receive Flight Gear environment messages.
float rpm[FG_NET_FDM_MAX_ENGINES]
Atmosphere model (pressure, wind) for NPS.
float rpm[FG_NET_FDM_MAX_ENGINES]
#define FG_NET_FDM_VERSION
float course_deviation_deg