mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-21 04:38:28 -04:00
Clean up CRC class/interface, make more like boost::crc_basic.
This commit is contained in:
parent
c38beb70e5
commit
7cded79b59
3 changed files with 62 additions and 67 deletions
|
@ -132,23 +132,18 @@ struct PacketTooLong {
|
|||
|
||||
struct CRCCheck {
|
||||
bool operator()(const ::Packet& packet) {
|
||||
const size_t fcs_length = 16;
|
||||
const size_t data_and_fcs_length = packet.size() - 7;
|
||||
const size_t data_length = data_and_fcs_length - 16;
|
||||
const size_t data_length = data_and_fcs_length - fcs_length;
|
||||
|
||||
CRCFieldReader field_crc { packet };
|
||||
CRC<uint16_t> ais_fcs { 0x1021 };
|
||||
CRC<uint16_t> ais_fcs { 0x1021, 0xffff, 0xffff };
|
||||
|
||||
uint16_t crc_calculated = 0xffff;
|
||||
|
||||
for(size_t i=0; i<data_length + 16; i+=8) {
|
||||
if( i == data_length ) {
|
||||
crc_calculated ^= 0xffff;
|
||||
}
|
||||
const uint8_t byte = field_crc.read(i, 8);
|
||||
crc_calculated = ais_fcs.calculate_byte(crc_calculated, byte);
|
||||
for(size_t i=0; i<data_length; i+=8) {
|
||||
ais_fcs.process_byte(field_crc.read(i, 8));
|
||||
}
|
||||
|
||||
return crc_calculated == 0x0000;
|
||||
|
||||
return ais_fcs.checksum() == field_crc.read(data_length, fcs_length);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -87,22 +87,19 @@ bool Packet::crc_ok() const {
|
|||
bool Packet::crc_ok_scm() const {
|
||||
CRC<uint16_t> ert_bch { 0x6f63 };
|
||||
size_t start_bit = 5;
|
||||
auto crc_calculated = ert_bch.calculate_byte(0x0000, reader_.read(0, start_bit));
|
||||
ert_bch.process_byte(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);
|
||||
ert_bch.process_byte(reader_.read(i, 8));
|
||||
}
|
||||
return crc_calculated == 0x0000;
|
||||
return ert_bch.checksum() == 0x0000;
|
||||
}
|
||||
|
||||
bool Packet::crc_ok_idm() const {
|
||||
CRC<uint16_t> ert_crc_ccitt { 0x1021 };
|
||||
uint16_t crc_calculated = 0xffff;
|
||||
CRC<uint16_t> ert_crc_ccitt { 0x1021, 0xffff, 0x1d0f };
|
||||
for(size_t i=0; i<length(); i+=8) {
|
||||
const uint8_t byte = reader_.read(i, 8);
|
||||
crc_calculated = ert_crc_ccitt.calculate_byte(crc_calculated, byte);
|
||||
ert_crc_ccitt.process_byte(reader_.read(i, 8));
|
||||
}
|
||||
return crc_calculated == 0x1d0f;
|
||||
return ert_crc_ccitt.checksum() == 0x0000;
|
||||
}
|
||||
|
||||
} /* namespace ert */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue