From 1f0bd76f673416b74c28a392b2cf165f5c789e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 27 Jan 2022 00:25:52 +0100 Subject: [PATCH] Handle the whole flags as flags, not as type + flags --- src/data/gpiparser.cpp | 46 +++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/data/gpiparser.cpp b/src/data/gpiparser.cpp index 5e0e5e5c..0cd4cd94 100644 --- a/src/data/gpiparser.cpp +++ b/src/data/gpiparser.cpp @@ -429,41 +429,45 @@ static quint32 readImageInfo(DataStream &stream, Waypoint &waypoint, return rs + rh.size; } -static int speed(quint8 flags) +static int speed(quint16 flags) { return (((flags >> 3) & 0x0F) * 10) + (((flags >> 2) & 1) * 5); } -static bool portable(quint8 flags) +static QString units(quint16 flags) +{ + return (flags & (1<<8)) ? "km/h" : "mi/h"; +} + +static bool portable(quint16 flags) { return (flags & 1); } -static QString cameraDesc(quint8 type, quint8 flags) +static bool redLight(quint16 flags) { - switch (type) { - case 8: - return portable(flags) - ? QString("%1 mi/h").arg(speed(flags)) - : QString("%1 mi/h").arg(speed(flags)); - case 9: - return portable(flags) - ? QString("%1 km/h").arg(speed(flags)) - : QString("%1 km/h").arg(speed(flags)); - break; - case 10: - case 11: - return "Red light camera"; - } + return (flags & (1<<9)); +} - return QString(); +static QString cameraDesc(quint16 flags) +{ + if (redLight(flags)) + return "Red light camera"; + else { + QString desc(QString::number(speed(flags)) + " " + units(flags)); + if (portable(flags)) + return "" + desc + ""; + else + return desc; + } } static quint32 readCamera(DataStream &stream, QVector &waypoints, QList &polygons) { RecordHeader rh; - quint8 flags, type, s7, rs; + quint8 s7, rs; + quint16 flags; qint32 top, right, bottom, left, lat, lon; quint32 ds = 15; @@ -473,7 +477,7 @@ static quint32 readCamera(DataStream &stream, QVector &waypoints, right = stream.readInt24(); bottom = stream.readInt24(); left = stream.readInt24(); - stream >> flags >> type >> s7; + stream >> flags >> s7; if (s7) { quint32 skip = s7 + 2 + s7/4; @@ -494,7 +498,7 @@ static quint32 readCamera(DataStream &stream, QVector &waypoints, Area area(RectC(Coordinates(toWGS24(left), toWGS24(top)), Coordinates(toWGS24(right), toWGS24(bottom)))); - area.setDescription(cameraDesc(type, flags)); + area.setDescription(cameraDesc(flags)); waypoints.append(Coordinates(toWGS24(lon), toWGS24(lat))); polygons.append(area);