From 939ea663f29b185d4352da5e7d896339d04ad68e Mon Sep 17 00:00:00 2001 From: Jiri Benc Date: Tue, 30 Aug 2016 21:41:14 +0200 Subject: [PATCH] Initial version --- Makefile | 2 ++ README | 2 ++ gp102-poi.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 gp102-poi.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e056551 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +gp102-poi: gp102-poi.c + gcc -W -Wall -o $@ $< diff --git a/README b/README new file mode 100644 index 0000000..bbaa629 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +Based on Canmore G-Porter POI Reader by Archil Imnadze, +https://github.com/aimnadze/canmore-gporter-poi-reader diff --git a/gp102-poi.c b/gp102-poi.c new file mode 100644 index 0000000..d761887 --- /dev/null +++ b/gp102-poi.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include + +struct poi_data { + uint8_t unknown1; /* seems to be always 0x01 */ + uint8_t icon; + uint8_t unknown2[10]; /* seems to be always 0x00 0x00 0x10 followed by zeros */ + char name[10]; + uint8_t unknown3[54]; /* seems to be always zeros; perhaps still (part of) the name? */ + uint32_t lat; + uint32_t lon; + uint8_t unused[44]; /* 0xff */ +}; + +static char icon_names[][11] = { + "star", "home", "checkpoint", + "car", "cafe", "train", + "gas", "office", "airport", +}; +#define ICONS (sizeof(icon_names) / sizeof(icon_names[0])) + +static void print_coord(double coord, int len, const char *mod) +{ + int deg = abs((int)coord); + + printf("%c %0*d° %06.3f", mod[!!(coord < 0)], len, deg, (fabs(coord) - deg) * 60); +} + +static int read_poi(const char *fname) +{ + FILE *f; + struct poi_data data; + uint8_t buf; + double lat, lon; + + f = fopen(fname, "rb"); + if (!f) + goto err; + if (fread(&data, sizeof(data), 1, f) < 1) + goto err; + if (fread(&buf, 1, 1, f)) { + fprintf(stderr, "Error: unexpected size of `%s'.\n", fname); + fclose(f); + return 1; + } + fclose(f); + + if (data.icon >= ICONS) { + fprintf(stderr, "Error: %s: invalid file type.\n", fname); + return 1; + } + if (data.unknown1 != 0x01) + fprintf(stderr, "Warning: %s: invalid signature, continuing anyway.\n", fname); + lat = (double)(int32_t)le32toh(data.lat) / 100000; + lon = (double)(int32_t)le32toh(data.lon) / 100000; + printf("%s (%s) ", data.name, icon_names[data.icon]); + print_coord(lat, 2, "NS"); + printf(" "); + print_coord(lon, 3, "EW"); + printf("\n"); + + return 0; + +err: + fprintf(stderr, "Error reading from `%s': %s\n", fname, strerror(errno)); + if (f) + fclose(f); + return 1; +} + +int main(int argc, char **argv) +{ + int i, err = 0; + + if (argc <= 1) { + printf("Usage: %s poi_file [poi_file...]\n", argv[0]); + return 1; + } + + for (i = 1; i < argc; i++) + err |= read_poi(argv[i]); + return err; +}