如何在 c++ 中正确读取 GRC 块"Random Source"的字节输出数据到自己的 OOT 块中?
How do I read byte output data of GRC block "Random Source" into own OOT-block in c++ correctly?
我正在在gnuradio-companion中做我的第一步,并希望在C 中为自己的三个块编码以进行信号处理。我通过gnuradio教程工作,并且对C 有一些了解,但我不是专家。
系统设置:Ubuntu 18.04.2 LtsGNU无线电3.7.13.4
我想使用grc-block"随机源"生成字节,然后将它们传递到三个插值器中,该块将创建脉冲位置符号。
"随机源"块的配置如下:最小:0最大:4(为2^m = ppm符号中的脉冲位置计数(数字样本:16或32重复:是
我的三个块是C 中的一个插值块,具有一个输入和一个输出。构造函数中的插值值为6000,这意味着输入的关系船:输出为1:6000。一个函数将输入作为参数获取,并生成类型gr_complex的向量,其脉冲位于[0]中的脉冲位置,可以为[0,1,1,2,3]。带有PPM符号的向量将返回到工作(( - 函数。
观察到的问题:第一个问题:如果"随机源"生成一个具有值0x00的字节,并且我使用std :: cout打印[0]的值,则以下错误显示在运行Gnuradio-companion的终端窗口中:p>/home/xyz/software/gnuradio/lib/python2.7/dist-packages/gnuradio/grc/gui/gui/dialogs.py:65:gtkwarning:gtk_text_buffer_emit_insert:assert' self.get_buffer((。插入(self.get_buffer((。get_end_iter((,line(
解决方案:我的解决方案是将[0]中的值复制到整数变量中。std :: cout按预期打印值。
第二个问题:如果我将"随机源"的数字从16设置为16或更高,请观察[0]中的值(将其复制到INT变量中(在端子中使用STD :: COUT值与"随机源"生成的值不匹配,并显示在" QT GUI时槽"中。我真的不知道是什么原因引起了问题。
解决方案:到目前为止尚无解决方案...
这是我的三个块的代码
namespace gr {
namespace newmodulator {
pre_mod_v2::sptr
pre_mod_v2::make(int M, float duty_cycle, int samples_per_symbol)
{
return gnuradio::get_initial_sptr
(new pre_mod_v2_impl(M, duty_cycle, samples_per_symbol));
}
/*
* The private constructor
*/
pre_mod_v2_impl::pre_mod_v2_impl(int M, float duty_cycle, int samples_per_symbol)
: gr::sync_interpolator("pre_mod_v2",
gr::io_signature::make(1, 1, sizeof(char)),
gr::io_signature::make(1, 1, sizeof(gr_complex)), samples_per_symbol + 94) /*, d_M(M), d_duty_cycle(duty_cycle), d_samples_per_symbol(samples_per_symbol)*/
{
d_M = M;
d_duty_cycle = duty_cycle;
d_samples_per_symbol = samples_per_symbol;
//Variablen die in der Funktion set_vppm_symbol benötigt werden.
count_slots_per_symbol = 0;
vppm_slots = pow(2, M);
samples_per_slot = samples_per_symbol / vppm_slots;
pulse_length = (samples_per_symbol / 100 * duty_cycle);
symbol_value = 0;
//preamble = {{0, 5}, {0, 0}, {0, 0}, {0, 0}, {0, 5}};
preamble = {{0, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 1}, {0, 0}, {0, 0},
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{0, 0}, {0, 0}, {0, 0}, {0, 1}};
}
/*
* Our virtual destructor.
*/
pre_mod_v2_impl::~pre_mod_v2_impl()
{
}
/* noutput_items = zahl (interpolation factor)
*/
int
pre_mod_v2_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
/* es werden Zeiger deklariert, die auf die Startadresse von input_items und output_items zeigen.
* Die Größe eines Zeigers wird durch typ* festgelegt
* ninput_items hat nur ein Element,
* während output_items so viele Elemente hat, wie oben durch den Interpolation-Faktor samples_per_symbol angegeben ist */
const unsigned char *in = (const unsigned char *) input_items[0];
gr_complex *out = (gr_complex *) output_items[0];
//std::cout << "symbol_value: " << in[0] << std::endl;
std::vector<gr_complex> vppm_symbols(d_samples_per_symbol + 94);
vppm_symbols = set_vppm_symbol(in, d_M, d_duty_cycle, d_samples_per_symbol);
//std::cout << "noutput_items: " << noutput_items << std::endl;
for (int i = 0; i < noutput_items; i++)
{
out[i] = vppm_symbols[i];
}
// es werden insgesamt noutput_items verarbeitet
consume_each(noutput_items);
// Tell runtime system how many output items we produced.
return noutput_items;
}
std::vector<gr_complex> pre_mod_v2_impl::set_vppm_symbol(const unsigned char* in, int &M, float &duty_cycle, int &samples_per_symbol)
{
symbol_value = in[0];
// if (!symbol_value){
// symbol_value = 0;
// }
std::cout << "symbol_value: " << static_cast<int>(in[0]) << std::endl;
std::vector<gr_complex> vppm_symbol(samples_per_symbol);
for (int i = (symbol_value * samples_per_slot); i < (symbol_value * samples_per_slot + pulse_length); i++)
{
vppm_symbol[i] = {static_cast<float>(1.0), 0};
}
vppm_symbol.insert(vppm_symbol.begin(), preamble.begin(), preamble.end());
return vppm_symbol;
}
} /* namespace newmodulator */
} /* namespace gr */
好吧,我解决了我的问题。我只将函数set_vppm_symbol的代码添加到我的工作功能中,并删除了" ablemume_each(noutput_items("行,尽管在手册中,它被描述为使用函数使我感到刺激。现在我将获得预期的输出。
- 更改.cpp程序的输入文件中数据的位置会意外更改输出
- 使用 python 或 c ++ 中的 sql 根据输入数据输出输出示例
- 尝试从 txt 文件中读取两条数据并输出它们 [C++]
- 将多个效果与 libSox 链接并读取输出数据的正确方法
- 如何将函数的输出数据存储在文本文件中
- 如何从amd gpus的显示输出中获取图像数据
- 自定义堆栈上 std::string 数据的输出
- 如何从文本文件输出数据?(学生成绩单计划)
- 为什么我的数据/输出文件为空?
- C++:如何将数据输出到多个.dat文件
- C++:将存储在List容器中的数据输出到文本文件中
- .wav C++数据输出不正确
- C++:模拟餐饮公司计费程序-无法将错误数据输出到错误文件
- 使用iomanip将数据输出格式化为具有Qt的文本文件
- matPutVariable:尝试将数据输出到mat文件时出错(matrix::serialize::WrongSize
- 如何使用类似于gcc-xml的clang生成元数据输出
- 如何使用Python从UART Beaglebone获取数据输出
- GP635T gps传感器的数据输出
- 如何在Windows控制台中将数据输出到自定义流(3>4>等)?
- 流数据输出问题