gr-gmr1: Add special file sink to record RACH in text format
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
parent
98fec6650d
commit
2efc4ddc4e
|
@ -22,5 +22,6 @@ install(FILES
|
|||
gsmtap_sink.xml
|
||||
rach_demod.xml
|
||||
rach_detect_fft.xml
|
||||
rach_file_sink.xml
|
||||
DESTINATION share/gnuradio/grc/blocks
|
||||
)
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0"?>
|
||||
<block>
|
||||
<name>RACH File Sink</name>
|
||||
<key>rach_file_sink</key>
|
||||
<category>GMR-1</category>
|
||||
<import>from gnuradio import gmr1</import>
|
||||
<make>gmr1.rach_file_sink($filename, $center_freq, $sample_rate)</make>
|
||||
<param>
|
||||
<name>Filename</name>
|
||||
<key>filename</key>
|
||||
<type>string</type>
|
||||
</param>
|
||||
<param>
|
||||
<name>Center Frequency</name>
|
||||
<key>center_freq</key>
|
||||
<value>0</value>
|
||||
<type>float</type>
|
||||
</param>
|
||||
<param>
|
||||
<name>Sample Rate</name>
|
||||
<key>sample_rate</key>
|
||||
<value>0</value>
|
||||
<type>float</type>
|
||||
</param>
|
||||
<sink>
|
||||
<name>pdus</name>
|
||||
<type>message</type>
|
||||
</sink>
|
||||
</block>
|
|
@ -26,5 +26,6 @@ install(FILES
|
|||
gsmtap_sink.h
|
||||
rach_demod.h
|
||||
rach_detect_fft.h
|
||||
rach_file_sink.h
|
||||
DESTINATION include/gnuradio/gmr1
|
||||
)
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* Copyright 2015 Sylvain Munaut <tnt@246tNt.com>
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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 this software; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_GR_GMR1_RACH_FILE_SINK_H
|
||||
#define INCLUDED_GR_GMR1_RACH_FILE_SINK_H
|
||||
|
||||
#include <gnuradio/gmr1/api.h>
|
||||
|
||||
#include <gnuradio/blocks/pdu.h>
|
||||
#include <gnuradio/block.h>
|
||||
|
||||
namespace gr {
|
||||
namespace gmr1 {
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
* \ingroup
|
||||
*/
|
||||
class GR_GMR1_API rach_file_sink : virtual public block
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr<rach_file_sink> sptr;
|
||||
|
||||
static sptr make(const std::string &filename,
|
||||
const double center_freq, const double sample_rate);
|
||||
|
||||
virtual std::string filename() const = 0;
|
||||
|
||||
virtual double center_freq() const = 0;
|
||||
virtual double sample_rate() const = 0;
|
||||
|
||||
virtual void set_center_freq(const double center_freq) = 0;
|
||||
virtual void set_sample_rate(const double sample_rate) = 0;
|
||||
};
|
||||
|
||||
} // namespace gmr1
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_GR_GMR1_RACH_FILE_SINK_H */
|
|
@ -46,6 +46,7 @@ list(APPEND gmr1_sources
|
|||
gsmtap_sink_impl.cc
|
||||
rach_demod_impl.cc
|
||||
rach_detect_fft_impl.cc
|
||||
rach_file_sink_impl.cc
|
||||
)
|
||||
|
||||
add_library(gnuradio-gmr1 SHARED ${gmr1_sources})
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* Copyright 2015 Sylvain Munaut <tnt@246tNt.com>
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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 this software; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <cstdio>
|
||||
|
||||
#include <gnuradio/io_signature.h>
|
||||
|
||||
#include "rach_file_sink_impl.h"
|
||||
|
||||
|
||||
namespace gr {
|
||||
namespace gmr1 {
|
||||
|
||||
rach_file_sink::sptr
|
||||
rach_file_sink::make(const std::string &filename,
|
||||
const double center_freq, const double sample_rate)
|
||||
{
|
||||
return gnuradio::get_initial_sptr(
|
||||
new rach_file_sink_impl(filename, center_freq, sample_rate)
|
||||
);
|
||||
}
|
||||
|
||||
rach_file_sink_impl::rach_file_sink_impl(const std::string &filename,
|
||||
const double center_freq,
|
||||
const double sample_rate)
|
||||
: gr::block("rach_file_sink",
|
||||
io_signature::make(0, 0, 0),
|
||||
io_signature::make(0, 0, 0)),
|
||||
d_filename(filename),
|
||||
d_center_freq(center_freq), d_sample_rate(sample_rate)
|
||||
{
|
||||
message_port_register_in(PDU_PORT_ID);
|
||||
set_msg_handler(PDU_PORT_ID, boost::bind(&rach_file_sink_impl::send_pdu, this, _1));
|
||||
|
||||
this->d_fh = fopen(filename.c_str(), "a");
|
||||
if (!this->d_fh)
|
||||
throw std::runtime_error("Unable to open output file");
|
||||
}
|
||||
|
||||
rach_file_sink_impl::~rach_file_sink_impl()
|
||||
{
|
||||
fclose(this->d_fh);
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
rach_file_sink_impl::filename() const
|
||||
{
|
||||
return this->d_filename;
|
||||
}
|
||||
|
||||
double
|
||||
rach_file_sink_impl::center_freq() const
|
||||
{
|
||||
return this->d_center_freq;
|
||||
}
|
||||
|
||||
double
|
||||
rach_file_sink_impl::sample_rate() const
|
||||
{
|
||||
return this->d_sample_rate;
|
||||
}
|
||||
|
||||
void
|
||||
rach_file_sink_impl::set_center_freq(const double center_freq)
|
||||
{
|
||||
this->d_center_freq = center_freq;
|
||||
}
|
||||
|
||||
void
|
||||
rach_file_sink_impl::set_sample_rate(const double sample_rate)
|
||||
{
|
||||
this->d_sample_rate = sample_rate;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
rach_file_sink_impl::start()
|
||||
{
|
||||
/* Nothing yet */
|
||||
}
|
||||
|
||||
bool
|
||||
rach_file_sink_impl::stop()
|
||||
{
|
||||
fflush(this->d_fh);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
rach_file_sink_impl::send_pdu(pmt::pmt_t pdu)
|
||||
{
|
||||
static const pmt::pmt_t key_sb_mask = pmt::string_to_symbol("sb_mask");
|
||||
static const pmt::pmt_t key_freq = pmt::string_to_symbol("freq");
|
||||
|
||||
pmt::pmt_t meta = pmt::car(pdu);
|
||||
pmt::pmt_t vector = pmt::cdr(pdu);
|
||||
size_t len = pmt::length(vector);
|
||||
size_t offset(0);
|
||||
const uint8_t* rach = (const uint8_t*) pmt::uniform_vector_elements(vector, offset);
|
||||
|
||||
/* Validate */
|
||||
if (!is_dict(meta) ||
|
||||
!dict_has_key(meta, key_sb_mask) ||
|
||||
!dict_has_key(meta, key_freq))
|
||||
throw std::runtime_error("Invalid RACH PDU");
|
||||
|
||||
/* Grab SB_Mask & freq */
|
||||
uint8_t sb_mask = pmt::to_long(pmt::dict_ref(meta, key_sb_mask, pmt::PMT_NIL));
|
||||
double freq = pmt::to_double(pmt::dict_ref(meta, key_freq, pmt::PMT_NIL));
|
||||
|
||||
fprintf(this->d_fh, "%02hhx %.17g %.17g ",
|
||||
sb_mask,
|
||||
freq,
|
||||
this->d_center_freq + (this->d_sample_rate * freq / (2.0 * M_PI))
|
||||
);
|
||||
|
||||
/* Raw bytes */
|
||||
for (int i=0; i<len; i++)
|
||||
fprintf(this->d_fh, "%02hhx", rach[i]);
|
||||
|
||||
/* EOL */
|
||||
fprintf(this->d_fh, "\n");
|
||||
}
|
||||
|
||||
} // namespace gmr1
|
||||
} // namespace gr
|
|
@ -0,0 +1,66 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* Copyright 2015 Sylvain Munaut <tnt@246tNt.com>
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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 this software; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef INCLUDED_GR_GMR1_RACH_FILE_SINK_IMPL_H
|
||||
#define INCLUDED_GR_GMR1_RACH_FILE_SINK_IMPL_H
|
||||
|
||||
#include <gnuradio/gmr1/rach_file_sink.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace gr {
|
||||
namespace gmr1 {
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
* \ingroup gmr1
|
||||
*/
|
||||
class rach_file_sink_impl : public rach_file_sink
|
||||
{
|
||||
private:
|
||||
std::string d_filename;
|
||||
double d_center_freq;
|
||||
double d_sample_rate;
|
||||
|
||||
FILE *d_fh;
|
||||
|
||||
void send_pdu(pmt::pmt_t pdu);
|
||||
|
||||
public:
|
||||
rach_file_sink_impl(const std::string &filename,
|
||||
const double center_freq, const double sample_rate);
|
||||
virtual ~rach_file_sink_impl();
|
||||
|
||||
std::string filename() const;
|
||||
double center_freq() const;
|
||||
double sample_rate() const;
|
||||
|
||||
void set_center_freq(const double center_freq);
|
||||
void set_sample_rate(const double sample_rate);
|
||||
|
||||
bool start();
|
||||
bool stop();
|
||||
};
|
||||
|
||||
} // namespace gmr1
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_GR_GMR1_RACH_FILE_SINK_IMPL_H */
|
|
@ -13,6 +13,7 @@
|
|||
#include "gnuradio/gmr1/gsmtap_sink.h"
|
||||
#include "gnuradio/gmr1/rach_demod.h"
|
||||
#include "gnuradio/gmr1/rach_detect_fft.h"
|
||||
#include "gnuradio/gmr1/rach_file_sink.h"
|
||||
%}
|
||||
|
||||
%include "gnuradio/gmr1/burst_to_tagged_stream.h"
|
||||
|
@ -26,3 +27,6 @@ GR_SWIG_BLOCK_MAGIC2(gmr1, rach_demod);
|
|||
|
||||
%include "gnuradio/gmr1/rach_detect_fft.h"
|
||||
GR_SWIG_BLOCK_MAGIC2(gmr1, rach_detect_fft);
|
||||
|
||||
%include "gnuradio/gmr1/rach_file_sink.h"
|
||||
GR_SWIG_BLOCK_MAGIC2(gmr1, rach_file_sink);
|
||||
|
|
Loading…
Reference in New Issue