Merge pull request #95 from nkaramolegos/frame_file_sink
Add sink block for saving the frame to file
This commit is contained in:
commit
4e5eec817f
|
@ -50,5 +50,6 @@ endif()
|
||||||
install(FILES
|
install(FILES
|
||||||
${enabled_blocks}
|
${enabled_blocks}
|
||||||
satnogs_ogg_source.xml
|
satnogs_ogg_source.xml
|
||||||
satnogs_noaa_apt_sink.xml DESTINATION share/gnuradio/grc/blocks
|
satnogs_noaa_apt_sink.xml
|
||||||
|
satnogs_frame_file_sink.xml DESTINATION share/gnuradio/grc/blocks
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<block>
|
||||||
|
<name>Frame File Sink</name>
|
||||||
|
<key>satnogs_frame_file_sink</key>
|
||||||
|
<category>[satnogs]</category>
|
||||||
|
<import>import satnogs</import>
|
||||||
|
<make>satnogs.frame_file_sink($prefix_name, $output_type)</make>
|
||||||
|
<!-- Make one 'param' node for every Parameter you want settable from the
|
||||||
|
GUI. Sub-nodes: * name * key (makes the value accessible as $keyname, e.g.
|
||||||
|
in the make node) * type -->
|
||||||
|
|
||||||
|
<param>
|
||||||
|
<name>Prefix name</name>
|
||||||
|
<key>prefix_name</key>
|
||||||
|
<value>test</value>
|
||||||
|
<type>string</type>
|
||||||
|
</param>
|
||||||
|
|
||||||
|
<param>
|
||||||
|
<name>Output type</name>
|
||||||
|
<key>output_type</key>
|
||||||
|
<type>enum</type>
|
||||||
|
<option>
|
||||||
|
<name>Clear Text</name>
|
||||||
|
<key>0</key>
|
||||||
|
</option>
|
||||||
|
<option>
|
||||||
|
<name>Hex</name>
|
||||||
|
<key>1</key>
|
||||||
|
</option>
|
||||||
|
<option>
|
||||||
|
<name>Binary</name>
|
||||||
|
<key>2</key>
|
||||||
|
</option>
|
||||||
|
</param>
|
||||||
|
|
||||||
|
<sink>
|
||||||
|
<name>frame</name>
|
||||||
|
<type>message</type>
|
||||||
|
</sink>
|
||||||
|
|
||||||
|
</block>
|
|
@ -64,5 +64,6 @@ endif()
|
||||||
install(FILES
|
install(FILES
|
||||||
${HEADER_FILES}
|
${HEADER_FILES}
|
||||||
ogg_source.h
|
ogg_source.h
|
||||||
noaa_apt_sink.h DESTINATION include/satnogs
|
noaa_apt_sink.h
|
||||||
|
frame_file_sink.h DESTINATION include/satnogs
|
||||||
)
|
)
|
|
@ -0,0 +1,55 @@
|
||||||
|
/* -*- c++ -*- */
|
||||||
|
/*
|
||||||
|
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017, Libre Space Foundation <http://librespacefoundation.org/>
|
||||||
|
*
|
||||||
|
* This program 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 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INCLUDED_SATNOGS_FRAME_FILE_SINK_H
|
||||||
|
#define INCLUDED_SATNOGS_FRAME_FILE_SINK_H
|
||||||
|
|
||||||
|
#include <satnogs/api.h>
|
||||||
|
#include <gnuradio/block.h>
|
||||||
|
|
||||||
|
namespace gr
|
||||||
|
{
|
||||||
|
namespace satnogs
|
||||||
|
{
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief <+description of block+>
|
||||||
|
* \ingroup satnogs
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class SATNOGS_API frame_file_sink : virtual public gr::block
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef boost::shared_ptr<frame_file_sink> sptr;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Frame to file, sink block
|
||||||
|
* @param prefix_name Prefix of the file name, including the directory path
|
||||||
|
* @param output_type Format type of the output file, txt, hex, bin
|
||||||
|
*/
|
||||||
|
static sptr
|
||||||
|
make (const std::string& prefix_name, int output_type);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace satnogs
|
||||||
|
} // namespace gr
|
||||||
|
|
||||||
|
#endif /* INCLUDED_SATNOGS_FRAME_FILE_SINK_H */
|
||||||
|
|
|
@ -62,7 +62,8 @@ list(APPEND satnogs_sources
|
||||||
qb50_deframer_impl.cc
|
qb50_deframer_impl.cc
|
||||||
waterfall_sink_impl.cc
|
waterfall_sink_impl.cc
|
||||||
ogg_source_impl.cc
|
ogg_source_impl.cc
|
||||||
noaa_apt_sink_impl.cc)
|
noaa_apt_sink_impl.cc
|
||||||
|
frame_file_sink_impl.cc)
|
||||||
|
|
||||||
if(${INCLUDE_DEBUG_BLOCKS})
|
if(${INCLUDE_DEBUG_BLOCKS})
|
||||||
list(APPEND satnogs_sources ${satnogs_debug_sources})
|
list(APPEND satnogs_sources ${satnogs_debug_sources})
|
||||||
|
|
|
@ -0,0 +1,145 @@
|
||||||
|
/* -*- c++ -*- */
|
||||||
|
/*
|
||||||
|
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017, Libre Space Foundation <http://librespacefoundation.org/>
|
||||||
|
*
|
||||||
|
* This program 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 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gnuradio/io_signature.h>
|
||||||
|
#include "frame_file_sink_impl.h"
|
||||||
|
|
||||||
|
namespace gr
|
||||||
|
{
|
||||||
|
namespace satnogs
|
||||||
|
{
|
||||||
|
|
||||||
|
frame_file_sink::sptr
|
||||||
|
frame_file_sink::make (const std::string& prefix_name, int output_type)
|
||||||
|
{
|
||||||
|
return gnuradio::get_initial_sptr (
|
||||||
|
new frame_file_sink_impl (prefix_name, output_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The private constructor
|
||||||
|
*/
|
||||||
|
frame_file_sink_impl::frame_file_sink_impl (const std::string& prefix_name,
|
||||||
|
int output_type) :
|
||||||
|
gr::block ("frame_file_sink", gr::io_signature::make (0, 0, 0),
|
||||||
|
gr::io_signature::make (0, 0, 0)),
|
||||||
|
d_prefix_name (prefix_name),
|
||||||
|
d_output_type (output_type)
|
||||||
|
{
|
||||||
|
message_port_register_in (pmt::mp ("frame"));
|
||||||
|
set_msg_handler (
|
||||||
|
pmt::mp ("frame"),
|
||||||
|
boost::bind (&frame_file_sink_impl::msg_handler_frame, this, _1));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Our virtual destructor.
|
||||||
|
*/
|
||||||
|
frame_file_sink_impl::~frame_file_sink_impl ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
frame_file_sink_impl::msg_handler_frame (pmt::pmt_t msg)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* check for the current UTC time */
|
||||||
|
std::stringstream tmp_time;
|
||||||
|
std::time_t t = std::time (nullptr);
|
||||||
|
tmp_time << std::put_time (std::gmtime (&t), "%FT%H-%M-%S");
|
||||||
|
std::string time2string = tmp_time.str ();
|
||||||
|
|
||||||
|
/* create name of the file according prefix and timestamp */
|
||||||
|
std::string filename;
|
||||||
|
filename.append (d_prefix_name);
|
||||||
|
filename.append ("_");
|
||||||
|
filename.append (time2string);
|
||||||
|
|
||||||
|
uint8_t *su;
|
||||||
|
|
||||||
|
switch (d_output_type)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
/* add .txt to filename */
|
||||||
|
filename.append (".txt");
|
||||||
|
FILE *fd = fopen (filename.c_str (), "w");
|
||||||
|
if (fd == NULL) {
|
||||||
|
throw std::invalid_argument ("Error opening file");
|
||||||
|
|
||||||
|
}
|
||||||
|
fwrite ((const char *) pmt::blob_data (msg), pmt::blob_length (msg),
|
||||||
|
1, fd);
|
||||||
|
fclose (fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
/* add .hex to filename */
|
||||||
|
filename.append (".hex");
|
||||||
|
FILE *fd = fopen (filename.c_str (), "w");
|
||||||
|
if (fd == NULL) {
|
||||||
|
throw std::invalid_argument ("Error opening file");
|
||||||
|
|
||||||
|
}
|
||||||
|
su = (uint8_t *) pmt::blob_data (msg);
|
||||||
|
std::stringstream tmp_hex;
|
||||||
|
for (size_t i = 0; i < pmt::blob_length (msg); i++) {
|
||||||
|
tmp_hex << std::hex << std::showbase << std::setw (4)
|
||||||
|
<< (uint32_t) su[i] << " ";
|
||||||
|
}
|
||||||
|
std::string str_hex = tmp_hex.str ();
|
||||||
|
fprintf (fd, "%s", str_hex.c_str ());
|
||||||
|
fclose (fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
/* add .bin to filename */
|
||||||
|
filename.append (".bin");
|
||||||
|
FILE *fd = fopen (filename.c_str (), "w");
|
||||||
|
if (fd == NULL) {
|
||||||
|
throw std::invalid_argument ("Error opening file");
|
||||||
|
|
||||||
|
}
|
||||||
|
su = (uint8_t *) pmt::blob_data (msg);
|
||||||
|
std::stringstream tmp_bin;
|
||||||
|
for (size_t i = 0; i < pmt::blob_length (msg); i++) {
|
||||||
|
tmp_bin << "0b" << std::bitset<8> (su[i]) << " ";
|
||||||
|
}
|
||||||
|
std::string str_bin = tmp_bin.str ();
|
||||||
|
fprintf (fd, "%s", str_bin.c_str ());
|
||||||
|
fclose (fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw std::invalid_argument ("Invalid format");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace satnogs */
|
||||||
|
} /* namespace gr */
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/* -*- c++ -*- */
|
||||||
|
/*
|
||||||
|
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017, Libre Space Foundation <http://librespacefoundation.org/>
|
||||||
|
*
|
||||||
|
* This program 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 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INCLUDED_SATNOGS_FRAME_FILE_SINK_IMPL_H
|
||||||
|
#define INCLUDED_SATNOGS_FRAME_FILE_SINK_IMPL_H
|
||||||
|
|
||||||
|
#include <satnogs/frame_file_sink.h>
|
||||||
|
|
||||||
|
namespace gr
|
||||||
|
{
|
||||||
|
namespace satnogs
|
||||||
|
{
|
||||||
|
|
||||||
|
class frame_file_sink_impl : public frame_file_sink
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const std::string d_prefix_name;
|
||||||
|
int d_output_type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
frame_file_sink_impl (const std::string& prefix_name, int output_type);
|
||||||
|
~frame_file_sink_impl ();
|
||||||
|
|
||||||
|
void
|
||||||
|
msg_handler_frame (pmt::pmt_t msg);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace satnogs
|
||||||
|
} // namespace gr
|
||||||
|
|
||||||
|
#endif /* INCLUDED_SATNOGS_FRAME_FILE_SINK_IMPL_H */
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "satnogs/ogg_encoder.h"
|
#include "satnogs/ogg_encoder.h"
|
||||||
#include "satnogs/ogg_source.h"
|
#include "satnogs/ogg_source.h"
|
||||||
#include "satnogs/noaa_apt_sink.h"
|
#include "satnogs/noaa_apt_sink.h"
|
||||||
|
#include "satnogs/frame_file_sink.h"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,3 +107,5 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, ogg_encoder);
|
||||||
GR_SWIG_BLOCK_MAGIC2(satnogs, ogg_source);
|
GR_SWIG_BLOCK_MAGIC2(satnogs, ogg_source);
|
||||||
%include "satnogs/noaa_apt_sink.h"
|
%include "satnogs/noaa_apt_sink.h"
|
||||||
GR_SWIG_BLOCK_MAGIC2(satnogs, noaa_apt_sink);
|
GR_SWIG_BLOCK_MAGIC2(satnogs, noaa_apt_sink);
|
||||||
|
%include "satnogs/frame_file_sink.h"
|
||||||
|
GR_SWIG_BLOCK_MAGIC2(satnogs, frame_file_sink);
|
||||||
|
|
Loading…
Reference in New Issue