AP_HAL_SITL: add file based gps

This commit is contained in:
Michael Oborne 2015-08-30 14:53:29 +08:00 committed by Andrew Tridgell
parent 0000ff45cb
commit b861233677
3 changed files with 34 additions and 0 deletions

View File

@ -98,6 +98,7 @@ private:
void _update_gps_nmea(const struct gps_data *d);
void _sbp_send_message(uint16_t msg_type, uint16_t sender_id, uint8_t len, uint8_t *payload);
void _update_gps_sbp(const struct gps_data *d);
void _update_gps_file(const struct gps_data *d);
void _update_gps(double latitude, double longitude, float altitude,
double speedN, double speedE, double speedD, bool have_lock);

View File

@ -25,6 +25,9 @@
#include <time.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#pragma GCC diagnostic ignored "-Wunused-result"
@ -699,6 +702,31 @@ void SITL_State::_update_gps_sbp(const struct gps_data *d)
do_every_count++;
}
/*
temporary method to use file as GPS data
*/
void SITL_State::_update_gps_file(const struct gps_data *d)
{
static int fd = -1;
if (fd == -1) {
fd = open("/tmp/gps.dat", O_RDONLY);
}
if (fd == -1) {
return;
}
char buf[200];
ssize_t ret = ::read(fd, buf, sizeof(buf));
if (ret > 0) {
::printf("wrote gps %u bytes\n", (unsigned)ret);
_gps_write((const uint8_t *)buf, ret);
}
if (ret == 0) {
::printf("gps rewind\n");
lseek(fd, 0, SEEK_SET);
}
}
/*
possibly send a new GPS packet
*/
@ -802,6 +830,10 @@ void SITL_State::_update_gps(double latitude, double longitude, float altitude,
_update_gps_sbp(&d);
break;
case SITL::GPS_TYPE_FILE:
_update_gps_file(&d);
break;
}
}

View File

@ -47,6 +47,7 @@ public:
GPS_TYPE_MTK19 = 4,
GPS_TYPE_NMEA = 5,
GPS_TYPE_SBP = 6,
GPS_TYPE_FILE = 7
};
struct sitl_fdm state;