diff options
author | Tomas Kukosa <kukosa@herman.cz> | 2021-08-31 13:12:47 +0200 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-08-31 16:55:52 +0000 |
commit | 16b1cdb23fa9b164879592d7e30020a114e757f9 (patch) | |
tree | 87d27330673b63eb1bc66eb4d78a087d6f74cfe8 /epan/dissectors/asn1/ieee1609dot2/packet-ieee1609dot2-template.c | |
parent | a728da1f2880a1014de086251b300765c1bffd28 (diff) |
IEEE1609dot2: use custom formatters for better readability
Diffstat (limited to 'epan/dissectors/asn1/ieee1609dot2/packet-ieee1609dot2-template.c')
-rw-r--r-- | epan/dissectors/asn1/ieee1609dot2/packet-ieee1609dot2-template.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/epan/dissectors/asn1/ieee1609dot2/packet-ieee1609dot2-template.c b/epan/dissectors/asn1/ieee1609dot2/packet-ieee1609dot2-template.c index 5b95e87bfe..1ad34ce75e 100644 --- a/epan/dissectors/asn1/ieee1609dot2/packet-ieee1609dot2-template.c +++ b/epan/dissectors/asn1/ieee1609dot2/packet-ieee1609dot2-template.c @@ -15,6 +15,8 @@ #include "config.h" +#include <time.h> + #include <epan/packet.h> #include <epan/conversation.h> #include <epan/oids.h> @@ -57,6 +59,67 @@ ieee1609dot2_set_next_default_psid(packet_info *pinfo, guint32 psid) #include "packet-ieee1609dot2-fn.c" +static void +ieee1609dot2_NinetyDegreeInt_fmt(gchar *s, guint32 v) +{ + gint32 lat = (gint32)v; + if (lat == 900000001) { + g_snprintf(s, ITEM_LABEL_LENGTH, "unavailable(%d)", lat); + } else { + g_snprintf(s, ITEM_LABEL_LENGTH, "%u°%u'%.3f\"%c (%d)", + abs(lat) / 10000000, + abs(lat) % 10000000 * 6 / 1000000, + abs(lat) % 10000000 * 6 % 1000000 * 6.0 / 100000.0, + (lat >= 0) ? 'N' : 'S', + lat); + } +} + +static void +ieee1609dot2_OneEightyDegreeInt_fmt(gchar *s, guint32 v) +{ + gint32 lng = (gint32)v; + if (lng == 1800000001) { + g_snprintf(s, ITEM_LABEL_LENGTH, "unavailable(%d)", lng); + } else { + g_snprintf(s, ITEM_LABEL_LENGTH, "%u°%u'%.3f\"%c (%d)", + abs(lng) / 10000000, + abs(lng) % 10000000 * 6 / 1000000, + abs(lng) % 10000000 * 6 % 1000000 * 6.0 / 100000.0, + (lng >= 0) ? 'E' : 'W', + lng); + } +} + +static void +ieee1609dot2_ElevInt_fmt(gchar *s, guint32 v) +{ + // Range is from -4096 to 61439 in units of one-tenth of a meter + gint32 alt = (gint32)v - 4096; + g_snprintf(s, ITEM_LABEL_LENGTH, "%.2fm (%u)", alt * 0.1, v); +} + +static void +ieee1609dot2_Time32_fmt(gchar *s, guint32 v) +{ + time_t secs = v + 1072915200 - 5; + struct tm *tm = gmtime(&secs); + g_snprintf(s, ITEM_LABEL_LENGTH, "%u-%02u-%02u %02u:%02u:%02u (%" G_GUINT64_FORMAT ")", + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, v + ); +} + +static void +ieee1609dot2_Time64_fmt(gchar *s, guint64 v) +{ + time_t secs = v / 1000000 + 1072915200 - 5; + guint32 usecs = v % 1000000; + struct tm *tm = gmtime(&secs); + g_snprintf(s, ITEM_LABEL_LENGTH, "%u-%02u-%02u %02u:%02u:%02u.%06u (%" G_GUINT64_FORMAT ")", + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, usecs, v + ); +} + /*--- proto_register_ieee1609dot2 ----------------------------------------------*/ void proto_register_ieee1609dot2(void) { |