RSS Git Download  Clone
Raw Blame History
/*******************************************************************************
 *	PuServer.cc	PuServer process
 *			T.Barnaby,	BEAM Ltd,	2007-02-07
 *******************************************************************************
 */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <Debug.h>
#include <PuServer.h>
#include <Control.h>
#include <main.h>

PuServer::PuServer(Control& control, UInt32 number, int physNumber) : ocontrol(control){
	onumber = number;
	ophysNumber = physNumber;
}

PuServer::~PuServer(){
}

BError PuServer::init(){
	BError		err;
	BString		url;

	if(ocontrol.boapnsHost() != ""){
		url = BString("//") + ocontrol.boapnsHost() + "/";
	}
	
	opuControl.connectService(url + "puControl-" + ophysNumber);
	opuProcess.connectService(url + "puProcess-" + ophysNumber);

	err = opuProcess.addEventServer(url + "tmsEvent");
	
	return err;
}

UInt32 PuServer::getNumber(){
	return onumber;
}

BError PuServer::handleError(BError err, int e){
	BError	errRet;

	printf("PuServer::handleError: %d\n", err.getErrorNo());
	if((err.getErrorNo() == -EPIPE) && (e < 2)){
		// Try a reconnect
		opuControl.disconnectService();
		opuProcess.disconnectService();
		init();
	}
	else if(err.getErrorNo() == -ECONNREFUSED){
		errRet.set(err.getErrorNo(), BString("PuConnection Error: ") + err.getString());
	}
	else {
		errRet = err;
	}
	
	return errRet;
}

BError	PuServer::configure(ConfigInfo configInfo){
	BError	err;
	int	n = 0;
	
	while(err = opuControl.configure(configInfo)){
		if(err = handleError(err, n++))
			break;
	}
	
	return err;
}

BError	PuServer::test(BList<BError>& errors){
	BError	err;
	int	n = 0;
	
	while(err = opuControl.test(errors)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}

BError	PuServer::getStatus(BList<NameValue>& statusList){
	BError	err;
	int	n = 0;
	
	while(err = opuControl.getStatus(statusList)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}

BError	PuServer::getStatistics(BList<NameValue>& statsList){
	BError	err;
	int	n = 0;
	
	while(err = opuControl.getStatistics(statsList)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}


// Test functions
BError	PuServer::setTestMode(PuChannel puChannel, UInt32 testOutput, UInt32 timingDisableMask){
	BError	err;
	int	n = 0;
	
	while(err = opuControl.setTestMode(puChannel, testOutput, timingDisableMask)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}

BError	PuServer::setTimingSignals(PuChannel puChannel, UInt32 timingSignals){
	BError	err;
	int	n = 0;
	
	while(err = opuControl.setTimingSignals(puChannel, timingSignals)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}

BError	PuServer::captureTestData(PuChannel puChannel, TestCaptureInfo captureInfo, BArray<UInt64>& data){
	BError	err;
	int	n = 0;
	
	while(err = opuControl.captureTestData(puChannel, captureInfo, data)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}

BError	PuServer::setTestData(PuChannel puChannel, Int32 on, BArray<UInt32> data){
	BError	err;
	int	n = 0;
	
	while(err = opuControl.setTestData(puChannel, on, data)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}

BError PuServer::setPupeConfig(PuChannel puPhysChannel, PupeConfig pupeConfig){
	BError	err;
	int	n = 0;
	
	while(err = opuControl.setPupeConfig(puPhysChannel, pupeConfig)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}



BError	PuServer::setControlInfo(CycleParam params){
	BError	err;
	int	n = 0;
	
	while(err = opuProcess.setControlInfo(params)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}

BError	PuServer::setNextCycle(UInt32 cycleNumber, BString cycleType){
	BError	err;
	int	n = 0;
	
	while(err = opuProcess.setNextCycle(cycleNumber, cycleType)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}

BError	PuServer::getStatus(PuChannel puChannel, PuStatus& puStatus){
	BError	err;
	int	n = 0;
	
	while(err = opuProcess.getStatus(puChannel, puStatus)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}

BError	PuServer::getData(PuChannel puChannel, DataInfo dataInfo, Data& data){
	BError	err;
	int	n = 0;

	while(err = opuProcess.getData(puChannel, dataInfo, data)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}

BError	PuServer::requestData(PuChannel puChannel, DataInfo dataInfo){
	BError	err;
	int	n = 0;
	
	while(err = opuProcess.requestData(puChannel, dataInfo)){
		if(err = handleError(err, n++))
			break;
	}

	return err;
}