diff --git a/MAC/APL/StationCU/src/HardwareMonitor/PVSSDatapointDefs.h b/MAC/APL/StationCU/src/HardwareMonitor/PVSSDatapointDefs.h index 41eb932ecdefbef606100a32ef911765949bd7d1..ea0bee633e438b461a943bda650ea1ca59002491 100644 --- a/MAC/APL/StationCU/src/HardwareMonitor/PVSSDatapointDefs.h +++ b/MAC/APL/StationCU/src/HardwareMonitor/PVSSDatapointDefs.h @@ -1,4 +1,4 @@ -// This file was generated by create_db_files v1.0 on Tue Nov 18 15:00:28 UTC 2008 +// This file was generated by create_db_files v1.0 on Mon Dec 22 14:31:33 UTC 2008 #ifndef LOFAR_DEPLOYMENT_PVSSDATAPOINTS_H #define LOFAR_DEPLOYMENT_PVSSDATAPOINTS_H @@ -270,10 +270,6 @@ #define PSN_SOFTWARE_MONITOR "LOFAR_PermSW_SoftwareMonitor" #define PST_SOFTWARE_MONITOR "SoftwareMonitor" -// TemperatureMonitor -#define PSN_TEMPERATURE_MONITOR "LOFAR_PermSW_TemperatureMonitor" -#define PST_TEMPERATURE_MONITOR "TemperatureMonitor" - // MACInfoServer #define PSN_MAC_INFO_SERVER "LOFAR_PermSW_MACInfoServer" #define PST_MAC_INFO_SERVER "MACInfoServer" @@ -288,6 +284,19 @@ #define PN_DBC_CONNECTED "connected" #define PN_DBC_CLOCK "clock" +// Antenna +#define PSN_ANTENNA "@antenna@" +#define PST_ANTENNA "Antenna" +#define PN_ANT_STATUS_STATE "status.state" +#define PN_ANT_STATUS_CHILD_STATE "status.childState" +#define PN_ANT_STATUS_MESSAGE "status.message" +#define PN_ANT_STATUS_LEAF "status.leaf" +#define PN_ANT_RCUX "RCUX" +#define PN_ANT_RCUY "RCUY" +#define PN_ANT_DELTAX "deltaX" +#define PN_ANT_DELTAY "deltaY" +#define PN_ANT_DELTAZ "deltaZ" + // StnObservation #define PSN_STN_OBSERVATION "LOFAR_ObsSW_@observation@" #define PST_STN_OBSERVATION "StnObservation" diff --git a/MAC/APL/StationCU/src/HardwareMonitor/RSPMonitor.cc b/MAC/APL/StationCU/src/HardwareMonitor/RSPMonitor.cc index 8730e10e3faa94f8d0ddfa6698440a378644d545..59e9abf07d53aec5013c9d2f9feeb0aa4dad3079 100644 --- a/MAC/APL/StationCU/src/HardwareMonitor/RSPMonitor.cc +++ b/MAC/APL/StationCU/src/HardwareMonitor/RSPMonitor.cc @@ -22,11 +22,14 @@ #include <lofar_config.h> #include <Common/LofarLogger.h> #include <Common/LofarConstants.h> +#include <Common/LofarLocators.h> #include <Common/StringUtil.h> +#include <APS/ParameterSet.h> #include <GCF/PVSS/GCF_PVTypes.h> #include <MACIO/MACServiceInfo.h> #include <APL/APLCommon/ControllerDefines.h> +#include <APL/APLCommon/AntennaMapper.h> #include <APL/RTDBCommon/RTDButilities.h> #include <APL/RSP_Protocol/RSP_Protocol.ph> #include <GCF/RTDB/DP_Protocol.ph> @@ -38,6 +41,7 @@ #include "RCUConstants.h" #include "PVSSDatapointDefs.h" +#define MAX2(a,b) ((a) > (b)) ? (a) : (b) namespace LOFAR { using namespace APLCommon; @@ -45,6 +49,7 @@ namespace LOFAR { using namespace GCF::TM; using namespace GCF::PVSS; using namespace GCF::RTDB; + using namespace ACC::APS; namespace StationCU { // @@ -55,11 +60,14 @@ RSPMonitor::RSPMonitor(const string& cntlrName) : itsOwnPropertySet (0), itsTimerPort (0), itsRSPDriver (0), + itsDPservice (0), itsPollInterval (10), itsNrRCUs (0), itsNrRSPboards (0), itsNrSubracks (0), - itsNrCabinets (0) + itsNrCabinets (0), + itsRCUquery (0), + itsAntMapper (0) { LOG_TRACE_OBJ_STR (cntlrName << " construction"); @@ -72,6 +80,9 @@ RSPMonitor::RSPMonitor(const string& cntlrName) : ASSERTSTR(itsRSPDriver, "Cannot allocate TCPport to RSPDriver"); itsRSPDriver->setInstanceNr(0); + itsDPservice = new DPservice(this); + ASSERTSTR(itsDPservice, "Can't allocate DPservice"); + } @@ -82,11 +93,15 @@ RSPMonitor::~RSPMonitor() { LOG_TRACE_OBJ_STR (getName() << " destruction"); - if (itsRSPDriver) { - itsRSPDriver->close(); - } + if (itsRSPDriver) itsRSPDriver->close(); + + if (itsDPservice) delete itsDPservice; - // ... + if (itsTimerPort) delete itsTimerPort; + + if (itsRSPDriver) delete itsRSPDriver; + + if (itsAntMapper) delete itsAntMapper; } @@ -245,15 +260,20 @@ GCFEvent::TResult RSPMonitor::askConfiguration(GCFEvent& event, ((itsNrRSPboards%NR_RSPBOARDS_PER_SUBRACK) ? 1 : 0); itsNrCabinets = (itsNrSubracks /NR_SUBRACKS_PER_CABINET) + ((itsNrSubracks%NR_SUBRACKS_PER_CABINET) ? 1 : 0); + + // Read number of Antenna's from RemoteStation.conf file. + ConfigLocator CL; + ParameterSet RSconf(CL.locate("RemoteStation.conf")); + itsNrHBAs = RSconf.getInt("RS.N_HBAS", 0); + itsNrLBAs = RSconf.getInt("RS.N_LBAS", 0); // inform user LOG_DEBUG(formatString("nr RCUs = %d",ack.n_rcus)); LOG_DEBUG(formatString("nr RSPboards = %d",ack.max_rspboards)); LOG_DEBUG(formatString("nr Subracks = %d", itsNrSubracks)); LOG_DEBUG(formatString("nr Cabinets = %d", itsNrCabinets)); - LOG_DEBUG_STR("("<<itsNrRSPboards<<"/"<<NR_RSPBOARDS_PER_SUBRACK<<") + (("<<itsNrRSPboards<<"%"<<NR_RSPBOARDS_PER_SUBRACK<<") ? 1 : 0)"); - LOG_DEBUG_STR("("<<itsNrRSPboards<<"/"<<NR_RSPBOARDS_PER_SUBRACK<<") = " << itsNrRSPboards/NR_RSPBOARDS_PER_SUBRACK); - LOG_DEBUG_STR("("<<itsNrRSPboards<<"%"<<NR_RSPBOARDS_PER_SUBRACK<<") = " << itsNrRSPboards%NR_RSPBOARDS_PER_SUBRACK); + LOG_DEBUG(formatString("nr LBAs = %d", itsNrLBAs)); + LOG_DEBUG(formatString("nr HBAs = %d", itsNrHBAs)); // do some checks if (itsNrRSPboards != (uint32)ack.max_rspboards) { @@ -264,6 +284,12 @@ GCFEvent::TResult RSPMonitor::askConfiguration(GCFEvent& event, LOG_INFO_STR("RSP:Station not fully equiped, only " << itsNrRCUs << " of " << itsNrRSPboards * NR_RCUS_PER_RSPBOARD << "RCUs"); } + if (itsNrLBAs > (itsNrRCUs / 2)) { + LOG_INFO_STR("LBA antennas are connected to LBL and LBH inputs of the RCUs"); + } + else { + LOG_INFO_STR("LBL inputs of the RCUs are not used."); + } LOG_DEBUG ("Going to allocate the property-sets"); // itsOwnPropertySet->setValue(PN_HWM_RSP_ERROR,GCFPVString("")); @@ -361,9 +387,9 @@ GCFEvent::TResult RSPMonitor::createPropertySets(GCFEvent& event, for (uint32 rcu = 0; rcu < itsNrRCUs; rcu++) { ASSERTSTR(itsRCUs[rcu], "Allocation of PS for rcu " << rcu << " failed."); } - LOG_DEBUG_STR("Allocation of all propertySets successfull, going to operational mode"); + LOG_DEBUG_STR("Allocation of all propertySets successfull, going to subscribe to RCU states"); // itsOwnPropertySet->setValue(PN_HWM_RSP_ERROR,GCFPVString("")); - TRAN(RSPMonitor::askVersion); + TRAN(RSPMonitor::subscribeToRCUs); } break; @@ -387,6 +413,74 @@ GCFEvent::TResult RSPMonitor::createPropertySets(GCFEvent& event, } +// +// subscribeToRCUs(event, port) +// +// Get a subscription to the state of the RCU's +// +GCFEvent::TResult RSPMonitor::subscribeToRCUs(GCFEvent& event, + GCFPortInterface& port) +{ + LOG_DEBUG_STR ("subscribeToRCUs:" << eventName(event) << "@" << port.getName()); + + GCFEvent::TResult status = GCFEvent::HANDLED; + + switch (event.signal) { + + case F_ENTRY: { + itsOwnPropertySet->setValue(PN_FSM_CURRENT_ACTION,GCFPVString("RSP:Subscribe to RCUstates")); + // time to init our RCU admin + itsAntMapper = new AntennaMapper(itsNrRCUs, itsNrLBAs, itsNrHBAs); + itsRCUstates.resize(itsNrRCUs); + itsRCUstates = RTDB_OBJ_STATE_OFF; + itsRCUInputStates.resize(itsNrRCUs, AntennaMapper::RI_MAX_INPUTS); + itsRCUInputStates = false; + + itsDPservice->query("'LOFAR_PIC_*.status.state'", "_DPT=\"RCU\""); + itsTimerPort->setTimer(5.0); // give database some time to finish the job + } + break; + + case F_TIMER: { + ASSERTSTR(itsRCUquery, "No response on the query for the RCU states"); + LOG_DEBUG_STR("No initial values received for RCU states, going to ask version info"); + TRAN(RSPMonitor::askVersion); + } + break; + + case F_DISCONNECTED: + _disconnectedHandler(port); // might result in transition to connect2RSP + break; + + case DP_QUERY_SUBSCRIBED: { + DPQuerySubscribedEvent DPevent(event); + ASSERTSTR(DPevent.result == SA_NO_ERROR, "Query on RCU states returned error code " << DPevent.result); + itsRCUquery = DPevent.QryID; + LOG_DEBUG_STR("RCU queryID = " << itsRCUquery << ", waiting for first response"); + } + break; + + case DP_QUERY_CHANGED: { + _doQueryChanged(event); + itsTimerPort->cancelAllTimers(); + LOG_DEBUG_STR("States of RCU's received, going to ask version info"); + TRAN(RSPMonitor::askVersion); + } + break; + + case F_QUIT: + TRAN (RSPMonitor::finish_state); + break; + + default: + LOG_DEBUG_STR ("createPropertySets, DEFAULT"); + break; + } + + return (status); +} + + // // askVersion(event, port) // @@ -464,6 +558,10 @@ GCFEvent::TResult RSPMonitor::askVersion(GCFEvent& event, case DP_SET: break; + case DP_QUERY_CHANGED: + _doQueryChanged(event); + break; + case F_QUIT: TRAN (RSPMonitor::finish_state); break; @@ -599,6 +697,10 @@ GCFEvent::TResult RSPMonitor::askRSPinfo(GCFEvent& event, case DP_SET: break; + case DP_QUERY_CHANGED: + _doQueryChanged(event); + break; + case F_QUIT: TRAN (RSPMonitor::finish_state); break; @@ -699,6 +801,10 @@ GCFEvent::TResult RSPMonitor::askTDstatus(GCFEvent& event, case DP_SET: break; + case DP_QUERY_CHANGED: + _doQueryChanged(event); + break; + case F_QUIT: TRAN (RSPMonitor::finish_state); break; @@ -778,6 +884,10 @@ GCFEvent::TResult RSPMonitor::askSPUstatus(GCFEvent& event, case DP_SET: break; + case DP_QUERY_CHANGED: + _doQueryChanged(event); + break; + case F_QUIT: TRAN (RSPMonitor::finish_state); break; @@ -836,7 +946,7 @@ GCFEvent::TResult RSPMonitor::askRCUinfo(GCFEvent& event, GCFPortInterface& port // move the information to the database. string versionStr; string DPEname; - for (uint32 rcu = 0; rcu < itsNrRCUs; rcu++) { + for (int rcu = 0; rcu < (int)itsNrRCUs; rcu++) { uint32 rawValue = ack.settings()(rcu).getRaw(); LOG_DEBUG(formatString("Updating rcu %d with %08lX", rcu, rawValue)); // update all RCU variables @@ -876,9 +986,38 @@ GCFEvent::TResult RSPMonitor::askRCUinfo(GCFEvent& event, GCFPortInterface& port itsRCUs[rcu]->flush(); setObjectState(getName(), itsRCUs[rcu]->getFullScope(), (rawValue & ADC_POWER_MASK) ? RTDB_OBJ_STATE_OPERATIONAL : RTDB_OBJ_STATE_OFF); + + // update own RCU admin also + itsRCUInputStates(rcu, AntennaMapper::RI_LBL) = rawValue & LBL_ANT_POWER_MASK; + itsRCUInputStates(rcu, AntennaMapper::RI_LBH) = rawValue & LBH_ANT_POWER_MASK; + itsRCUInputStates(rcu, AntennaMapper::RI_HBA) = rawValue & HBA_ANT_POWER_MASK; + itsRCUstates(rcu) = (rawValue & ADC_POWER_MASK) ? RTDB_OBJ_STATE_OPERATIONAL : RTDB_OBJ_STATE_OFF; + } // for all boards - LOG_DEBUG ("Updated all RCU information, waiting for next cycle"); + LOG_DEBUG ("Updated all RCU information, updating antenna states"); + for (uint ant = 0; ant < itsNrLBAs; ant++) { + if (itsRCUInputStates(itsAntMapper->XRCU(ant), itsAntMapper->RCUinput(ant, AntennaMapper::AT_LBA)) || + itsRCUInputStates(itsAntMapper->YRCU(ant), itsAntMapper->RCUinput(ant, AntennaMapper::AT_LBA))) { + setObjectState(getName(), formatString("LBA%02d", ant), + MAX2(itsRCUstates(itsAntMapper->XRCU(ant)), itsRCUstates(itsAntMapper->YRCU(ant)) ) ); + } + else { + setObjectState(getName(), formatString("LBA%02d", ant), RTDB_OBJ_STATE_OFF); + } + } + for (uint ant = 0; ant < itsNrHBAs; ant++) { + if (itsRCUInputStates(itsAntMapper->XRCU(ant), itsAntMapper->RCUinput(ant, AntennaMapper::AT_HBA)) || + itsRCUInputStates(itsAntMapper->YRCU(ant), itsAntMapper->RCUinput(ant, AntennaMapper::AT_HBA))) { + setObjectState(getName(), formatString("HBA%02d", ant), + MAX2(itsRCUstates(itsAntMapper->XRCU(ant)), itsRCUstates(itsAntMapper->YRCU(ant)) ) ); + } + else { + setObjectState(getName(), formatString("HBA%02d", ant), RTDB_OBJ_STATE_OFF); + } + } + + LOG_DEBUG ("Updated all station information, waiting for next cycle"); // itsOwnPropertySet->setValue(PN_HWM_RSP_ERROR,GCFPVString("")); TRAN(RSPMonitor::waitForNextCycle); // go to next state. } @@ -891,6 +1030,10 @@ GCFEvent::TResult RSPMonitor::askRCUinfo(GCFEvent& event, GCFPortInterface& port case DP_SET: break; + case DP_QUERY_CHANGED: + _doQueryChanged(event); + break; + case F_QUIT: TRAN (RSPMonitor::finish_state); break; @@ -941,6 +1084,10 @@ GCFEvent::TResult RSPMonitor::waitForNextCycle(GCFEvent& event, case DP_SET: break; + case DP_QUERY_CHANGED: + _doQueryChanged(event); + break; + case F_QUIT: TRAN (RSPMonitor::finish_state); break; @@ -967,6 +1114,44 @@ void RSPMonitor::_disconnectedHandler(GCFPortInterface& port) } } + +// +// _doQueryChanged(event) +// +void RSPMonitor::_doQueryChanged(GCFEvent& event) +{ + DPQueryChangedEvent DPevent(event); + if (DPevent.result != SA_NO_ERROR) { + LOG_ERROR_STR("PVSS reported error " << DPevent.result << " for query " << DPevent.QryID); + return; + } + + int nrDPs = ((GCFPVDynArr*)(DPevent.DPnames._pValue))->getValue().size(); + GCFPVDynArr* DPnames = (GCFPVDynArr*)(DPevent.DPnames._pValue); + GCFPVDynArr* DPvalues = (GCFPVDynArr*)(DPevent.DPvalues._pValue); + // register all states + for (int idx = 0; idx < nrDPs; ++idx) { + string nameStr = DPnames->getValue() [idx]->getValueAsString(); + int status = ((GCFPVInteger *)(DPvalues->getValue()[idx]))->getValue(); + uint rcuNr; + // get rcuNr from name + if (sscanf(nameStr.c_str(), "%*s_RCU%d.%*s", &rcuNr) != 1) { + LOG_WARN_STR("Unrecognized datapointname ignored: " << nameStr); + continue; + } + + // check rcuNr + if (rcuNr >= itsNrRCUs) { + LOG_WARN_STR("Illegal RCUnumber " << rcuNr << " in " << nameStr << ", ignoring status change!"); + continue; + } + + // store for later + itsRCUstates(rcuNr) = status; + LOG_INFO(formatString("RCU %d = %d", rcuNr, status)); + } // for +} + // // finish_state(event, port) // diff --git a/MAC/APL/StationCU/src/HardwareMonitor/RSPMonitor.h b/MAC/APL/StationCU/src/HardwareMonitor/RSPMonitor.h index 6bd090fb7859426287b830fdffc7e639ab554792..00697e8bc7fb8cb5fd455f3aa65df9155c6b6171 100644 --- a/MAC/APL/StationCU/src/HardwareMonitor/RSPMonitor.h +++ b/MAC/APL/StationCU/src/HardwareMonitor/RSPMonitor.h @@ -24,12 +24,15 @@ #define STATIONCU_RSP_MONITOR_H //# Common Includes +#include <blitz/array.h> #include <Common/lofar_string.h> #include <Common/lofar_vector.h> //# GCF Includes +#include <APL/APLCommon/AntennaMapper.h> #include <GCF/TM/GCF_Control.h> #include <GCF/RTDB/RTDB_PropertySet.h> +#include <GCF/RTDB/DPservice.h> // forward declaration @@ -42,6 +45,8 @@ using GCF::TM::GCFTCPPort; using GCF::TM::GCFPortInterface; using GCF::TM::GCFTask; using GCF::RTDB::RTDBPropertySet; +using GCF::RTDB::DPservice; +using APLCommon::AntennaMapper; class RSPMonitor : public GCFTask @@ -56,6 +61,7 @@ private: GCFEvent::TResult connect2RSP (GCFEvent& e, GCFPortInterface& p); GCFEvent::TResult askConfiguration (GCFEvent& e, GCFPortInterface& p); GCFEvent::TResult createPropertySets (GCFEvent& e, GCFPortInterface& p); + GCFEvent::TResult subscribeToRCUs (GCFEvent& e, GCFPortInterface& p); GCFEvent::TResult askVersion (GCFEvent& e, GCFPortInterface& p); GCFEvent::TResult askRSPinfo (GCFEvent& e, GCFPortInterface& p); @@ -71,14 +77,16 @@ private: RSPMonitor(const RSPMonitor&); RSPMonitor& operator=(const RSPMonitor&); + // helper functions void _disconnectedHandler(GCFPortInterface& port); + void _doQueryChanged (GCFEvent& event); // Data members RTDBPropertySet* itsOwnPropertySet; GCFTimerPort* itsTimerPort; - GCFTCPPort* itsRSPDriver; + DPservice* itsDPservice; uint32 itsPollInterval; @@ -86,11 +94,19 @@ private: uint32 itsNrRSPboards; uint32 itsNrSubracks; uint32 itsNrCabinets; + uint32 itsNrLBAs; + uint32 itsNrHBAs; vector<RTDBPropertySet*> itsCabinets; vector<RTDBPropertySet*> itsSubracks; vector<RTDBPropertySet*> itsRSPs; vector<RTDBPropertySet*> itsRCUs; + + blitz::Array<uint,1> itsRCUstates; // actual status of the RCUs + blitz::Array<bool,2> itsRCUInputStates; // enable state of the three RCU inputs + int itsRCUquery; // ID of the PVSS query + AntennaMapper* itsAntMapper; + }; };//StationCU diff --git a/MAC/APL/StationCU/src/HardwareMonitor/TBBMonitor.cc b/MAC/APL/StationCU/src/HardwareMonitor/TBBMonitor.cc index 959675ce69f67fd09f4964abd613089cf3657ddf..bf5bb5cb44f1b6b8acf40af977c058a3b9befd80 100644 --- a/MAC/APL/StationCU/src/HardwareMonitor/TBBMonitor.cc +++ b/MAC/APL/StationCU/src/HardwareMonitor/TBBMonitor.cc @@ -250,7 +250,7 @@ GCFEvent::TResult TBBMonitor::askConfiguration(GCFEvent& event, GCFPortInterface TBBGetConfigAckEvent ack(event); // calc size of the propertyset vectors - itsBoardMask = bitset<MAX_N_TBBBOARDS>(ack.active_boards_mask); + itsBoardMask = bitset<MAX_N_TBBOARDS>(ack.active_boards_mask); itsNrTBboards = ack.max_boards; itsNrRCUs = itsNrTBboards * NR_RCUS_PER_TBBOARD; diff --git a/MAC/APL/StationCU/src/HardwareMonitor/TBBMonitor.h b/MAC/APL/StationCU/src/HardwareMonitor/TBBMonitor.h index 3f6a2b0d5746946be95b58b05d435672deab6cf7..1b9a43b54efabe508dd6e13af5108a19cf95225b 100644 --- a/MAC/APL/StationCU/src/HardwareMonitor/TBBMonitor.h +++ b/MAC/APL/StationCU/src/HardwareMonitor/TBBMonitor.h @@ -88,7 +88,7 @@ private: uint32 itsNrRCUs; uint32 itsNrTBboards; - bitset<MAX_N_TBBBOARDS> itsBoardMask; + bitset<MAX_N_TBBOARDS> itsBoardMask; vector<RTDBPropertySet*> itsTBBs; vector<RTDBPropertySet*> itsRCUs;