Skip to content
Snippets Groups Projects
Commit 6e2d4149 authored by Tobias Winchen's avatar Tobias Winchen
Browse files

Refactored VDIF HEader into View and Setter

parent 4134b96e
Branches
Tags
No related merge requests found
...@@ -17,10 +17,37 @@ namespace edd { ...@@ -17,10 +17,37 @@ namespace edd {
const size_t vlbiHeaderSize = 8 * 32 / 8; // bytes [8 words a 32 bit] 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 /// class VDIFHeader stores a VDIF compliant header block with conveniant
/// setters and getters. See https://vlbi.org/vlbi-standards/vdif/ /// setters and getters. See https://vlbi.org/vlbi-standards/vdif/
/// specification 1.1.1 from June 2014 for details. /// specification 1.1.1 from June 2014 for details.
class VDIFHeader class VDIFHeader : public VDIFHeaderView
{ {
private: private:
uint32_t data[8]; uint32_t data[8];
...@@ -30,51 +57,29 @@ class VDIFHeader ...@@ -30,51 +57,29 @@ class VDIFHeader
// return pointer to the data block for low level manipulation // return pointer to the data block for low level manipulation
uint32_t* getData(); uint32_t* getData();
void setInvalid(); void setInvalid();
void setValid(); void setValid();
bool isValid() const;
void setSecondsFromReferenceEpoch(uint32_t value); void setSecondsFromReferenceEpoch(uint32_t value);
uint32_t getSecondsFromReferenceEpoch() const;
void setReferenceEpoch(uint32_t value); void setReferenceEpoch(uint32_t value);
uint32_t getReferenceEpoch() const;
/// set reference epoch and seconds from reference epoch from POSIX time /// set reference epoch and seconds from reference epoch from POSIX time
/// stamp /// stamp
void setTimeReferencesFromTimestamp(size_t); void setTimeReferencesFromTimestamp(size_t);
/// converts time reference data to POSIX time /// converts time reference data to POSIX time
size_t getTimestamp();
void setDataFrameNumber(uint32_t value); void setDataFrameNumber(uint32_t value);
uint32_t getDataFrameNumber() const;
void setDataFrameLength(uint32_t value); void setDataFrameLength(uint32_t value);
uint32_t getDataFrameLength() const;
uint32_t getVersionNumber() const;
void setNumberOfChannels(uint32_t value); void setNumberOfChannels(uint32_t value);
uint32_t getNumberOfChannels() const;
bool isRealDataType() const;
bool isComplexDataType() const;
void setComplexDataType(); void setComplexDataType();
void setRealDataType(); void setRealDataType();
void setBitsPerSample(uint32_t value); void setBitsPerSample(uint32_t value);
uint32_t getBitsPerSample() const;
void setThreadId(uint32_t value); void setThreadId(uint32_t value);
uint32_t getThreadId() const;
void setStationId(uint32_t value); void setStationId(uint32_t value);
uint32_t getStationId() const;
}; };
/** /**
@class VLBI @class VLBI
@brief Convert data to 2bit data in VDIF format. @brief Convert data to 2bit data in VDIF format.
......
...@@ -12,7 +12,73 @@ namespace psrdada_cpp { ...@@ -12,7 +12,73 @@ namespace psrdada_cpp {
namespace effelsberg { namespace effelsberg {
namespace edd { 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++) { for (int i = 0; i < 8; i++) {
data[i] = 0U; data[i] = 0U;
} }
...@@ -31,62 +97,26 @@ void VDIFHeader::setInvalid() { setBitsWithValue(data[0], 31, 31, 1); } ...@@ -31,62 +97,26 @@ void VDIFHeader::setInvalid() { setBitsWithValue(data[0], 31, 31, 1); }
void VDIFHeader::setValid() { setBitsWithValue(data[0], 31, 31, 0); } 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) { void VDIFHeader::setSecondsFromReferenceEpoch(uint32_t value) {
setBitsWithValue(data[0], 0, 29, value); setBitsWithValue(data[0], 0, 29, value);
} }
uint32_t VDIFHeader::getSecondsFromReferenceEpoch() const {
return getBitsValue(data[0], 0, 29);
}
void VDIFHeader::setReferenceEpoch(uint32_t value) { void VDIFHeader::setReferenceEpoch(uint32_t value) {
setBitsWithValue(data[1], 24, 29, value); setBitsWithValue(data[1], 24, 29, value);
} }
uint32_t VDIFHeader::getReferenceEpoch() const {
return getBitsValue(data[1], 24, 29);
}
void VDIFHeader::setDataFrameNumber(uint32_t value) { void VDIFHeader::setDataFrameNumber(uint32_t value) {
setBitsWithValue(data[1], 0, 23, value); setBitsWithValue(data[1], 0, 23, value);
} }
uint32_t VDIFHeader::getDataFrameNumber() const {
return getBitsValue(data[1], 0, 23);
}
void VDIFHeader::setDataFrameLength(uint32_t value) { void VDIFHeader::setDataFrameLength(uint32_t value) {
setBitsWithValue(data[2], 0, 23, 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) { void VDIFHeader::setNumberOfChannels(uint32_t value) {
setBitsWithValue(data[2], 24, 28, 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::setComplexDataType() { setBitsWithValue(data[3], 31, 31, 1); }
void VDIFHeader::setRealDataType() { setBitsWithValue(data[0], 31, 31, 0); } void VDIFHeader::setRealDataType() { setBitsWithValue(data[0], 31, 31, 0); }
...@@ -95,26 +125,14 @@ void VDIFHeader::setBitsPerSample(uint32_t value) { ...@@ -95,26 +125,14 @@ void VDIFHeader::setBitsPerSample(uint32_t value) {
setBitsWithValue(data[3], 26, 30, value); setBitsWithValue(data[3], 26, 30, value);
} }
uint32_t VDIFHeader::getBitsPerSample() const {
return getBitsValue(data[3], 26, 30);
}
void VDIFHeader::setThreadId(uint32_t value) { void VDIFHeader::setThreadId(uint32_t value) {
setBitsWithValue(data[3], 16, 25, value); setBitsWithValue(data[3], 16, 25, value);
} }
uint32_t VDIFHeader::getThreadId() const {
return getBitsValue(data[3], 16, 25);
}
void VDIFHeader::setStationId(uint32_t value) { void VDIFHeader::setStationId(uint32_t value) {
setBitsWithValue(data[3], 0, 15, 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) { void VDIFHeader::setTimeReferencesFromTimestamp(size_t sync_time) {
boost::posix_time::ptime pt = boost::posix_time::from_time_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) { ...@@ -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, __global__ void pack2bit_nonLinear(const float *__restrict__ input,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment