summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dabOutput/dabOutput.h6
-rw-r--r--src/dabOutput/dabOutputZMQ.cpp9
2 files changed, 13 insertions, 2 deletions
diff --git a/src/dabOutput/dabOutput.h b/src/dabOutput/dabOutput.h
index 72a15d4..6048d51 100644
--- a/src/dabOutput/dabOutput.h
+++ b/src/dabOutput/dabOutput.h
@@ -278,9 +278,15 @@ struct zmq_dab_message_t
}
uint32_t version;
int16_t buflen[NUM_FRAMES_PER_ZMQ_MESSAGE];
+ /* The head stops here. Use the macro below to calculate
+ * the head size.
+ */
+
uint8_t buf[NUM_FRAMES_PER_ZMQ_MESSAGE*6144];
};
+#define ZMQ_DAB_MESSAGE_HEAD_LENGTH (4 + NUM_FRAMES_PER_ZMQ_MESSAGE*2)
+
// -------------- ZeroMQ message queue ------------------
class DabOutputZMQ : public DabOutput
{
diff --git a/src/dabOutput/dabOutputZMQ.cpp b/src/dabOutput/dabOutputZMQ.cpp
index ac26403..6a9d669 100644
--- a/src/dabOutput/dabOutputZMQ.cpp
+++ b/src/dabOutput/dabOutputZMQ.cpp
@@ -70,6 +70,7 @@ int DabOutputZMQ::Write(void* buffer, int size)
{
int offset = 0;
+ // Increment the offset by the accumulated frame offsets
for (int i = 0; i < zmq_message_ix; i++) {
offset += zmq_message.buflen[i];
}
@@ -77,12 +78,17 @@ int DabOutputZMQ::Write(void* buffer, int size)
if (offset + size > NUM_FRAMES_PER_ZMQ_MESSAGE*6144) {
throw std::runtime_error("FAULT: invalid ETI frame size!");
}
+
+ // Append the new frame to our message
memcpy(zmq_message.buf + offset, buffer, size);
zmq_message.buflen[zmq_message_ix] = size;
zmq_message_ix++;
+ // As soon as we have NUM_FRAMES_PER_ZMQ_MESSAGE frames, we transmit
if (zmq_message_ix == NUM_FRAMES_PER_ZMQ_MESSAGE) {
- int full_length = 0;
+
+ // Size of the header:
+ int full_length = ZMQ_DAB_MESSAGE_HEAD_LENGTH;
for (int i = 0; i < NUM_FRAMES_PER_ZMQ_MESSAGE; i++) {
full_length += zmq_message.buflen[i];
@@ -93,7 +99,6 @@ int DabOutputZMQ::Write(void* buffer, int size)
const int flags = 0;
zmq_send(zmq_pub_sock_,
(uint8_t*)&zmq_message,
- NUM_FRAMES_PER_ZMQ_MESSAGE * sizeof(*zmq_message.buflen) +
full_length, flags);
for (int i = 0; i < NUM_FRAMES_PER_ZMQ_MESSAGE; i++) {