#
# Garmin Points of Interest "garmin_gpi" (.gpi)
#
gpsbabel -i garmin_gpi -f ${REFERENCE}/garmin_gpi.gpi -o gpx -F ${TMPDIR}/garmin_gpi.gpx
compare ${REFERENCE}/garmin_gpi.gpx ${TMPDIR}/garmin_gpi.gpx

gpsbabel -i gpx -f ${REFERENCE}/garmin_gpi.gpx -o garmin_gpi -F ${TMPDIR}/garmin_gpi.gpi
gpsbabel -i garmin_gpi -f ${TMPDIR}/garmin_gpi.gpi -o gpx -F ${TMPDIR}/garmin_gpi2.gpx
compare ${REFERENCE}/garmin_gpi.gpx ${TMPDIR}/garmin_gpi2.gpx

gpsbabel -i gpx -f ${REFERENCE}/track/vitovtt-sample.gpx -x transform,wpt=trk -o garmin_gpi -F ${TMPDIR}/garmin_gpi3a.gpi
gpsbabel -i garmin_gpi -f ${TMPDIR}/garmin_gpi3a.gpi -o garmin_gpi -F ${TMPDIR}/garmin_gpi3b.gpi
bincompare ${TMPDIR}/garmin_gpi3a.gpi ${TMPDIR}/garmin_gpi3b.gpi

gpsbabel -i garmin_gpi -f ${REFERENCE}/gpi_ext-sample.gpi -o unicsv -F ${TMPDIR}/gpi_ext-sample.csv
compare ${REFERENCE}/gpi_ext-sample.csv ${TMPDIR}/gpi_ext-sample.csv

# Don't test writing this sample file from garminonline.de/extras/poi, but 
# prove we can read it
gpsbabel -i garmin_gpi -f ${REFERENCE}/umsonstdraussen.gpi -o gpx,garminextensions -F ${TMPDIR}/umsonstdraussen.gpx
compare ${REFERENCE}/umsonstdraussen.gpx ${TMPDIR}/umsonstdraussen.gpx

# look for differences between latin1 and windows-1252
gpsbabel -i garmin_gpi -f ${REFERENCE}/garmin_gpi_encoding.gpi -o gpx,gpxver=1.1 -F ${TMPDIR}/garmin_gpi_encoding.gpx
compare ${REFERENCE}/garmin_gpi_encoding.gpx ${TMPDIR}/garmin_gpi_encoding.gpx
gpsbabel -i gpx -f ${REFERENCE}/garmin_gpi_encoding.gpx  -o garmin_gpi -F ${TMPDIR}/garmin_gpi_encoding.gpi
gpsbabel -i garmin_gpi -f ${TMPDIR}/garmin_gpi_encoding.gpi -o gpx,gpxver=1.1 -F ${TMPDIR}/garmin_gpi_encoding2.gpi.gpx
compare ${TMPDIR}/garmin_gpi_encoding.gpx ${TMPDIR}/garmin_gpi_encoding2.gpi.gpx

# check category encoding
gpsbabel -i gpx -f ${REFERENCE}/garmin_gpi.gpx -o garmin_gpi,category="Vinícolas",hide -F ${TMPDIR}/garmin_gpi_category~gpx.gpi
compare ${REFERENCE}/garmin_gpi_category~gpx.gpi ${TMPDIR}/garmin_gpi_category~gpx.gpi

# check position option 
gpsbabel -i gpx -f ${REFERENCE}/garmin_gpi.gpx -o garmin_gpi,position -F ${TMPDIR}/garmin_gpi_position~gpx.gpi
compare ${REFERENCE}/garmin_gpi_position~gpx.gpi ${TMPDIR}/garmin_gpi_position~gpx.gpi

