Commit 9a5786fa authored by Tobias Winchen's avatar Tobias Winchen
Browse files

Added conversion from POSIX Timestamp to VDIF Reference epoch, fix FDIF header

parent 5047a7a2
......@@ -41,6 +41,13 @@ class VDIFHeader
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;
......
#include "psrdada_cpp/effelsberg/edd/VLBI.cuh"
#include "psrdada_cpp/effelsberg/edd/Packer.cuh"
#include "psrdada_cpp/effelsberg/edd/Tools.cuh"
#include "psrdada_cpp/cuda_utils.hpp"
#include "ascii_header.h" // dada
#include <cuda.h>
#include <cuda_profiler_api.h>
#include <thrust/system/cuda/execution_policy.h>
......@@ -62,8 +63,7 @@ VLBI<HandlerType>::VLBI(std::size_t buffer_bytes, std::size_t input_bitDepth,
_unpacker.reset(new Unpacker(_proc_stream));
_vdifHeader.setBitsPerSample(_output_bitDepth);
_vdifHeader.setNumberOfChannels(1);
_vdifHeader.setBitsPerSample(_output_bitDepth - 1); // bits per sample - 1
_vdifHeader.setRealDataType();
} // constructor
......@@ -78,6 +78,24 @@ template <class HandlerType> VLBI<HandlerType>::~VLBI() {
template <class HandlerType> void VLBI<HandlerType>::init(RawBytes &block) {
BOOST_LOG_TRIVIAL(debug) << "VLBI init called";
size_t sync_time = 0;
if (ascii_header_get(block.ptr(), "SYNC_TIME", "%ld", &sync_time) != 1)
{
BOOST_LOG_TRIVIAL(warning) << "No or multiple SYNC_TIME parameters in header stream! Not setting reference";
return;
}
size_t sample_clock_start = 0;
if (ascii_header_get(block.ptr(), "SAMPLE_CLOCK_START", "%ld", &sample_clock_start) != 1)
{
BOOST_LOG_TRIVIAL(warning) << "No or multiple SAMPLE_CLOCK_START in header stream! Not setting reference time";
return;
}
size_t timestamp = sync_time + sample_clock_start / _sampleRate;
BOOST_LOG_TRIVIAL(info) << "POSIX timestamp captured from header: " << timestamp;
_vdifHeader.setTimeReferencesFromTimestamp(timestamp);
std::stringstream headerInfo;
headerInfo << "\n"
<< "# VLBI parameters: \n";
......
......@@ -5,6 +5,9 @@
#include <cuda.h>
#include <cstdint>
#include "boost/date_time/posix_time/posix_time.hpp"
#include "boost/date_time/gregorian/gregorian.hpp"
namespace psrdada_cpp {
namespace effelsberg {
namespace edd {
......@@ -112,6 +115,33 @@ 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);
boost::gregorian::date epochBegin(pt.date().year(),
((pt.date().month() <= 6) ? 1 : 7), 1);
setReferenceEpoch((epochBegin.year() - 2000) * 2 + (epochBegin.month() >= 7));
boost::posix_time::time_duration delta =
pt - boost::posix_time::ptime(epochBegin);
setSecondsFromReferenceEpoch(delta.total_seconds());
BOOST_LOG_TRIVIAL(debug) << " Time stamp: " << sync_time
<< " => VDIF Reference epoch: " << getReferenceEpoch()
<< " at " << getSecondsFromReferenceEpoch() << " s";
}
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,
uint32_t *__restrict__ output,
......
......@@ -131,12 +131,10 @@ int main(int argc, char **argv) {
// ToDo: Options to set values
effelsberg::edd::VDIFHeader vdifHeader;
vdifHeader.setDataFrameLength(payload_size);
vdifHeader.setDataFrameLength((payload_size + effelsberg::edd::vlbiHeaderSize) / 8); // In units of 8 bytes (SIC) according to VDIF spec.
vdifHeader.setNumberOfChannels(0); // log_2 (channel number)
vdifHeader.setThreadId(thread_id);
vdifHeader.setStationId(station_id);
BOOST_LOG_TRIVIAL(warning) << "SETTING FIXED REFERENCE EPOCH AND SECONDS FROM EPOCH!! Should be read from data stream!!";
vdifHeader.setReferenceEpoch(0);
vdifHeader.setSecondsFromReferenceEpoch(42); // for first block
std::cout << "Running with output_type: " << output_type << std::endl;
......
#include "gtest/gtest.h"
#include <time.h>
#include <stdlib.h>
#include "psrdada_cpp/effelsberg/edd/VLBI.cuh"
......@@ -99,7 +98,26 @@ TEST(VDIFHeader, getSetWord3)
EXPECT_EQ(header.getStationId(), 42);
}
TEST(VDIFHeader, testTimeStampConversion)
{
VDIFHeader header;
size_t currentTime = 1554915838;
header.setTimeReferencesFromTimestamp(currentTime);
EXPECT_EQ(currentTime, header.getTimestamp()) << "Reference epoch: " << header.getReferenceEpoch() << " + " << header.getSecondsFromReferenceEpoch() << " s";
header.setTimeReferencesFromTimestamp(946684800);
EXPECT_EQ(0, header.getReferenceEpoch());
EXPECT_EQ(0, header.getSecondsFromReferenceEpoch());
header.setTimeReferencesFromTimestamp(962409600);
EXPECT_EQ(1, header.getReferenceEpoch());
EXPECT_EQ(0, header.getSecondsFromReferenceEpoch());
header.setTimeReferencesFromTimestamp(962409600 + 100);
EXPECT_EQ(1, header.getReferenceEpoch());
EXPECT_EQ(100, header.getSecondsFromReferenceEpoch());
}
//int main(int argc, char **argv) {
// ::testing::InitGoogleTest(&argc, argv);
......
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