Example #1
0
int main(int argc, char* argv[])
{
	// Some signals should lead to a normal shutdown of the daq stream client. Afterwards the program exists.
	signal( SIGTERM, &sigHandler);
	signal( SIGINT, &sigHandler);

	if ((argc<2) || (std::string(argv[1])=="-h") ) {
		std::cout << "syntax: " << argv[0] << " <stream server address>" << std::endl;
		return EXIT_SUCCESS;
	}

	static const std::string streamMetaFilename = "streamMeta.dump";
	streamMetaFile.open(streamMetaFilename);

	signalContainer.setDataCb(dataCb);
	signalContainer.setSignalMetaCb(signalMetaInformationCb);

	streamClient.setStreamMetaCb(streamMetaInformationCb);
	streamClient.setSignalContainer(&signalContainer);

	// connect to the daq stream service and give control to the receiving function.
	// returns on signal (terminate, interrupt) buffer overrun on the server side or loss of connection.
	try {
		streamClient.start(argv[1], hbm::streaming::DAQSTREAM_PORT);
	} catch (const std::runtime_error& e) {
		std::cerr << e.what();
		return EXIT_FAILURE;
	}
	return EXIT_SUCCESS;
}
Example #2
0
int main(int argc, char* argv[])
{
	// Some signals should lead to a normal shutdown of the daq stream client. Afterwards the program exists.
	signal( SIGTERM, &sigHandler);
	signal( SIGINT, &sigHandler);

	if ((argc<2) || (std::string(argv[1])=="-h") ) {
		std::cout << "syntax: " << argv[0] << " <stream server address> [ -q]" << std::endl;
		std::cout << "use option -q to print meta data only" << std::endl;
		return EXIT_SUCCESS;
	}
	
	if ((argc>=3) && (std::string(argv[2]) == "-q")) {
		signalContainer.setDataAsRawCb(dataCbQuiet);
	} else {
		signalContainer.setDataAsRawCb(rawCbVerbose);
	}

	signalContainer.setSignalMetaCb(signalMetaInformationCb);

	streamClient.setStreamMetaCb(streamMetaInformationCb);
	streamClient.setSignalContainer(&signalContainer);

	// connect to the daq stream service and give control to the receiving function.
	// returns on signal (terminate, interrupt) buffer overrun on the server side or loss of connection.
	streamClient.start(argv[1], hbm::streaming::DAQSTREAM_PORT);
	return EXIT_SUCCESS;
}
Example #3
0
static void streamMetaInformationCb(hbm::streaming::StreamClient& stream, const std::string& method, const Json::Value& params)
{
	if (method == hbm::streaming::META_METHOD_AVAILABLE) {
		std::cout << "The following signal(s) are available : ";
		// simply subscibe all signals that become available.
		hbm::streaming::signalReferences_t signalReferences;
		for (Json::ValueConstIterator iter = params.begin(); iter!= params.end(); ++iter) {
			const Json::Value& element = *iter;
			std::cout << element.asString() << ", ";
			signalReferences.push_back(element.asString());
		}
		std::cout << std::endl << std::endl;

		try {
			stream.subscribe(signalReferences);
			std::cout << "The following " << signalReferences.size() << " signal(s) were subscribed: ";
		} catch(const std::runtime_error& e) {
			std::cerr << "Error '" << e.what() << "' subscribing the following signal(s): ";
		}

		for(hbm::streaming::signalReferences_t::const_iterator iter=signalReferences.begin(); iter!=signalReferences.end(); ++iter) {
			std::cout << "'" << *iter << "' ";
		}
		std::cout << std::endl << std::endl;

	} else if(method==hbm::streaming::META_METHOD_UNAVAILABLE) {
		std::cout << "The following signal(s) are not available anyore: ";

		for (Json::ValueConstIterator iter = params.begin(); iter!= params.end(); ++iter) {
			const Json::Value& element = *iter;
			std::cout << element.asString() << ", ";
		}
		std::cout << std::endl << std::endl;

	} else if(method==hbm::streaming::META_METHOD_ALIVE) {
		// We do ignore this. We are using TCP keep alive in order to detect communication problems.
	} else if(method==hbm::streaming::META_METHOD_FILL) {
		if(params.empty()==false) {
			unsigned int fill = params[0u].asUInt();
			if(fill>25) {
				std::cout << stream.address() << ": ring buffer fill level is " << params[0u].asUInt() << "%" << std::endl;
			}
		}
	} else {
		std::cout << "Meta information: " << method << " " << Json::FastWriter().write(params) << std::endl;
	}
}
Example #4
0
int main(int argc, char* argv[])
{
	// Some signals should lead to a normal shutdown of the daq stream client. Afterwards the program exists.
	signal( SIGTERM, &sigHandler);
	signal( SIGINT, &sigHandler);

	if ((argc<2) || (std::string(argv[1])=="-h") ) {
		std::cout << "Subscribes all signals that become available." << std::endl;
		std::cout << "Each signal is expected to deliver a ramp with a defined slope." << std::endl;
		std::cout << std::endl;
		std::cout << "syntax: " << argv[0] << " <stream server address> <slope (default is " << rampValueDiff << ")>" << std::endl;
		return EXIT_SUCCESS;
	}

	if (argc==3) {
		char* pEnd;
		const char* pStart = argv[2];
		rampValueDiff = strtod(pStart, &pEnd);
		if (pEnd ==pStart) {
			std::cerr << "invalid slope value. Must be a number" << std::endl;
			return EXIT_FAILURE;
		}
	}

	signalContainer.setDataCb(dataCb);
	signalContainer.setSignalMetaCb(signalMetaInformationCb);

	streamClient.setStreamMetaCb(streamMetaInformationCb);
	streamClient.setSignalContainer(&signalContainer);

	// connect to the daq stream service and give control to the receiving function.
	// returns on signal (terminate, interrupt) buffer overrun on the server side or loss of connection.
	try {
		streamClient.start(argv[1], hbm::streaming::DAQSTREAM_PORT);
	} catch (const std::runtime_error& e) {
		std::cerr << e.what();
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Example #5
0
static void sigHandler(int)
{
	streamClient.stop();
}