Ejemplo n.º 1
0
    def packetise(self, msg):
        data = pmt.cdr(msg)
        meta = pmt.car(msg)
        if not pmt.is_u8vector(data):
            #raise NameError("Data is no u8 vector")
            return "Message data is not u8vector"

        buf = pmt.u8vector_elements(data)
        buf_str = "".join(map(chr, buf))

        # FIXME: Max: 4096-header-crc

        meta_dict = pmt.to_python(meta)
        if not (type(meta_dict) is dict):
            meta_dict = {}

        pkt = ""
        pkt += self.preamble
        pkt += packet_utils.make_packet(
            buf_str,
            0,  #self._samples_per_symbol,
            0,  #self._bits_per_symbol,
            #preamble=<default>
            access_code=self.access_code,
            pad_for_usrp=False,  #pad_for_usrp,
            whitener_offset=self.whitener_offset,
            whitening=self.whiten)
        pkt += self.postamble
        pkt = map(ord, list(pkt))
        if self.rotate_whitener_offset:
            self.whitener_offset = (self.whitener_offset + 1) % 16
        meta = pmt.to_pmt(meta_dict)
        data = pmt.init_u8vector(len(pkt), pkt)
        self.message_port_pub(pmt.intern('out'), pmt.cons(meta, data))
        '''
Ejemplo n.º 2
0
    def send_pkt(self, payload):
        """
		Wrap the payload in a packet and push onto the message queue.
		@param payload string, data to send
		"""
        packet = packet_utils.make_packet(payload, self._samples_per_symbol,
                                          self._bits_per_symbol,
                                          self._access_code,
                                          self._pad_for_usrp)
        msg = gr.message_from_string(packet)
        self._msgq_out.insert_tail(msg)
Ejemplo n.º 3
0
    def general_work(self, input_items, output_items):

        out = output_items[0]
        num_input_items = len(input_items[0])
	nread = self.nitems_read(0)
        tags = self.get_tags_in_range(0, nread, nread+num_input_items)

        i = 0 

	in0 = input_items[0]
	#print in0
	
	a2 = []
	s = ""
	su = 0

	gi = 0
	iv = 0

	ov = 0

        for tag in tags:

	    print "K: ",tag.key," V: ",tag.value
	    o = in0[i:i+int(str(tag.value))]

	    s = ""
	    for e in o:
		s+=chr(e)

	    packet = packet_utils.make_packet(
            	s,
            	self._samples_per_symbol,
            	self._bits_per_symbol,
            	self._preamble,
            	self._access_code,
            	self._pad_for_usrp
            )	

            arr = array.array('B', packet)
	    a2 = [ int(a) for a in arr ] 

	    ov += len(a2)

            for z in a2:
                out[gi] = z
                gi = gi + 1

	    self.consume(0,int(str(tag.value)))

	    return ov
        return 0
Ejemplo n.º 4
0
	def send_pkt(self, payload):
		"""
		Wrap the payload in a packet and push onto the message queue.
		@param payload string, data to send
		"""
		packet = packet_utils.make_packet(
			payload,
			self._samples_per_symbol,
			self._bits_per_symbol,
			self._access_code,
			self._pad_for_usrp
		)
		msg = gr.message_from_string(packet)
		self._msgq_out.insert_tail(msg)
Ejemplo n.º 5
0
    def general_work(self, input_items, output_items):

        out = output_items[0]
        num_input_items = len(input_items[0])
        nread = self.nitems_read(0)
        tags = self.get_tags_in_range(0, nread, nread + num_input_items)

        i = 0

        in0 = input_items[0]
        #print in0

        a2 = []
        s = ""
        su = 0

        gi = 0
        iv = 0

        ov = 0

        for tag in tags:

            print "K: ", tag.key, " V: ", tag.value
            o = in0[i:i + int(str(tag.value))]

            s = ""
            for e in o:
                s += chr(e)

            packet = packet_utils.make_packet(s, self._samples_per_symbol,
                                              self._bits_per_symbol,
                                              self._preamble,
                                              self._access_code,
                                              self._pad_for_usrp)

            arr = array.array('B', packet)
            a2 = [int(a) for a in arr]

            ov += len(a2)

            for z in a2:
                out[gi] = z
                gi = gi + 1

            self.consume(0, int(str(tag.value)))

            return ov
        return 0
Ejemplo n.º 6
0
    def work(self, input_items, output_items):
        while not len(self._pkt):
            try: msg = self.pop_msg_queue()
            except: return -1
            if not pmt.pmt_is_blob(msg.value): continue
            pkt = packet_utils.make_packet(
                pmt.pmt_blob_data(msg.value).tostring(),
                self._samples_per_symbol,
                self._bits_per_symbol,
                self._access_code,
                False, #pad_for_usrp,
                self._whitener_offset,
            )
            self._pkt = numpy.fromstring(pkt, numpy.uint8)
            if self._use_whitener_offset:
                self._whitener_offset = (self._whitener_offset + 1) % 16

        num_items = min(len(self._pkt), len(output_items[0]))
        output_items[0][:num_items] = self._pkt[:num_items]
        self._pkt = self._pkt[num_items:] #residue for next work()
        return num_items
Ejemplo n.º 7
0
    def work(self, input_items, output_items):
        while not len(self._pkt):
            try:
                msg = self.pop_msg_queue()
            except:
                return -1
            if not pmt.pmt_is_blob(msg.value): continue
            pkt = packet_utils.make_packet(
                pmt.pmt_blob_data(msg.value).tostring(),
                self._samples_per_symbol,
                self._bits_per_symbol,
                self._access_code,
                False,  #pad_for_usrp,
                self._whitener_offset,
            )
            self._pkt = numpy.fromstring(pkt, numpy.uint8)
            if self._use_whitener_offset:
                self._whitener_offset = (self._whitener_offset + 1) % 16

        num_items = min(len(self._pkt), len(output_items[0]))
        output_items[0][:num_items] = self._pkt[:num_items]
        self._pkt = self._pkt[num_items:]  #residue for next work()
        return num_items
Ejemplo n.º 8
0
 def packetise(self, msg):
     data = pmt.cdr(msg)
     meta = pmt.car(msg)
     if not pmt.is_u8vector(data):
         #raise NameError("Data is no u8 vector")
         return "Message data is not u8vector"
     
     buf = pmt.u8vector_elements(data)
     buf_str = "".join(map(chr, buf))
     
     # FIXME: Max: 4096-header-crc
     
     meta_dict = pmt.to_python(meta)
     if not (type(meta_dict) is dict):
         meta_dict = {}
     
     pkt = ""
     pkt += self.preamble
     pkt += packet_utils.make_packet(
         buf_str,
         0,#self._samples_per_symbol,
         0,#self._bits_per_symbol,
         #preamble=<default>
         access_code=self.access_code,
         pad_for_usrp=False,#pad_for_usrp,
         whitener_offset=self.whitener_offset,
         whitening=self.whiten
         )
     pkt += self.postamble
     pkt = map(ord, list(pkt))
     if self.rotate_whitener_offset:
         self.whitener_offset = (self.whitener_offset + 1) % 16
     meta = pmt.to_pmt(meta_dict)
     data = pmt.init_u8vector(len(pkt), pkt)
     self.message_port_pub(pmt.intern('out'), pmt.cons(meta, data))
     '''
