Use a proper enum for TPMS signal type.

This commit is contained in:
Jared Boone 2016-01-18 22:28:33 -08:00
parent 9a41961aeb
commit 5e6a76dfe7
2 changed files with 18 additions and 9 deletions

View File

@ -30,6 +30,8 @@ using namespace portapack;
#include "crc.hpp" #include "crc.hpp"
#include "utility.hpp"
namespace tpms { namespace tpms {
Timestamp Packet::received_at() const { Timestamp Packet::received_at() const {
@ -44,9 +46,9 @@ Optional<Reading> Packet::reading() const {
const auto length = crc_valid_length(); const auto length = crc_valid_length();
switch(length) { switch(length) {
case 64: return Reading { 64, reader_.read(0, 32), reader_.read(32, 8) }; case 64: return Reading { Reading::Type::FLM_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 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 { 80, reader_.read(8, 32), reader_.read(48, 8), reader_.read(56, 8), reader_.read(64, 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 { }; default: return { };
} }
} }
@ -147,7 +149,7 @@ void TPMSAppView::draw(const tpms::Packet& packet) {
const auto reading_opt = packet.reading(); const auto reading_opt = packet.reading();
if( reading_opt.is_valid() ) { if( reading_opt.is_valid() ) {
const auto reading = reading_opt.value(); 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); s += " " + to_string_hex(reading.value_1(), 2);
if( reading.value_2().is_valid() ) { if( reading.value_2().is_valid() ) {
s += " " + to_string_hex(reading.value_2().value(), 2); s += " " + to_string_hex(reading.value_2().value(), 2);

View File

@ -48,8 +48,15 @@ private:
class Reading { class Reading {
public: public:
enum Type {
None = 0,
FLM_64 = 1,
FLM_72 = 2,
FLM_80 = 3,
};
constexpr Reading( constexpr Reading(
) : type_ { 0 }, ) : type_ { Type::None },
id_ { 0 }, id_ { 0 },
value_1_ { 0 }, value_1_ { 0 },
value_2_ { 0 }, value_2_ { 0 },
@ -58,7 +65,7 @@ public:
} }
constexpr Reading( constexpr Reading(
uint32_t type, Type type,
uint32_t id, uint32_t id,
uint16_t value_1 uint16_t value_1
) : type_ { type }, ) : type_ { type },
@ -70,7 +77,7 @@ public:
} }
constexpr Reading( constexpr Reading(
uint32_t type, Type type,
uint32_t id, uint32_t id,
uint16_t value_1, uint16_t value_1,
uint16_t value_2, uint16_t value_2,
@ -83,7 +90,7 @@ public:
{ {
} }
uint32_t type() const { Type type() const {
return type_; return type_;
} }
@ -104,7 +111,7 @@ public:
} }
private: private:
uint32_t type_; Type type_;
uint32_t id_; uint32_t id_;
uint16_t value_1_; uint16_t value_1_;
Optional<uint16_t> value_2_; Optional<uint16_t> value_2_;