def test22_absolute_serialization_int_uvecs(self): # u8_vector SERDES in_vec = [1, 3, 128, 255] in_str = b'\n\x00\x00\x00\x00\x04\x01\x00\x01\x03\x80\xff' out_str = pmt.serialize_str(pmt.init_u8vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) in_str = b'\n\x00\x00\x00\x00\x07\x01\x00\x02\x03\x04\t\n\x19@' in_vec = [2, 3, 4, 9, 10, 25, 64] out_vec = pmt.u8vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec) # s8_vector SERDES in_vec = [1, 3, 127, -128] in_str = b'\n\x01\x00\x00\x00\x04\x01\x00\x01\x03\x7f\x80' out_str = pmt.serialize_str(pmt.init_s8vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) in_str = b'\n\x01\x00\x00\x00\x07\x01\x00\x02\x00\x04\xf7\n\x19\xc0' in_vec = [2, 0, 4, -9, 10, 25, -64] out_vec = pmt.s8vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec) # u16_vector SERDES in_vec = [0xfffe, 0, 256, 0xffff] in_str = b'\n\x02\x00\x00\x00\x04\x01\x00\xff\xfe\x00\x00\x01\x00\xff\xff' out_str = pmt.serialize_str(pmt.init_u16vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) in_str = b'\n\x02\x00\x00\x00\x04\x01\x00\xff\xff\x00\x00\x00\x01\x00\x02' in_vec = [0xffff, 0, 1, 2] out_vec = pmt.u16vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec) # s16_vector SERDES in_vec = [0x7fff, 0, -256, -0x8000] in_str = b'\n\x03\x00\x00\x00\x04\x01\x00\x7f\xff\x00\x00\xff\x00\x80\x00' out_str = pmt.serialize_str(pmt.init_s16vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) in_str = b'\n\x03\x00\x00\x00\x05\x01\x00\x00\x01\x00\x02\x00\x03\x00\x04\xff\xfb' in_vec = [1, 2, 3, 4, -5] out_vec = pmt.s16vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec) # u32_vector SERDES in_vec = [0x01020304, 0x05060708, 0, 100000000] in_str = b'\n\x04\x00\x00\x00\x04\x01\x00\x01\x02\x03\x04\x05\x06\x07\x08\x00\x00\x00\x00\x05\xf5\xe1\x00' out_str = pmt.serialize_str(pmt.init_u32vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) in_str = b'\n\x04\x00\x00\x00\x06\x01\x00\x00\x00\x000\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x0c\x00\x00\x10\x00' in_vec = [48, 0xffffffff, 0, 9, 12, 4096] out_vec = pmt.u32vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec) # s32_vector SERDES in_vec = [-0x0, -0x8000000, 1, 0x7ffffff] in_str = b'\n\x05\x00\x00\x00\x04\x01\x00\x00\x00\x00\x00\xf8\x00\x00\x00\x00\x00\x00\x01\x07\xff\xff\xff' out_str = pmt.serialize_str(pmt.init_s32vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) in_str = b'\n\x05\x00\x00\x00\x05\x01\x00\x00\x00\x000\x7f\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xf7\xff\xff\xff\xf3' in_vec = [48, 0x7fffffff, 0, -9, -13] out_vec = pmt.s32vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec)
def set_angle_degrees(self, angle_degrees): self.angle_degrees = angle_degrees self.theta = self.angle_degrees * pi / 180.0 # Calculate the weights w = [0.0 + 0.0j] * self.num_elements m = 0 for m in range(self.num_elements): w[m] = np.exp( ((-2.0 * pi * float(m) * self.sep_lambda * sin(self.theta))) * 1.0j) vec = pmt.init_c32vector(len(w), w) sz = pmt.init_u32vector(2, [1, len(w)]) self.message_port_pub(pmt.intern("weights"), pmt.cons(sz, vec))
def test09(self): v = pmt.init_u32vector(3, [11, 22, 33]) s = pmt.serialize_str(v) d = pmt.deserialize_str(s) self.assertTrue(pmt.equal(v, d))
def send(self): # , input_items, output_items): #output_items[0][:] = input_items[0] # consume(0, len(input_items[0])) # print "sent flag = %d" % self.sent_flag if self.sent_flag == 0: start_time = 315964800 epoch_length = 7200 code_length = 12288 key = [0x54, 0x65, 0x17, 0x98, 0x13, 0x65, 0x34, 0x87, 0x087, 0x14, 0x57, 0x81, 0x30, 0x13, 0x20, 0x23, 0x13, 0x13, 0x05, 0x43, 0x40, 0x54, 0x34, 0x67, 0x89, 0x14, 0x54, 0x18, 0x94, 0x10, 0x35, 0x00] key = "".join([chr(item) for item in key]) current_time = 1452709080 # current_time = 0 # current_time = 1461629066 #time.time() adjusted_time = current_time - start_time adjusted_time = adjusted_time - (adjusted_time % epoch_length) print "adjusted time = {}".format(adjusted_time) pt = numpy.zeros(code_length/8, dtype=numpy.uint8) pt = "".join([chr(item) for item in pt]) ctr = Counter.new(128, initial_value=adjusted_time) cipher = AES.new(key, AES.MODE_CTR, counter=ctr) ct = cipher.encrypt(pt) cipher_stream = numpy.uint8([ord(item) for item in ct]) spreading = numpy.zeros(code_length/8, dtype=numpy.uint8) for index in range(0, len(cipher_stream)): temp = numpy.binary_repr(cipher_stream[index], width=8) spreading[index] = int(temp[::-1], 2) spreading = numpy.fliplr(spreading.reshape(code_length/8/16, 16)) spreading = spreading.reshape(code_length/8) spreading = numpy.fliplr(spreading.reshape(code_length/8/4, 4)) data = spreading.reshape(code_length/8).view("uint32") #pmt_seq = pmt.make_u32vector(len(data), 0) #for i, val in enumerate(data): # pmt.u32vector_set(pmt_seq, i, 0xffffffff) #True) # val) #self.message_port_pub(pmt.intern("scramb_seq"), pmt_seq) #print data print "1 %s" % type(data[0]) data_len = len(data) data_pmt = pmt.to_pmt(data) #print data_pmt data = pmt.u32vector_elements(pmt.to_pmt(data)) #print data # print type(data) data = pmt.init_u32vector(data_len, data) #print data_len #print data meta = pmt.get_PMT_NIL() # msg = pmt.cons(meta, data) # print data self.message_port_pub(self.msg_buf_out, pmt.cons(meta, data)) # print "sent message" time.sleep(5) self.sent_flag = 1
def __init__(self, fname='', has_header=True, data_type='uint8', period=1000, start_delay=0, repeat=True): gr.sync_block.__init__(self, "CSV Reader", in_sig=None, out_sig=None) self.file = fname self.has_header = has_header self.data_type = data_type self.period = period self.repeat = repeat self.start_delay = start_delay # setup logger logger_name = 'gr_log.' + self.to_basic_block().alias() if logger_name in gr.logger_get_names(): self.log = gr.logger(logger_name) else: self.log = gr.logger('log') # metadata field mappings self.metadata_mappings = { 'string': lambda x: pmt.intern(x), 'bool': lambda x: pmt.from_bool(bool(x)), 'long': lambda x: pmt.from_long(int(x)), 'uint64': lambda x: pmt.from_uint64(int(x)), 'float': lambda x: pmt.from_float(float(x)), 'double': lambda x: pmt.from_double(float(x)), 'complex': lambda x: pmt.from_complex(complex(x)), 'time': lambda x: pmt.cons(pmt.from_uint64(int(math.modf(float(x))[1])), pmt.from_double(math.modf(float(x))[0])), 'time_tuple': lambda x: pmt.make_tuple( pmt.from_uint64(int(math.modf(float(x))[1])), pmt.from_double(math.modf(float(x))[0])) } self.data_type_mappings = { 'uint8': lambda x: pmt.init_u8vector(len(x), [int(y) for y in x]), 'int8': lambda x: pmt.init_s8vector(len(x), [int(y) for y in x]), 'uint16': lambda x: pmt.init_u16vector(len(x), [int(y) for y in x]), 'int16': lambda x: pmt.init_s16vector(len(x), [int(y) for y in x]), 'uint32': lambda x: pmt.init_u32vector(len(x), [int(y) for y in x]), 'int32': lambda x: pmt.init_s32vector(len(x), [int(y) for y in x]), 'float': lambda x: pmt.init_f32vector(len(x), [float(y) for y in x]), 'complex float': lambda x: pmt.init_c32vector(len(x), [complex(y) for y in x]), 'double': lambda x: pmt.init_f64vector(len(x), [float(y) for y in x]), 'complex double': lambda x: pmt.init_c64vector(len(x), [complex(y) for y in x]) } # ensure valid data type if self.data_type not in self.data_type_mappings.keys(): raise ValueError('Invalid data type {}'.format(data_type)) # set file name self.set_fname(self.file) self.message_port_name = pmt.intern('out') self.message_port_register_out(self.message_port_name) # flag for when to stop self.stop_signal_called = False # no timer yet self.timer = None # file lock self.lock = threading.Lock()