Skip to content

Incorrect CRC equation #1

@rmkolany

Description

@rmkolany

The equation for calculating CRC for each record is incorrect in the code. From ruby_extensions.rb, this is the current CRC equation:

crc = RTP::CRC_SEED
self.each_codepoint do |byte|
  crc = RTP::CRC_TABLE[(crc ^ byte) & 0xff] ^ (crc >> 8)
end
return crc

With CRC_SEED and CRC_TABLE stored in constants.rb. However, the Elekta documentation (in Appendix A) in this repository gives an equation that is slightly different (in C)
LED17001.pdf

while(len--)
         seed = crc_tbl[*((unsigned char *) buf)++ ^ (unsigned char) seed] ^(unsigned char) (seed >> 8)

Based on this, the new Ruby code should be the following, switching crc and byte within the CRC_TABLE argument

crc = RTP::CRC_SEED
self.each_codepoint do |byte|
  crc = RTP::CRC_TABLE[(byte ^ crc) & 0xff] ^ (crc >> 8)
end
return crc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions