39 #include <sys/types.h>
44 #include <actuatordesired.h>
46 #if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__)
47 # include <Winsock2.h>
49 # include <sys/select.h>
52 #ifndef INVALID_SOCKET
53 #define INVALID_SOCKET (-1)
71 float accels[3], rates[3],
lat, lng,
alt, vels[3], temp, press;
81 ssize_t cnt = recv(fg_dev->
socket, buf,
sizeof(buf) - 1,
94 sscanf(buf,
"%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%d",
95 accels, accels+1, accels+2,
96 rates, rates+1, rates+2,
99 &temp, &press, &count);
106 ActuatorDesiredData act_desired;
108 ActuatorDesiredGet(&act_desired);
112 snprintf(sendbuf,
sizeof(sendbuf),
"%f,%f,%f,%f,%d\n",
119 if (sendto(fg_dev->
socket, sendbuf, strlen(sendbuf), 0,
126 accel_data.
x = accel_data.
x * 0.3 + accels[0] * 0.7;
127 accel_data.
y = accel_data.
y * 0.3 + accels[1] * 0.7;
128 accel_data.
z = accel_data.
z * 0.3 + accels[2] * 0.7;
130 gyro_data.
x = gyro_data.
x * 0.3 + rates[0] * 0.7;
131 gyro_data.
y = gyro_data.
y * 0.3 + rates[1] * 0.7;
132 gyro_data.
z = gyro_data.
z * 0.3 + rates[2] * 0.7;
141 FD_SET(fg_dev->
socket, &r);
144 struct timeval timeout = {
149 select(fg_dev->
socket + 1, &r, NULL, NULL, &timeout);
151 if (FD_ISSET(fg_dev->
socket, &r)) {
165 memset(fg_dev, 0,
sizeof(*fg_dev));
168 fg_dev->
socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
170 #if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__)
180 setsockopt(fg_dev->
socket, SOL_SOCKET, SO_REUSEADDR, &optval,
sizeof(optval));
182 printf(
"binding sockets on ports %d, %d\n", port, port+1);
184 const struct in_addr any_addr = {
185 .s_addr = (INADDR_ANY)
188 struct sockaddr_in saddr = {
189 .sin_family = AF_INET,
190 .sin_addr = any_addr,
191 .sin_port = htons(port)
194 fg_dev->
send_addr = (
struct sockaddr_in) {
195 .sin_family = AF_INET,
196 .sin_addr = any_addr,
197 .sin_port = htons(port + 1)
200 int res = bind(fg_dev->
socket, (
struct sockaddr*)&saddr,
203 perror(
"Binding socket failed");
232 printf(
"fg dev %p - socket %i opened\n", fg_dev, fg_dev->
socket);
struct pios_queue * PIOS_Queue_Create(size_t queue_length, size_t item_size)
void PIOS_SENSORS_SetMaxGyro(int32_t rate)
Set the maximum gyro rate in deg/s.
Main PiOS header to include all the compiled in PiOS options.
int32_t PIOS_FLIGHTGEAR_Init(flightgear_dev_t *dev, uint16_t port)
struct pios_queue * accel_queue
FlightGear driver header.
void * PIOS_malloc(size_t size)
bool PIOS_Queue_Send(struct pios_queue *queuep, const void *itemp, uint32_t timeout_ms)
static void PIOS_FLIGHTGEAR_RxTask(void *param)
struct pios_queue * gyro_queue
#define PIOS_THREAD_STACK_SIZE_MIN
Pios sensor structure for generic accel data.
struct sockaddr_in send_addr
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
int32_t PIOS_SENSORS_Register(enum pios_sensor_type type, struct pios_queue *queue)
Register a queue-based sensor with the PIOS_SENSORS interface.
Pios sensor structure for generic gyro data.
void PIOS_SENSORS_SetSampleRate(enum pios_sensor_type type, uint32_t sample_rate)
Set the sample rate of a sensor (Hz)
Includes PiOS and core architecture components.
int printf(const char *format,...)
int snprintf(char *buf, size_t count, const char *format,...)