From 5e6a76dfe7557dbf6b2f51cb472bfbf97b3c485f Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Mon, 18 Jan 2016 22:28:33 -0800 Subject: [PATCH] Use a proper enum for TPMS signal type. --- firmware/application/tpms_app.cpp | 10 ++++++---- firmware/application/tpms_app.hpp | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index 47e43fcb..336a86b8 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -30,6 +30,8 @@ using namespace portapack; #include "crc.hpp" +#include "utility.hpp" + namespace tpms { Timestamp Packet::received_at() const { @@ -44,9 +46,9 @@ Optional Packet::reading() const { const auto length = crc_valid_length(); switch(length) { - case 64: return Reading { 64, reader_.read(0, 32), reader_.read(32, 8) }; - case 72: return Reading { 72, reader_.read(0, 32), reader_.read(40, 8), reader_.read(48, 8), reader_.read(56, 8) }; - case 80: return Reading { 80, reader_.read(8, 32), reader_.read(48, 8), reader_.read(56, 8), reader_.read(64, 8) }; + case 64: return Reading { Reading::Type::FLM_64, reader_.read(0, 32), reader_.read(32, 8) }; + case 72: return Reading { Reading::Type::FLM_72, reader_.read(0, 32), reader_.read(40, 8), reader_.read(48, 8), reader_.read(56, 8) }; + case 80: return Reading { Reading::Type::FLM_80, reader_.read(8, 32), reader_.read(48, 8), reader_.read(56, 8), reader_.read(64, 8) }; default: return { }; } } @@ -147,7 +149,7 @@ void TPMSAppView::draw(const tpms::Packet& packet) { const auto reading_opt = packet.reading(); if( reading_opt.is_valid() ) { const auto reading = reading_opt.value(); - auto s = to_string_dec_uint(reading.type(), 2) + " " + to_string_hex(reading.id(), 8); + auto s = to_string_dec_uint(toUType(reading.type()), 2) + " " + to_string_hex(reading.id(), 8); s += " " + to_string_hex(reading.value_1(), 2); if( reading.value_2().is_valid() ) { s += " " + to_string_hex(reading.value_2().value(), 2); diff --git a/firmware/application/tpms_app.hpp b/firmware/application/tpms_app.hpp index ad06d8df..d0d477f7 100644 --- a/firmware/application/tpms_app.hpp +++ b/firmware/application/tpms_app.hpp @@ -48,8 +48,15 @@ private: class Reading { public: + enum Type { + None = 0, + FLM_64 = 1, + FLM_72 = 2, + FLM_80 = 3, + }; + constexpr Reading( - ) : type_ { 0 }, + ) : type_ { Type::None }, id_ { 0 }, value_1_ { 0 }, value_2_ { 0 }, @@ -58,7 +65,7 @@ public: } constexpr Reading( - uint32_t type, + Type type, uint32_t id, uint16_t value_1 ) : type_ { type }, @@ -70,7 +77,7 @@ public: } constexpr Reading( - uint32_t type, + Type type, uint32_t id, uint16_t value_1, uint16_t value_2, @@ -83,7 +90,7 @@ public: { } - uint32_t type() const { + Type type() const { return type_; } @@ -104,7 +111,7 @@ public: } private: - uint32_t type_; + Type type_; uint32_t id_; uint16_t value_1_; Optional value_2_;