2011-10-01 18:45:20 +00:00
|
|
|
/*!
|
|
|
|
* \file gnss_sdr_valve.cc
|
2011-12-28 21:55:11 +00:00
|
|
|
* \brief Implementation of a GNU Radio block that sends a STOP message to the
|
|
|
|
* control queue right after a specific number of samples have passed through it.
|
2018-11-14 17:28:14 +00:00
|
|
|
* \author Javier Arribas, 2018. jarribas(at)cttc.es
|
2011-10-01 18:45:20 +00:00
|
|
|
* \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2018-05-13 20:49:11 +00:00
|
|
|
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
|
|
|
* GNSS-SDR 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
|
2015-01-08 18:49:59 +00:00
|
|
|
* (at your option) any later version.
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR 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
|
2018-05-13 20:49:11 +00:00
|
|
|
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gnss_sdr_valve.h"
|
2019-03-05 07:59:04 +00:00
|
|
|
#include "control_message_factory.h" // for ControlMessageFactory
|
|
|
|
#include <glog/logging.h> // for LOG
|
|
|
|
#include <gnuradio/io_signature.h> // for io_signature
|
|
|
|
#include <algorithm> // for min
|
|
|
|
#include <cstring> // for memcpy
|
|
|
|
#include <unistd.h> // for usleep
|
2018-12-03 14:43:43 +00:00
|
|
|
#include <utility>
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
Gnss_Sdr_Valve::Gnss_Sdr_Valve(size_t sizeof_stream_item,
|
2018-12-08 17:49:31 +00:00
|
|
|
uint64_t nitems,
|
2018-11-18 12:29:54 +00:00
|
|
|
gr::msg_queue::sptr queue,
|
|
|
|
bool stop_flowgraph) : gr::sync_block("valve",
|
2019-06-17 16:13:06 +00:00
|
|
|
gr::io_signature::make(1, 20, sizeof_stream_item),
|
|
|
|
gr::io_signature::make(1, 20, sizeof_stream_item)),
|
2018-11-18 12:29:54 +00:00
|
|
|
d_nitems(nitems),
|
|
|
|
d_ncopied_items(0),
|
2018-12-03 14:43:43 +00:00
|
|
|
d_queue(std::move(queue)),
|
2018-11-18 12:29:54 +00:00
|
|
|
d_stop_flowgraph(stop_flowgraph)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2018-11-14 17:28:14 +00:00
|
|
|
d_open_valve = false;
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2012-10-28 12:38:11 +00:00
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
boost::shared_ptr<gr::block> gnss_sdr_make_valve(size_t sizeof_stream_item, uint64_t nitems, gr::msg_queue::sptr queue, bool stop_flowgraph)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2019-02-22 09:47:24 +00:00
|
|
|
boost::shared_ptr<Gnss_Sdr_Valve> valve_(new Gnss_Sdr_Valve(sizeof_stream_item, nitems, std::move(queue), stop_flowgraph));
|
2014-05-05 09:21:18 +00:00
|
|
|
return valve_;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 12:29:54 +00:00
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
boost::shared_ptr<gr::block> gnss_sdr_make_valve(size_t sizeof_stream_item, uint64_t nitems, gr::msg_queue::sptr queue)
|
2018-11-14 17:28:14 +00:00
|
|
|
{
|
2019-02-22 09:47:24 +00:00
|
|
|
boost::shared_ptr<Gnss_Sdr_Valve> valve_(new Gnss_Sdr_Valve(sizeof_stream_item, nitems, std::move(queue), true));
|
2018-11-14 17:28:14 +00:00
|
|
|
return valve_;
|
|
|
|
}
|
2012-10-28 12:38:11 +00:00
|
|
|
|
2018-11-18 12:29:54 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
void Gnss_Sdr_Valve::open_valve()
|
2018-11-14 17:28:14 +00:00
|
|
|
{
|
|
|
|
d_open_valve = true;
|
|
|
|
}
|
2018-11-18 12:29:54 +00:00
|
|
|
|
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
int Gnss_Sdr_Valve::work(int noutput_items,
|
2018-03-03 01:03:39 +00:00
|
|
|
gr_vector_const_void_star &input_items,
|
|
|
|
gr_vector_void_star &output_items)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2018-11-14 17:28:14 +00:00
|
|
|
if (d_open_valve == false)
|
|
|
|
{
|
|
|
|
if (d_ncopied_items >= d_nitems)
|
|
|
|
{
|
2018-12-03 15:25:11 +00:00
|
|
|
auto *cmf = new ControlMessageFactory();
|
2018-11-14 17:28:14 +00:00
|
|
|
d_queue->handle(cmf->GetQueueMessage(200, 0));
|
|
|
|
LOG(INFO) << "Stopping receiver, " << d_ncopied_items << " samples processed";
|
|
|
|
delete cmf;
|
|
|
|
if (d_stop_flowgraph)
|
|
|
|
{
|
|
|
|
return -1; // Done!
|
|
|
|
}
|
2018-12-03 21:08:19 +00:00
|
|
|
usleep(1000000);
|
|
|
|
return 0; // do not produce or consume
|
2018-11-14 17:28:14 +00:00
|
|
|
}
|
2018-12-08 17:49:31 +00:00
|
|
|
uint64_t n = std::min(d_nitems - d_ncopied_items, static_cast<uint64_t>(noutput_items));
|
2019-02-11 20:13:02 +00:00
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2019-06-17 21:42:16 +00:00
|
|
|
// multichannel support
|
|
|
|
for (unsigned int ch = 0; ch < output_items.size(); ch++)
|
2019-06-17 16:13:06 +00:00
|
|
|
{
|
|
|
|
memcpy(output_items[ch], input_items[ch], n * input_signature()->sizeof_stream_item(ch));
|
|
|
|
}
|
2018-11-14 17:28:14 +00:00
|
|
|
d_ncopied_items += n;
|
|
|
|
return n;
|
|
|
|
}
|
2019-06-17 21:42:16 +00:00
|
|
|
for (unsigned int ch = 0; ch < output_items.size(); ch++)
|
2019-06-17 16:13:06 +00:00
|
|
|
{
|
|
|
|
memcpy(output_items[ch], input_items[ch], noutput_items * input_signature()->sizeof_stream_item(ch));
|
|
|
|
}
|
2018-12-03 21:08:19 +00:00
|
|
|
return noutput_items;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|