From 9a41961aeb4a6a976041821ab1e7b89690547c13 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Mon, 18 Jan 2016 22:18:49 -0800 Subject: [PATCH] Store TPMS "packet type". For now, completely dumb CRC-OK packet length, since I only handle three packet types, which differ in length. --- firmware/application/tpms_app.cpp | 9 +++++---- firmware/application/tpms_app.hpp | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index d264cba0..47e43fcb 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -44,9 +44,9 @@ Optional Packet::reading() const { const auto length = crc_valid_length(); switch(length) { - case 64: return Reading { reader_.read(0, 32), reader_.read(32, 8) }; - case 72: return Reading { reader_.read(0, 32), reader_.read(40, 8), reader_.read(48, 8), reader_.read(56, 8) }; - case 80: return Reading { reader_.read(8, 32), reader_.read(48, 8), reader_.read(56, 8), reader_.read(64, 8) }; + 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) }; default: return { }; } } @@ -147,7 +147,8 @@ 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_hex(reading.id(), 8) + " " + to_string_hex(reading.value_1(), 2); + auto s = to_string_dec_uint(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 40931b04..ad06d8df 100644 --- a/firmware/application/tpms_app.hpp +++ b/firmware/application/tpms_app.hpp @@ -49,7 +49,8 @@ private: class Reading { public: constexpr Reading( - ) : id_ { 0 }, + ) : type_ { 0 }, + id_ { 0 }, value_1_ { 0 }, value_2_ { 0 }, value_3_ { 0 } @@ -57,9 +58,11 @@ public: } constexpr Reading( + uint32_t type, uint32_t id, uint16_t value_1 - ) : id_ { id }, + ) : type_ { type }, + id_ { id }, value_1_ { value_1 }, value_2_ { }, value_3_ { } @@ -67,17 +70,23 @@ public: } constexpr Reading( + uint32_t type, uint32_t id, uint16_t value_1, uint16_t value_2, uint16_t value_3 - ) : id_ { id }, + ) : type_ { type }, + id_ { id }, value_1_ { value_1 }, value_2_ { value_2 }, value_3_ { value_3 } { } + uint32_t type() const { + return type_; + } + uint32_t id() const { return id_; } @@ -95,6 +104,7 @@ public: } private: + uint32_t type_; uint32_t id_; uint16_t value_1_; Optional value_2_;