diff --git a/MAC/APL/StationCU/configure.in b/MAC/APL/StationCU/configure.in index b926cc4bc410fd78c1850015e10ecaa5565c1494..6835f24171898c2ed684366c84903e571b7b70a5 100644 --- a/MAC/APL/StationCU/configure.in +++ b/MAC/APL/StationCU/configure.in @@ -66,7 +66,7 @@ lofar_INTERNAL(MAC/APL/APLCommon, aplcommon,, 1, APL/APLCommon/APL_Defines.h,,) lofar_INTERNAL(MAC/APL/PAC/BS_Protocol, BS_Protocol,, 1, APL/BS_Protocol/BS_Protocol.ph,,) lofar_INTERNAL(MAC/APL/PAC/CAL_Protocol, CAL_Protocol,, 1, APL/CAL_Protocol/CAL_Protocol.ph,,) lofar_INTERNAL(MAC/APL/PIC/RSP_Protocol, RSP_Protocol,, 1, APL/RSP_Protocol/RSP_Protocol.ph,,) -dnl lofar_EXTERNAL(boost,1.32,boost/date_time/date.hpp, boost_date_time-gcc) +lofar_EXTERNAL(boost,1.32,boost/date_time/date.hpp, boost_date_time-gcc) dnl lofar_EXTERNAL(pqxx,2.5.5,pqxx/pqxx, pqxx) dnl lofar_EXTERNAL(pq,,libpq-fe.h, pq, /usr/local/pgsql) diff --git a/MAC/APL/StationCU/src/BeamControl/BeamControl.cc b/MAC/APL/StationCU/src/BeamControl/BeamControl.cc index eb581131ddc88fdefe3796a43e270ded3251b8fd..1454cb518ca11031c08ed3f966a86933aa2e4ed7 100644 --- a/MAC/APL/StationCU/src/BeamControl/BeamControl.cc +++ b/MAC/APL/StationCU/src/BeamControl/BeamControl.cc @@ -33,6 +33,7 @@ #include <APL/APLCommon/APLUtilities.h> #include <APL/APLCommon/APLCommonExceptions.h> #include <APL/APLCommon/Controller_Protocol.ph> +#include <APL/APLCommon/StationInfo.h> #include <APL/BS_Protocol/BS_Protocol.ph> #include "BeamControl.h" @@ -65,11 +66,22 @@ BeamControl::BeamControl(const string& cntlrName) : { LOG_TRACE_OBJ_STR (cntlrName << " construction"); + // First readin our observation related config file. + LOG_DEBUG_STR("Reading parset file:" << LOFAR_SHARE_LOCATION << "/" << cntlrName); + globalParameterSet()->adoptFile(string(LOFAR_SHARE_LOCATION)+"/"+cntlrName); + + // Readin some parameters from the ParameterSet. itsTreePrefix = globalParameterSet()->getString("prefix"); - itsInstanceNr = globalParameterSet()->getUint32(itsTreePrefix + ".instanceNr"); - itsStartTime = globalParameterSet()->getTime (itsTreePrefix + ".starttime"); - itsStopTime = globalParameterSet()->getTime (itsTreePrefix + ".stoptime"); + itsInstanceNr = globalParameterSet()->getUint32("_instanceNr"); + + // get Observation based information + itsStartTime = time_from_string(globalParameterSet()-> + getString("Observation.startTime")); + itsStopTime = time_from_string(globalParameterSet()-> + getString("Observation.stopTime")); + itsClaimPeriod = globalParameterSet()->getTime ("Observation.claimPeriod"); + itsPreparePeriod = globalParameterSet()->getTime ("Observation.preparePeriod"); // attach to parent control task itsParentControl = ParentControl::instance(); @@ -151,7 +163,7 @@ void BeamControl::handlePropertySetAnswer(GCFEvent& answer) getName().c_str(), pPropAnswer->pScope)); } // always let timer expire so main task will continue. - itsTimerPort->setTimer(0.0); + itsTimerPort->setTimer(1.0); break; } @@ -208,10 +220,10 @@ GCFEvent::TResult BeamControl::initial_state(GCFEvent& event, GCFEvent::TResult status = GCFEvent::HANDLED; switch (event.signal) { - case F_INIT: + case F_ENTRY: break; - case F_ENTRY: { + case F_INIT: { // Get access to my own propertyset. LOG_DEBUG ("Activating PropertySet"); string propSetName = formatString(BC_PROPSET_NAME, itsInstanceNr); @@ -243,16 +255,11 @@ GCFEvent::TResult BeamControl::initial_state(GCFEvent& event, break; case F_CONNECTED: - ASSERTSTR (&port == itsBeamServer, + ASSERTSTR (&port == itsParentPort, "F_CONNECTED event from port " << port.getName()); break; case F_DISCONNECTED: - port.close(); - ASSERTSTR (&port == itsBeamServer, - "F_DISCONNECTED event from port " << port.getName()); - LOG_DEBUG("Connection with BeamServer failed, retry in 2 seconds"); - itsTimerPort->setTimer(2.0); break; default: @@ -276,9 +283,6 @@ GCFEvent::TResult BeamControl::active_state(GCFEvent& event, GCFPortInterface& p GCFEvent::TResult status = GCFEvent::HANDLED; switch (event.signal) { - case F_INIT: - break; - case F_ENTRY: { // update PVSS itsPropertySet->setValue(string(PVSSNAME_FSM_STATE),GCFPVString("active")); @@ -286,18 +290,25 @@ GCFEvent::TResult BeamControl::active_state(GCFEvent& event, GCFPortInterface& p break; } + case F_INIT: + itsBeamServer->open(); + break; + case F_ACCEPT_REQ: break; case F_CONNECTED: { - ASSERTSTR (&port == itsBeamServer, + ASSERTSTR (&port == itsBeamServer || &port == itsParentPort, "F_CONNECTED event from port " << port.getName()); - itsTimerPort->cancelAllTimers(); - LOG_DEBUG ("Connected with BeamServer"); - setState(CTState::CLAIMED); - CONTROLClaimedEvent answer; -//TODO answer.cntlrName = msg.cntlrName; - port.send(answer); + if (&port == itsBeamServer) { + itsTimerPort->cancelAllTimers(); + LOG_DEBUG ("Connected with BeamServer"); + setState(CTState::CLAIMED); + CONTROLClaimedEvent answer; + answer.cntlrName = getName(); + answer.result = CT_RESULT_NO_ERROR; + itsParentPort->send(answer); + } break; } @@ -347,11 +358,7 @@ GCFEvent::TResult BeamControl::active_state(GCFEvent& event, GCFPortInterface& p CONTROLPrepareEvent msg(event); LOG_DEBUG_STR("Received PREPARE(" << msg.cntlrName << ")"); setState(CTState::PREPARE); - doPrepare (msg.cntlrName); - setState(CTState::PREPARED); - CONTROLPreparedEvent answer; - answer.cntlrName = msg.cntlrName; - port.send(answer); + doPrepare(msg.cntlrName); // will result in BS_BEAMALLOCACK event break; } @@ -359,6 +366,7 @@ GCFEvent::TResult BeamControl::active_state(GCFEvent& event, GCFPortInterface& p CONTROLResumeEvent msg(event); LOG_DEBUG_STR("Received RESUME(" << msg.cntlrName << ")"); setState(CTState::ACTIVE); + // TODO: implement something useful CONTROLResumedEvent answer; answer.cntlrName = msg.cntlrName; port.send(answer); @@ -369,6 +377,7 @@ GCFEvent::TResult BeamControl::active_state(GCFEvent& event, GCFPortInterface& p CONTROLSuspendEvent msg(event); LOG_DEBUG_STR("Received SUSPEND(" << msg.cntlrName << ")"); setState(CTState::SUSPENDED); + // TODO: implement something useful CONTROLSuspendedEvent answer; answer.cntlrName = msg.cntlrName; port.send(answer); @@ -388,9 +397,19 @@ GCFEvent::TResult BeamControl::active_state(GCFEvent& event, GCFPortInterface& p } // -------------------- EVENTS RECEIVED FROM BEAMSERVER -------------------- - case BS_BEAMALLOCACK: - handleBeamAllocAck(event); + case BS_BEAMALLOCACK: { + BSBeamallocackEvent msg(event); + uint16 result = handleBeamAllocAck(event); + if (result == CT_RESULT_NO_ERROR) { + setState(CTState::PREPARED); + } + + CONTROLPreparedEvent answer; + answer.cntlrName = getName(); + answer.result = result; + port.send(answer); break; + } case BS_BEAMFREEACK: handleBeamFreeAck(event); @@ -411,87 +430,92 @@ GCFEvent::TResult BeamControl::active_state(GCFEvent& event, GCFPortInterface& p // void BeamControl::doPrepare(const string& cntlrName) { - try { - vector<int> subbandsVector; - vector<int> beamletsVector; - // TODO use parameterset of 'cntlrname' - APLUtilities::string2Vector(m_parameterSet.getString(string("subbands")),subbandsVector); - APLUtilities::string2Vector(m_parameterSet.getString(string("beamlets")),beamletsVector); - - BSBeamallocEvent beamAllocEvent; - beamAllocEvent.name = getName(); - beamAllocEvent.subarrayname = m_parameterSet.getString(string("subarrayName")); - vector<int>::iterator beamletIt = beamletsVector.begin(); - vector<int>::iterator subbandIt = subbandsVector.begin(); - while (beamletIt != beamletsVector.end() && subbandIt != subbandsVector.end()) { - beamAllocEvent.allocation()[*beamletIt++] = *subbandIt++; - } - itsBeamServer->send(beamAllocEvent); // will result in BS_BEAMALLOCACK; - } - catch(Exception& e) { - LOG_ERROR(formatString("Error preparing BeamServer: %s",e.message().c_str())); + // TODO use parameterset of 'cntlrname' when being shared controller + + string subbandList(globalParameterSet()->getString("Observation.subbandList")); + string beamletList(globalParameterSet()->getString("Observation.beamletList")); + LOG_DEBUG_STR("subbandlist:" << subbandList); + LOG_DEBUG_STR("beamletList:" << beamletList); + + vector<int> subbandsVector; + vector<int> beamletsVector; + APLUtilities::string2Vector(subbandList,subbandsVector); + APLUtilities::string2Vector(beamletList,beamletsVector); + ASSERTSTR (subbandsVector.size() == beamletsVector.size(), + "size of subbandList " << subbandsVector.size() << " != " << + " size of beamletList" << beamletsVector.size()); + + BSBeamallocEvent beamAllocEvent; + beamAllocEvent.name = getName(); + beamAllocEvent.subarrayname = globalParameterSet()->getString("Observation.subarrayName"); + LOG_DEBUG_STR("subarrayName:" << beamAllocEvent.subarrayname); + + vector<int>::iterator beamletIt = beamletsVector.begin(); + vector<int>::iterator subbandIt = subbandsVector.begin(); + while (beamletIt != beamletsVector.end() && subbandIt != subbandsVector.end()) { + beamAllocEvent.allocation()[*beamletIt++] = *subbandIt++; } + + LOG_DEBUG_STR("Sending Alloc event to BeamServer"); + itsBeamServer->send(beamAllocEvent); // will result in BS_BEAMALLOCACK; } // // handleBeamAllocAck(event); // -bool BeamControl::handleBeamAllocAck(GCFEvent& event) +uint16 BeamControl::handleBeamAllocAck(GCFEvent& event) { // check the beam ID and status of the ACK message BSBeamallocackEvent ackEvent(event); if (ackEvent.status != 0) { -// errorCode = CT_RESULT_BEAMALLOC_ERROR; LOG_ERROR_STR("Beamlet allocation failed with errorcode: " << ackEvent.status); - return (false); + return (CT_RESULT_BEAMALLOC_FAILED); } + itsBeamID = ackEvent.handle; // read new angles from parameterfile. - m_beamID = ackEvent.handle; - - double directionAngle1(0.0); - double directionAngle2(0.0); - vector<string> sourceTimes; - vector<double> declinations; - vector<double> rightAscentions; - - try { - sourceTimes = m_parameterSet.getStringVector(string("sourceTimes")); - declinations = m_parameterSet.getDoubleVector(string("declination")); - rightAscentions = m_parameterSet.getDoubleVector(string("rightAscention")); - } - catch(Exception &e) { - } + vector<string> sourceTimes; + vector<double> angles1; + vector<double> angles2; + string beam(globalParameterSet()->locateModule("Beam")+"."); + sourceTimes = globalParameterSet()->getStringVector(beam+"angleTimes"); + angles1 = globalParameterSet()->getDoubleVector(beam+"angle1"); + angles2 = globalParameterSet()->getDoubleVector(beam+"angle2"); // point the new beam BSBeampointtoEvent beamPointToEvent; - beamPointToEvent.handle = m_beamID; + beamPointToEvent.handle = itsBeamID; beamPointToEvent.pointing.setType(static_cast<Pointing::Type> - (convertDirection(m_parameterSet.getString(string("directionType"))))); + (convertDirection(globalParameterSet()->getString(beam+"directionTypes")))); - if (sourceTimes.size() == 0 || sourceTimes.size() != declinations.size() || - sourceTimes.size() != rightAscentions.size()) { + // only 1 angle? + if (sourceTimes.size() == 0 || sourceTimes.size() != angles1.size() || + sourceTimes.size() != angles2.size()) { // key sourceTimes not found: use one fixed angle - directionAngle1=m_parameterSet.getDouble(string("declination")); - directionAngle2=m_parameterSet.getDouble(string("rightAscention")); + double directionAngle1(0.0); + double directionAngle2(0.0); + directionAngle1=globalParameterSet()->getDouble(beam+"declination"); + directionAngle2=globalParameterSet()->getDouble(beam+"rightAscention"); beamPointToEvent.pointing.setTime(RTC::Timestamp()); // asap beamPointToEvent.pointing.setDirection(directionAngle1,directionAngle2); itsBeamServer->send(beamPointToEvent); - } - else { // its a vecor with angles. - vector<double>::iterator declination = declinations.begin(); - vector<double>::iterator rightAscention = rightAscentions.begin(); - for (vector<string>::iterator timesIt = sourceTimes.begin(); - timesIt != sourceTimes.end(); ++timesIt) { - beamPointToEvent.pointing.setTime(RTC::Timestamp( - APLUtilities::decodeTimeString(*timesIt),0)); - beamPointToEvent.pointing.setDirection(*declination++,*rightAscention++); - itsBeamServer->send(beamPointToEvent); - } + // NB: will NOT result in an answer event of the beamserver. + return (CT_RESULT_NO_ERROR); } - return (true); + // its a vecor with angles. + vector<double>::iterator angle1Iter = angles1.begin(); + vector<double>::iterator angle2Iter = angles2.begin(); + for (vector<string>::iterator timesIt = sourceTimes.begin(); + timesIt != sourceTimes.end(); ++timesIt) { + beamPointToEvent.pointing.setTime(RTC::Timestamp( + APLUtilities::decodeTimeString(*timesIt),0)); + beamPointToEvent.pointing.setDirection(*angle1Iter++,*angle2Iter++); + itsBeamServer->send(beamPointToEvent); + // NB: will NOT result in an answer event of the beamserver. + } + return (CT_RESULT_NO_ERROR); } // @@ -500,8 +524,8 @@ bool BeamControl::handleBeamAllocAck(GCFEvent& event) void BeamControl::doRelease(GCFEvent& event) { BSBeamfreeEvent beamFreeEvent; -//TODO beamFreeEvent.handle = ...beamID ... - itsBeamServer->send(beamFreeEvent); + beamFreeEvent.handle = itsBeamID; + itsBeamServer->send(beamFreeEvent); // will result in BS_BEAMFREEACK event } diff --git a/MAC/APL/StationCU/src/BeamControl/BeamControl.comp b/MAC/APL/StationCU/src/BeamControl/BeamControl.comp deleted file mode 100644 index a11569d2cda8d4b3eabff70d3a96d5451c14c8b5..0000000000000000000000000000000000000000 --- a/MAC/APL/StationCU/src/BeamControl/BeamControl.comp +++ /dev/null @@ -1,50 +0,0 @@ -# -# Component description of the BeamController -# -# $Id$ -# -# name name of the node -# version version of this node specification -# quality stable | test | development -# constraint python script to check multiparameter constrains -# may return OK, NotOK, Unknown -# description What this module does. -# -# Note 1: to seperate the parameterlines from the Node lines each node line -# begins with the label 'Node'. -# Note 2: To define dependancies between nodes the label 'Uses' is used. -# A + sign may be added to the versionnr to indicate that the given -# versionnr is the minimal version the module schould have. (NOT YET IMPLEMENTED) -# - - -######################################################################################################### -# -- Station Operations -- -# name vers qual constr. descr. -#-------------------------------------------------------------------------------------------------------- -node "BeamControl" 1.0.0 test 'node constraint' "Station BeamControl" - -# -# name name of the parameter -# direction I: input only; O: changes will be logged during runtime; IO: both -# type parametertype: should exist in param_type table of OTDB (= ParamTypeConv) -# unit name of unit of parameter (should exist in unit table (= UnitConv) -# pruninglevel when parameter values are thrown away from the database. (NOT YET USED) -# validationMoment moment the parameter values is validated (NOT YET USED) -# value value(range) of the parameter. -# constraint script to run to check its value -# description what the parameter manages. -#-------------------------------------------------------------------------------------------------------- -# name dir. type unit prun. vm value constr. descr. -#-------------------------------------------------------------------------------------------------------- -par instanceNr I uint - 10 0 0 - 'BeamController instancenumber' -par starttime I uint - 10 0 >>Observation.stoptime - 'Starttime of observation' -par stoptime I uint - 10 0 >>Observation.starttime - 'Stoptime of observation' -par subarrayName I text - 10 0 0 - 'Unique name of the subarray' -par subbands I vuint - 10 0 0 - 'Subbands in the subarray' -par beamlets I vuint - 10 0 0 - 'The beamlets allocated on the subarray' -par sourceTimes I vuint - 10 0 0 - 'Relative time (to starttime) when to activate the declination and rightAscentions' -par declination I vdbl - 10 0 0 - 'Declination(s) of the source(s)' -par rightAscention I vdbl - 10 0 0 - 'rightAscention(s) of the source(s)' -par directionType I text - 10 0 0 - 'Coord.system used for sources' - diff --git a/MAC/APL/StationCU/src/BeamControl/BeamControl.conf.in b/MAC/APL/StationCU/src/BeamControl/BeamControl.conf.in deleted file mode 100644 index ec61a61ec386e57706c9d779ec58205e284c8f68..0000000000000000000000000000000000000000 --- a/MAC/APL/StationCU/src/BeamControl/BeamControl.conf.in +++ /dev/null @@ -1,19 +0,0 @@ -# new setup -prefix = Observation0.BeamServer - -Observation0.BeamServer.instanceNr = 0 -Observation0.BeamServer.starttime = 0 -Observation0.BeamServer.stoptime = 1 - -Observation0.BeamServer.subbands = [string] -Observation0.BeamServer.beamlets = [string] -Observation0.BeamServer.subarrayName = string -Observation0.BeamServer.angleTimes = [string] -Observation0.BeamServer.declination = [double] -Observation0.BeamServer.rightAscention = [double] -Observation0.BeamServer.directionType = string - -# next parameters are optional, defaultvalues are shown -#ChildControl.StartupRetryInterval = 10s -#ChildControl.MaxStartupRetry = 5 - diff --git a/MAC/APL/StationCU/src/BeamControl/BeamControl.h b/MAC/APL/StationCU/src/BeamControl/BeamControl.h index 4ca2c67bf0d74a0b619237cfee8119b61147bc84..f2901b4a1e4e1a5307871cfef0556ed9a26a0757 100644 --- a/MAC/APL/StationCU/src/BeamControl/BeamControl.h +++ b/MAC/APL/StationCU/src/BeamControl/BeamControl.h @@ -45,6 +45,7 @@ //# Common Includes #include <Common/lofar_string.h> #include <Common/lofar_vector.h> +#include <Common/lofar_datetime.h> #include <Common/LofarLogger.h> //# ACC Includes @@ -90,7 +91,7 @@ private: int32 convertDirection(const string& typeName); void doPrepare(const string& cntlrName); - bool handleBeamAllocAck(GCFEvent& event); + uint16 handleBeamAllocAck(GCFEvent& event); bool handleBeamFreeAck(GCFEvent& event); void doRelease(GCFEvent& event); void _connectedHandler(GCFPortInterface& port); @@ -129,12 +130,11 @@ private: // ParameterSet variables string itsTreePrefix; uint32 itsInstanceNr; - time_t itsStartTime; - time_t itsStopTime; - - //TODO - ACC::APS::ParameterSet m_parameterSet; - uint32 m_beamID; + ptime itsStartTime; + ptime itsStopTime; + uint32 itsClaimPeriod; + uint32 itsPreparePeriod; + uint32 itsBeamID; }; };//StationCU diff --git a/MAC/APL/StationCU/src/BeamControl/BeamControl.log_prop.in b/MAC/APL/StationCU/src/BeamControl/BeamControl.log_prop.in index 806b2f6567a19675018dd377e2d833893c05cc9e..7696b5b09b9373a768acd5d563415fc91c21f7e3 100644 --- a/MAC/APL/StationCU/src/BeamControl/BeamControl.log_prop.in +++ b/MAC/APL/StationCU/src/BeamControl/BeamControl.log_prop.in @@ -8,7 +8,7 @@ log4cplus.additivity.TRC=FALSE log4cplus.appender.STDOUT=log4cplus::ConsoleAppender log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout -log4cplus.appender.STDOUT.layout.ConversionPattern=%x %D{%d-%m-%y %H:%M:%S.%q} %-5p %c{9} - %m [%.25l]%n +log4cplus.appender.STDOUT.layout.ConversionPattern=%D{%d-%m-%y %H:%M:%S.%q} %-5p %c{9} - %m [%.25l]%n log4cplus.appender.STDOUT.logToStdErr=true log4cplus.appender.FILE=log4cplus::RollingFileAppender @@ -16,5 +16,5 @@ log4cplus.appender.FILE.File=../log/BeamControl.log log4cplus.appender.FILE.MaxFileSize=5MB log4cplus.appender.FILE.MaxBackupIndex=5 log4cplus.appender.FILE.layout=log4cplus::PatternLayout -log4cplus.appender.FILE.layout.ConversionPattern=%x %D{%d-%m-%y %H:%M:%S.%q} %-5p %c{3} - %m [%.25l]%n +log4cplus.appender.FILE.layout.ConversionPattern=%D{%d-%m-%y %H:%M:%S.%q} %-5p %c{3} - %m [%.25l]%n diff --git a/MAC/APL/StationCU/src/BeamControl/Makefile.am b/MAC/APL/StationCU/src/BeamControl/Makefile.am index 0f7665fb86ce52d79507b1da1f1a8b3da6643f4c..a2189efe96be907817106e11011e9b39227e1b5b 100644 --- a/MAC/APL/StationCU/src/BeamControl/Makefile.am +++ b/MAC/APL/StationCU/src/BeamControl/Makefile.am @@ -26,18 +26,11 @@ configfilesdir=$(bindir) configfiles_DATA = #customPrepPVSSDB.ctl -sysconf_DATA = BeamControl.conf \ - BeamControl.log_prop +sysconf_DATA = BeamControl.log_prop %.log_prop: %.log_prop.in cp $< $@ -%.conf: %.conf.in - cp $< $@ - -%.ctl: %.ctl.in - cp $< $@ - clean-local: rm -f *.ph