Esempio n. 1
0
// syndrome takes a bitstream and uses the parity bits from the BCH polynomial
// generator to calculate if the bits are received correctly.
// A 0 return means the bits are correct.
// Thanks to multimon-ng (https://github.com/EliasOenal/multimon-ng) for
// detailing implmentation of this.
func syndrome(bits []datatypes.Bit) uint32 {
	bytes := utils.MSBBitsToBytes(bits, 8)

	// take the parity-bit out from our codeword
	codeword := utils.Btouint32(bytes) >> 1

	// put the mask bit to the far left in the bitstream
	mask := uint32(1 << (BCH_N))
	coeff := uint32(BHC_COEFF)

	// step over each data-bit (the first 21)
	for a := 0; a < BCH_K; a += 1 {
		// step the coefficient and mask right in the bitstream
		mask >>= 1
		coeff >>= 1

		// if the current bit in the codeword is 1 then XOR the codeword with the coefficient
		if (codeword & mask) > 0 {
			codeword = codeword ^ coeff
		}
	}

	// in the end, if the coefficient matches the codeword they
	// are canceled out by the XOR, returning 0

	return codeword
}
Esempio n. 2
0
// isIdle matches 4 bytes to the POCSAG idle codeword 0x7A89C197
func isIdle(bytes []byte) bool {
	return utils.Btouint32(bytes) == POCSAG_IDLE
}
Esempio n. 3
0
// isPreamble matches 4 bytes to the POCSAG preamble 0x7CD215D8
func isPreamble(bytes []byte) bool {
	return utils.Btouint32(bytes) == POCSAG_PREAMBLE
}