mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-05-29 19:51:29 -04:00
ERT CRC checking for SCM packets.
IDM coming as soon as I can address packet truncation...
This commit is contained in:
parent
1c01f54717
commit
b9ea7fa786
2 changed files with 19 additions and 0 deletions
|
@ -29,6 +29,7 @@ using namespace portapack;
|
|||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
#include "crc.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
namespace ert {
|
||||
|
@ -71,6 +72,21 @@ Consumption Packet::consumption() const {
|
|||
return invalid_consumption;
|
||||
}
|
||||
|
||||
bool Packet::crc_ok() const {
|
||||
if( type() == ERTPacket::Type::SCM ) {
|
||||
CRC<uint16_t> ert_bch { 0x6f63 };
|
||||
size_t start_bit = 5;
|
||||
auto crc_calculated = ert_bch.calculate_byte(0x0000, reader_.read(0, start_bit));
|
||||
for(size_t i=start_bit; i<length(); i+=8) {
|
||||
const uint8_t byte = reader_.read(i, 8);
|
||||
crc_calculated = ert_bch.calculate_byte(crc_calculated, byte);
|
||||
}
|
||||
return crc_calculated == 0x0000;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} /* namespace ert */
|
||||
|
||||
ERTModel::ERTModel() {
|
||||
|
@ -122,6 +138,7 @@ void ERTView::on_packet(const ert::Packet& packet) {
|
|||
msg += to_string_dec_uint(packet.id(), 10);
|
||||
msg += " ";
|
||||
msg += to_string_dec_uint(packet.consumption(), 10);
|
||||
msg += packet.crc_ok() ? " *" : " x";
|
||||
break;
|
||||
|
||||
case ERTPacket::Type::IDM:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue