Separate ERT packet and UI code.

This commit is contained in:
Jared Boone 2015-12-08 16:04:48 -08:00
parent 644d3837ff
commit 2e81d1f5b7
5 changed files with 185 additions and 129 deletions

View file

@ -32,78 +32,6 @@ using namespace lpc43xx;
#include "crc.hpp"
#include "string_format.hpp"
namespace ert {
size_t Packet::length() const {
return decoder_.symbols_count();
}
bool Packet::is_valid() const {
return true;
}
rtc::RTC Packet::received_at() const {
return received_at_;
}
ERTPacketMessage::Type Packet::type() const {
return type_;
}
ID Packet::id() const {
if( type() == ERTPacketMessage::Type::SCM ) {
const auto msb = reader_.read(0, 2);
const auto lsb = reader_.read(35, 24);
return (msb << 24) | lsb;
}
if( type() == ERTPacketMessage::Type::IDM ) {
return reader_.read(5 * 8, 32);
}
return invalid_id;
}
Consumption Packet::consumption() const {
if( type() == ERTPacketMessage::Type::SCM ) {
return reader_.read(11, 24);
}
if( type() == ERTPacketMessage::Type::IDM ) {
return reader_.read(25 * 8, 32);
}
return invalid_consumption;
}
ManchesterFormatted Packet::symbols_formatted() const {
return format_manchester(decoder_);
}
bool Packet::crc_ok() const {
switch(type()) {
case ERTPacketMessage::Type::SCM: return crc_ok_scm();
case ERTPacketMessage::Type::IDM: return crc_ok_idm();
default: return false;
}
}
bool Packet::crc_ok_scm() const {
CRC<uint16_t> ert_bch { 0x6f63 };
size_t start_bit = 5;
ert_bch.process_byte(reader_.read(0, start_bit));
for(size_t i=start_bit; i<length(); i+=8) {
ert_bch.process_byte(reader_.read(i, 8));
}
return ert_bch.checksum() == 0x0000;
}
bool Packet::crc_ok_idm() const {
CRC<uint16_t> ert_crc_ccitt { 0x1021, 0xffff, 0x1d0f };
for(size_t i=0; i<length(); i+=8) {
ert_crc_ccitt.process_byte(reader_.read(i, 8));
}
return ert_crc_ccitt.checksum() == 0x0000;
}
} /* namespace ert */
ERTModel::ERTModel() {
receiver_model.set_baseband_configuration({
.mode = 6,