From 6e2d4149c0acb1e1ebc3bcc842e3ee5b2025033a Mon Sep 17 00:00:00 2001 From: Tobias Winchen <tobias.winchen@rwth-aachen.de> Date: Thu, 13 Jun 2019 09:28:16 +0000 Subject: [PATCH] Refactored VDIF HEader into View and Setter --- psrdada_cpp/effelsberg/edd/VLBI.cuh | 57 ++++++----- psrdada_cpp/effelsberg/edd/src/VLBI.cu | 125 +++++++++++++------------ 2 files changed, 98 insertions(+), 84 deletions(-) diff --git a/psrdada_cpp/effelsberg/edd/VLBI.cuh b/psrdada_cpp/effelsberg/edd/VLBI.cuh index ca9624a5..c53b4c0b 100644 --- a/psrdada_cpp/effelsberg/edd/VLBI.cuh +++ b/psrdada_cpp/effelsberg/edd/VLBI.cuh @@ -17,10 +17,37 @@ namespace edd { const size_t vlbiHeaderSize = 8 * 32 / 8; // bytes [8 words a 32 bit] + +/// class VDIFHeaderView provides interprets a data block as VDIF compliant header +/// See https://vlbi.org/vlbi-standards/vdif/specification 1.1.1 from June 2014 for details. +class VDIFHeaderView +{ + private: + const uint32_t *data; + public: + VDIFHeaderView(const uint32_t* data); + void setDataLocation(const uint32_t* _data); + uint32_t getVersionNumber() const; + bool isValid() const; + uint32_t getSecondsFromReferenceEpoch() const; + uint32_t getReferenceEpoch() const; + size_t getTimestamp() const; + uint32_t getDataFrameNumber() const; + uint32_t getDataFrameLength() const; + uint32_t getNumberOfChannels() const; + bool isRealDataType() const; + bool isComplexDataType() const; + uint32_t getBitsPerSample() const; + uint32_t getThreadId() const; + uint32_t getStationId() const; + +}; + + /// class VDIFHeader stores a VDIF compliant header block with conveniant /// setters and getters. See https://vlbi.org/vlbi-standards/vdif/ /// specification 1.1.1 from June 2014 for details. -class VDIFHeader +class VDIFHeader : public VDIFHeaderView { private: uint32_t data[8]; @@ -30,51 +57,29 @@ class VDIFHeader // return pointer to the data block for low level manipulation uint32_t* getData(); - void setInvalid(); void setValid(); - bool isValid() const; - void setSecondsFromReferenceEpoch(uint32_t value); - uint32_t getSecondsFromReferenceEpoch() const; - void setReferenceEpoch(uint32_t value); - uint32_t getReferenceEpoch() const; /// set reference epoch and seconds from reference epoch from POSIX time /// stamp void setTimeReferencesFromTimestamp(size_t); /// converts time reference data to POSIX time - size_t getTimestamp(); - - void setDataFrameNumber(uint32_t value); - uint32_t getDataFrameNumber() const; - void setDataFrameLength(uint32_t value); - uint32_t getDataFrameLength() const; - - uint32_t getVersionNumber() const; - void setNumberOfChannels(uint32_t value); - uint32_t getNumberOfChannels() const; - - bool isRealDataType() const; - bool isComplexDataType() const; void setComplexDataType(); void setRealDataType(); - void setBitsPerSample(uint32_t value); - uint32_t getBitsPerSample() const; - void setThreadId(uint32_t value); - uint32_t getThreadId() const; - void setStationId(uint32_t value); - uint32_t getStationId() const; }; + + + /** @class VLBI @brief Convert data to 2bit data in VDIF format. diff --git a/psrdada_cpp/effelsberg/edd/src/VLBI.cu b/psrdada_cpp/effelsberg/edd/src/VLBI.cu index 8de4f18b..bc4134d0 100644 --- a/psrdada_cpp/effelsberg/edd/src/VLBI.cu +++ b/psrdada_cpp/effelsberg/edd/src/VLBI.cu @@ -12,7 +12,73 @@ namespace psrdada_cpp { namespace effelsberg { namespace edd { -VDIFHeader::VDIFHeader() { + + +VDIFHeaderView::VDIFHeaderView(const uint32_t* data) : data(data) {}; +void VDIFHeaderView::setDataLocation(const uint32_t* _data) { + data = _data; +}; + +bool VDIFHeaderView::isValid() const { + return (getBitsValue(data[0], 31, 31) == 0); +} + +uint32_t VDIFHeaderView::getSecondsFromReferenceEpoch() const { + return getBitsValue(data[0], 0, 29); +} + +uint32_t VDIFHeaderView::getReferenceEpoch() const { + return getBitsValue(data[1], 24, 29); +} + +uint32_t VDIFHeaderView::getDataFrameNumber() const { + return getBitsValue(data[1], 0, 23); +} +uint32_t VDIFHeaderView::getDataFrameLength() const { + return getBitsValue(data[2], 0, 23); +} + +uint32_t VDIFHeaderView::getVersionNumber() const { + return getBitsValue(data[2], 29, 31); +} + +uint32_t VDIFHeaderView::getNumberOfChannels() const { + return getBitsValue(data[2], 24, 28); +} + +bool VDIFHeaderView::isRealDataType() const { + return (getBitsValue(data[3], 31, 31) == 0); +} + +bool VDIFHeaderView::isComplexDataType() const { + return (getBitsValue(data[3], 31, 31) == 1); +} + +uint32_t VDIFHeaderView::getBitsPerSample() const { + return getBitsValue(data[3], 26, 30); +} + +uint32_t VDIFHeaderView::getThreadId() const { + return getBitsValue(data[3], 16, 25); +} + +uint32_t VDIFHeaderView::getStationId() const { + return getBitsValue(data[3], 0, 15); +} + +size_t VDIFHeaderView::getTimestamp() const { + boost::gregorian::date vdifEpochBegin(getReferenceEpoch() / 2 + 2000, + ((getReferenceEpoch() % 2) * 6) + 1, 1); + boost::posix_time::ptime pt = boost::posix_time::ptime(vdifEpochBegin) + boost::posix_time::seconds(getSecondsFromReferenceEpoch()); + boost::posix_time::ptime unixEpoch = + boost::posix_time::time_from_string("1970-01-01 00:00:00.000"); + boost::posix_time::time_duration delta = pt - unixEpoch; + return delta.total_seconds(); +} + + +VDIFHeader::VDIFHeader() : VDIFHeaderView(data) +{ for (int i = 0; i < 8; i++) { data[i] = 0U; } @@ -31,62 +97,26 @@ void VDIFHeader::setInvalid() { setBitsWithValue(data[0], 31, 31, 1); } void VDIFHeader::setValid() { setBitsWithValue(data[0], 31, 31, 0); } -bool VDIFHeader::isValid() const { - return (getBitsValue(data[0], 31, 31) == 0); -} - void VDIFHeader::setSecondsFromReferenceEpoch(uint32_t value) { setBitsWithValue(data[0], 0, 29, value); } -uint32_t VDIFHeader::getSecondsFromReferenceEpoch() const { - return getBitsValue(data[0], 0, 29); -} - void VDIFHeader::setReferenceEpoch(uint32_t value) { setBitsWithValue(data[1], 24, 29, value); } -uint32_t VDIFHeader::getReferenceEpoch() const { - return getBitsValue(data[1], 24, 29); -} - void VDIFHeader::setDataFrameNumber(uint32_t value) { setBitsWithValue(data[1], 0, 23, value); } -uint32_t VDIFHeader::getDataFrameNumber() const { - return getBitsValue(data[1], 0, 23); -} - void VDIFHeader::setDataFrameLength(uint32_t value) { setBitsWithValue(data[2], 0, 23, value); } -uint32_t VDIFHeader::getDataFrameLength() const { - return getBitsValue(data[2], 0, 23); -} - -uint32_t VDIFHeader::getVersionNumber() const { - return getBitsValue(data[2], 29, 31); -} - void VDIFHeader::setNumberOfChannels(uint32_t value) { setBitsWithValue(data[2], 24, 28, value); } -uint32_t VDIFHeader::getNumberOfChannels() const { - return getBitsValue(data[2], 24, 28); -} - -bool VDIFHeader::isRealDataType() const { - return (getBitsValue(data[3], 31, 31) == 0); -} - -bool VDIFHeader::isComplexDataType() const { - return (getBitsValue(data[3], 31, 31) == 1); -} - void VDIFHeader::setComplexDataType() { setBitsWithValue(data[3], 31, 31, 1); } void VDIFHeader::setRealDataType() { setBitsWithValue(data[0], 31, 31, 0); } @@ -95,26 +125,14 @@ void VDIFHeader::setBitsPerSample(uint32_t value) { setBitsWithValue(data[3], 26, 30, value); } -uint32_t VDIFHeader::getBitsPerSample() const { - return getBitsValue(data[3], 26, 30); -} - void VDIFHeader::setThreadId(uint32_t value) { setBitsWithValue(data[3], 16, 25, value); } -uint32_t VDIFHeader::getThreadId() const { - return getBitsValue(data[3], 16, 25); -} - void VDIFHeader::setStationId(uint32_t value) { setBitsWithValue(data[3], 0, 15, value); } -uint32_t VDIFHeader::getStationId() const { - return getBitsValue(data[3], 0, 15); -} - void VDIFHeader::setTimeReferencesFromTimestamp(size_t sync_time) { boost::posix_time::ptime pt = boost::posix_time::from_time_t(sync_time); @@ -132,15 +150,6 @@ void VDIFHeader::setTimeReferencesFromTimestamp(size_t sync_time) { } -size_t VDIFHeader::getTimestamp() { - boost::gregorian::date vdifEpochBegin(getReferenceEpoch() / 2 + 2000, - ((getReferenceEpoch() % 2) * 6) + 1, 1); - boost::posix_time::ptime pt = boost::posix_time::ptime(vdifEpochBegin) + boost::posix_time::seconds(getSecondsFromReferenceEpoch()); - boost::posix_time::ptime unixEpoch = - boost::posix_time::time_from_string("1970-01-01 00:00:00.000"); - boost::posix_time::time_duration delta = pt - unixEpoch; - return delta.total_seconds(); -} __global__ void pack2bit_nonLinear(const float *__restrict__ input, -- GitLab