Exemplo n.º 1
0
    def msg_handler(self, p):

        length = pmt.length(p)

        for i in range(0,length):
           element = pmt.nth(i, p)

           key = pmt.nth(0, element)
           value = pmt.nth(1, element)

           if str(key) == "power":
               output = pmt.f32vector_elements(value)[0]


               output = 10 * math.log(output, 10)           
               output = pmt.make_f32vector(1, output)

               if i==0:
                   outpmt = pmt.list1(pmt.list2(pmt.string_to_symbol(str(key) + "_dB"), output))
               else:
                   outpmt = pmt.list_add(outpmt, pmt.list2(pmt.string_to_symbol(str(key) + "_dB"), output))



           output = pmt.nth(1, element)

           if i==0:
               outpmt = pmt.list1(pmt.list2(key, output))
           else:
               outpmt = pmt.list_add(outpmt, pmt.list2(key, output))

       
        self.message_port_pub(pmt.string_to_symbol("out"), outpmt)
Exemplo n.º 2
0
 def int_list_to_pmt(self, items):
     if len(items) == 0:
         return pmt.from_bool(pmt.PMT_F)
     else:
         pmtl = pmt.list1(pmt.from_long(items[0]))
         for i in range(len(items) - 1):
             pmtl = pmt.list_add(pmtl, pmt.from_long(items[i + 1]))
         return pmtl
Exemplo n.º 3
0
 def int_list_to_pmt(self, items):
     if len(items) == 0:
         return pmt.from_bool(pmt.PMT_F)
     else:
         pmtl = pmt.list1(pmt.from_long(items[0]))
         for i in range(len(items) - 1):
             pmtl = pmt.list_add(pmtl, pmt.from_long(items[i + 1]))
         return pmtl
Exemplo n.º 4
0
    def msg_handler(self, p):

        length = pmt.length(p)

        # iterate over all elements
        for i in range(0, length):
            element = pmt.nth(i, p)

            key = pmt.nth(0, element)
            value = pmt.nth(1, element)

            initial_phase = None

            # when we found the phase key
            if str(key) == "phase" and pmt.length(value) >= 1:
                # print "length of vector: ", pmt.length(value)
                value = pmt.f32vector_elements(value)[0]
                self.last_val = value

                # save that value
                initial_phase = value

                value = value - self.subtract
                while value < -numpy.pi:
                    value = value + numpy.pi
                while value > numpy.pi:
                    value = value - numpy.pi

                initial_phase = pmt.make_f32vector(1, initial_phase)
                initial_phase = pmt.list2(pmt.string_to_symbol("phase_initial"), initial_phase)

                outvalue = pmt.make_f32vector(1, value)
                output = pmt.list2(pmt.string_to_symbol(str(key)), outvalue)

            else:
                output = element

            if i == 0:
                outpmt = pmt.list1(output)
            else:
                outpmt = pmt.list_add(outpmt, output)

            if initial_phase != None:
                outpmt = pmt.list_add(outpmt, initial_phase)

        self.message_port_pub(pmt.string_to_symbol("out"), outpmt)
Exemplo n.º 5
0
    def handle_msg(self, msg):
        cell_id = pmt.to_long(msg)
        if self.cell_id == cell_id:
            return
        else:
            self.cell_id = cell_id
        print "received cell_id = " + str(cell_id)

        seqs = []

        seq = lte.encode_nrz(lte.generate_pn_sequence(1920, cell_id))

        pmt_list = pmt.list1(pmt.from_double(seq[0]))
        for i in range(len(seq) - 1):
            pmt_list = pmt.list_add(pmt_list, pmt.from_double(seq[i + 1]))
        self.message_port_pub(self.msg_buf_out, pmt_list)
Exemplo n.º 6
0
    def handle_msg(self, msg):
        cell_id = pmt.to_long(msg)
        if self.cell_id == cell_id:
            return
        else:
            self.cell_id = cell_id
        print "received cell_id = " + str(cell_id)

        seqs = []

        seq = lte.encode_nrz(lte.generate_pn_sequence(1920, cell_id))

        pmt_list = pmt.list1(pmt.from_double(seq[0]))
        for i in range(len(seq) - 1):
            pmt_list = pmt.list_add(pmt_list, pmt.from_double(seq[i+1]))
        self.message_port_pub(self.msg_buf_out, pmt_list)
