[Tutor] Don't understand this class/constructor call syntax
dave
dave at csc.lsu.edu
Mon Jul 25 02:20:49 CEST 2011
I was dimly aware of the functioning of booleans, but I see now that it
doesn't specify an actual boolean type. Still, the code confuses me. Is the
usage of pad_for_usrp consistent with it being treated as a boolean? Why
would the entire self reference be transmitted then?
Example code again:
class transmit_path(gr.top_block)
[...]
self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self,
spb=self._spb, msgq_limit=2)
The class from the ieee802_15_4_pkt module:
class ieee802_15_4_mod_pkts(gr.hier_block2):
"""
IEEE 802.15.4 modulator that is a GNU Radio source.
Send packets by calling send_pkt
"""
def __init__(self, pad_for_usrp=True, *args, **kwargs):
"""
Hierarchical block for the 802_15_4 O-QPSK modulation.
Packets to be sent are enqueued by calling send_pkt.
The output is the complex modulated signal at baseband.
@param msgq_limit: maximum number of messages in message queue
@type msgq_limit: int
@param pad_for_usrp: If true, packets are padded such that they end up
a multiple of 128 samples
See 802_15_4_mod for remaining parameters
"""
try:
self.msgq_limit = kwargs.pop('msgq_limit')
except KeyError:
pass
gr.hier_block2.__init__(self, "ieee802_15_4_mod_pkts",
gr.io_signature(0, 0, 0), # Input
gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output
self.pad_for_usrp = pad_for_usrp
# accepts messages from the outside world
self.pkt_input = gr.message_source(gr.sizeof_char, self.msgq_limit)
self.ieee802_15_4_mod = ieee802_15_4.ieee802_15_4_mod(self, *args,
**kwargs)
self.connect(self.pkt_input, self.ieee802_15_4_mod, self)
def send_pkt(self, seqNr, addressInfo, payload='', eof=False):
"""
Send the payload.
@param seqNr: sequence number of packet
@type seqNr: byte
@param addressInfo: address information for packet
@type addressInfo: string
@param payload: data to send
@type payload: string
"""
if eof:
msg = gr.message(1) # tell self.pkt_input we're not sending any
more packets
else:
FCF = make_FCF()
pkt = make_ieee802_15_4_packet(FCF,
seqNr,
addressInfo,
payload,
self.pad_for_usrp)
#print "pkt =", packet_utils.string_to_hex_list(pkt), len(pkt)
msg = gr.message_from_string(pkt)
#ERROR OCCURS HERE (a few functions in while inserting onto the msg queue)
self.pkt_input.msgq().insert_tail(msg)
------- End of Forwarded Message -------
More information about the Tutor
mailing list