1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/* -*- c++ -*- */
/*
* Copyright 2012 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio 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.
*
* GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include <rpcpmtconverters_ice.h>
#include <Ice/Ice.h>
#include <gnuradio.h>
GNURadio::KnobPtr
rpcpmtconverter::from_pmt(const pmt::pmt_t& knob, const Ice::Current& c)
{
if(pmt::is_real(knob)) {
return new GNURadio::KnobD(Ice::Double(pmt::to_double(knob)));
}
else if(pmt::is_symbol(knob)) {
std::string stuff = pmt::symbol_to_string(knob);
if(stuff.length() != 1) {
return new GNURadio::KnobS(stuff);
}
else {
return new GNURadio::KnobC(stuff[0]);
}
//TODO: FLOAT!!!
}
else if(pmt::is_integer(knob)) {
return new GNURadio::KnobI(pmt::to_long(knob));
}
else if(pmt::is_bool(knob)) {
return new GNURadio::KnobB(pmt::to_bool(knob));
}
else if(pmt::is_uint64(knob)) {
return new GNURadio::KnobL(pmt::to_uint64(knob));
//const std::complex<float> *c32vector_elements(pmt_t v, size_t &len); //< len is in elements
}
else if(pmt::is_c32vector(knob)) { // c32 sent as interleaved floats
size_t size(pmt::length(knob));
const float* start((const float*) pmt::c32vector_elements(knob,size));
return new GNURadio::KnobVecF(std::vector<float>(start,start+size*2));
}
else if (pmt::is_s32vector(knob)) {
size_t size(pmt::length(knob));
const int* start((const int*) pmt::s32vector_elements(knob,size));
return new GNURadio::KnobVecI(std::vector<int>(start,start+size));
}
else if(pmt::is_f32vector(knob)) {
size_t size(pmt::length(knob));
const float* start((const float*) pmt::f32vector_elements(knob,size));
return new GNURadio::KnobVecF(std::vector<float>(start,start+size));
}
else if (pmt::is_u8vector(knob)) {
size_t size(pmt::length(knob));
const uint8_t* start((const uint8_t*) pmt::u8vector_elements(knob,size));
return new GNURadio::KnobVecC(std::vector<Ice::Byte>(start,start+size));
}
else {
std::cerr << "Error: Don't know how to handle Knob Type (from): " << std::endl; assert(0);}
//TODO: VECTORS!!!
return new GNURadio::Knob();
}
pmt::pmt_t
rpcpmtconverter::to_pmt(const GNURadio::KnobPtr& knob, const Ice::Current& c)
{
std::string id(knob->ice_id(c).substr(12));
if(id == "KnobD") {
GNURadio::KnobDPtr k(GNURadio::KnobDPtr::dynamicCast(knob));
return pmt::mp(k->value);
}
else if(id == "KnobF") {
GNURadio::KnobFPtr k(GNURadio::KnobFPtr::dynamicCast(knob));
return pmt::mp(k->value);
}
else if(id == "KnobI") {
GNURadio::KnobIPtr k(GNURadio::KnobIPtr::dynamicCast(knob));
return pmt::mp(k->value);
}
else if(id == "KnobS") {
GNURadio::KnobSPtr k(GNURadio::KnobSPtr::dynamicCast(knob));
return pmt::string_to_symbol(k->value);
}
else if(id == "KnobB") {
GNURadio::KnobBPtr k(GNURadio::KnobBPtr::dynamicCast(knob));
return pmt::mp(k->value);
}
else if(id == "KnobC") {
GNURadio::KnobCPtr k(GNURadio::KnobCPtr::dynamicCast(knob));
return pmt::mp(k->value);
}
else if(id == "KnobL") {
GNURadio::KnobLPtr k(GNURadio::KnobLPtr::dynamicCast(knob));
return pmt::mp((long)k->value);
} else if(id == "KnobVecC") {
GNURadio::KnobVecCPtr k(GNURadio::KnobVecCPtr::dynamicCast(knob));
return pmt::init_u8vector(k->value.size(), &k->value[0]);
} else if(id == "KnobVecI") {
GNURadio::KnobVecIPtr k(GNURadio::KnobVecIPtr::dynamicCast(knob));
return pmt::init_s32vector(k->value.size(), &k->value[0]);
}
//else if(id == "KnobVecF") {
// GNURadio::KnobVecFPtr k(GNURadio::KnobVecFPtr::dynamicCast(knob));
// return pmt::mp(k->value);
//TODO: FLOAT!!!
//TODO: VECTORS!!!
else {
std::cerr << "Error: Don't know how to handle Knob Type: " << id << std::endl; assert(0);
}
return pmt::pmt_t();
}
|