/*************************************************************************** * Copyright (C) 2012 by gempa GmbH * * * * All Rights Reserved. * * * * NOTICE: All information contained herein is, and remains * * the property of gempa GmbH and its suppliers, if any. The intellectual * * and technical concepts contained herein are proprietary to gempa GmbH * * and its suppliers. * * Dissemination of this information or reproduction of this material * * is strictly forbidden unless prior written permission is obtained * * from gempa GmbH. * ***************************************************************************/ #include #include #include #include #include #include #include namespace Gempa { namespace CAPS { bool RTCM2DataRecord::RTCM2Header::put(std::streambuf &buf) const { Endianess::Writer put(buf); put(samplingTime.year); put(samplingTime.yday); put(samplingTime.hour); put(samplingTime.minute); put(samplingTime.second); put(samplingTime.usec); put(samplingFrequencyNumerator); put(samplingFrequencyDenominator); return put.good; } RTCM2DataRecord::RTCM2DataRecord() { _header.samplingFrequencyDenominator = 0; _header.samplingFrequencyNumerator = 0; // Just a bunch of bytes _header.dataType = DT_Unknown; } void RTCM2DataRecord::setTimeStamp(const Time &ts) { timeToTimestamp(_header.samplingTime, ts); _startTime = ts; } void RTCM2DataRecord::setSamplingFrequency(uint16_t numerator, uint16_t denominator) { _header.samplingFrequencyNumerator = numerator; _header.samplingFrequencyDenominator = denominator; } const char *RTCM2DataRecord::formatName() const { return "RTC2"; } bool RTCM2DataRecord::readMetaData(std::streambuf &buf, int size, Header &header, Time &startTime, Time &endTime) { Endianess::Reader get(buf); get(header.samplingTime.year); get(header.samplingTime.yday); get(header.samplingTime.hour); get(header.samplingTime.minute); get(header.samplingTime.second); get(header.samplingTime.usec); get(header.samplingFrequencyNumerator); get(header.samplingFrequencyDenominator); startTime = timestampToTime(header.samplingTime); if ( header.samplingFrequencyDenominator == 0 || header.samplingFrequencyNumerator == 0 ) { endTime = startTime; } else { TimeSpan ts = header.samplingFrequencyDenominator / header.samplingFrequencyNumerator; endTime = startTime + ts; } return true; } const DataRecord::Header *RTCM2DataRecord::header() const { return &_header; } Time RTCM2DataRecord::startTime() const { return _startTime; } Time RTCM2DataRecord::endTime() const { return _endTime; } bool RTCM2DataRecord::canTrim() const { return false; } bool RTCM2DataRecord::canMerge() const { return false; } bool RTCM2DataRecord::trim(const Time &start, const Time &end) const { return false; } size_t RTCM2DataRecord::dataSize(bool withHeader) const { if ( withHeader ) return _data.size() + _header.dataSize(); else return _data.size(); } DataRecord::ReadStatus RTCM2DataRecord::get(std::streambuf &buf, int size, const Time &start, const Time &end, int) { size -= _header.dataSize(); if ( size < 0 ) return RS_Error; if ( !_header.get(buf) ) return RS_Error; if ( _header.samplingFrequencyNumerator == 0 || _header.samplingFrequencyDenominator == 0 ) { CAPS_ERROR("Sampling frequency not set"); return RS_Error; } TimeSpan ts = _header.samplingFrequencyDenominator / _header.samplingFrequencyNumerator; _startTime = timestampToTime(_header.samplingTime); _endTime = _startTime + ts; if ( end.valid() && (end <= _startTime) ) return RS_AfterTimeWindow; if ( start.valid() && (start >= _endTime) ) return RS_BeforeTimeWindow; RIFF::VectorChunk<1,false> dataChunk(_data, 0, size); return dataChunk.get(buf, size)?RS_Complete:RS_Error; } bool RTCM2DataRecord::put(std::streambuf &buf, bool withHeader) const { if ( withHeader && !_header.put(buf) ) return false; RIFF::CPtrChunk<1,false> dataChunk(&_data[0], _data.size()); return dataChunk.put(buf); } } }