diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index 2809fa0d..e13b7dcb 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -28,6 +28,8 @@ using namespace portapack; #include "string_format.hpp" +#include "crc.hpp" + namespace tpms { Timestamp Packet::received_at() const { @@ -38,6 +40,46 @@ ManchesterFormatted Packet::symbols_formatted() const { return format_manchester(decoder_); } +size_t Packet::crc_valid_length() const { + constexpr uint32_t checksum_bytes = 0b1111111; + constexpr uint32_t crc_72_bytes = 0b111111111; + constexpr uint32_t crc_80_bytes = 0b1111111110; + + std::array bytes; + for(size_t i=0; i crc_72 { 0x01, 0xff }; + CRC crc_80 { 0x01, 0xff }; + + for(size_t i=0; i 0 ) { + const size_t length_chars = packet_length * 2 / 8; + const auto hex_formatted = packet.symbols_formatted(); + console.writeln(hex_formatted.data.substr(0, length_chars)); + } } } /* namespace ui */ diff --git a/firmware/application/tpms_app.hpp b/firmware/application/tpms_app.hpp index 3a1571f1..48104f4f 100644 --- a/firmware/application/tpms_app.hpp +++ b/firmware/application/tpms_app.hpp @@ -23,8 +23,9 @@ #define __TPMS_APP_H__ #include "ui_console.hpp" -#include "message.hpp" +#include "field_reader.hpp" +#include "baseband_packet.hpp" #include "manchester.hpp" #include "log_file.hpp" @@ -35,7 +36,8 @@ public: constexpr Packet( const baseband::Packet& packet ) : packet_ { packet }, - decoder_ { packet_, 1 } + decoder_ { packet_, 1 }, + reader_ { decoder_ } { } @@ -43,9 +45,15 @@ public: ManchesterFormatted symbols_formatted() const; + size_t crc_valid_length() const; + private: + using Reader = FieldReader; + const baseband::Packet packet_; const ManchesterDecoder decoder_; + + const Reader reader_; }; } /* namespace tpms */