|
From: | jacob |
Subject: | Re: Convert PDU message to a PMT message |
Date: | Thu, 06 Jul 2023 15:43:39 +0000 |
pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))
Jeff,Thank you for your corrections. However, based on my debug information, a PMT message as output from a Message_Strobe is:PST_SYMBOL = 0x02UVI_U8 = 0x00length of symbolssymbol vectorwhereas a PDU has a form:PST_PAIRPST_NULLPST_UNIFORM_VECTORetc.Using the string "GNU Radio", a PMT generates:2 0 9 71 78 85 32 82 97 100 105 111and a PDU generates:7 6 10 0 0 0 0 9 1 0 71 78 85 32 82 97 100 105 111So the construct of `pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))` seems to generate a PDU. What is the construct for a PMT?Thanks!---Barry Duggan---- On Thu, 06 Jul 2023 08:03:26 -0500 Jeff Long <willcode4@gmail.com> wrote ---b_len is defined in the try block, and is out of scope by the time it is checked below.This code should work. The routine returns in the except clause and b_len is set after the try/except.import numpy as np
from gnuradio import gr
import pmt
import array
class blk(gr.sync_block):
def __init__(self):
gr.sync_block.__init__(
self,
name='EPB: Packet to PMT', # will show up in GRC
in_sig=None,
out_sig=None)
self.message_port_register_in(pmt.intern('msg_in'))
self.message_port_register_out(pmt.intern('msg_out'))
self.set_msg_handler(pmt.intern('msg_in'), self.handle_msg)
def handle_msg(self, msg):
_debug = 0 # set to zero to turn off diagnostics
try:
buff = pmt.to_python(pmt.cdr(msg))
except Exception as e:
gr.log.error("Error with message conversion: %s" % str(e))
return
b_len = len (buff)
if (_debug):
print ("new_val =", buff, b_len)
if (b_len != 52):
self.message_port_pub (pmt.intern('msg_out'), pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))
elif ((buff[0] != 37) and (buff[51] != 93)):
self.message_port_pub (pmt.intern('msg_out'), pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))On Wed, Jul 5, 2023 at 6:11 PM Barry Duggan <barry@dcsmail.net> wrote:I would like to receive a PDU message containing a string using an Embedded Python Block and, after discarding certain messages, send a PMT message with that string to the output message port. My efforts so far have not produced a valid PMT format. My current code is:```import numpy as npfrom gnuradio import grimport pmtimport arrayclass blk(gr.sync_block):def __init__(self):gr.sync_block.__init__(self,name='EPB: Packet to PMT', # will show up in GRCin_sig=None,out_sig=None)self.message_port_register_in(pmt.intern('msg_in'))self.message_port_register_out(pmt.intern('msg_out'))self.set_msg_handler(pmt.intern('msg_in'), self.handle_msg)def handle_msg(self, msg):_debug = 0 # set to zero to turn off diagnosticstry:buff = pmt.to_python(pmt.cdr(msg))b_len = len (buff)except Exception as e:gr.log.error("Error with message conversion: %s" % str(e))if (_debug):print ("new_val =", buff, b_len)if (b_len != 52):self.message_port_pub (pmt.intern('msg_out'), pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))elif ((buff[0] != 37) and (buff[51] != 93)):self.message_port_pub (pmt.intern('msg_out'), pmt.cons(pmt.PMT_NIL,pmt.to_pmt(buff)))```Any help will be appreciated!---Barry Duggan
[Prev in Thread] | Current Thread | [Next in Thread] |