Exemplo n.º 7
0
    def msg_handler(self, p):
        #os.system("pwd")
        #time.sleep(1)
        fd = open(self.filename, "r")

        s = fd.readline()
        fd.close()

        #print "Got string ", s
        try:
            s = float(s)
        except ValueError:
            s = -200000.0

        p = pmt.list_add(p, pmt.list2(pmt.string_to_symbol(self.key), pmt.make_f32vector(1, s)))

        #if(s>-100000.0):
        self.message_port_pub(pmt.string_to_symbol("out"), p)
Exemplo n.º 8
0
 def rs_pos_to_pmt(self, rs_poss):
     pmt_rs = pmt.list1(self.int_list_to_pmt(rs_poss[0]))
     for i in range(len(rs_poss) - 1):
         pmt_rs = pmt.list_add(pmt_rs, self.int_list_to_pmt(rs_poss[i + 1]))
     return pmt_rs
Exemplo n.º 9
0
 def rs_val_to_pmt(self, rs_vals):
     pmt_vals = pmt.list1(self.complex_list_to_pmt(rs_vals[0]))
     for i in range(len(rs_vals) - 1):
         pmt_vals = pmt.list_add(pmt_vals,
                                 self.complex_list_to_pmt(rs_vals[i + 1]))
     return pmt_vals
Exemplo n.º 10
0
 def rs_pos_to_pmt(self, rs_poss):
     pmt_rs = pmt.list1(self.int_list_to_pmt(rs_poss[0]))
     for i in range(len(rs_poss) - 1):
         pmt_rs = pmt.list_add(pmt_rs, self.int_list_to_pmt(rs_poss[i + 1]))
     return pmt_rs
Exemplo n.º 11
0
 def rs_val_to_pmt(self, rs_vals):
     pmt_vals = pmt.list1(self.complex_list_to_pmt(rs_vals[0]))
     for i in range(len(rs_vals) - 1):
         pmt_vals = pmt.list_add(pmt_vals, self.complex_list_to_pmt(rs_vals[i + 1]))
     return pmt_vals
Exemplo n.º 12
0
    def msg_handler(self, p):

        verbose = False

        length = pmt.length(p)
        
        if verbose:
            print "PMT contrains " + str(length) + " key/value pairs"

        for i in range(0,length):
           element = pmt.nth(i, p)

           key = pmt.nth(0, element)
           value = pmt.nth(1, element)

           if verbose:
               print "Key of " + str(i) + "th element: " + str(key)
               print "Value of " + str(i) + "th element: " + str(value)
               print

           found = False
           for j in range(0, len(self.n)):
               if str(key) == self.kk[j]:
                   found = True

                   if verbose:
                       print "found the key " + str(key)

                   #rotate the values, the latest one disappears
                   self.prev_values[j] = numpy.roll(self.prev_values[j], -1)

                   #set the vector accordingly
                   self.prev_values[j][-1] = pmt.f32vector_elements(value)[0]
                   

                   output = sum(self.prev_values[j])/len(self.prev_values[j])
                   output = pmt.make_f32vector(1, output)

                   if i==0:
                       outpmt = pmt.list1(pmt.list2(pmt.string_to_symbol(str(key) + "_filtered"), output))
                   else:
                       outpmt = pmt.list_add(outpmt, pmt.list2(pmt.string_to_symbol(str(key) + "_filtered"), output))



           output = pmt.nth(1, element)

           if i==0:
               outpmt = pmt.list1(pmt.list2(key, output))
           else:
               outpmt = pmt.list_add(outpmt, pmt.list2(key, output))

        if verbose:
            print


        #iterate over all keys
        for i in range(0, len(self.kk)):
            minimum = self.prev_values[i][0]
            maximum = self.prev_values[i][0]
            #iterate over all saved values
            for j in range(0, self.n[i]):
                if self.prev_values[i][j] < minimum:
                    minimum = self.prev_values[i][j]
                if self.prev_values[i][j] > maximum:
                    maximum = self.prev_values[i][j]
        
        #print out a min, diff, max for every key
        difference = maximum-minimum
        outpmt = pmt.list_add(outpmt, pmt.list2(pmt.string_to_symbol("min"), pmt.make_f32vector(1, minimum)))
        outpmt = pmt.list_add(outpmt, pmt.list2(pmt.string_to_symbol("max"), pmt.make_f32vector(1, maximum)))
        outpmt = pmt.list_add(outpmt, pmt.list2(pmt.string_to_symbol("diff"), pmt.make_f32vector(1, difference)))


        self.message_port_pub(pmt.string_to_symbol("out"), outpmt)