Displaying timezone in Blackbox Log chooser - stronnag/mwptools GitHub Wiki

Introduction

Unmaintained Article Please check the manual for more up-to-date information.

In iNav 2.0, there are some new timezone and 'daylight saving` (DST) options to provide a better timestamp in blackbox logs. mwp displays the this time in its blackbox log chooser; however the time zone is displayed as a numeric offset and there is always the possibility that the pilot has not configured the FC for DST, so it may be incorrect.

In order to provide a nicer (better) experience in mwp, the user can choose to have mwp display the relevent local time and time zone using the machine's location in the blackbox log to determine the correct zone.

mwp's TZ options

mwp can generate a timezone from one of two sources:

  • A local application
  • An internet service

each of these requires some effect from the user and a configuration setting in mwp. If both sources are configured, mwp will use the local application.

geonames.org internet TZ service

geonames.org provides a RESTful web service that will return the time zone from a latitude and longitude. In order to use this service, it is necessary to:

Configure mwp to use geonames for TZ lookups:

$ gsettings set org.mwptools.planner geouser MYUSERNAME

Obviously, this requires you have an internet connection; however mwp should behave gracefully if a connection in unavailable.

Local Application

It is also possible to use a local application. This requires you to install a suitable application (some recommendations are given below), however it does not require a network connection. mwp expects to supply the latitude and longitude to the local application, which should return a time zone on stdout. This may require a wrapper script; an example is provided below (and as samples/tzget.sh).

Configure mwp to use a local application; in this case the wrapper script tzget.sh which is on the PATH.

gsettings set org.mwptools.planner zone-detect tzget.sh

Example of a local time zone detection application

https://github.com/evansiroky/timezone-boundary-builder provides a time zone database and links to libraries and applications that use the database to determine a time zone from a location.

ZoneDetect https://github.com/BertoldVdb/ZoneDetect is a simple C language application that uses the above database. While the application is simple, its installation is not conventional:

git clone https://github.com/BertoldVdb/ZoneDetect
cd ZoneDetect/
cd library/
make
cd ..
gcc -O2 -I ./library/ -L ./library -lzonedetect -lm demo.c -o zone-detect
sudo cp library/libzonedetect.so /usr/local/lib
sudo mkdir -p /usr/local/share/zonedectect/
sudo cp -a  database/* /usr/local/share/zonedectect
sudo cp zone-detect /usr/local/bin/zone-detect
sudo ldconfig

Then place samples/tzget.sh on the path, the script runs zone-detect and presents the output as mwp requires.

#!/bin/bash

# Using ZoneDetect https://github.com/BertoldVdb/ZoneDetect
# based on data from https://github.com/evansiroky/timezone-boundary-builder
# the latter has links to other implementations
#
# ZoneDetect databses:
#  timezone16.bin has a longitude resolution of 0.0055 degrees (~0.5km).
#  timezone21.bin has a longitude resolution of 0.00017 degrees (~20m).
#
# Example installation
# sudo cp library/libzonedetect.so /usr/local/lib
# sudo mkdir -p /usr/local/share/zonedectect/
# sudo cp -a  database/* /usr/local/share/zonedectect
# sudo cp zone-detect /usr/local/bin/zone-detect
# sudo ldconfig
#

DATABASE=/usr/local/share/zonedectect/timezone21.bin
ZONE=
while read K V
do
  case $K in
    TimezoneIdPrefix:) ZONE=$V ;;
    TimezoneId:) ZONE=${ZONE}${V} ;;
  esac
done < <(zone-detect $DATABASE $1 $2)
echo $ZONE

Note it uses the higher precision (20m resolution) database. Finally, as above, configure mwp to use the wrapper script:

gsettings set org.mwptools.planner zone-detect tzget.sh

Conclusion

Here's what the result looks like:

TZ Example

Note that mwp now also zooms into the blackbox location as it analyses the BB file.