def test_003_blockify_uint32(self): # Note that this test relies on bit extraction # make random bytes src = numpy.random.bytes(1000) # for different block lengths for block_size in xrange(1,26): # blockify the string blocks = rf.vectorui() rf.Utils.BlockifyUint32(src, block_size * 300, block_size, blocks) # check output for i in xrange(300): # get the block's bits from the string blockBits = rf.Utils.returnStringBits(src, i * block_size, block_size) # convert into a uint32 blockVal = 0 for j, ch in enumerate(blockBits): blockVal += ord(ch) << (8 * j) self.assertEqual(blockVal, blocks[i], "block_size %d; block %d doesn't match: expected %d got %d" % (block_size, i, blockVal, blocks[i]))
def test_003_blockify_uint32(self): # Note that this test relies on bit extraction # make random bytes src = numpy.random.bytes(1000) # for different block lengths for block_size in xrange(1, 26): # blockify the string blocks = rf.vectorui() rf.Utils.BlockifyUint32(src, block_size * 300, block_size, blocks) # check output for i in xrange(300): # get the block's bits from the string blockBits = rf.Utils.returnStringBits(src, i * block_size, block_size) # convert into a uint32 blockVal = 0 for j, ch in enumerate(blockBits): blockVal += ord(ch) << (8 * j) self.assertEqual( blockVal, blocks[i], "block_size %d; block %d doesn't match: expected %d got %d" % (block_size, i, blockVal, blocks[i]))
def make_encoder(codeSpec, packetLength): if codeSpec['type'] != 'multiplexed': return None numEncoders = codeSpec['numEncoders'] subPacketLength = packetLength / numEncoders encoders = [EncoderFactory._make(codeSpec['spec'], subPacketLength)[0] for i in xrange(numEncoders)] encodersVec = wireless.codes.vector_encoder() for e in encoders: encodersVec.push_back(e) lengthsVec = wireless.vectorui([subPacketLength] * numEncoders) encoder = wireless.codes.EncoderMultiplexer(encodersVec, lengthsVec) return encoder, wireless.vectorus