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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/*
* Copyright 2011-2013 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "block_gateway_impl.h"
#include <gnuradio/io_signature.h>
#include <boost/bind.hpp>
#include <iostream>
namespace gr {
/***********************************************************************
* Helper routines
**********************************************************************/
template <typename OutType, typename InType>
void copy_pointers(OutType& out, const InType& in)
{
out.resize(in.size());
for (size_t i = 0; i < in.size(); i++) {
out[i] = (void*)(in[i]);
}
}
block_gateway::sptr block_gateway::make(feval_ll* handler,
const std::string& name,
gr::io_signature::sptr in_sig,
gr::io_signature::sptr out_sig,
const block_gw_work_type work_type,
const unsigned factor)
{
return block_gateway::sptr(
new block_gateway_impl(handler, name, in_sig, out_sig, work_type, factor));
}
block_gateway_impl::block_gateway_impl(feval_ll* handler,
const std::string& name,
gr::io_signature::sptr in_sig,
gr::io_signature::sptr out_sig,
const block_gw_work_type work_type,
const unsigned factor)
: block(name, in_sig, out_sig), _handler(handler), _work_type(work_type)
{
switch (_work_type) {
case GR_BLOCK_GW_WORK_GENERAL:
_decim = 1; // not relevant, but set anyway
_interp = 1; // not relevant, but set anyway
break;
case GR_BLOCK_GW_WORK_SYNC:
_decim = 1;
_interp = 1;
this->set_fixed_rate(true);
break;
case GR_BLOCK_GW_WORK_DECIM:
_decim = factor;
_interp = 1;
break;
case GR_BLOCK_GW_WORK_INTERP:
_decim = 1;
_interp = factor;
this->set_output_multiple(_interp);
break;
}
}
void block_gateway_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required)
{
switch (_work_type) {
case GR_BLOCK_GW_WORK_GENERAL:
_message.action = block_gw_message_type::ACTION_FORECAST;
_message.forecast_args_noutput_items = noutput_items;
_message.forecast_args_ninput_items_required = ninput_items_required;
_handler->calleval(0);
ninput_items_required = _message.forecast_args_ninput_items_required;
return;
default:
unsigned ninputs = ninput_items_required.size();
for (unsigned i = 0; i < ninputs; i++)
ninput_items_required[i] = fixed_rate_noutput_to_ninput(noutput_items);
return;
}
}
int block_gateway_impl::general_work(int noutput_items,
gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items)
{
switch (_work_type) {
case GR_BLOCK_GW_WORK_GENERAL:
_message.action = block_gw_message_type::ACTION_GENERAL_WORK;
_message.general_work_args_noutput_items = noutput_items;
_message.general_work_args_ninput_items = ninput_items;
copy_pointers(_message.general_work_args_input_items, input_items);
_message.general_work_args_output_items = output_items;
_handler->calleval(0);
return _message.general_work_args_return_value;
default:
int r = work(noutput_items, input_items, output_items);
if (r > 0)
consume_each(r * _decim / _interp);
return r;
}
}
int block_gateway_impl::work(int noutput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items)
{
_message.action = block_gw_message_type::ACTION_WORK;
_message.work_args_ninput_items = fixed_rate_noutput_to_ninput(noutput_items);
if (_message.work_args_ninput_items == 0)
return -1;
_message.work_args_noutput_items = noutput_items;
copy_pointers(_message.work_args_input_items, input_items);
_message.work_args_output_items = output_items;
_handler->calleval(0);
return _message.work_args_return_value;
}
int block_gateway_impl::fixed_rate_noutput_to_ninput(int noutput_items)
{
return (noutput_items * _decim / _interp) + history() - 1;
}
int block_gateway_impl::fixed_rate_ninput_to_noutput(int ninput_items)
{
return std::max(0, ninput_items - (int)history() + 1) * _interp / _decim;
}
bool block_gateway_impl::start(void)
{
_message.action = block_gw_message_type::ACTION_START;
_handler->calleval(0);
return _message.start_args_return_value;
}
bool block_gateway_impl::stop(void)
{
_message.action = block_gw_message_type::ACTION_STOP;
_handler->calleval(0);
return _message.stop_args_return_value;
}
block_gw_message_type& block_gateway_impl::block_message(void) { return _message; }
} /* namespace gr */
|