def test_from_pam(self): self.emitter = pdu_utils.message_emitter() #self.flip = pdu_utils.pdu_binary_tools(pdu_utils.pdu_binary_tools.FROM_PAM) self.flip = pdu_utils.pdu_binary_tools(2) self.debug = blocks.message_debug() self.tb.msg_connect((self.emitter, 'msg'), (self.flip, 'pdu_in')) self.tb.msg_connect((self.flip, 'pdu_out'), (self.debug, 'store')) i_vec = pmt.init_f32vector(6, [1, -1, -1, 1, -1, 1]) e_vec = pmt.init_u8vector(6, [1, 0, 0, 1, 0, 1]) in_pdu = pmt.cons(pmt.make_dict(), i_vec) e_pdu = pmt.cons(pmt.make_dict(), e_vec) self.tb.start() time.sleep(.001) self.emitter.emit(in_pdu) time.sleep(.01) self.tb.stop() self.tb.wait() print("test from_pam:") print("pdu expected: " + repr(pmt.car(e_pdu))) print("pdu got: " + repr(pmt.car(self.debug.get_message(0)))) print("data expected: " + repr(pmt.u8vector_elements(pmt.cdr(e_pdu)))) print("data got: " + repr(pmt.u8vector_elements(pmt.cdr(self.debug.get_message(0))))) print() self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
def test_endian(self): self.emitter = pdu_utils.message_emitter() #self.endi = pdu_utils.pdu_binary_tools(pdu_utils.pdu_binary_tools.ENDIAN_SWAP8) self.endi = pdu_utils.pdu_binary_tools(4) self.debug = blocks.message_debug() self.tb.msg_connect((self.emitter, 'msg'), (self.endi, 'pdu_in')) self.tb.msg_connect((self.endi, 'pdu_out'), (self.debug, 'store')) i_vec = pmt.init_u8vector( 16, [1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0]) e_vec = pmt.init_u8vector( 16, [1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1]) in_pdu = pmt.cons(pmt.make_dict(), i_vec) e_pdu = pmt.cons(pmt.make_dict(), e_vec) self.tb.start() time.sleep(.001) self.emitter.emit(in_pdu) time.sleep(.01) self.tb.stop() self.tb.wait() print("test endian_swap8:") print("pdu expected: " + repr(pmt.car(e_pdu))) print("pdu got: " + repr(pmt.car(self.debug.get_message(0)))) print("data expected: " + repr(pmt.u8vector_elements(pmt.cdr(e_pdu)))) print("data got: " + repr(pmt.u8vector_elements(pmt.cdr(self.debug.get_message(0))))) print() self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))