mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-08 06:32:35 -04:00
Make tpms::Packet into real type.
This commit is contained in:
parent
feec99ac6a
commit
fbcf784959
2 changed files with 40 additions and 12 deletions
|
@ -28,8 +28,20 @@ using namespace portapack;
|
||||||
|
|
||||||
#include "string_format.hpp"
|
#include "string_format.hpp"
|
||||||
|
|
||||||
void TPMSLogger::on_packet(const Timestamp& timestamp, const tpms::Packet& packet) {
|
namespace tpms {
|
||||||
const auto hex_formatted = format_manchester(packet);
|
|
||||||
|
Timestamp Packet::received_at() const {
|
||||||
|
return packet_.timestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
ManchesterFormatted Packet::symbols_formatted() const {
|
||||||
|
return format_manchester(decoder_);
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace tpms */
|
||||||
|
|
||||||
|
void TPMSLogger::on_packet(const tpms::Packet& packet) {
|
||||||
|
const auto hex_formatted = packet.symbols_formatted();
|
||||||
|
|
||||||
if( log_file.is_ready() ) {
|
if( log_file.is_ready() ) {
|
||||||
const auto tuning_frequency = receiver_model.tuning_frequency();
|
const auto tuning_frequency = receiver_model.tuning_frequency();
|
||||||
|
@ -37,7 +49,7 @@ void TPMSLogger::on_packet(const Timestamp& timestamp, const tpms::Packet& packe
|
||||||
const auto tuning_frequency_str = to_string_dec_uint(tuning_frequency, 10);
|
const auto tuning_frequency_str = to_string_dec_uint(tuning_frequency, 10);
|
||||||
|
|
||||||
std::string entry = tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors;
|
std::string entry = tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors;
|
||||||
log_file.write_entry(timestamp, entry);
|
log_file.write_entry(packet.received_at(), entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +63,8 @@ TPMSAppView::TPMSAppView() {
|
||||||
EventDispatcher::message_map().register_handler(Message::ID::TPMSPacket,
|
EventDispatcher::message_map().register_handler(Message::ID::TPMSPacket,
|
||||||
[this](Message* const p) {
|
[this](Message* const p) {
|
||||||
const auto message = static_cast<const TPMSPacketMessage*>(p);
|
const auto message = static_cast<const TPMSPacketMessage*>(p);
|
||||||
this->on_packet(message->packet);
|
const tpms::Packet packet { message->packet };
|
||||||
|
this->on_packet(packet);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -72,14 +85,13 @@ void TPMSAppView::set_parent_rect(const Rect new_parent_rect) {
|
||||||
console.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() });
|
console.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TPMSAppView::on_packet(const baseband::Packet& baseband_packet) {
|
void TPMSAppView::on_packet(const tpms::Packet& packet) {
|
||||||
const tpms::Packet tpms_packet { baseband_packet, 1 };
|
this->logger.on_packet(packet);
|
||||||
this->logger.on_packet(baseband_packet.timestamp(), tpms_packet);
|
this->draw(packet);
|
||||||
this->draw(tpms_packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TPMSAppView::draw(const tpms::Packet& packet) {
|
void TPMSAppView::draw(const tpms::Packet& packet) {
|
||||||
const auto hex_formatted = format_manchester(packet);
|
const auto hex_formatted = packet.symbols_formatted();
|
||||||
console.writeln(hex_formatted.data.substr(0, 240 / 8));
|
console.writeln(hex_formatted.data.substr(0, 240 / 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,29 @@
|
||||||
|
|
||||||
namespace tpms {
|
namespace tpms {
|
||||||
|
|
||||||
using Packet = ManchesterDecoder;
|
class Packet {
|
||||||
|
public:
|
||||||
|
constexpr Packet(
|
||||||
|
const baseband::Packet& packet
|
||||||
|
) : packet_ { packet },
|
||||||
|
decoder_ { packet_, 1 }
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Timestamp received_at() const;
|
||||||
|
|
||||||
|
ManchesterFormatted symbols_formatted() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const baseband::Packet packet_;
|
||||||
|
const ManchesterDecoder decoder_;
|
||||||
|
};
|
||||||
|
|
||||||
} /* namespace tpms */
|
} /* namespace tpms */
|
||||||
|
|
||||||
class TPMSLogger {
|
class TPMSLogger {
|
||||||
public:
|
public:
|
||||||
void on_packet(const Timestamp& timestamp, const tpms::Packet& packet);
|
void on_packet(const tpms::Packet& packet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LogFile log_file { "tpms.txt" };
|
LogFile log_file { "tpms.txt" };
|
||||||
|
@ -56,7 +72,7 @@ private:
|
||||||
|
|
||||||
Console console;
|
Console console;
|
||||||
|
|
||||||
void on_packet(const baseband::Packet& packet);
|
void on_packet(const tpms::Packet& packet);
|
||||||
void draw(const tpms::Packet& packet);
|
void draw(const tpms::Packet& packet);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue