Pre-ci test passed git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4000 818b1a75-f10b-46b9-bf7c-635c3b92a50f
118 lines
2.6 KiB
C
118 lines
2.6 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
#include <time.h>
|
|
#include <gps.h>
|
|
#include <forms.h>
|
|
|
|
struct gps_data_t *gps_data = NULL;
|
|
struct gps_fix_t dummy_gps_data;
|
|
FILE *dumpfile_id = NULL;
|
|
|
|
|
|
void gps_data_callback(int gps_fd, void* data)
|
|
{
|
|
//char tmptxt[1024];
|
|
time_t timer;
|
|
struct tm *now;
|
|
|
|
timer = time(NULL);
|
|
|
|
//printf("GPS timer called\n");
|
|
if (gps_data)
|
|
{
|
|
if (gps_poll(gps_data) != 0)
|
|
{
|
|
//sprintf(tmptxt,"Error polling data from GPS, gps_data = %x", gps_data);
|
|
printf("Error polling data from GPS\n");
|
|
}
|
|
else
|
|
now = localtime(&timer);
|
|
printf("%04d%02d%02d%02d%02d%02d,%g,%g\n",
|
|
now->tm_year+1900,now->tm_mon+1,now->tm_mday,now->tm_hour, now->tm_min, now->tm_sec,
|
|
//asctime(localtime(&timer)),
|
|
gps_data->fix.latitude,gps_data->fix.longitude);
|
|
}
|
|
//fl_set_timer(ob, 0.05);
|
|
|
|
//write GPS
|
|
if (gps_data)
|
|
{
|
|
if (fwrite(&(gps_data->fix), sizeof(char), sizeof(struct gps_fix_t), dumpfile_id) != sizeof(struct gps_fix_t))
|
|
{
|
|
printf("Error writing to dumpfile, stopping recording\n");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
printf("WARNING: No GPS data available, storing dummy packet\n");
|
|
if (fwrite(&(dummy_gps_data), sizeof(char), sizeof(struct gps_fix_t), dumpfile_id) != sizeof(struct gps_fix_t))
|
|
{
|
|
printf("Error writing to dumpfile, stopping recording\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
void stop_gps(int sig) {
|
|
|
|
// stop gps
|
|
if (gps_data)
|
|
fl_remove_io_callback(gps_data->gps_fd, FL_READ , &gps_data_callback);
|
|
|
|
// close the GPS
|
|
if (gps_data)
|
|
gps_close(gps_data);
|
|
|
|
fclose(dumpfile_id);
|
|
dumpfile_id = NULL;
|
|
|
|
fl_finish();
|
|
|
|
exit(0);
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
time_t timer;
|
|
char log_filename[256], date_str[128];
|
|
struct tm *now;
|
|
|
|
timer = time(NULL);
|
|
now = localtime(&timer);
|
|
|
|
// open GPS
|
|
gps_data = gps_open("127.0.0.1","2947");
|
|
if (gps_data == NULL)
|
|
{
|
|
printf("Could not open GPS\n");
|
|
exit(-1);
|
|
}
|
|
else if (gps_stream(gps_data, WATCH_ENABLE,NULL) != 0)
|
|
{
|
|
//sprintf(tmptxt,"Error sending command to GPS, gps_data = %x", gps_data);
|
|
printf("Error sending command to GPS\n");
|
|
exit(-1);
|
|
}
|
|
|
|
strftime(date_str, 128, "%Y%m%d_%H%M%S", now);
|
|
sprintf(log_filename,"gps_trace_%s.log", date_str);
|
|
dumpfile_id = fopen(log_filename,"w");
|
|
if (dumpfile_id == NULL)
|
|
{
|
|
printf("Error opening dumpfile\n");
|
|
exit(-1);
|
|
}
|
|
|
|
signal(SIGINT, stop_gps);
|
|
|
|
fl_initialize(&argc, argv, "GPS Tracer", 0, 0);
|
|
|
|
if (gps_data)
|
|
fl_add_io_callback(gps_data->gps_fd, FL_READ, &gps_data_callback, NULL);
|
|
|
|
fl_do_forms();
|
|
|
|
exit(0);
|
|
}
|
|
|