Commit f8a13b2a authored by Tobias Winchen's avatar Tobias Winchen
Browse files

Fixed whitespace and improved VLBI console output

parent 8b008971
......@@ -29,20 +29,20 @@ class VDIFHeaderView
void setDataLocation(const uint32_t* _data);
const uint32_t* getDataLocation() const;
uint32_t getVersionNumber() const;
bool isValid() const;
uint32_t getSecondsFromReferenceEpoch() const;
uint32_t getReferenceEpoch() const;
bool isValid() const;
uint32_t getSecondsFromReferenceEpoch() const;
uint32_t getReferenceEpoch() const;
size_t getTimestamp() const;
uint32_t getDataFrameNumber() const;
// Length of the data frame including the header, in units of 8 bytes
uint32_t getDataFrameLength() const;
uint32_t getNumberOfChannels() const;
uint32_t getDataFrameNumber() const;
// Length of the data frame including the header, in units of 8 bytes
uint32_t getDataFrameLength() const;
uint32_t getNumberOfChannels() const;
bool isRealDataType() const;
bool isComplexDataType() const;
// Number of bits per sample -1 (max 32/bits per sample)
uint32_t getBitsPerSample() const;
uint32_t getThreadId() const;
uint32_t getStationId() const;
bool isComplexDataType() const;
// Number of bits per sample -1 (max 32/bits per sample)
uint32_t getBitsPerSample() const;
uint32_t getThreadId() const;
uint32_t getStationId() const;
};
......@@ -52,33 +52,33 @@ class VDIFHeaderView
/// specification 1.1.1 from June 2014 for details.
class VDIFHeader : public VDIFHeaderView
{
private:
uint32_t data[8];
private:
uint32_t data[8];
public:
VDIFHeader();
VDIFHeader(const VDIFHeader &v);
VDIFHeader& operator=(const VDIFHeader& other);
public:
VDIFHeader();
VDIFHeader(const VDIFHeader &v);
VDIFHeader& operator=(const VDIFHeader& other);
// return pointer to the data block for low level manipulation
uint32_t* getData();
void setInvalid();
void setValid();
void setSecondsFromReferenceEpoch(uint32_t value);
void setReferenceEpoch(uint32_t value);
uint32_t* getData();
void setInvalid();
void setValid();
void setSecondsFromReferenceEpoch(uint32_t value);
void setReferenceEpoch(uint32_t value);
/// set reference epoch and seconds from reference epoch from POSIX time
/// stamp
void setTimeReferencesFromTimestamp(size_t);
/// converts time reference data to POSIX time
void setDataFrameNumber(uint32_t value);
void setDataFrameLength(uint32_t value);
void setNumberOfChannels(uint32_t value);
void setComplexDataType();
void setRealDataType();
void setBitsPerSample(uint32_t value);
void setThreadId(uint32_t value);
void setStationId(uint32_t value);
void setDataFrameNumber(uint32_t value);
void setDataFrameLength(uint32_t value);
void setNumberOfChannels(uint32_t value);
void setComplexDataType();
void setRealDataType();
void setBitsPerSample(uint32_t value);
void setThreadId(uint32_t value);
void setStationId(uint32_t value);
};
......
......@@ -56,13 +56,13 @@ VLBI<HandlerType>::VLBI(std::size_t buffer_bytes, std::size_t input_bitDepth,
<< _packed_voltage.size() << " byte";
_spillOver.reserve(vdifHeader.getDataFrameLength() * 8 - vlbiHeaderSize);
// number of vlbi frames per input block
size_t nSamplesPerInputBlock = _packed_voltage.size() * 8 / _output_bitDepth;
size_t frames_per_block = _packed_voltage.size() / (vdifHeader.getDataFrameLength() * 8 - vlbiHeaderSize);
// number of vlbi frames per input block
size_t nSamplesPerInputBlock = _packed_voltage.size() * 8 / _output_bitDepth;
size_t frames_per_block = _packed_voltage.size() / (vdifHeader.getDataFrameLength() * 8 - vlbiHeaderSize);
BOOST_LOG_TRIVIAL(debug) << " this correspoonds to " << frames_per_block << " - " << frames_per_block + 1 << " frames";
_outputBuffer.resize((frames_per_block+1) * vdifHeader.getDataFrameLength() * 8 );
// potetnitally invalidating the last frame
_outputBuffer.resize((frames_per_block+1) * vdifHeader.getDataFrameLength() * 8 );
// potetnitally invalidating the last frame
BOOST_LOG_TRIVIAL(info) << " Output data in VDIF format with " << _outputBuffer.size() << " bytes per buffer";
......@@ -230,7 +230,7 @@ bool VLBI<HandlerType>::operator()(RawBytes &block) {
const size_t outputBlockSize = _vdifHeader.getDataFrameLength() * 8 - vlbiHeaderSize;
const size_t totalSizeOfData = _packed_voltage.size() + _spillOver.size(); // current array + remaining of previous
size_t numberOfBlocksInOutput = totalSizeOfData / outputBlockSize;
size_t remainingBytes = outputBlockSize - _spillOver.size();
......@@ -285,8 +285,8 @@ bool VLBI<HandlerType>::operator()(RawBytes &block) {
const uint32_t samplesPerDataFrame = outputBlockSize * 8 / _output_bitDepth;
const uint32_t dataFramesPerSecond = _sampleRate / samplesPerDataFrame;
BOOST_LOG_TRIVIAL(debug) << " Samples per data frame: " << samplesPerDataFrame;
BOOST_LOG_TRIVIAL(debug) << " Dataframes per second: " << dataFramesPerSecond;
BOOST_LOG_TRIVIAL(debug) << " Samples per data frame: " << samplesPerDataFrame;
BOOST_LOG_TRIVIAL(debug) << " Dataframes per second: " << dataFramesPerSecond;
for (uint32_t ib = 0; ib < _outputBuffer.a().size(); ib += _vdifHeader.getDataFrameLength() * 8)
{
......@@ -294,19 +294,19 @@ bool VLBI<HandlerType>::operator()(RawBytes &block) {
std::copy(reinterpret_cast<uint8_t *>(_vdifHeader.getData()),
reinterpret_cast<uint8_t *>(_vdifHeader.getData()) + vlbiHeaderSize,
_outputBuffer.a().begin() + ib);
size_t i = ib / _vdifHeader.getDataFrameLength() / 8;
// invalidate rest of data so it can be dropped later.
// Needed so that the outpuitbuffer can have always the same size
if (i < numberOfBlocksInOutput)
{
_vdifHeader.setValid();
}
else
{
_vdifHeader.setInvalid();
continue;
}
size_t i = ib / _vdifHeader.getDataFrameLength() / 8;
// invalidate rest of data so it can be dropped later.
// Needed so that the outpuitbuffer can have always the same size
if (i < numberOfBlocksInOutput)
{
_vdifHeader.setValid();
}
else
{
_vdifHeader.setInvalid();
continue;
}
// update header
uint32_t dataFrame = _vdifHeader.getDataFrameNumber();
......
......@@ -15,12 +15,13 @@ namespace edd {
VDIFHeaderView::VDIFHeaderView(const uint32_t* data) : data(data) {};
void VDIFHeaderView::setDataLocation(const uint32_t* _data) {
data = _data;
};
const uint32_t* VDIFHeaderView::getDataLocation() const {
return data;
return data;
};
bool VDIFHeaderView::isValid() const {
......@@ -97,18 +98,18 @@ VDIFHeader::VDIFHeader() : VDIFHeaderView(data)
VDIFHeader::VDIFHeader(const VDIFHeader &v): VDIFHeaderView(data)
{
for (int i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
data[i] = v.getDataLocation()[i];
}
setDataLocation(data);
setDataLocation(data);
}
VDIFHeader& VDIFHeader::operator=(const VDIFHeader& other)
{
for (int i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
data[i] = other.getDataLocation()[i];
}
return *this;
return *this;
}
uint32_t *VDIFHeader::getData() { return data; }
......
......@@ -34,6 +34,9 @@ class VDIF_Sender
int port;
double max_rate;
uint32_t currentSecondFromReferenceEpoch;
size_t noOfSendFrames; // frames in last second
boost::asio::ip::udp::socket socket;
boost::asio::ip::udp::endpoint remote_endpoint;
......@@ -48,7 +51,7 @@ class VDIF_Sender
* communication.
*/
VDIF_Sender(const std::string &source_ip, const std::string &destination_ip, int port, double max_rate, boost::asio::io_service&
io_service): socket(io_service), source_ip(source_ip), destination_ip(destination_ip), port(port), max_rate(max_rate)
io_service): socket(io_service), source_ip(source_ip), destination_ip(destination_ip), port(port), max_rate(max_rate), currentSecondFromReferenceEpoch(0), noOfSendFrames(0)
{
}
......@@ -97,18 +100,31 @@ class VDIF_Sender
BOOST_LOG_TRIVIAL(debug) << " Length of first frame: " << vdifHeader.getDataFrameLength() * 8 << " bytes";
size_t counter = 0;
size_t invalidFrames = 0;
auto start = std::chrono::high_resolution_clock::now();
for(char* frame_start = block.ptr(); frame_start < block.ptr() + blockSize; frame_start += vdifHeader.getDataFrameLength() * 8)
{
vdifHeader.setDataLocation(reinterpret_cast<uint32_t*>(frame_start));
// skip invalid blocks
if (!vdifHeader.isValid())
continue;
// skip invalid blocks
if (!vdifHeader.isValid())
{
invalidFrames++;
continue;
}
if (vdifHeader.getSecondsFromReferenceEpoch() > currentSecondFromReferenceEpoch)
{
BOOST_LOG_TRIVIAL(info) << " New second frome reference epoch: " << vdifHeader.getSecondsFromReferenceEpoch() << ", send " << noOfSendFrames << " in previous second.";
BOOST_LOG_TRIVIAL(debug) << " Previous second from refEpoch " << currentSecondFromReferenceEpoch << " delta = " << vdifHeader.getSecondsFromReferenceEpoch() - currentSecondFromReferenceEpoch;
currentSecondFromReferenceEpoch = vdifHeader.getSecondsFromReferenceEpoch();
noOfSendFrames = 0;
}
uint32_t frameLength = vdifHeader.getDataFrameLength() * 8; // in units of 8 bytes
socket.send_to(boost::asio::buffer(frame_start, frameLength), remote_endpoint, 0, err);
noOfSendFrames++;
counter++;
size_t processed_bytes = (frame_start - block.ptr()) + frameLength;
......@@ -124,11 +140,11 @@ class VDIF_Sender
//BOOST_LOG_TRIVIAL(debug) << counter << " Set delay to " << delay.count()<< " ns. Current rate " << current_rate << ", processed_bytes: " << processed_bytes;
}
if (counter < 5)
BOOST_LOG_TRIVIAL(debug) << counter << " Send - FN: " << vdifHeader.getDataFrameNumber() << ", Sec f. E.: " << vdifHeader.getSecondsFromReferenceEpoch() << " Get TS.: " << vdifHeader.getTimestamp();
if (counter < 5)
BOOST_LOG_TRIVIAL(debug) << counter << " Send - FN: " << vdifHeader.getDataFrameNumber() << ", Sec f. E.: " << vdifHeader.getSecondsFromReferenceEpoch() << " Get TS.: " << vdifHeader.getTimestamp();
}
BOOST_LOG_TRIVIAL(info) << "Send " << counter << " frames of " << block.used_bytes() << " bytes total size.";
BOOST_LOG_TRIVIAL(debug) << "Send " << counter << " frames of " << block.used_bytes() << " bytes total size. " << invalidFrames << " invalid frames in block.";
return false;
}
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment