ref: a0578c7de4163344d936ea78191a836556495bba
dir: /gps.c/
#include <u.h> #include <libc.h> #include <draw.h> #include "dat.h" #include "fns.h" GPos getlocation() { int fd; GPos ret; char buf[256]; char *fields[9]; int n, quality; char *nop; ret.lon = 0.; ret.lat = 0.; fd = open("/mnt/gps/position", OREAD); if (fd < 0) { debugprint("unable to open gps: %r\n"); return ret; } if ((n = read(fd, buf, 256)) <= 0) { fprint(2, "read error: %r\n"); close(fd); return ret; } close(fd); buf[n] = 0; quality = atoi(buf); if (!quality) return ret; if (getfields(buf, fields, 9, 1, " ") != 9) { fprint(2, "read error: invalid fields\n"); return ret; } ret.lon = /*180 +*/ strtod(fields[3], &nop); ret.lat = /*90 +*/ strtod(fields[4], &nop); debugprint("GPS: %f %f\n", ret.lon, ret.lat); return ret; }