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

List:       gnuradio-discuss
Subject:    [Discuss-gnuradio] Calling public C++ function in OOT module using Python
From:       Edwin Li <lbyhplby () gmail ! com>
Date:       2018-07-31 23:09:03
Message-ID: CA+qGr-Fo=YPmzAD6e-bAZYQGyM-abFUdFSTeFbxsz8j36L_rGw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

I've been trying to make a function in my OOT module public. The module is
called chaotic_prefix_bc.
I declare a pure virtual function called *Logistic_map()* in
chaotic_prefix_bc.h, and overload it in chaotic_prefix_bc_impl.h and
chaotic_prefix_bc_impl.cc.
When I call this function in a vector source(in GNURadio) using:
chaos.chaotic_prefix_bc(0.8,3.98,50,'len_tag_key').Logistic_map(0.8,3.98,50),
it says 'chaotic_prefix_bc_sptr' object has no attribute 'Logistic_map'.
I tried the make clean trick mentioned in the mailing list, but to no avail.
I attached my code below. Please help me~

Regards,
Edwin

[Attachment #5 (text/html)]

<div dir="ltr">Hi,<div><br></div><div>I&#39;ve been trying to make a function in my \
OOT module public. The module is called chaotic_prefix_bc.  </div><div>I declare a \
pure virtual function called <i><b>Logistic_map()</b></i> in chaotic_prefix_bc.h, and \
overload it in chaotic_prefix_bc_impl.h and chaotic_prefix_bc_impl.cc.</div><div>When \
I call this function in a vector source(in GNURadio) using: \
chaos.chaotic_prefix_bc(0.8,3.98,50,&#39;len_tag_key&#39;).Logistic_map(0.8,3.98,50), \
it says &#39;chaotic_prefix_bc_sptr&#39; object has no attribute \
&#39;Logistic_map&#39;.  </div><div>I tried the make clean trick mentioned in the \
mailing list, but to no avail.</div><div>I attached my code below. Please help \
me~</div><div><br></div><div>Regards,</div><div>Edwin</div><div><br></div><div><br></div></div>


--000000000000b084fc057253aa63--


["chaotic_prefix_bc_impl.h" (text/x-chdr)]

/* -*- c++ -*- */
/* 
 * Copyright 2018 <+YOU OR YOUR COMPANY+>.
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#ifndef INCLUDED_CHAOS_CHAOTIC_PREFIX_BC_IMPL_H
#define INCLUDED_CHAOS_CHAOTIC_PREFIX_BC_IMPL_H

#include <chaos/chaotic_prefix_bc.h>

namespace gr {
  namespace chaos {

    class chaotic_prefix_bc_impl : public chaotic_prefix_bc
    {
     private:
	float d_init;
	float d_parameter;
	unsigned int d_header_len;
	

      // Nothing to declare in this block.
     

     protected:
      int calculate_output_stream_length(const gr_vector_int &ninput_items);

     public:
      chaotic_prefix_bc_impl(float init, float parameter, unsigned int header_len, \
const std::string &len_tag_key);  ~chaotic_prefix_bc_impl();
     std::vector<float> Logistic_map(float init, float parameter, unsigned int \
seq_len);   // Where all the action really happens
      int work(int noutput_items,
           gr_vector_int &ninput_items,
           gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items);
    };

  } // namespace chaos
} // namespace gr

#endif /* INCLUDED_CHAOS_CHAOTIC_PREFIX_BC_IMPL_H */


["chaotic_prefix_bc_impl.cc" (text/x-c++src)]

/* -*- c++ -*- */
/* 
 * Copyright 2018 <+YOU OR YOUR COMPANY+>.
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gnuradio/io_signature.h>
#include "chaotic_prefix_bc_impl.h"

namespace gr {
  namespace chaos {

    chaotic_prefix_bc::sptr
    chaotic_prefix_bc::make(float init, float parameter, unsigned int header_len, \
const std::string &len_tag_key)  {
      return gnuradio::get_initial_sptr
        (new chaotic_prefix_bc_impl(init, parameter, header_len, len_tag_key));
    }

    /*
     * The private constructor
     */
    chaotic_prefix_bc_impl::chaotic_prefix_bc_impl(float init, float parameter, \
unsigned int header_len, const std::string &len_tag_key)  : \
gr::tagged_stream_block("chaotic_prefix_bc",  gr::io_signature::make(1, 1, \
                sizeof(char)),
              gr::io_signature::make(1, 1, sizeof(gr_complex)), len_tag_key),
              d_init(init),
	      d_parameter(parameter),
	      d_header_len(header_len)
    {
	set_tag_propagation_policy(TPP_DONT);// dont propagate tags
    }

    /*
     * Our virtual destructor.
     */
    chaotic_prefix_bc_impl::~chaotic_prefix_bc_impl()
    {
    }

    std::vector<float> chaotic_prefix_bc_impl::Logistic_map(float init, float \
parameter, unsigned int seq_len)  {
	//float parameter=3.62;
	std::vector<float> chaotic_seq;
	chaotic_seq.push_back(init);
	float x_nn;
	float sum=d_init;
	for (int i=1;i<seq_len;i++)
	{
	   x_nn=parameter*chaotic_seq[i-1]*(1-chaotic_seq[i-1]);
	   
	//   x_nn=0;
	   sum+=x_nn;
	   chaotic_seq.push_back(x_nn);	
	}
	//normalize chaotic_seq
	sum=sum/seq_len;

	float maxabs=0;
	for (int i=0;i<seq_len;i++)
	{
	  chaotic_seq[i]=chaotic_seq[i]-sum;
	  if (std::abs(chaotic_seq[i])>maxabs)
          {
	     maxabs=std::abs(chaotic_seq[i]);
	  }
		
	}

	for (int i=0;i<seq_len;i++)
	{
	  chaotic_seq[i]=chaotic_seq[i]/maxabs;
	  
	}
	return chaotic_seq;

    }

    int
    chaotic_prefix_bc_impl::calculate_output_stream_length(const gr_vector_int \
&ninput_items)  {
      int noutput_items = d_header_len;
      return noutput_items ;
    }

    int
    chaotic_prefix_bc_impl::work (int noutput_items,
                       gr_vector_int &ninput_items,
                       gr_vector_const_void_star &input_items,
                       gr_vector_void_star &output_items)
    {
      const char *in = (const char *) input_items[0];
      gr_complex *out = (gr_complex *) output_items[0];
	
      std::vector<float> chaotic_float=Logistic_map(d_init, d_parameter, \
d_header_len);  std::vector<gr_complex> chaotic_complex;
      for (int i=0;i<d_header_len;i++)
      {

	chaotic_complex.push_back(gr_complex(chaotic_float[i],0));
	
      }
      //std::vector<gr_complex> *p=&chaotic_complex; 
      memcpy((void *)out,&chaotic_complex[0],d_header_len*sizeof(gr_complex));
	out+=d_header_len;
      // Do <+signal processing+>
	noutput_items=d_header_len;
      // Tell runtime system how many output items we produced.
      return noutput_items;
    }

  } /* namespace chaos */
} /* namespace gr */


