c++ Manchester-L(Biphase-L)在GNU Radio中的有限状态机实现

twh00eeo  于 2023-04-01  发布在  其他
关注(0)|答案(1)|浏览(229)

由于GnuRadio的选择有限,我正在实现线路编码块。我已经完成了NRZ的实现和测试(L\M\S)使用有限状态机(FSM)并且它们看起来工作正常。现在,我尝试实现曼彻斯特(L\M\S),从L作为基线开始。波形可以在下面的图表中看到。摘自NASA的深空网络遥测数据解码(208)

有限状态机的构造如下所示。我决定使用FSM,因为在我看来,它是实现行代码的一种非常标准化的方式。
下面是用于测试实现的gnuradio流程图。通过发送BPSK信号进行测试(具有CCSDS Reed-Solomon +加扰器)发送到能够接收信号并处理遥测的外部设备。该实现已经用NRZ-L\M\S成功测试。CCSDS帧从文件读取,解包并发送到OOT块debug_linecode_bp以进行曼彻斯特编码曼彻斯特编码之后是OOT块debug_pulseshape_pam_2块,其将滤波器抽头和每个符号的样本数量作为自变量。接下来是一个OOT块debug_bpsk_modulator,它执行简单的BPSKMap(Inphase = in[i],quadrature = 0)。

头文件的代码如下所示

#ifndef INCLUDED_BASEBAND_DEBUG_LINECODE_BP_IMPL_H
#define INCLUDED_BASEBAND_DEBUG_LINECODE_BP_IMPL_H

#include <baseband/debug_linecode_bp.h>

namespace gr {
namespace baseband {

class debug_linecode_bp_impl : public debug_linecode_bp
{
 private:
  char last_state;
  int d_code;
  void fsm_decode_state(char state, unsigned char &bit0, unsigned char &bit1);
  void fsm_encode_state(int code, unsigned char input, char last_state, char &next_state);
 public:
  debug_linecode_bp_impl(int code);
  ~debug_linecode_bp_impl();

  // Where all the action really happens
  int work(int noutput_items,
     gr_vector_const_void_star &input_items,
     gr_vector_void_star &output_items);
};

 } // namespace baseband
 } // namespace gr

#endif /* INCLUDED_BASEBAND_DEBUG_LINECODE_BP_IMPL_H */

下面是实现文件

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

#include <gnuradio/io_signature.h>
#include "debug_linecode_bp_impl.h"
#include <iostream>
using namespace std;
namespace gr {
namespace baseband {

debug_linecode_bp::sptr
debug_linecode_bp::make(int code)
{
  return gnuradio::get_initial_sptr
    (new debug_linecode_bp_impl(code));
}

/*
 * The private constructor
 */
debug_linecode_bp_impl::debug_linecode_bp_impl(int code)
  : gr::sync_interpolator("debug_linecode_bp",
              gr::io_signature::make(1, 1, sizeof(unsigned char)),
              gr::io_signature::make(1, 1, sizeof(unsigned char)), 2),
d_code(code),last_state('a')
{}

/*
 * Our virtual destructor.
 */
debug_linecode_bp_impl::~debug_linecode_bp_impl()
{
}
void
debug_linecode_bp_impl::fsm_decode_state(char state, unsigned char &bit0, unsigned char &bit1)
{
  switch(state)
{
case 'a':
  bit0 = 0x00;
  bit1 = 0x00;
  break;
case 'b':
  bit0 = 0x00;
  bit1 = 0x01;
  break;
case 'c':
  bit0 = 0x01;
  bit1 = 0x01;
  break;
case 'd':
  bit0 = 0x01;
  bit1 = 0x00;
  break;
}
}

void
debug_linecode_bp_impl::fsm_encode_state(int code, unsigned char input, char last_state, char &next_state)
{
  switch(code)
{
case 0://Biphae-L
  switch(last_state)
    {
    case 'a': //Illegal state
      next_state = 'b';
      cout << "Illegal state [a] encountered" << endl;
      break;
    case 'b':
      next_state = (input & 0x01) ? 'd' : 'b';
      break;
    case 'c': //Illegal state
      next_state = 'b';
      cout << "Illegal state [b] encountered" << endl;
      break;
    case 'd':
      next_state = (input & 0x01) ? 'd' : 'b';
      break;
    }
  break;
case 1://Biphase-S
  switch(last_state)
    {
    case 'a':
      next_state = (input & 0x01) ? 'c' : 'd';
      break;
    case 'b':
      next_state = (input & 0x01) ? 'a' : 'b';
      break;
    case 'c': 
      next_state = (input & 0x01) ? 'a' : 'b';
      break;
    case 'd':
      next_state = (input & 0x01) ? 'c' : 'd';
      break;
    }
  break;
case 2://Biphase-M
  switch(last_state)
    {
    case 'a':
      next_state = (input & 0x01) ? 'd' : 'c';
      break;
    case 'b':
      next_state = (input & 0x01) ? 'b' : 'a';
      break;
    case 'c': 
      next_state = (input & 0x01) ? 'b' : 'a';
      break;
    case 'd':
      next_state = (input & 0x01) ? 'd' : 'c';
      break;
    }
  break;
}
}

int
debug_linecode_bp_impl::work(int noutput_items,
             gr_vector_const_void_star &input_items,
             gr_vector_void_star &output_items)
{
  const unsigned char *in = (const unsigned char *) input_items[0];
  unsigned char *out = (unsigned char *) output_items[0];

  char next_state;
  unsigned char bit0;
  unsigned char bit1;
  for (int i = 0; i < noutput_items/2; i++) {
fsm_encode_state(d_code,in[i],last_state, next_state);
fsm_decode_state(next_state, bit0, bit1);
for (int j = 0; j < 2; j++) {
  out[i + j]     = bit0;
  out[i + j + 1] = bit1;
}
last_state = next_state;
  }

  // Tell runtime system how many output items we produced.
  return noutput_items;
}

} /* namespace baseband */
} /* namespace gr */

到目前为止,测试还没有成功。我用来从这个流图接收信号的设备甚至不能拾取一个数据包。我的结论是错误来自曼彻斯特编码器。任何关于上面代码的想法都是非常受欢迎的。
谢谢。

cwtwac6a

cwtwac6a1#

一段时间后,我发现了代码中的错误。实际上,问题出在复制输出的方式上。我所要做的就是删除内部的for循环并直接使用memcpy复制输出。这就是现在的work函数。

int
debug_linecode_bp_impl::work(int noutput_items,
             gr_vector_const_void_star &input_items,
             gr_vector_void_star &output_items)
{
  const unsigned char *in = (const unsigned char *) input_items[0];
  unsigned char *out = (unsigned char *) output_items[0];

  char next_state;
  unsigned char bit0;
  unsigned char bit1;
  vector<unsigned char> bits;
  for (int i = 0; i < noutput_items/2; i++) {
      fsm_encode_state(d_code,in[i],last_state, next_state);
      fsm_decode_state(next_state, bit0, bit1);
      bits.push_back(bit0);
      bits.push_back(bit1);
      memcpy(out,bits.data(),2);
      bits.clear();
      out+=2;
      last_state = next_state;
  }

  // Tell runtime system how many output items we produced.
  return noutput_items;
}

这是调制器输出

处的波形

相关问题