Ejemplo n.º 9
0
    def work(self, input_items, output_items):
        while not len(self._pkt):
            try: msg = self.pop_msg_queue()
            except: return -1
            if not pmt.pmt_is_blob(msg.value): 
                self.tx_time,data,self.more_frame_cnt = pmt.to_python(msg.value)
                self.has_tx_time = True
                #print data
                #print tx_time
                #print data.tostring()
            else:
                data = pmt.pmt_blob_data(msg.value)
                #print data
                self.has_tx_time = False
            
                
            pkt = packet_utils.make_packet(
                data.tostring(),
                self._samples_per_symbol,
                self._bits_per_symbol,
                self._access_code,
                False, #pad_for_usrp,
                self._whitener_offset,
                )
            pkt += "".join(map(chr, [0x55] * 64))
            self._pkt = numpy.fromstring(pkt, numpy.uint8)
            if self._use_whitener_offset:
                self._whitener_offset = (self._whitener_offset + 1) % 16

            #shouldn't really need to send start of burst
            #only need to do sob if looking for timed transactions

            num_items = min(len(self._pkt), len(output_items[0]))
            output_items[0][:num_items] = self._pkt[:num_items]
            self._pkt = self._pkt[num_items:] #residue for next work()
            
            if len(self._pkt) == 0 :
                item_index = num_items #which output item gets the tag?
                offset = self.nitems_written(0) + item_index
                source = pmt.pmt_string_to_symbol("framer")
                
                #print 'frame cnt',self.more_frame_cnt
                
                if self.has_tx_time:
                    key = pmt.pmt_string_to_symbol("tx_sob")
                    self.add_item_tag(0, self.nitems_written(0), key, pmt.PMT_T, source)
                    key = pmt.pmt_string_to_symbol("tx_time")
                    self.add_item_tag(0, self.nitems_written(0), key, pmt.from_python(self.tx_time), source)
                    #if self.keep:
                    #    print 'bad order'
                    #self.keep = True

                
                if self.more_frame_cnt == 0:
                    key = pmt.pmt_string_to_symbol("tx_eob")
                    self.add_item_tag(0, offset - 1, key, pmt.PMT_T, source)
                    #if self.keep:
                    #    print 'good order'
                    #self.keep = False
                else:
                    self.more_frame_cnt -= 1

 
                
            return num_items