["chaotic_prefix_bc.h" (text/x-chdr)]

/* -*- c++ -*- */
/* 
 * Copyright 2018 <+YOU OR YOUR COMPANY+>.
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */


#ifndef INCLUDED_CHAOS_CHAOTIC_PREFIX_BC_H
#define INCLUDED_CHAOS_CHAOTIC_PREFIX_BC_H

#include <chaos/api.h>
#include <gnuradio/tagged_stream_block.h>

namespace gr {
  namespace chaos {

    /*!
     * \brief <+description of block+>
     * \ingroup chaos
     *
     */
    class CHAOS_API chaotic_prefix_bc : virtual public gr::tagged_stream_block
    {
     public:
      typedef boost::shared_ptr<chaotic_prefix_bc> sptr;

      /*!
       * \brief Return a shared_ptr to a new instance of chaos::chaotic_prefix_bc.
       *
       * To avoid accidental use of raw pointers, chaos::chaotic_prefix_bc's
       * constructor is in a private implementation
       * class. chaos::chaotic_prefix_bc::make is the public interface for
       * creating new instances.
       */
      virtual std::vector<float> Logistic_map(float init, float parameter, unsigned \
                int seq_len)=0;
      static sptr make(float init, float parameter, unsigned int header_len, const \
std::string &len_tag_key);  };

  } // namespace chaos
} // namespace gr

#endif /* INCLUDED_CHAOS_CHAOTIC_PREFIX_BC_H */



_______________________________________________
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