26 #include <boost/format.hpp>
62 std::string units, std::string desc,
63 myType
min, myType max, myType deflt,
66 d_functionbase(functionbase), d_units(units), d_desc(desc),
67 d_min(min), d_max(max), d_deflt(deflt), d_dtype(dtype),
76 d_rpc_vars.push_back(s);
80 myType rVal = d_deflt;
81 if(d_callback == NULL) {
82 printf(
"WARNING: pycallback_object get() called without py callback set!\n");
87 PyGILState_STATE state = PyGILState_Ensure();
93 func = (PyObject *) d_callback;
95 result = PyEval_CallObject(func,NULL);
99 rVal = pyCast(result);
104 PyGILState_Release(state);
119 (boost::format(
"%s%d") % d_name % d_id).str() , d_functionbase.c_str(),
127 PyObject* d_callback;
128 std::string d_functionbase, d_units, d_desc;
129 myType d_min, d_max, d_deflt;
137 myType pyCast(PyObject* obj) {
138 printf(
"TYPE NOT IMPLEMENTED!\n");
145 std::vector<boost::any> d_rpc_vars;
156 return std::string(PyString_AsString(obj));
162 return PyFloat_AsDouble(obj);
168 return (
float)PyFloat_AsDouble(obj);
174 return PyInt_AsLong(obj);
180 int size = PyObject_Size(obj);
181 std::vector<float> rval(size);
182 for(
int i=0; i<size; i++) {
183 rval[i] = (float)PyFloat_AsDouble(PyList_GetItem(obj, i));
191 int size = PyObject_Size(obj);
192 std::vector<gr_complex> rval(size);
193 for(
int i=0; i<size; i++){ rval[i] =
\
194 gr_complex((
float)PyComplex_RealAsDouble(PyList_GetItem(obj, i)),
195 (
float)PyComplex_ImagAsDouble(PyList_GetItem(obj, i)));
Definition: pycallback_object.h:30
pycallback_object(std::string name, std::string functionbase, std::string units, std::string desc, myType min, myType max, myType deflt, DisplayType dtype)
Definition: pycallback_object.h:61
float min(float a, float b)
int pycallback_object_count
Definition: pycallback_object.h:33
void setup_rpc()
Definition: pycallback_object.h:114
static pmt::pmt_t make(myType _val)
Definition: pycallback_object.h:39
pyport_t
Definition: pycallback_object.h:28
Definition: rpccallbackregister_base.h:48
Definition: pycallback_object.h:58
Registers a 'get' function to get a parameter over ControlPort.
Definition: rpcregisterhelpers.h:987
std::complex< float > gr_complex
Definition: gr_complex.h:27
void set_callback(PyObject *cb)
Definition: pycallback_object.h:109
PMT_API pmt_t init_f32vector(size_t k, const float *data)
PMT_API pmt_t init_c32vector(size_t k, const std::complex< float > *data)
Definition: pycallback_object.h:29
void add_rpc_variable(rpcbasic_sptr s)
Definition: pycallback_object.h:74
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:56
Definition: pycallback_object.h:36
static pmt_t mp(const std::string &s)
Make pmt symbol.
Definition: pmt_sugar.h:36
myType get()
Definition: pycallback_object.h:79
uint32_t DisplayType
Definition: rpccallbackregister_base.h:29