Ejemplo n.º 10
0
    def work(self, input_items, output_items):
        while not len(self._pkt):
            try:
                msg = self.pop_msg_queue()
            except:
                return -1
            if not pmt.pmt_is_blob(msg.value):
                self.tx_time, data, self.more_frame_cnt = pmt.to_python(
                    msg.value)
                self.has_tx_time = True
                #print data
                #print tx_time
                #print data.tostring()
            else:
                data = pmt.pmt_blob_data(msg.value)
                #print data
                self.has_tx_time = False

            pkt = packet_utils.make_packet(
                data.tostring(),
                self._samples_per_symbol,
                self._bits_per_symbol,
                self._access_code,
                False,  #pad_for_usrp,
                self._whitener_offset,
            )
            self._pkt = numpy.fromstring(pkt, numpy.uint8)
            if self._use_whitener_offset:
                self._whitener_offset = (self._whitener_offset + 1) % 16

            #shouldn't really need to send start of burst
            #only need to do sob if looking for timed transactions

            num_items = min(len(self._pkt), len(output_items[0]))
            output_items[0][:num_items] = self._pkt[:num_items]
            self._pkt = self._pkt[num_items:]  #residue for next work()

            if len(self._pkt) == 0:
                item_index = num_items  #which output item gets the tag?
                offset = self.nitems_written(0) + item_index
                source = pmt.pmt_string_to_symbol("framer")

                #print 'frame cnt',self.more_frame_cnt

                if self.has_tx_time:
                    key = pmt.pmt_string_to_symbol("tx_sob")
                    self.add_item_tag(0, self.nitems_written(0), key,
                                      pmt.PMT_T, source)
                    key = pmt.pmt_string_to_symbol("tx_time")
                    self.add_item_tag(0, self.nitems_written(0), key,
                                      pmt.from_python(self.tx_time), source)
                    #if self.keep:
                    #    print 'bad order'
                    #self.keep = True

                if self.more_frame_cnt == 0:
                    key = pmt.pmt_string_to_symbol("tx_eob")
                    self.add_item_tag(0, offset - 1, key, pmt.PMT_T, source)
                    #if self.keep:
                    #    print 'good order'
                    #self.keep = False
                else:
                    self.more_frame_cnt -= 1

            return num_items