aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Csete <oz9aec@gmail.com>2016-10-03 22:47:05 +0200
committerDimitri Stolnikov <horiz0n@gmx.net>2017-02-27 22:26:26 +0100
commit6ea6c19028f8a93c3a942856def5afcf894cba9d (patch)
tree15337f26d7bc999368b6389ffdcaa816600bb12d
parent0dc8154f087a0b2b9b2e53351592d16e3c278786 (diff)
rfspace: Send periodic keep-alive packets.
This patch enables sending keep-alive packets at 1 minute interval to RFSpace networked radios. Without this the TCP connection to the radio is closed after about 5 minutes (by the OS?).
-rw-r--r--lib/rfspace/rfspace_source_c.cc34
-rw-r--r--lib/rfspace/rfspace_source_c.h3
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/rfspace/rfspace_source_c.cc b/lib/rfspace/rfspace_source_c.cc
index f9c587d..74708c6 100644
--- a/lib/rfspace/rfspace_source_c.cc
+++ b/lib/rfspace/rfspace_source_c.cc
@@ -475,6 +475,16 @@ rfspace_source_c::rfspace_source_c (const std::string &args)
set_sample_rate( 240000 );
set_bandwidth( 0 );
}
+
+ /* start TCP keepalive thread */
+ if ( RFSPACE_NETSDR == _radio ||
+ RFSPACE_SDR_IP == _radio ||
+ RFSPACE_CLOUDIQ == _radio )
+ {
+ _run_tcp_keepalive_task = true;
+ _thread = gr::thread::thread( boost::bind(&rfspace_source_c::tcp_keepalive_task, this) );
+ }
+
#if 0
std::cerr << "sample_rates: " << get_sample_rates().to_pp_string() << std::endl;
std::cerr << "sample rate: " << (uint32_t)get_sample_rate() << std::endl;
@@ -505,6 +515,12 @@ rfspace_source_c::~rfspace_source_c ()
_thread.join();
}
+ else
+ {
+ _run_tcp_keepalive_task = false;
+ _thread.interrupt();
+ _thread.join();
+ }
close(_usb);
@@ -580,6 +596,8 @@ bool rfspace_source_c::transaction( const unsigned char *cmd, size_t size,
}
else
{
+ boost::mutex::scoped_lock lock(_tcp_lock);
+
#ifdef USE_ASIO
_t.write_some( boost::asio::buffer(cmd, size) );
@@ -730,6 +748,22 @@ void rfspace_source_c::usb_read_task()
}
}
+/* send periodic status requests to keep TCP connection alive */
+void rfspace_source_c::tcp_keepalive_task()
+{
+ std::vector< unsigned char > response;
+ unsigned char status_pkt[] = { 0x04, 0x20, 0x05, 0x00 };
+
+ if ( -1 == _tcp )
+ return;
+
+ while ( _run_tcp_keepalive_task )
+ {
+ boost::this_thread::sleep_for(boost::chrono::seconds(60));
+ transaction( status_pkt, sizeof(status_pkt), response );
+ }
+}
+
bool rfspace_source_c::start()
{
_sequence = 0;
diff --git a/lib/rfspace/rfspace_source_c.h b/lib/rfspace/rfspace_source_c.h
index 7d89ddc..c656063 100644
--- a/lib/rfspace/rfspace_source_c.h
+++ b/lib/rfspace/rfspace_source_c.h
@@ -129,6 +129,7 @@ private: /* functions */
std::vector< unsigned char > &response );
void usb_read_task();
+ void tcp_keepalive_task();
private: /* members */
enum radio_type
@@ -162,6 +163,8 @@ private: /* members */
gr::thread::thread _thread;
bool _run_usb_read_task;
+ bool _run_tcp_keepalive_task;
+ boost::mutex _tcp_lock;
boost::circular_buffer<gr_complex> *_fifo;
boost::mutex _fifo_lock;