diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp new file mode 100644 index 000000000..9e9d41a77 --- /dev/null +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp @@ -0,0 +1,281 @@ +#include "receiverInterface.h" +#include "sls_detector_defs.h" + + +#include +#include +#include +#include +#include +#include +#include + + + +receiverInterface::receiverInterface(MySocketTCP *socket):dataSocket(socket){} + + + +receiverInterface::~receiverInterface(){ + delete dataSocket; +} + + + +int receiverInterface::sendString(int fnum, char retval[], char arg[]){ + int ret = slsDetectorDefs::FAIL; + char mess[100] = ""; + + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->SendDataOnly(arg,MAX_STR_LENGTH); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==slsDetectorDefs::FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); + } + dataSocket->Disconnect(); + } + return ret; +} + + + +int receiverInterface::sendInt(int fnum, int &retval, int arg){ + int ret = slsDetectorDefs::FAIL; + char mess[100] = ""; + + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->SendDataOnly(&arg,sizeof(arg)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==slsDetectorDefs::FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + dataSocket->Disconnect(); + } + return ret; +} + + + +int receiverInterface::getInt(int fnum, int &retval){ + int ret = slsDetectorDefs::FAIL; + + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + dataSocket->Disconnect(); + } + return ret; +} + + + +int receiverInterface::getLastClientIP(int fnum, char retval[]){ + int ret = slsDetectorDefs::FAIL; + + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + dataSocket->ReceiveDataOnly(retval,sizeof(retval)); + dataSocket->Disconnect(); + } + } + return ret; +} + + + +int receiverInterface::executeFunction(int fnum){ + + int ret = slsDetectorDefs::FAIL; + char mess[100] = ""; + + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==slsDetectorDefs::FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + dataSocket->Disconnect(); + } + } + return ret; +} + + + + /* + set or read the acquisition timers + enum timerIndex { + FRAME_NUMBER, + ACQUISITION_TIME, + FRAME_PERIOD, + DELAY_AFTER_TRIGGER, + GATES_NUMBER, + PROBES_NUMBER + CYCLES_NUMBER, + GATE_INTEGRATED_TIME + } + */ + /* +int64_t receiverInterface::setTimer(timerIndex index, int64_t t){ + + + int fnum=F_SET_TIMER; + int64_t retval; + uint64_t ut; + char mess[100]; + int ret=OK; + int n=0; + + if (index!=MEASUREMENTS_NUMBER) { + + +#ifdef VERBOSE + std::cout<< "Setting timer "<< index << " to " << t << "ns" << std::endl; +#endif + ut=t; + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (controlSocket) { + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&index,sizeof(index)); + n=controlSocket->SendDataOnly(&t,sizeof(t)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==slsDetectorDefs::FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->timerValue[index]=retval; + } + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) { + updateDetector(); +#ifdef VERBOSE + std::cout<< "Updated!" << std::endl; +#endif + + } + } + } + } else { + //std::cout<< "offline " << std::endl; + if (t>=0) + thisDetector->timerValue[index]=t; + } + } else { + if (t>=0) + thisDetector->timerValue[index]=t; + } +#ifdef VERBOSE + std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl; +#endif + if (index==PROBES_NUMBER) { + setDynamicRange(); + //cout << "Changing probes: data size = " << thisDetector->dataBytes <timerValue[index]; + +}; + + */ + + + + + + + /* + + + +int64_t receiverInterface::getTimeLeft(timerIndex index){ + + + int fnum=F_GET_TIME_LEFT; + int64_t retval; + char mess[100]; + int ret=OK; + +#ifdef VERBOSE + std::cout<< "Getting timer "<< index << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (stopSocket) { + if (stopSocket->Connect()>=0) { + stopSocket->SendDataOnly(&fnum,sizeof(fnum)); + stopSocket->SendDataOnly(&index,sizeof(index)); + stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==slsDetectorDefs::FAIL) { + stopSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } else { + stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + stopSocket->Disconnect(); + } + } + } +#ifdef VERBOSE + std::cout<< "Time left is "<< retval << std::endl; +#endif + return retval; + +}; + + + + + + + +int receiverInterface::exitServer(){ + + int retval; + int fnum=F_EXIT_SERVER; + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (controlSocket) { + controlSocket->Connect(); + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + controlSocket->Disconnect(); + } + } + if (retval!=OK) { + std::cout<< std::endl; + std::cout<< "Shutting down the server" << std::endl; + std::cout<< std::endl; + } + return retval; + +}; + + */ + + diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h new file mode 100644 index 000000000..f0f27d041 --- /dev/null +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h @@ -0,0 +1,98 @@ + + + +#ifndef SLS_RECEIVER_INTERFACE_H +#define SLS_RECEIVER_INTERFACE_H + +#include "MySocketTCP.h" + + + +/** + * + * @short the slsReceiverInterface class is the interface between the sls detector and the sls receiver + * @author Dhanya Maliakal + * @version 0.1alpha + */ + + +/** + @short interface between sls detector and sls receiver + */ +class receiverInterface{ + +public: + + /** + * (default) constructor + * @param socket tcp socket between client and receiver + */ + receiverInterface(MySocketTCP *socket); + + + /** + * destructor + */ + virtual ~receiverInterface(); + + + void setSocket(MySocketTCP *socket){dataSocket=socket;}; + + + /** + * Send a string to receiver + * @param fnum function enum to determine what parameter + * @param retval return value + * @param arg value to send + * \returns success of operation + */ + int sendString(int fnum, char retval[], char arg[]); + + + /** + * Send a string to receiver + * @param fnum function enum to determine what parameter + * @param retval return value + * @param arg value to send + * \returns success of operation + */ + int sendInt(int fnum, int &retval, int arg); + + + /** + * Send a string to receiver + * @param fnum function enum to determine what parameter + * @param retval return value + * \returns success of operation + */ + int getInt(int fnum, int &retval); + + + /** + * Send a string to receiver + * @param fnum function enum to get last client up + * @param retval return value + * \returns success of operation + */ + int getLastClientIP(int fnum, char retval[]); + + + /** + * Send a string to receiver + * @param fnum function enum to determine which function to execute + * \returns success of operation + */ + int executeFunction(int fnum); + + + +private: + + /** + * socket for data acquisition + */ + MySocketTCP *dataSocket; + +}; + +#endif