[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gnuradio-discuss
Subject:    Re: [Discuss-gnuradio] Read and Write a PMT input/output GNURadio C++
From:       Marcus_Müller <marcus.mueller () ettus ! com>
Date:       2017-06-27 12:20:59
Message-ID: 9a078ee2-3c91-158d-66a1-0811ad405b4f () ettus ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Cristian,

> How can I take just the real number of that pair?

pmt::car and pmt::cdr give you the first and second element of a pmt::cons.

> do you have a reference page of the command?

https://gnuradio.org/doc/doxygen/namespacepmt.html#a7ab95721db5cbda1852f13a92eee5362

I must admit that I find PMT not the best-documented piece of software
myself.

> I understood that I need to send the pair. Is it possible to send just
> the real number?
As said, you can send /any/ PMT – it's just customary to follow a few
common patterns. But sure, you can just as well just send
pmt::from_double(your_double).

Best regards,
Marcus


On 27.06.2017 14:16, Cristian Rodríguez wrote:
> Hi Marcus.
> 
> Thanks for your message.
> 
> How can I take just the real number of that pair? do you have a
> reference page of the command?
> I was reading a lot yesterday and my search wasn't well.
> 
> I understood that I need to send the pair. Is it possible to send just
> the real number?
> 
> Again, thanks a lot for your time.
> 
> Best regards,
> 
> Cristian
> 
> On Jun 27, 2017 3:48 AM, "Marcus Müller" <marcus.mueller@ettus.com
> <mailto:marcus.mueller@ettus.com>> wrote:
> 
> You're explicitly sending a pair (pmt::cons), not a real or
> integer number!
> 
> 
> On 27.06.2017 04:57, Cristian Rodríguez wrote:
> > Hi.
> > 
> > Thanks a lot for your time to read.
> > 
> > I read the two links that you shared to me, Marcus. Thanks a lot
> > for your help. But i still have a problem.
> > 
> > I've implemented as follows:
> > 
> > * I create, the output, input and the handler:
> > 
> > message_port_register_out(pmt::mp("out_threshold"));
> > 
> > message_port_register_in(pmt::mp("in_threshold"));
> > set_msg_handler(pmt::mp("in_threshold"),
> > boost::bind(&sync_short_impl::set_msg, this, _1));
> > 
> > * I create, the next function to handle the inputs
> > 
> > void set_msg(pmt::pmt_t msg) { d_msg= msg;
> > dout << "Nueva lectura : " << d_msg << " ninput: " <<
> > std::endl;
> > if (pmt::is_integer(d_msg)) {
> > d_threshold = (double) pmt::to_long(d_msg);
> > } else if (pmt::is_real(d_msg)) {
> > d_threshold = pmt::to_double(d_msg);
> > } else {
> > // We really expected an integer or a double here, so we don't
> > know what to do
> > throw std::runtime_error("expected an integer!");
> > }
> > 
> > }
> > 
> > * In the block i linked the input and the output, just to check
> > that the function set_msg(), works.
> > 
> > 
> > Imágenes integradas 3
> > 
> > * I compile the c++ codes, etc... all that is necessary.
> > * I write the output as follows (that's working, i checked that
> > with a message debug):
> > 
> > message_port_pub(pmt::mp("out_threshold"),
> > pmt::cons(pmt::PMT_NIL, pmt::from_double(d_threshold)));
> > 
> > * When i start the flowgraph, the block put in the output a PMT
> > message, after that, as it is linked with the input, the
> > message go to the input port. When it is recevied, the
> > function set_msg is launched, but the type of the number in
> > the PMT is not recognized as double. *Here is my problem, I
> > don't understand why it is happening, because the PMT that I
> > put in the output is build from a double, then it is
> > supposed, the one that i received is too a double. What do
> > you think?*
> > 
> > Imágenes integradas 2
> > 
> > 
> > Thanks in advance.
> > 
> > 
> > Best regards,
> > 
> > 
> > Cristian
> > 
> > 2017-06-26 12:45 GMT-05:00 Marcus Müller
> > <marcus.mueller@ettus.com <mailto:marcus.mueller@ettus.com>>:
> > 
> > Hi Cristian,
> > 
> > you need to subscribe a /handler/ to the message port. See:
> > 
> > https://wiki.gnuradio.org/index.php/Guided_Tutorial_Programming_Topics#5.3.2_Adding_Message_Passing_to_the_Code
> >  <https://wiki.gnuradio.org/index.php/Guided_Tutorial_Programming_Topics#5.3.2_Adding_Message_Passing_to_the_Code>
> >  
> > It's absolutely up to you what kind of PMT you're publishing
> > over a message port, but it's canonical to have a PMT dict
> > that maps
> > 
> > pmt::mp("propertyname") -> pmt::whateversuitsyourproperty.
> > 
> > As an example, see what the gr-uhd blocks accept [1]
> > 
> > Best regards,
> > 
> > Marcus
> > 
> > [1]
> > https://gnuradio.org/doc/doxygen/page_uhd.html#uhd_command_syntax
> > <https://gnuradio.org/doc/doxygen/page_uhd.html#uhd_command_syntax>
> > 
> > On 06/26/2017 07:35 PM, Cristian Rodríguez wrote:
> > > Hi all,
> > > 
> > > I'm not sure about how to read and write PMT ports from and
> > > to local variables. I'm going to expose what i'm doing, and
> > > if someone can help me i would be very greatful.
> > > 
> > > I've created an input and an output of PMT type.
> > > 
> > > message_port_register_in(pmt::pmt_t in_threshold)
> > > message_port_register_out(pmt::pmt_t out_threshold)
> > > 
> > > Now i want to read the port, and save the data in a local
> > > variable, do operations with that variable, and later write
> > > it in the output,
> > > 
> > > I create the variables,
> > > 
> > > double d_threshold;
> > > pmt::pmt_t target;
> > > 
> > > *I read it, I don't know how to do it. But I suppose:
> > > 
> > > *
> > > message_port_sub(pmt::pmt_t
> > > <https://gnuradio.org/doc/doxygen/namespacepmt.html#ab4b70d9293452eb74dd07c670e6811fa>
> > >  in_threshold,pmt::pmt_t
> > > <https://gnuradio.org/doc/doxygen/namespacepmt.html#ab4b70d9293452eb74dd07c670e6811fa>
> > >  target);
> > > d_threshold= pmt::to_double
> > > <https://gnuradio.org/doc/doxygen/namespacepmt.html#a0f58166fe9f449249f5de7dc7b3ab754>(target);
> > >  
> > > And, I think i can write it as follows:
> > > 
> > > msg=pmt::from_double
> > > <https://gnuradio.org/doc/doxygen/namespacepmt.html#ad20c287c509e8470d03d1c8e97fea12d>(d_threshold);
> > >  message_port_pub(pmt::pmt_t
> > > <https://gnuradio.org/doc/doxygen/namespacepmt.html#ab4b70d9293452eb74dd07c670e6811fa>
> > >  out_threshold,pmt::pmt_t
> > > <https://gnuradio.org/doc/doxygen/namespacepmt.html#ab4b70d9293452eb74dd07c670e6811fa>
> > >  msg);
> > > 
> > > What do you think, i've seen several examples, and they do
> > > this, message_port_pub(pmt::mp("symbols"),
> > > pmt::cons(pmt::make_dict(), pmt::init_c32vector(48, symbols)));
> > > 
> > > But I don't understand why it is necessary to use
> > > pmt::make_dict().
> > > 
> > > Thanks in advance.
> > > 
> > > Best regards,
> > > 
> > > Cristian
> > > 
> > > 
> > > 
> > > _______________________________________________
> > > Discuss-gnuradio mailing list
> > > Discuss-gnuradio@gnu.org <mailto:Discuss-gnuradio@gnu.org>
> > > https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
> > > <https://lists.gnu.org/mailman/listinfo/discuss-gnuradio>
> > 
> > 
> > _______________________________________________
> > Discuss-gnuradio mailing list
> > Discuss-gnuradio@gnu.org <mailto:Discuss-gnuradio@gnu.org>
> > https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
> > <https://lists.gnu.org/mailman/listinfo/discuss-gnuradio>
> > 
> > 
> 
> 


[Attachment #5 (multipart/related)]

[Attachment #7 (text/html)]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div dir="auto">Hi Cristian,<br>
      <br>
    </div>
    <div dir="auto">&gt;How can I take just the real number of that
      pair? <br>
      <br>
      pmt::car and pmt::cdr give you the first and second element of a
      pmt::cons. <br>
      <br>
      &gt; do you have a reference page of the command?<br>
      <br>
<a class="moz-txt-link-freetext" \
href="https://gnuradio.org/doc/doxygen/namespacepmt.html#a7ab95721db5cbda1852f13a92eee \
5362">https://gnuradio.org/doc/doxygen/namespacepmt.html#a7ab95721db5cbda1852f13a92eee5362</a><br>
  <br>
      I must admit that I find PMT not the best-documented piece of
      software myself.<br>
      <br>
      <blockquote type="cite">I understood that I need to send the pair.
        Is it possible to send just the real number?</blockquote>
      As said, you can send <i>any</i> PMT – it's just customary to
      follow a few common patterns. But sure, you can just as well just
      send pmt::from_double(your_double).<br>
      <br>
      Best regards,<br>
      Marcus<br>
      <br>
    </div>
    <br>
    <div class="moz-cite-prefix">On 27.06.2017 14:16, Cristian Rodríguez
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAG=rXKYBtmUNgxOdDCQ_FVVALA_eeXY3N9q+JTv+Buaods33Cw@mail.gmail.com">
      <div dir="auto">
        <div>Hi Marcus.</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Thanks for your message.</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">How can I take just the real number of that
          pair? do you have a reference page of the command?</div>
        <div dir="auto">I was reading a lot yesterday and my search
          wasn't well.</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">I understood that I need to send the pair. Is it
          possible to send just the real number?</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Again, thanks a lot for your time.</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Best regards,</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Cristian<br>
          <div class="gmail_extra" dir="auto"><br>
            <div class="gmail_quote">On Jun 27, 2017 3:48 AM, "Marcus
              Müller" &lt;<a href="mailto:marcus.mueller@ettus.com"
                moz-do-not-send="true">marcus.mueller@ettus.com</a>&gt;
              wrote:<br type="attribution">
              <blockquote class="quote" style="margin:0 0 0
                .8ex;border-left:1px #ccc solid;padding-left:1ex">
                <div text="#000000" bgcolor="#FFFFFF">
                  <p>You're explicitly sending a pair (pmt::cons), not a
                    real or integer number! <br>
                  </p>
                  <div class="elided-text"> <br>
                    <div class="m_8965256943116432903moz-cite-prefix">On
                      27.06.2017 04:57, Cristian Rodríguez wrote:<br>
                    </div>
                    <blockquote type="cite">
                      <div dir="ltr">
                        <div>
                          <div>Hi.<br>
                            <br>
                          </div>
                          <div>Thanks a lot for your time to read.<br>
                          </div>
                          <div><br>
                          </div>
                          I read the two links that you shared to me,
                          Marcus. Thanks a lot for your help. But i
                          still have a problem.<br>
                          <br>
                        </div>
                        I've implemented as follows:<br>
                        <ul>
                          <li>I create, the output, input and the
                            handler:</li>
                        </ul>
                        <p>    \
message_port_register_out(pmt:<wbr>:mp("out_threshold"));<br>  <br>
                              \
                message_port_register_in(pmt::<wbr>mp("in_threshold"));<br>
                              set_msg_handler(pmt::mp("in_<wbr>threshold"),
                          boost::bind(&amp;sync_short_impl::<wbr>set_msg,
                          this, _1));<br>
                        </p>
                        <ul>
                          <li>I create, the next function to handle the
                            inputs</li>
                        </ul>
                        <p>void set_msg(pmt::pmt_t msg) { d_msg= msg;<br>
                                  dout &lt;&lt; "Nueva lectura : "
                          &lt;&lt; d_msg &lt;&lt; " ninput: " &lt;&lt;
                          std::endl;<br>
                          if (pmt::is_integer(d_msg)) {<br>
                              d_threshold = (double)
                          pmt::to_long(d_msg);<br>
                          } else if (pmt::is_real(d_msg)) {<br>
                              d_threshold = pmt::to_double(d_msg);<br>
                          } else {<br>
                           // We really expected an integer or a double
                          here, so we don't know what to do<br>
                              throw std::runtime_error("expected an
                          integer!");<br>
                          }<br>
                          <br>
                           }</p>
                        <ul>
                          <li>In the block i linked the input and the
                            output, just to check that the function
                            set_msg(), works.</li>
                        </ul>
                        <p><br>
                        </p>
                        <p><img
                            src="cid:part2.38767B93.1C2B900D@ettus.com"
                            alt="Imágenes integradas 3" class=""
                            height="259" width="472"><br>
                        </p>
                        <ul>
                          <li>I compile the c++ codes, etc... all that
                            is necessary.</li>
                          <li>I write the output as follows (that's
                            working, i checked that with a message
                            debug):</li>
                        </ul>
                        <p>message_port_pub(pmt::mp("out_<wbr>threshold"),
                          pmt::cons(pmt::PMT_NIL,
                          pmt::from_double(d_threshold))<wbr>);<br>
                        </p>
                        <div>
                          <div>
                            <div>
                              <div class="gmail_extra">
                                <ul>
                                  <li>When i start the flowgraph, the
                                    block put in the output a PMT
                                    message, after that, as it is linked
                                    with the input, the message go to
                                    the input port. When it is recevied,
                                    the function set_msg is launched,
                                    but the type of the number in the
                                    PMT is not recognized as double. <b>Here
                                      is my problem, I don't understand
                                      why it is happening, because the
                                      PMT that I put in the output is
                                      build from a double, then it is
                                      supposed, the one that i received
                                      is too a double. What do you
                                      think?</b><br>
                                  </li>
                                </ul>
                                <p><img
                                    src="cid:part3.0F9DAA33.FEFF364E@ettus.com"
                                    alt="Imágenes integradas 2" class=""
                                    height="74" width="478"></p>
                                <p><br>
                                </p>
                                <p>Thanks in advance.</p>
                                <p><br>
                                </p>
                                <p>Best regards,</p>
                                <p><br>
                                </p>
                                <p>Cristian<br>
                                </p>
                                <div class="gmail_quote">2017-06-26
                                  12:45 GMT-05:00 Marcus Müller <span
                                    dir="ltr">&lt;<a
                                      href="mailto:marcus.mueller@ettus.com"
                                      target="_blank"
                                      \
moz-do-not-send="true">marcus.mueller@ettus.com</a>&gt;</span>:<br>  <blockquote \
class="gmail_quote"  style="margin:0px 0px 0px
                                    0.8ex;border-left:1px solid
                                    rgb(204,204,204);padding-left:1ex">
                                    <div bgcolor="#FFFFFF">
                                      <p>Hi Cristian,</p>
                                      <p>you need to subscribe a <i>handler</i>
                                        to the message port. See:</p>
                                      <p><a
class="m_8965256943116432903gmail-m_-1080164876778811938moz-txt-link-freetext"
href="https://wiki.gnuradio.org/index.php/Guided_Tutorial_Programming_Topics#5.3.2_Adding_Message_Passing_to_the_Code"
  target="_blank"
                                          \
moz-do-not-send="true">https://wiki.gnuradio.org/inde<wbr>x.php/Guided_Tutorial_Programm<wbr>ing_Topics#5.3.2_Adding_<wbr>Message_Passing_to_the_Code</a></p>
  <p>It's absolutely up to you what
                                        kind of PMT you're publishing
                                        over a message port, but it's
                                        canonical to have a PMT dict
                                        that maps</p>
                                      <p>pmt::mp("propertyname") -&gt;
                                        pmt::whateversuitsyourproperty<wbr>.</p>
                                      <p>As an example, see what the
                                        gr-uhd blocks accept [1]<br>
                                      </p>
                                      <p>Best regards,</p>
                                      <p>Marcus</p>
                                      <p>[1] <a
class="m_8965256943116432903gmail-m_-1080164876778811938moz-txt-link-freetext"
href="https://gnuradio.org/doc/doxygen/page_uhd.html#uhd_command_syntax"
                                          target="_blank"
                                          \
moz-do-not-send="true">https://gnuradio.org/doc/doxyg<wbr>en/page_uhd.html#uhd_command_<wbr>syntax</a><br>
  </p>
                                      <div>
                                        <div
                                          class="m_8965256943116432903gmail-h5">
                                          <div
                                            \
class="m_8965256943116432903gmail-m_-1080164876778811938moz-cite-prefix">On  \
06/26/2017 07:35 PM,  Cristian Rodríguez wrote:<br>
                                          </div>
                                        </div>
                                      </div>
                                      <blockquote type="cite">
                                        <div>
                                          <div
                                            class="m_8965256943116432903gmail-h5">
                                            <div dir="ltr">
                                              <div>
                                                <div>Hi all,<br>
                                                  <br>
                                                </div>
                                                <div>I'm not sure about
                                                  how to read and write
                                                  PMT ports from and to
                                                  local variables. I'm
                                                  going to expose what
                                                  i'm doing, and if
                                                  someone can help me i
                                                  would be very
                                                  greatful.<br>
                                                </div>
                                                <div><br>
                                                </div>
                                                I've created an input
                                                and an output of PMT
                                                type. <br>
                                                <br>
                                                <div
                                                  \
style="margin-left:40px">message_port_register_in(pmt::<wbr>pmt_t  in_threshold)<br>
                                                </div>
                                                <div
                                                  \
style="margin-left:40px">message_port_register_out(pmt:<wbr>:pmt_t  \
out_threshold)<br>  <br>
                                                </div>
                                                Now i want to read the
                                                port, and save the data
                                                in a local variable, do
                                                operations with that
                                                variable, and later
                                                write it in the output,<br>
                                                <br>
                                                I create the variables,<br>
                                                <br>
                                                <div
                                                  style="margin-left:40px">double
                                                  d_threshold;<br>
                                                  pmt::pmt_t target;<br>
                                                </div>
                                                <br>
                                              </div>
                                              <div><b>I read it, I don't
                                                  know how to do it. But
                                                  I suppose:<br>
                                                  <br>
                                                </b>
                                                <div
                                                  \
style="margin-left:40px">message_port_sub(<a \
class="m_8965256943116432903gmail-m_-1080164876778811938gmail-code" \
href="https://gnuradio.org/doc/doxygen/namespacepmt.html#ab4b70d9293452eb74dd07c670e6811fa"
  target="_blank"
                                                    \
moz-do-not-send="true">pmt::pmt_t</a>  in_threshold,<a
                                                    \
class="m_8965256943116432903gmail-m_-1080164876778811938gmail-code" \
href="https://gnuradio.org/doc/doxygen/namespacepmt.html#ab4b70d9293452eb74dd07c670e6811fa"
  target="_blank"
                                                    \
moz-do-not-send="true">pmt::pmt_t</a>  target);</div>
                                              </div>
                                              <div
                                                style="margin-left:40px">d_threshold=
                                                <a
                                                  \
class="m_8965256943116432903gmail-m_-1080164876778811938gmail-code" \
href="https://gnuradio.org/doc/doxygen/namespacepmt.html#a0f58166fe9f449249f5de7dc7b3ab754"
  target="_blank"
                                                  \
moz-do-not-send="true">pmt::to_double</a>(target);</div>  <br>
                                              And, I think i can write
                                              it as follows:<br>
                                              <div
                                                style="margin-left:40px"><br>
                                                msg=<a
                                                  \
class="m_8965256943116432903gmail-m_-1080164876778811938gmail-code" \
href="https://gnuradio.org/doc/doxygen/namespacepmt.html#ad20c287c509e8470d03d1c8e97fea12d"
  target="_blank"
                                                  \
moz-do-not-send="true">pmt::from_double</a>(d_thresho<wbr>ld);</div>  <div
                                                \
style="margin-left:40px">message_port_pub(<a \
class="m_8965256943116432903gmail-m_-1080164876778811938gmail-code" \
href="https://gnuradio.org/doc/doxygen/namespacepmt.html#ab4b70d9293452eb74dd07c670e6811fa"
  target="_blank"
                                                  \
moz-do-not-send="true">pmt::pmt_t</a>  out_threshold,<a
class="m_8965256943116432903gmail-m_-1080164876778811938gmail-m_-6445872483550357649gmail-code"
 href="https://gnuradio.org/doc/doxygen/namespacepmt.html#ab4b70d9293452eb74dd07c670e6811fa"
  target="_blank"
                                                  \
moz-do-not-send="true">pmt::pmt_t</a>  msg);</div>
                                              <div><br>
                                              </div>
                                              <div>What do you think,
                                                i've seen several
                                                examples, and they do
                                                this,
                                                \
message_port_pub(pmt::mp("symb<wbr>ols"), pmt::cons(pmt::make_dict(), \
pmt::init_c32vector(48, symbols)));<br>  <br>
                                              </div>
                                              <div>But I don't
                                                understand why it is
                                                necessary to use
                                                pmt::make_dict().<br>
                                                <br>
                                              </div>
                                              <div>Thanks in advance.<br>
                                              </div>
                                              <div><br>
                                              </div>
                                              <div>Best regards,<br>
                                                <br>
                                              </div>
                                              <div>Cristian<br>
                                              </div>
                                              <div><br>
                                              </div>
                                            </div>
                                            <br>
                                            <fieldset
class="m_8965256943116432903gmail-m_-1080164876778811938mimeAttachmentHeader"></fieldset>
  <br>
                                          </div>
                                        </div>
                                        \
<pre>______________________________<wbr>_________________ Discuss-gnuradio mailing \
list <a class="m_8965256943116432903gmail-m_-1080164876778811938moz-txt-link-abbreviated" \
href="mailto:Discuss-gnuradio@gnu.org" target="_blank" \
moz-do-not-send="true">Discuss-gnuradio@gnu.org</a> <a \
class="m_8965256943116432903gmail-m_-1080164876778811938moz-txt-link-freetext" \
href="https://lists.gnu.org/mailman/listinfo/discuss-gnuradio" target="_blank" \
moz-do-not-send="true">https://lists.gnu.org/mailman/<wbr>listinfo/discuss-gnuradio</a>
 </pre>
                                      </blockquote>
                                      <br>
                                    </div>
                                    <br>
                                    \
______________________________<wbr>_________________<br>  Discuss-gnuradio mailing \
list<br>  <a
                                      href="mailto:Discuss-gnuradio@gnu.org"
                                      target="_blank"
                                      \
moz-do-not-send="true">Discuss-gnuradio@gnu.org</a><br>  <a
                                      \
href="https://lists.gnu.org/mailman/listinfo/discuss-gnuradio"  rel="noreferrer" \
                target="_blank"
                                      \
moz-do-not-send="true">https://lists.gnu.org/mailman/<wbr>listinfo/discuss-gnuradio</a><br>
  <br>
                                  </blockquote>
                                </div>
                                <br>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </blockquote>
                    <br>
                  </div>
                </div>
              </blockquote>
            </div>
            <br>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>


["image.png" (image/png)]
["image.png" (image/png)]

_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic