CRC¶
-
class
baseband.vlbi_base.utils.
CRC
(polynomial)[source] [edit on github]¶ Bases:
object
Cyclic Redundancy Check for a bitstream.
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 check that the CRC at the end of a stream is correct.Parameters: polynomial : int
Binary encoded CRC divisor. For instance, that used by Mark 4 headers is 0x180f, or x^12 + x^11 + x^3 + x^2 + x + 1.
Methods Summary
__call__
(stream)Calculate CRC for the given stream. check
(stream)Check that the CRC at the end of the stream is correct. Methods Documentation
-
__call__
(stream)[source] [edit on github]¶ Calculate CRC for the given stream.
Parameters: stream : array of bool or unsigned int
The dimension is treated as the index into the bits. For a single stream, the array should thus be of type
bool
. Integers represent multiple streams. E.g., for a 64-track Mark 4 header, the stream would be an array ofnp.uint64
words.Returns: crc : 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 the stream is correct.
Parameters: stream : array of bool or unsigned int
The dimension is treated as the index into the bits. For a single stream, the array should thus be of type
bool
. Integers represent multiple streams. E.g., for a 64-track Mark 4 header, the stream would be an array ofnp.uint64
words.Returns: ok : bool
True
if the calculated CRC is all zero (which should be the case if the CRC at the end of the stream is correct).
-