Update to version 2

This commit is contained in:
2022-11-18 13:42:30 +01:00
parent 284fef3ec2
commit 8934eeac6b
23 changed files with 5109 additions and 5695 deletions

View File

@ -44,10 +44,10 @@ class Encoder {
virtual void reset() { _sampleCount = 0; }
virtual int type() const = 0;
const SPClock& clk() { return _clk; }
const SPClock &clk() { return _clk; }
void setStartTime(const SPClock::INT_TIME &time) { _clk.sync_time(time); }
const SPClock::INT_TIME currentTime() const { return _clk.get_time(0); }
void setStartTime(const Time &time) { _clk.syncTime(time); }
const Time currentTime() const { return _clk.getTime(0); }
int timingQuality() { return _timingQuality; }
void setTimingQuality(int quality) { _timingQuality = quality; }

View File

@ -18,7 +18,6 @@
*****************************************************************************/
#include <gempa/caps/mseedpacket.h>
#include <gempa/caps/rawpacket.h>
#include "mseed.h"
#include "slink.h"
@ -27,23 +26,26 @@
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <stdint.h>
#include <netinet/in.h>
namespace Gempa {
namespace CAPS {
MSEEDFormat::MSEEDFormat(const std::string &netcode, const std::string &stacode,
const std::string &loccode, const std::string &chacode,
unsigned short freqn, unsigned short freqd,
unsigned short packtype_init,
unsigned short packType,
uint8_t recordLength)
: networkCode(netcode), stationCode(stacode), locationCode(loccode),
channelCode(chacode), packType(packtype_init), recordLength(recordLength)
: networkCode(netcode)
, stationCode(stacode)
, locationCode(loccode)
, channelCode(chacode)
, packType(packType)
, recordLength(recordLength)
{
if(freqn == 0 || freqd == 0) {
sample_rate_factor = 0;
@ -63,8 +65,10 @@ MSEEDFormat::MSEEDFormat(const std::string &netcode, const std::string &stacode,
}
}
MSEEDDataRecord *MSEEDFormat::get_buffer(const SPClock::INT_TIME &it, int usec_correction,
int timing_quality, void *&dataptr, int &datalen) {
MSEEDDataRecord *MSEEDFormat::getBuffer(const Time &it, int usec_correction,
int timing_quality, void *&dataptr,
int &datalen) {
size_t buflen = 1 << recordLength;
MSEEDDataRecord *record = new MSEEDDataRecord();
record->data()->resize(buflen);
@ -151,12 +155,10 @@ void MSEEDFormat::updateBuffer(MSEEDDataRecord *rec, int samples, int frames) {
if ( ntohs(blkt_1000->next_blkt) != 0 ) {
sl_blkt_1001_s* blkt_1001 = (sl_blkt_1001_s *)((char *) fsdh +
sizeof(sl_fsdh_s) + sizeof(sl_blkt_1000_s));
blkt_1001->frame_cnt = frames;
}
rec->unpackHeader();
}
}
}

View File

@ -58,16 +58,16 @@ struct MSEEDFormat {
template<class T>
MSEEDEncoderPacket<T>
get_packet(const SPClock::INT_TIME &it, int usec_correction, int timing_quality) {
getPacket(const Time &it, int usec_correction, int timing_quality) {
void *dataptr = NULL;
int datalen = 0;
unsigned int size = 0;
MSEEDDataRecord *rec = get_buffer(it, usec_correction, timing_quality, dataptr, datalen);
MSEEDDataRecord *rec = getBuffer(it, usec_correction, timing_quality, dataptr, datalen);
return MSEEDEncoderPacket<T>(rec, size, dataptr, datalen);
}
MSEEDDataRecord *get_buffer(const SPClock::INT_TIME &it, int usec_correction,
MSEEDDataRecord *getBuffer(const Time &it, int usec_correction,
int timing_quality,
void *&dataptr, int &datalen);

View File

@ -17,6 +17,7 @@
* 01.01.2013 Adapted code to CAPS client library requirements (gempa GmbH)
*****************************************************************************/
#ifndef CAPS_MSEED_SPCLOCK_H
#define CAPS_MSEED_SPCLOCK_H
@ -28,51 +29,43 @@ namespace Gempa {
namespace CAPS {
class SPClock
{
public:
typedef Gempa::CAPS::Time INT_TIME;
class SPClock {
public:
SPClock(int freqn, int freqd)
: freqn(freqn), freqd(freqd) {}
private:
INT_TIME itime;
int ticks;
int corr;
void syncTime(const Time &time) {
_itime = time;
_ticks = 0;
_corr = 0;
}
public:
const int freqn;
const int freqd;
void tick() {
++_ticks;
}
SPClock(int freqn_init, int freqd_init): ticks(0), corr(0),
freqn(freqn_init), freqd(freqd_init)
{}
Time getTime(int tickDiff) const {
int64_t correctness = (double)freqd / (double)freqn * 1000000 * (_ticks - tickDiff - _corr);
return _itime + TimeSpan(long(correctness / 1000000), long(correctness % 1000000));
}
void sync_time(const INT_TIME &time)
{
itime = time;
ticks = 0;
corr = 0;
}
int correction() const {
return _corr;
}
void tick()
{
++ticks;
}
public:
const int freqn;
const int freqd;
INT_TIME get_time(int tick_diff) const
{
int64_t correctness = (double)freqd / (double)freqn * 1000000 * (ticks - tick_diff - corr);
return itime + Gempa::CAPS::TimeSpan(long(correctness/1000000),long(correctness%1000000));
}
int correction() const
{
return corr;
}
};
private:
Time _itime;
int _ticks{0};
int _corr{0};
};
}
}
#endif // SPCLOCK_H
#endif

View File

@ -33,8 +33,8 @@ namespace CAPS {
//*****************************************************************************
struct Steim1Frame {
u_int32_t nibble_word;
u_int32_t sample_word[15];
u_int32_t nibbleWord;
u_int32_t sampleWord[15];
};
//*****************************************************************************
@ -43,42 +43,44 @@ struct Steim1Frame {
template<typename T>
class Steim1Encoder: public Encoder {
private:
MSEEDFormat *format;
int frame_count;
int bp;
int fp;
int spw;
int32_t last_sample;
int32_t buf[5];
u_int32_t nibble_word;
MSEEDEncoderPacket<Steim1Frame> current_packet;
void update_spw(int bp);
void store(int32_t value);
void init_packet();
void finish_packet();
void update_packet();
MSEEDEncoderPacket<Steim1Frame> get_packet() {
return format->get_packet<Steim1Frame>(_clk.get_time(bp),
_clk.correction(), _timingQuality);
}
void queue_packet(MSEEDEncoderPacket<Steim1Frame> &pckt);
int number_of_frames(const MSEEDEncoderPacket<Steim1Frame> &packet) {
return (packet.datalen >> 6);
}
public:
Steim1Encoder(MSEEDFormat *format, int freqn, int freqd)
: Encoder(freqn, freqd), format(format), frame_count(0),
bp(0), fp(0), spw(4), last_sample(0), nibble_word(0) {}
: Encoder(freqn, freqd), _format(format), _frameCount(0)
, _bp(0), _fp(0), _spw(4), _lastSample(0), _nibbleWord(0) {}
virtual ~Steim1Encoder();
virtual void flush();
virtual void push(void *value);
virtual int type() const { return DE_STEIM1; }
private:
void updateSpw(int bp);
void store(int32_t value);
void initPacket();
void updatePacket();
void finishPacket();
MSEEDEncoderPacket<Steim1Frame> getPacket() {
return _format->getPacket<Steim1Frame>(_clk.getTime(_bp),
_clk.correction(), _timingQuality);
}
void queuePacket(MSEEDEncoderPacket<Steim1Frame> &pckt);
int numberOfFrames(const MSEEDEncoderPacket<Steim1Frame> &packet) {
return (packet.datalen >> 6);
}
private:
MSEEDFormat *_format;
int _frameCount;
int _bp;
int _fp;
int _spw;
int32_t _lastSample;
int32_t _buf[5];
u_int32_t _nibbleWord;
MSEEDEncoderPacket<Steim1Frame> _currentPacket;
};

View File

@ -27,158 +27,181 @@
namespace Gempa {
namespace CAPS {
template<typename T> Steim1Encoder<T>::~Steim1Encoder() {
if ( format != NULL ) delete format;
template<typename T>
Steim1Encoder<T>::~Steim1Encoder() {
if ( _format ) {
delete _format;
}
}
template<typename T> void Steim1Encoder<T>::update_spw(int bp) {
template<typename T>
void Steim1Encoder<T>::updateSpw(int bp) {
int spw1 = 4;
assert(bp < 4);
if(buf[bp] < -32768 || buf[bp] > 32767) spw1 = 1;
else if(buf[bp] < -128 || buf[bp] > 127) spw1 = 2;
if(spw1 < spw) spw = spw1;
if ( _buf[bp] < -32768 || _buf[bp] > 32767 ) spw1 = 1;
else if ( _buf[bp] < -128 || _buf[bp] > 127 ) spw1 = 2;
if ( spw1 < _spw ) _spw = spw1;
}
template<typename T> void Steim1Encoder<T>::store(int32_t value) {
assert(bp < 4);
buf[bp] = value - last_sample;
last_sample = value;
update_spw(bp);
++bp;
template<typename T>
void Steim1Encoder<T>::store(int32_t value) {
assert(_bp < 4);
_buf[_bp] = value - _lastSample;
_lastSample = value;
updateSpw(_bp);
++_bp;
}
template<typename T> void Steim1Encoder<T>::init_packet() {
template<typename T>
void Steim1Encoder<T>::initPacket() {
int i;
int32_t begin_sample = last_sample;
int32_t beginSample = _lastSample;
for(i = 1; i < bp; ++i) {
begin_sample -= buf[i];
for ( i = 1; i < _bp; ++i ) {
beginSample -= _buf[i];
}
reset();
current_packet.data[0].sample_word[0] = htonl(begin_sample);
frame_count = 0;
nibble_word = 0;
fp = 2;
_currentPacket.data[0].sampleWord[0] = htonl(beginSample);
_frameCount = 0;
_nibbleWord = 0;
_fp = 2;
}
template<typename T> void Steim1Encoder<T>::finish_packet() {
template<typename T>
void Steim1Encoder<T>::finishPacket() {
int i;
int32_t end_sample = last_sample;
int32_t endSample = _lastSample;
for(i = 0; i < bp; ++i) {
end_sample -= buf[i];
for ( i = 0; i < _bp; ++i ) {
endSample -= _buf[i];
}
current_packet.data[0].sample_word[1] = htonl(end_sample);
_currentPacket.data[0].sampleWord[1] = htonl(endSample);
}
template<typename T> void Steim1Encoder<T>::update_packet() {
template<typename T>
void Steim1Encoder<T>::updatePacket() {
unsigned int nibble = 0;
u_int32_t sample_word = 0;
u_int32_t sampleWord = 0;
assert(bp < 5);
assert(_bp < 5);
int used = bp;
int used = _bp;
while(used > spw) {
while ( used > _spw ) {
--used;
spw = 4;
for(int i = 0; i < used; ++i) update_spw(i);
_spw = 4;
for ( int i = 0; i < used; ++i ) {
updateSpw(i);
}
}
while(used < spw) spw >>= 1;
while ( used < _spw ) {
_spw >>= 1;
}
used = spw;
used = _spw;
switch(spw) {
switch ( _spw ) {
case 4:
nibble = 1;
sample_word = ((buf[0] & 0xff) << 24) | ((buf[1] & 0xff) << 16) |
((buf[2] & 0xff) << 8) | (buf[3] & 0xff);
sampleWord = ((_buf[0] & 0xff) << 24) | ((_buf[1] & 0xff) << 16) |
((_buf[2] & 0xff) << 8) | (_buf[3] & 0xff);
break;
case 2:
nibble = 2;
sample_word = ((buf[0] & 0xffff) << 16) | (buf[1] & 0xffff);
sampleWord = ((_buf[0] & 0xffff) << 16) | (_buf[1] & 0xffff);
break;
case 1:
nibble = 3;
sample_word = buf[0];
sampleWord = _buf[0];
break;
default:
assert(0);
}
nibble_word |= (nibble << (30 - ((fp + 1) << 1)));
_nibbleWord |= (nibble << (30 - ((_fp + 1) << 1)));
spw = 4;
for(int i = 0; i < bp - used; ++i) {
buf[i] = buf[i + used];
update_spw(i);
_spw = 4;
for ( int i = 0; i < _bp - used; ++i ) {
_buf[i] = _buf[i + used];
updateSpw(i);
}
bp -= used;
_bp -= used;
_sampleCount += used;
current_packet.data[frame_count].nibble_word = htonl(nibble_word);
current_packet.data[frame_count].sample_word[fp] = htonl(sample_word);
if(++fp < 15) return;
_currentPacket.data[_frameCount].nibbleWord = htonl(_nibbleWord);
_currentPacket.data[_frameCount].sampleWord[_fp] = htonl(sampleWord);
if ( ++_fp < 15 ) {
return;
}
_nibbleWord = 0;
_fp = 0;
++_frameCount;
nibble_word = 0;
fp = 0;
++frame_count;
return;
}
template<typename T> void Steim1Encoder<T>::queue_packet(MSEEDEncoderPacket<Steim1Frame> &pckt) {
format->updateBuffer(pckt.record, _sampleCount, frame_count + (fp > 0));
template<typename T>
void Steim1Encoder<T>::queuePacket(MSEEDEncoderPacket<Steim1Frame> &pckt) {
_format->updateBuffer(pckt.record, _sampleCount, _frameCount + (_fp > 0));
Packet *packet = new Packet(DataRecordPtr(pckt.record), format->networkCode, format->stationCode,
format->locationCode, format->channelCode);
Packet *packet = new Packet(DataRecordPtr(pckt.record),
_format->networkCode,
_format->stationCode,
_format->locationCode,
_format->channelCode);
_packetQueue.push_back(PacketPtr(packet));
pckt.reset();
reset();
}
template<typename T> void Steim1Encoder<T>::push(void *value) {
template<typename T>
void Steim1Encoder<T>::push(void *value) {
int32_t sample_val = *static_cast<T*>(value);
store(sample_val);
_clk.tick();
while(bp >= spw) {
if(!current_packet.valid()) {
current_packet = get_packet();
init_packet();
while ( _bp >= _spw ) {
if ( !_currentPacket.valid() ) {
_currentPacket = getPacket();
initPacket();
}
update_packet();
if(frame_count == number_of_frames(current_packet)) {
finish_packet();
queue_packet(current_packet);
updatePacket();
if ( _frameCount == numberOfFrames(_currentPacket) ) {
finishPacket();
queuePacket(_currentPacket);
}
}
}
template<typename T> void Steim1Encoder<T>::flush() {
while(bp) {
if(!current_packet.valid()) {
current_packet = get_packet();
init_packet();
template<typename T>
void Steim1Encoder<T>::flush() {
while ( _bp ) {
if ( !_currentPacket.valid() ) {
_currentPacket = getPacket();
initPacket();
}
update_packet();
if(frame_count == number_of_frames(current_packet)) {
finish_packet();
queue_packet(current_packet);
updatePacket();
if ( _frameCount == numberOfFrames(_currentPacket) ) {
finishPacket();
queuePacket(_currentPacket);
}
}
if(current_packet.valid()) {
finish_packet();
queue_packet(current_packet);
if ( _currentPacket.valid() ) {
finishPacket();
queuePacket(_currentPacket);
}
}
}
}

View File

@ -31,8 +31,8 @@ namespace CAPS {
//*****************************************************************************
struct Steim2Frame {
u_int32_t nibble_word;
u_int32_t sample_word[15];
u_int32_t nibbleWord;
u_int32_t sampleWord[15];
};
//*****************************************************************************
@ -43,8 +43,8 @@ template<typename T>
class Steim2Encoder : public Encoder {
public:
Steim2Encoder(MSEEDFormat *format, int freqn, int freqd)
: Encoder(freqn, freqd), format(format), frame_count(0),
bp(0), fp(0), spw(4), last_sample(0), nibble_word(0) {
: Encoder(freqn, freqd), _format(format), _frameCount(0)
, _bp(0), _fp(0), _spw(4), _lastSample(0), _nibbleWord(0) {
}
virtual ~Steim2Encoder();
virtual void flush();
@ -53,34 +53,34 @@ class Steim2Encoder : public Encoder {
virtual int type() const { return DE_STEIM2; }
private:
void update_spw(int bp);
void updateSpw(int bp);
void store(int32_t value);
void init_packet();
void finish_packet();
void update_packet();
void initPacket();
void updatePacket();
void finishPacket();
MSEEDEncoderPacket<Steim2Frame> get_packet() {
return format->get_packet<Steim2Frame>(_clk.get_time(bp),
MSEEDEncoderPacket<Steim2Frame> getPacket() {
return _format->getPacket<Steim2Frame>(_clk.getTime(_bp),
_clk.correction(), _timingQuality);
}
void queue_packet(MSEEDEncoderPacket<Steim2Frame> &pckt);
void queuePacket(MSEEDEncoderPacket<Steim2Frame> &pckt);
int number_of_frames(const MSEEDEncoderPacket<Steim2Frame> &packet) {
int numberOfFrames(const MSEEDEncoderPacket<Steim2Frame> &packet) const {
return (packet.datalen >> 6);
}
private:
MSEEDFormat *format;
int frame_count;
int bp;
int fp;
int32_t last_s;
int spw;
int32_t last_sample;
int32_t buf[8];
u_int32_t nibble_word;
MSEEDEncoderPacket<Steim2Frame> current_packet;
MSEEDFormat *_format;
int _frameCount;
int _bp;
int _fp;
int32_t _last_s;
int _spw;
int32_t _lastSample;
int32_t _buf[8];
u_int32_t _nibbleWord;
MSEEDEncoderPacket<Steim2Frame> _currentPacket;
};

View File

@ -32,163 +32,174 @@ namespace CAPS {
template<typename T> Steim2Encoder<T>::~Steim2Encoder() {
if ( format != NULL ) delete format;
if ( _format ) {
delete _format;
}
}
template<typename T> void Steim2Encoder<T>::update_spw(int bp) {
assert(bp < 7);
template<typename T> void Steim2Encoder<T>::updateSpw(int bp) {
assert(_bp < 7);
if(buf[bp] < -536870912) {
if ( _buf[_bp] < -536870912 ) {
CAPS_WARNING("%s.%s.%s.%s: value %d is too large for Steim2 encoding",
format->networkCode.c_str(), format->stationCode.c_str(),
format->locationCode.c_str(), format->channelCode.c_str(),
buf[bp]);
buf[bp] = -536870912;
spw = 1;
_format->networkCode.c_str(), _format->stationCode.c_str(),
_format->locationCode.c_str(), _format->channelCode.c_str(),
_buf[_bp]);
_buf[_bp] = -536870912;
_spw = 1;
return;
}
if(buf[bp] > 536870911) {
if ( _buf[_bp] > 536870911 ) {
CAPS_WARNING("%s.%s.%s.%s: value %d is too large for Steim2 encoding",
format->networkCode.c_str(), format->stationCode.c_str(),
format->locationCode.c_str(), format->channelCode.c_str(),
buf[bp]);
buf[bp] = 536870911;
spw = 1;
_format->networkCode.c_str(), _format->stationCode.c_str(),
_format->locationCode.c_str(), _format->channelCode.c_str(),
_buf[_bp]);
_buf[_bp] = 536870911;
_spw = 1;
return;
}
int spw1 = 7;
if(buf[bp] < -16384 || buf[bp] > 16383) spw1 = 1;
else if(buf[bp] < -512 || buf[bp] > 511) spw1 = 2;
else if(buf[bp] < -128 || buf[bp] > 127) spw1 = 3;
else if(buf[bp] < -32 || buf[bp] > 31) spw1 = 4;
else if(buf[bp] < -16 || buf[bp] > 15) spw1 = 5;
else if(buf[bp] < -8 || buf[bp] > 7) spw1 = 6;
if(spw1 < spw) spw = spw1;
if ( _buf[_bp] < -16384 || _buf[_bp] > 16383 ) spw1 = 1;
else if ( _buf[_bp] < -512 || _buf[_bp] > 511 ) spw1 = 2;
else if ( _buf[_bp] < -128 || _buf[_bp] > 127 ) spw1 = 3;
else if ( _buf[_bp] < -32 || _buf[_bp] > 31 ) spw1 = 4;
else if ( _buf[_bp] < -16 || _buf[_bp] > 15 ) spw1 = 5;
else if ( _buf[_bp] < -8 || _buf[_bp] > 7 ) spw1 = 6;
if ( spw1 < _spw ) _spw = spw1;
}
template<typename T> void Steim2Encoder<T>::store(int32_t value) {
assert(bp < 7);
buf[bp] = value - last_sample;
last_sample = value;
update_spw(bp);
++bp;
assert(_bp < 7);
_buf[_bp] = value - _lastSample;
_lastSample = value;
updateSpw(_bp);
++_bp;
}
template<typename T> void Steim2Encoder<T>::init_packet() {
template<typename T> void Steim2Encoder<T>::initPacket() {
int i;
int32_t begin_sample = last_sample;
int32_t begin_sample = _lastSample;
for(i = 1; i < bp; ++i) {
begin_sample -= buf[i];
for ( i = 1; i < _bp; ++i ) {
begin_sample -= _buf[i];
}
reset();
current_packet.data[0].sample_word[0] = htonl(begin_sample);
frame_count = 0;
nibble_word = 0;
fp = 2;
_currentPacket.data[0].sampleWord[0] = htonl(begin_sample);
_frameCount = 0;
_nibbleWord = 0;
_fp = 2;
}
template<typename T> void Steim2Encoder<T>::finish_packet() {
template<typename T> void Steim2Encoder<T>::finishPacket() {
int i;
int32_t end_sample = last_sample;
int32_t endSample = _lastSample;
for(i = 0; i < bp; ++i) {
end_sample -= buf[i];
for ( i = 0; i < _bp; ++i ) {
endSample -= _buf[i];
}
current_packet.data[0].sample_word[1] = htonl(end_sample);
_currentPacket.data[0].sampleWord[1] = htonl(endSample);
}
template<typename T> void Steim2Encoder<T>::update_packet() {
template<typename T> void Steim2Encoder<T>::updatePacket() {
unsigned int nibble = 0;
u_int32_t sample_word = 0;
u_int32_t sampleWord = 0;
assert(bp < 8);
assert(_bp < 8);
int used = bp;
int used = _bp;
while(used > spw) {
while ( used > _spw ) {
--used;
spw = 7;
for(int i = 0; i < used; ++i) update_spw(i);
_spw = 7;
for ( int i = 0; i < used; ++i ) {
updateSpw(i);
}
}
spw = used;
_spw = used;
switch(spw) {
switch ( _spw ) {
case 7:
nibble = 3;
sample_word = (2U << 30) | ((buf[0] & 0xf) << 24) |
((buf[1] & 0xf) << 20) | ((buf[2] & 0xf) << 16) |
((buf[3] & 0xf) << 12) | ((buf[4] & 0xf) << 8) |
((buf[5] & 0xf) << 4) | (buf[6] & 0xf);
sampleWord = (2U << 30) | ((_buf[0] & 0xf) << 24) |
((_buf[1] & 0xf) << 20) | ((_buf[2] & 0xf) << 16) |
((_buf[3] & 0xf) << 12) | ((_buf[4] & 0xf) << 8) |
((_buf[5] & 0xf) << 4) | (_buf[6] & 0xf);
break;
case 6:
nibble = 3;
sample_word = (1U << 30) | ((buf[0] & 0x1f) << 25) |
((buf[1] & 0x1f) << 20) | ((buf[2] & 0x1f) << 15) |
((buf[3] & 0x1f) << 10) | ((buf[4] & 0x1f) << 5) |
(buf[5] & 0x1f);
sampleWord = (1U << 30) | ((_buf[0] & 0x1f) << 25) |
((_buf[1] & 0x1f) << 20) | ((_buf[2] & 0x1f) << 15) |
((_buf[3] & 0x1f) << 10) | ((_buf[4] & 0x1f) << 5) |
(_buf[5] & 0x1f);
break;
case 5:
nibble = 3;
sample_word = ((buf[0] & 0x3f) << 24) | ((buf[1] & 0x3f) << 18) |
((buf[2] & 0x3f) << 12) | ((buf[3] & 0x3f) << 6) |
(buf[4] & 0x3f);
sampleWord = ((_buf[0] & 0x3f) << 24) | ((_buf[1] & 0x3f) << 18) |
((_buf[2] & 0x3f) << 12) | ((_buf[3] & 0x3f) << 6) |
(_buf[4] & 0x3f);
break;
case 4:
nibble = 1;
sample_word = ((buf[0] & 0xff) << 24) | ((buf[1] & 0xff) << 16) |
((buf[2] & 0xff) << 8) | (buf[3] & 0xff);
sampleWord = ((_buf[0] & 0xff) << 24) | ((_buf[1] & 0xff) << 16) |
((_buf[2] & 0xff) << 8) | (_buf[3] & 0xff);
break;
case 3:
nibble = 2;
sample_word = (3U << 30) | ((buf[0] & 0x3ff) << 20) |
((buf[1] & 0x3ff) << 10) | (buf[2] & 0x3ff);
sampleWord = (3U << 30) | ((_buf[0] & 0x3ff) << 20) |
((_buf[1] & 0x3ff) << 10) | (_buf[2] & 0x3ff);
break;
case 2:
nibble = 2;
sample_word = (2U << 30) | ((buf[0] & 0x7fff) << 15) |
(buf[1] & 0x7fff);
sampleWord = (2U << 30) | ((_buf[0] & 0x7fff) << 15) |
(_buf[1] & 0x7fff);
break;
case 1:
nibble = 2;
sample_word = (1U << 30) | (buf[0] & 0x3fffffff);
sampleWord = (1U << 30) | (_buf[0] & 0x3fffffff);
break;
default:
assert(0);
break;
}
nibble_word |= (nibble << (30 - ((fp + 1) << 1)));
_nibbleWord |= (nibble << (30 - ((_fp + 1) << 1)));
spw = 7;
for(int i = 0; i < bp - used; ++i) {
buf[i] = buf[i + used];
update_spw(i);
_spw = 7;
for ( int i = 0; i < _bp - used; ++i ) {
_buf[i] = _buf[i + used];
updateSpw(i);
}
bp -= used;
_bp -= used;
_sampleCount += used;
current_packet.data[frame_count].nibble_word = htonl(nibble_word);
current_packet.data[frame_count].sample_word[fp] = htonl(sample_word);
if(++fp < 15) return;
_currentPacket.data[_frameCount].nibbleWord = htonl(_nibbleWord);
_currentPacket.data[_frameCount].sampleWord[_fp] = htonl(sampleWord);
if ( ++_fp < 15 ) {
return;
}
_nibbleWord = 0;
_fp = 0;
++_frameCount;
nibble_word = 0;
fp = 0;
++frame_count;
return;
}
template<typename T> void Steim2Encoder<T>::queue_packet(MSEEDEncoderPacket<Steim2Frame> &pckt) {
format->updateBuffer(pckt.record, _sampleCount, frame_count + (fp > 0));
template<typename T> void Steim2Encoder<T>::queuePacket(MSEEDEncoderPacket<Steim2Frame> &pckt) {
_format->updateBuffer(pckt.record, _sampleCount, _frameCount + (_fp > 0));
Packet *packet = new Packet(DataRecordPtr(pckt.record), format->networkCode, format->stationCode,
format->locationCode, format->channelCode);
Packet *packet = new Packet(DataRecordPtr(pckt.record), _format->networkCode,
_format->stationCode,
_format->locationCode,
_format->channelCode);
_packetQueue.push_back(PacketPtr(packet));
pckt.reset();
reset();
@ -200,37 +211,37 @@ template<typename T> void Steim2Encoder<T>::push(void *value) {
store(sample_val);
_clk.tick();
while ( bp >= spw ) {
if( !current_packet.valid() ) {
current_packet = get_packet();
init_packet();
while ( _bp >= _spw ) {
if ( !_currentPacket.valid() ) {
_currentPacket = getPacket();
initPacket();
}
update_packet();
if ( frame_count == number_of_frames(current_packet) ) {
finish_packet();
queue_packet(current_packet);
updatePacket();
if ( _frameCount == numberOfFrames(_currentPacket) ) {
finishPacket();
queuePacket(_currentPacket);
}
}
}
template<typename T> void Steim2Encoder<T>::flush() {
while ( bp ) {
if ( !current_packet.valid() ) {
current_packet = get_packet();
init_packet();
while ( _bp ) {
if ( !_currentPacket.valid() ) {
_currentPacket = getPacket();
initPacket();
}
update_packet();
if( frame_count == number_of_frames(current_packet) ) {
finish_packet();
queue_packet(current_packet);
updatePacket();
if ( _frameCount == numberOfFrames(_currentPacket) ) {
finishPacket();
queuePacket(_currentPacket);
}
}
if ( current_packet.valid() ) {
finish_packet();
queue_packet(current_packet);
if ( _currentPacket.valid() ) {
finishPacket();
queuePacket(_currentPacket);
}
}

View File

@ -12,28 +12,29 @@
* from gempa GmbH. *
***************************************************************************/
#ifndef CAPS_MSEED_UNCOMPRESSED_H
#define CAPS_MSEED_UNCOMPRESSED_H
#include "encoder.h"
#include "mseed.h"
#include <gempa/caps/endianess.h>
#include <iostream>
#include <netinet/in.h>
namespace Gempa {
namespace CAPS {
template<typename T> class UncompressedMSEED : public Encoder {
MSEEDEncoderPacket<T> get_packet() {
return _format->get_packet<T>(_clk.get_time(-_bp),
_clk.correction(), _timingQuality);
return _format->getPacket<T>(_clk.getTime(-_bp),
_clk.correction(), _timingQuality);
}
void queue_packet(MSEEDEncoderPacket<T> &pckt) {
void queuePacket(MSEEDEncoderPacket<T> &pckt) {
_format->updateBuffer(pckt.record, _sampleCount, 1);
Packet *packet = new Packet(DataRecordPtr(pckt.record), _format->networkCode, _format->stationCode,
@ -51,7 +52,7 @@ template<typename T> class UncompressedMSEED : public Encoder {
virtual ~UncompressedMSEED() { if ( _format ) delete _format; }
virtual void flush() {
if ( _current_packet.valid() ) {
queue_packet(_current_packet);
queuePacket(_current_packet);
}
}
@ -72,13 +73,15 @@ template<typename T> class UncompressedMSEED : public Encoder {
virtual int type() const { return _format->packType; }
private:
MSEEDFormat *_format;
MSEEDEncoderPacket<T> _current_packet;
int _bp;
MSEEDFormat *_format;
MSEEDEncoderPacket<T> _current_packet;
int _bp;
};
}
}
#endif // __STEIM1_H__