Initial commit based on common repo commit ffeb9c9b
This commit is contained in:
		
							
								
								
									
										19
									
								
								examples/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								examples/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
SET(APP_NAME raw2caps)
 | 
			
		||||
 | 
			
		||||
SET(SOURCES
 | 
			
		||||
	raw2caps.cpp
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
ADD_EXECUTABLE(${APP_NAME} ${SOURCES})
 | 
			
		||||
 | 
			
		||||
TARGET_LINK_LIBRARIES(${APP_NAME}
 | 
			
		||||
	capsclient
 | 
			
		||||
	mseed
 | 
			
		||||
	${Boost_program_options_LIBRARY}
 | 
			
		||||
	${Boost_filesystem_LIBRARY}
 | 
			
		||||
	${Boost_system_LIBRARY}
 | 
			
		||||
	${OPENSSL_LIBRARIES}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
INSTALL(TARGETS ${APP_NAME} DESTINATION examples)
 | 
			
		||||
INSTALL(DIRECTORY python DESTINATION examples)
 | 
			
		||||
							
								
								
									
										114
									
								
								examples/python/raw2caps.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								examples/python/raw2caps.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,114 @@
 | 
			
		||||
############################################################################
 | 
			
		||||
# 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.                                                         #
 | 
			
		||||
############################################################################
 | 
			
		||||
 | 
			
		||||
#!/usr/bin/env python
 | 
			
		||||
 | 
			
		||||
from __future__ import absolute_import, division, print_function
 | 
			
		||||
 | 
			
		||||
import getopt
 | 
			
		||||
import sys
 | 
			
		||||
import signal
 | 
			
		||||
 | 
			
		||||
import numpy as np
 | 
			
		||||
 | 
			
		||||
from gempa import CAPS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
usage_info = """
 | 
			
		||||
raw2caps - pushes raw samples into CAPS.
 | 
			
		||||
 | 
			
		||||
Usage: capstool [options]
 | 
			
		||||
 | 
			
		||||
Options:
 | 
			
		||||
    -H, --host                   host to connect to
 | 
			
		||||
    -h, --help                   display this help message and exit
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def usage(exitcode=0):
 | 
			
		||||
    sys.stderr.write(usage_info)
 | 
			
		||||
    return exitcode
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
output = CAPS.Plugin("raw2caps")
 | 
			
		||||
 | 
			
		||||
def signal_handler(sig, frame): #pylint: disable=W0613
 | 
			
		||||
    print('Caught Ctrl+C!')
 | 
			
		||||
    output.quit()
 | 
			
		||||
    sys.exit(0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def main():
 | 
			
		||||
    try:
 | 
			
		||||
        opts, _ = getopt.getopt(sys.argv[1:], "hH:d:n:",
 | 
			
		||||
                                ["help", "host=", "directory=", "network="])
 | 
			
		||||
    except getopt.GetoptError as err:
 | 
			
		||||
        # print help information and exit:
 | 
			
		||||
        print(str(err)) # will print something like "option -a not recognized"
 | 
			
		||||
        return usage(2)
 | 
			
		||||
 | 
			
		||||
    addr = None
 | 
			
		||||
 | 
			
		||||
    signal.signal(signal.SIGINT, signal_handler)
 | 
			
		||||
 | 
			
		||||
    for o, a in opts:
 | 
			
		||||
        if o in ["-h", "--help"]:
 | 
			
		||||
            return usage()
 | 
			
		||||
 | 
			
		||||
        if o in ["-H", "--host"]:
 | 
			
		||||
            addr = a
 | 
			
		||||
        else:
 | 
			
		||||
            assert False, "unhandled option"
 | 
			
		||||
 | 
			
		||||
    if addr:
 | 
			
		||||
        try:
 | 
			
		||||
            host, port = addr.split(":")
 | 
			
		||||
        except BaseException:
 | 
			
		||||
            sys.stderr.write("invalid host address given: %s\n" % addr)
 | 
			
		||||
            return 1
 | 
			
		||||
    else:
 | 
			
		||||
        host = None
 | 
			
		||||
        port = None
 | 
			
		||||
 | 
			
		||||
    if port:
 | 
			
		||||
        try:
 | 
			
		||||
            port = int(port)
 | 
			
		||||
        except BaseException:
 | 
			
		||||
            sys.stderr.write("invalid port given: %s\n" % port)
 | 
			
		||||
            return 1
 | 
			
		||||
    else:
 | 
			
		||||
        port = 18003
 | 
			
		||||
 | 
			
		||||
    if not host:
 | 
			
		||||
        host = "localhost"
 | 
			
		||||
 | 
			
		||||
    output.setHost(host)
 | 
			
		||||
    output.setPort(port)
 | 
			
		||||
    output.setBufferSize(1 << 30)
 | 
			
		||||
    output.enableLogging()
 | 
			
		||||
 | 
			
		||||
    startTime = CAPS.Time.GMT()
 | 
			
		||||
 | 
			
		||||
    x = np.array([1, 2], dtype=np.int32)
 | 
			
		||||
    res = output.push("AB", "HMA", "", "BHZ", startTime, 1, 1, "m", x,
 | 
			
		||||
                      CAPS.DT_INT32)
 | 
			
		||||
    if res != CAPS.Plugin.Success:
 | 
			
		||||
        sys.stderr.write("failed to send packet\n")
 | 
			
		||||
 | 
			
		||||
    output.close()
 | 
			
		||||
    return 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    sys.exit(main())
 | 
			
		||||
							
								
								
									
										112
									
								
								examples/raw2caps.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								examples/raw2caps.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,112 @@
 | 
			
		||||
/***************************************************************************
 | 
			
		||||
 * 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;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user