/* SITL handling - utility functions This simulates the APM1 hardware sufficiently for the APM code to think it is running on real hardware Andrew Tridgell November 2011 */ #include #include #include #include #include #include #include #include "desktop.h" /* swap one double */ double swap_double(double d) { union { double d; uint8_t b[8]; } in, out; int i; in.d = d; for (i=0; i<8; i++) { out.b[7-i] = in.b[i]; } return out.d; } /* swap an array of doubles */ void swap_doubles(double *d, unsigned count) { while (count--) { *d = swap_double(*d); d++; } } /* swap one float */ float swap_float(float f) { union { float f; uint8_t b[4]; } in, out; int i; in.f = f; for (i=0; i<4; i++) { out.b[4-i] = in.b[i]; } return out.f; } /* swap an array of floats */ void swap_floats(float *f, unsigned count) { while (count--) { *f = swap_float(*f); f++; } } void set_nonblocking(int fd) { unsigned v = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, v | O_NONBLOCK); }