Store TPMS "packet type".

For now, completely dumb CRC-OK packet length, since I only handle three packet types, which differ in length.
This commit is contained in:
Jared Boone 2016-01-18 22:18:49 -08:00
parent 7ad9ad2596
commit 9a41961aeb
2 changed files with 18 additions and 7 deletions

View File

@ -44,9 +44,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 { reader_.read(0, 32), reader_.read(32, 8) }; case 64: return Reading { 64, 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 72: return Reading { 72, 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 80: return Reading { 80, reader_.read(8, 32), reader_.read(48, 8), reader_.read(56, 8), reader_.read(64, 8) };
default: return { }; default: return { };
} }
} }
@ -147,7 +147,8 @@ 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_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() ) { 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

@ -49,7 +49,8 @@ private:
class Reading { class Reading {
public: public:
constexpr Reading( constexpr Reading(
) : id_ { 0 }, ) : type_ { 0 },
id_ { 0 },
value_1_ { 0 }, value_1_ { 0 },
value_2_ { 0 }, value_2_ { 0 },
value_3_ { 0 } value_3_ { 0 }
@ -57,9 +58,11 @@ public:
} }
constexpr Reading( constexpr Reading(
uint32_t type,
uint32_t id, uint32_t id,
uint16_t value_1 uint16_t value_1
) : id_ { id }, ) : type_ { type },
id_ { id },
value_1_ { value_1 }, value_1_ { value_1 },
value_2_ { }, value_2_ { },
value_3_ { } value_3_ { }
@ -67,17 +70,23 @@ public:
} }
constexpr Reading( constexpr Reading(
uint32_t type,
uint32_t id, uint32_t id,
uint16_t value_1, uint16_t value_1,
uint16_t value_2, uint16_t value_2,
uint16_t value_3 uint16_t value_3
) : id_ { id }, ) : type_ { type },
id_ { id },
value_1_ { value_1 }, value_1_ { value_1 },
value_2_ { value_2 }, value_2_ { value_2 },
value_3_ { value_3 } value_3_ { value_3 }
{ {
} }
uint32_t type() const {
return type_;
}
uint32_t id() const { uint32_t id() const {
return id_; return id_;
} }
@ -95,6 +104,7 @@ public:
} }
private: private:
uint32_t 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_;