RSS Git Download  Clone
Raw Blame History
/*
* Title:	Control.cpp
* Author:	M.Thomas BEAM Ltd
* Date:		2007-02-13
*
* Contents:	Tms Client control. All Server request are routed through here.
*
* Mod Rec:
*
*/


#include <Control.h>
#include <iostream>
#include <Debug.h>

using namespace std;
using namespace Tms;


Control::Control() {
	ohostName = "localhost";
};

Control::~Control(){};
	
BError		Control::init() {					///< Initialise the system
	BError	err;
	err = connect();
	return err;
}

void	Control::setHost(BString host) {				///< Set host
	ohostName = host;
}

BError	Control::connect() {
	BError	err;

	dprintf(DBG_CONTROL,"Connecting to server - Disconnecting services\n");

	otmsControl.disconnectService();
	otmsProcess.disconnectService();
	dprintf(DBG_CONTROL,"Connecting to server - Services Disconnected\n");
	dprintf(DBG_CONTROL,"Connecting to boap object - (%s/tmsControl)\n",ohostName.retStr());
	
	if(err = otmsControl.connectService(BString("//") + ohostName + "/tmsControl")){
		cerr << "Error: cannot connect to tmsControl: " << err.getString() << "\n";
		return err;
	}
	dprintf(DBG_CONTROL,"Connecting to boap object - (%s/tmsProcess)\n",ohostName.retStr());
	if(err = otmsProcess.connectService(BString("//") + ohostName + "/tmsProcess")){
		cerr << "Error: cannot connect to tmsProcess: " << err.getString() << "\n";
		return err;
	}
	emit newConnection();
	dprintf(DBG_CONTROL,"Connected to server objects\n");
	return err;
}

BError	Control::reconfigure(Tms::ConfigInfo info) {			///< Reconfigure the system
	otmsControl.configure(info);
	return otmsControl.configure(info);
}

BError	Control::getConfiguration(Tms::ConfigInfo& info) {		
	return otmsControl.getConfiguration(info);
}

BError	Control::setPupeConfig(Tms::PuChannel puChannel,Tms::PupeConfig pupeConfig) {
	return otmsControl.setPupeConfig(puChannel,pupeConfig);
}


BError	Control::setControlInfo(Tms::CycleParam	params) {		///< Setup cycle parameters
	return otmsProcess.setControlInfo(params);
}

BError	Control::runTest(BList<BError>& l) {				///< Start the system running
	return otmsControl.test(l);
}


BError	Control::getData(Tms::DataInfo info,Tms::Data& data) {		///< Get Data
	return otmsProcess.getData(info,data);
}

BError	Control::getTestData(PuChannel puPhysChannel, TestCaptureInfo captureInfo, BArray< UInt64 > &data) {
	return otmsControl.captureTestData(puPhysChannel,captureInfo,data);
}

BError	Control::getPuChannel (UInt32 puChannel, PuChannel &puPhysChannel){
	return otmsControl.getPuChannel(puChannel,puPhysChannel);
}

BError	Control::setTestData(PuChannel puChannel,Int32 on, BArray<UInt32> data) {
	return otmsControl.setTestData(puChannel,on,data);
}

BError	Control::getStatus(BList<Tms::NameValue>& l) {			///< Get Status
	return otmsControl.getStatus(l);
}

BError	Control::getStatistics(BList<Tms::NameValue>& l) {		///< Get Statistics
	return otmsControl.getStatistics(l);
}

BError	Control::getCycleNumber(UInt32& cycleNumber ) {
	BString cycleType;
	
	return otmsProcess.getCycleInfo(cycleNumber,cycleType);
}

BError	Control::setNextCycle(UInt32 cycleNumber,BString cycleType) {
	return otmsProcess.setNextCycle(cycleNumber,cycleType);
}

BError	Control::initialiseServer() {
	return otmsControl.init();
}