00001 #ifdef linux
00002 #undef linux
00003 #endif
00004
00005 #include "RunController.h"
00006 #include "CalibrationControllerImpl.h"
00007 #include "ipc/CalibrationController.h"
00008 #include "Sct/SctNames.h"
00009 #include "Sct/Exception.h"
00010 #include <rc/RunParamsInfo.h>
00011 #include <ipc/partition.h>
00012 #include <is/isinfo.h>
00013 #include <iostream>
00014 #include <fstream>
00015 #include <ilu/iluxport.h>
00016
00017 using namespace std;
00018 using namespace Sct;
00019
00020 int main(int argc, char** argv) {
00021 using namespace SctCalibrationController;
00022
00023 cout << "Starting Calibration controller" << endl;
00024 setExceptionHandlers(argv[0]);
00025
00026 IPCCore::init(true);
00027
00028
00029 RunControl& rc = RunControl::instance();
00030 cout << "Instance created" << endl;
00031
00032 rc.rc_start("CalibrationController", "SCT");
00033 cout << "All over" << endl;
00034
00035 return 0;
00036 }
00037
00038 namespace SctCalibrationController {
00039
00040 RunControl::RunControl() : cc (CalibrationControllerImpl::initialize(*this)) {
00041 }
00042
00043 RunControl& RunControl::instance() {
00044 static RunControl rc;
00045 return rc;
00046 }
00047
00048
00049 int RunControl::loadaction () {
00050 cout << "Loadaction" << endl;
00051 api = (Sct_SctApi_T_SctApi*)ipcPartition().lookup("Test_Server", "SCTSctApiServer", Sct_SctApi_T_SctApi::ILUClassRecord);
00052 if (!api) {
00053 SctNames::Mrs() << "RC_INIT" << MRS_TEXT("RunController failed to find SctApi") << MRS_ERROR << ENDM;
00054 return 1;
00055 }
00056 cc.setApi(*api);
00057 Sct_SctApiStatus s;
00058 api->initialiseAll(&s, 0);
00059
00060
00061 return 0;
00062 }
00063
00064 void RunControl::enterConfigured() {
00065 Sct_SctApiStatus status;
00066 api->configureAllModules(&status);
00067 }
00068
00069 void RunControl::enterRunning() {
00070 if (!api) {
00071 cout << "Can't enter running as we don't have the api" << endl;
00072 return;
00073 }
00074 cout << "enter Running" << endl;
00075 Sct_SctApiStatus status;
00077 RunParamsInfo runParams;
00078 ISInfoDictionary& is = SctNames::getISDictionary();
00079 ISInfo::Status isStatus;
00080
00081 isStatus = is.findValue("RunParams.RunParams", runParams);
00082 api->setRunNumber(&status, runParams.run_number);
00083 api->setScanNumber(&status, 0);
00084 cout << "New Run, setting run number and scan number: " << runParams.run_number << " " << 0 << endl;
00085 cc.takeControl(runParams.run_number);
00086 }
00087
00088 void RunControl::exitRunning() {
00089 Sct_SctApiStatus status;
00090 cout << "exit Running" << endl;
00091 cc.giveupControl();
00092 }
00093
00094 int RunControl::unloadaction () {
00095 cout << "unloadaction" << endl;
00096
00097 Sct_SctApiStatus status;
00098
00099 if (api) api->shutdownAll(&status);
00100
00101 return 0;
00102 }
00103
00104 int RunControl::resetaction () {
00105 cc.reset();
00106 return 0;
00107 }
00108
00109 void RunControl::sctApiError(ErrorState state, const string& reason) {
00110 this->setError(state, reason);
00111 api = 0;
00112 cc.giveupControl();
00113 }
00114
00115 }