# check dual language read
# spb_metro_norm.gpi from https://www.garmin.ru/download/extras/poi.php or  https://files.navicom.ru/spb_metro_norm.gpi
gpsbabel -i garmin_gpi,languagecode=RU -f ${REFERENCE}/spb_metro_norm.gpi -o gpx -F ${TMPDIR}/spb_metro_norm_ru~gpi.gpx
compare ${REFERENCE}/spb_metro_norm_ru~gpi.gpx ${TMPDIR}/spb_metro_norm_ru~gpi.gpx
gpsbabel -i garmin_gpi,languagecode=EN -f ${REFERENCE}/spb_metro_norm.gpi -o gpx -F ${TMPDIR}/spb_metro_norm_en~gpi.gpx
compare ${REFERENCE}/spb_metro_norm_en~gpi.gpx ${TMPDIR}/spb_metro_norm_en~gpi.gpx

# check utf8 write
gpsbabel -i gpx -f ${REFERENCE}/spb_metro_norm_ru~gpi.gpx -o garmin_gpi,writecodec=utf8,unique=0 -F ${TMPDIR}/spb_metro_norm_ru~gpi~gpx.gpi
gpsbabel -i garmin_gpi -f ${TMPDIR}/spb_metro_norm_ru~gpi~gpx.gpi -x sort,shortname -o unicsv -F ${TMPDIR}/spb_metro_norm_ru~gpi~gpx~gpi.csv
gpsbabel -i garmin_gpi,languagecode=RU -f ${REFERENCE}/spb_metro_norm.gpi -x sort,shortname -o unicsv -F ${TMPDIR}/spb_metro_norm_ru~gpi.csv
compare ${REFERENCE}/spb_metro_norm_ru~gpi.csv ${TMPDIR}/spb_metro_norm_ru~gpi~gpx~gpi.csv
compare ${REFERENCE}/spb_metro_norm_ru~gpi.csv ${TMPDIR}/spb_metro_norm_ru~gpi.csv

# speed folly
# These should be a speed of 30 in statute units, i.e. 30 mph, 0.5 miles
gpsbabel -i gpx -f ${REFERENCE}/gpispeed.gpx -o garmin_gpi,speed=30,proximity=0.5,units=s -F ${TMPDIR}/gpispeed_s.gpi
bincompare ${REFERENCE}/gpispeed.gpi ${TMPDIR}/gpispeed_s.gpi
gpsbabel -i gpx -f ${REFERENCE}/gpispeed.gpx -o garmin_gpi,speed=30mph,proximity=0.5mi -F ${TMPDIR}/gpispeed_mph.gpi
bincompare ${REFERENCE}/gpispeed.gpi ${TMPDIR}/gpispeed_mph.gpi
# These should show @48 (kph), 804.7m
gpsbabel -i garmin_gpi -f ${REFERENCE}/gpispeed.gpi -o unicsv -F ${TMPDIR}/gpispeed.csv
compare ${REFERENCE}/gpispeed_m.csv ${TMPDIR}/gpispeed.csv
gpsbabel -i garmin_gpi,units=m -f ${REFERENCE}/gpispeed.gpi -o unicsv -F ${TMPDIR}/gpispeed_m.csv
compare ${REFERENCE}/gpispeed_m.csv ${TMPDIR}/gpispeed_m.csv
# These should show @30 (mph), 804.7m
gpsbabel -i garmin_gpi,units=s -f ${REFERENCE}/gpispeed.gpi -o unicsv -F ${TMPDIR}/gpispeed_s.csv
compare ${REFERENCE}/gpispeed_s.csv ${TMPDIR}/gpispeed_s.csv
# interpret speed from waypoint name
gpsbabel -i unicsv -f ${REFERENCE}/gpispeed_s.csv -o garmin_gpi,alerts,units=s -F ${TMPDIR}/gpispeed_sn.gpi
gpsbabel -i garmin_gpi,units=s -f ${TMPDIR}/gpispeed_sn.gpi -o unicsv -F  ${TMPDIR}/gpispeed_s2.csv
compare ${REFERENCE}/gpispeed_s.csv ${TMPDIR}/gpispeed_s2.csv

