aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DabMod.cpp69
-rw-r--r--src/EtiReader.cpp16
-rw-r--r--src/EtiReader.h6
3 files changed, 48 insertions, 43 deletions
diff --git a/src/DabMod.cpp b/src/DabMod.cpp
index e48e748..a5c0de6 100644
--- a/src/DabMod.cpp
+++ b/src/DabMod.cpp
@@ -3,7 +3,7 @@
Her Majesty the Queen in Right of Canada (Communications Research
Center Canada)
- Copyright (C) 2016
+ Copyright (C) 2017
Matthias P. Braendli, matthias.braendli@mpb.li
http://opendigitalradio.org
@@ -777,51 +777,46 @@ int launch_modulator(int argc, char* argv[])
set_thread_name("modulator");
if (ediUdpInput.isEnabled()) {
- while (run_again) {
- Flowgraph flowgraph;
+ Flowgraph flowgraph;
- etiLog.level(debug) << "Build mod";
- auto modulator = make_shared<DabModulator>(
- ediReader, tiiConfig, outputRate, clockRate,
- dabMode, gainMode, digitalgain, normalise,
- filterTapsFilename);
-
- etiLog.level(debug) << "Connect";
- if (format_converter) {
- flowgraph.connect(modulator, format_converter);
- flowgraph.connect(format_converter, output);
- }
- else {
- flowgraph.connect(modulator, output);
- }
+ auto modulator = make_shared<DabModulator>(
+ ediReader, tiiConfig, outputRate, clockRate,
+ dabMode, gainMode, digitalgain, normalise,
+ filterTapsFilename);
- etiLog.level(debug) << "SetETISource";
+ if (format_converter) {
+ flowgraph.connect(modulator, format_converter);
+ flowgraph.connect(format_converter, output);
+ }
+ else {
+ flowgraph.connect(modulator, output);
+ }
#if defined(HAVE_OUTPUT_UHD)
- if (useUHDOutput) {
- ((OutputUHD*)output.get())->setETISource(modulator->getEtiSource());
- }
+ if (useUHDOutput) {
+ ((OutputUHD*)output.get())->setETISource(modulator->getEtiSource());
+ }
#endif
- etiLog.level(debug) << "Loop";
- size_t framecount = 0;
- while (true) {
- while (not ediReader.isFrameReady()) {
- ediUdpInput.rxPacket();
- }
- etiLog.level(debug) << "Frame Ready";
- framecount++;
- flowgraph.run();
- etiLog.level(debug) << "now clear";
- ediReader.clearFrame();
-
- /* Check every once in a while if the remote control
- * is still working */
- if ((framecount % 250) == 0) {
- rcs.check_faults();
+ size_t framecount = 0;
+ bool running = true;
+ while (running) {
+ while (not ediReader.isFrameReady()) {
+ bool success = ediUdpInput.rxPacket();
+ if (not success) {
+ running = false;
+ break;
}
}
+ framecount++;
+ flowgraph.run();
+ ediReader.clearFrame();
+ /* Check every once in a while if the remote control
+ * is still working */
+ if ((framecount % 250) == 0) {
+ rcs.check_faults();
+ }
}
}
else {
diff --git a/src/EtiReader.cpp b/src/EtiReader.cpp
index 3207a1f..e646392 100644
--- a/src/EtiReader.cpp
+++ b/src/EtiReader.cpp
@@ -308,7 +308,6 @@ uint32_t EtiReader::getPPSOffset()
unsigned EdiReader::getMode()
{
if (not m_fc_valid) {
- assert(false);
throw std::runtime_error("Trying to access Mode before it is ready!");
}
return m_fc.mid;
@@ -463,7 +462,6 @@ void EdiReader::add_subchannel(const EdiDecoder::eti_stc_data& stc)
void EdiReader::assemble()
{
- etiLog.level(debug) << "Calling assemble";
if (not m_proto_valid) {
throw std::logic_error("Cannot assemble EDI data before protocol");
}
@@ -529,7 +527,7 @@ int EdiUdpInput::Open(const std::string& uri)
return ret;
}
-void EdiUdpInput::rxPacket()
+bool EdiUdpInput::rxPacket()
{
const size_t packsize = 8192;
UdpPacket packet(packsize);
@@ -538,13 +536,21 @@ void EdiUdpInput::rxPacket()
if (ret == 0) {
const auto &buf = packet.getBuffer();
if (packet.getSize() == packsize) {
- fprintf(stderr, "Warning, possible UDP truncation\n");
+ etiLog.log(warn, "Warning, possible UDP truncation");
}
m_decoder.push_packet(buf);
+ return true;
}
else {
- fprintf(stderr, "Socket error: %s\n", inetErrMsg);
+ if (inetErrNo == EINTR) {
+ return false;
+ }
+ else {
+ stringstream ss;
+ ss << "EDI UDP Socket error: " << inetErrMsg;
+ throw std::runtime_error(ss.str());
+ }
}
}
diff --git a/src/EtiReader.h b/src/EtiReader.h
index 04d627d..78f0d3d 100644
--- a/src/EtiReader.h
+++ b/src/EtiReader.h
@@ -176,7 +176,11 @@ class EdiUdpInput {
bool isEnabled(void) const { return m_enabled; }
- void rxPacket(void);
+ /* Receive a packet and give it to the decoder. Returns
+ * true if a packet was received, false in case of socket
+ * read was interrupted by a signal.
+ */
+ bool rxPacket(void);
private:
bool m_enabled;