You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.1 KiB
C++

/***************************************************************************
* Copyright (C) 2021 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 <iostream>
#include <string>
#include <gempa/caps/log.h>
#include <gempa/caps/plugin.h>
#include <gempa/caps/mseed/steim2.h>
#include <gempa/caps/utils.h>
using namespace std;
using namespace Gempa::CAPS;
namespace {
#define LOG_CHANNEL(out, fmt) \
va_list ap;\
va_start(ap, fmt);\
fprintf(stderr, #out" "); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n");\
va_end(ap)
void LogError(const char *fmt, ...) {
LOG_CHANNEL(ERROR, fmt);
}
void LogWarning(const char *fmt, ...) {
LOG_CHANNEL(WARNING, fmt);
}
void LogNotice(const char *fmt, ...) {
LOG_CHANNEL(NOTICE, fmt);
}
void LogInfo(const char *fmt, ...) {
LOG_CHANNEL(INFO, fmt);
}
void LogDebug(const char *fmt, ...) {
LOG_CHANNEL(DEBUG, fmt);
}
}
int main(int argc, char **argv) {
if ( argc != 1 ) {
cerr << "Pushes samples to CAPS" << endl << endl;
cerr << "Usage: raw2caps" << endl;
return 1;
}
// Setup log handlers
int verbosity = 2;
switch ( verbosity ) {
case 4: Gempa::CAPS::SetLogHandler(LL_DEBUG, LogDebug);
case 3: Gempa::CAPS::SetLogHandler(LL_INFO, LogInfo);
case 2: Gempa::CAPS::SetLogHandler(LL_WARNING, LogWarning);
case 1: Gempa::CAPS::SetLogHandler(LL_ERROR, LogError);
default: Gempa::CAPS::SetLogHandler(LL_NOTICE, LogNotice);
}
Plugin plugin("raw2caps");
plugin.setHost("localhost");
plugin.setPort(18003);
// Enable on-the-fly MSEED Encoding
// Steim2EncoderFactory *factory = new Steim2EncoderFactory();
// plugin.setEncoderFactory(factory);
string networkCode = "AB";
string stationCode = "TEST";
string locationCode = "";
string channelCode = "HHZ";
uint16_t numerator = 100;
uint16_t denominator = 1;
Time startTime = Time::FromString("2021-01-01 00:00:00", "%F %T");
int timingQuality = 100;
string uom = "m";
vector<int> samples;
for ( int i = 0; i < 100; ++i ) {
samples.push_back(i);
}
Plugin::Status ret =
plugin.push(networkCode, stationCode, locationCode, channelCode, startTime,
numerator, denominator, uom, samples.data(), samples.size(),
DT_INT32, timingQuality);
if ( ret != Plugin::Success ) {
cerr << "Failed to send packet to CAPS" << endl;
return 1;
}
return 0;
}