CRC

class baseband.base.utils.CRC(polynomial)[source] [edit on github]

Bases: object

Cyclic Redundancy Check.

See https://en.wikipedia.org/wiki/Cyclic_redundancy_check

Once initialised, the instance can be used as a function that calculates the CRC, or one can use the check method to verify that the CRC in the lower bits of a value is correct.

Parameters:
polynomialint

Binary encoded CRC divisor. For instance, that used by Mark 5B headers is 0x18005, or x^16 + x^15 + x^2 + 1.

See also

baseband.base.utils.CRCStack

for calculating CRC on arrays where each entry represents a bit.

Methods Summary

__call__(stream)

Calculate CRC for the given stream.

check(stream)

Check that the CRC at the end of athe stream is correct.

Methods Documentation

__call__(stream)[source] [edit on github]

Calculate CRC for the given stream.

Parameters:
streamint or array of unsigned int

The integer (or array of integers) to calculate the CRC for.

Returns:
crcint or array

If an array, the crc will have the same dtype as the input stream.

check(stream)[source] [edit on github]

Check that the CRC at the end of athe stream is correct.

Parameters:
streamint or array of unsigned int

For an integer, the value is the stream to check the CRC for. For arrays, the dimension is treated as the index into the bits. A single stream would thus be of type bool. Unsigned integers represent multiple streams. E.g., for a 64-track Mark 4 header, the stream would be an array of np.uint64 words.

Returns:
okbool

True if the calculated CRC is all zero (which should be the case if the CRC at the end of the stream is correct).