From 5018352fbdc213b5e429baf4a23667cbf61ca42e Mon Sep 17 00:00:00 2001 From: Pieter Donker <donker@astron.nl> Date: Fri, 22 Sep 2006 11:03:53 +0000 Subject: [PATCH] BugID:335 Further development of the TBBDriver --- MAC/APL/PIC/TBBDriver/src/AllocCmd.cc | 166 +++++++++ MAC/APL/PIC/TBBDriver/src/AllocCmd.h | 85 +++++ MAC/APL/PIC/TBBDriver/src/BoardCmdHandler.cc | 138 ++++++-- MAC/APL/PIC/TBBDriver/src/BoardCmdHandler.h | 26 +- MAC/APL/PIC/TBBDriver/src/ClearCmd.cc | 163 +++++++++ MAC/APL/PIC/TBBDriver/src/ClearCmd.h | 86 +++++ MAC/APL/PIC/TBBDriver/src/ClientMsgHandler.cc | 5 +- MAC/APL/PIC/TBBDriver/src/Command.h | 17 +- MAC/APL/PIC/TBBDriver/src/ConfigCmd.cc | 164 +++++++++ MAC/APL/PIC/TBBDriver/src/ConfigCmd.h | 86 +++++ MAC/APL/PIC/TBBDriver/src/ErasefCmd.cc | 164 +++++++++ MAC/APL/PIC/TBBDriver/src/ErasefCmd.h | 87 +++++ MAC/APL/PIC/TBBDriver/src/FreeCmd.cc | 163 +++++++++ MAC/APL/PIC/TBBDriver/src/FreeCmd.h | 85 +++++ MAC/APL/PIC/TBBDriver/src/Makefile.am | 84 ++++- MAC/APL/PIC/TBBDriver/src/RawEvent.cc | 59 ++-- MAC/APL/PIC/TBBDriver/src/RawEvent.h | 39 +-- MAC/APL/PIC/TBBDriver/src/ReadCmd.cc | 166 +++++++++ MAC/APL/PIC/TBBDriver/src/ReadCmd.h | 86 +++++ MAC/APL/PIC/TBBDriver/src/ReadfCmd.cc | 174 ++++++++++ MAC/APL/PIC/TBBDriver/src/ReadfCmd.h | 88 +++++ MAC/APL/PIC/TBBDriver/src/RecordCmd.cc | 164 +++++++++ MAC/APL/PIC/TBBDriver/src/RecordCmd.h | 86 +++++ .../PIC/TBBDriver/src/RemoteStation.conf.in | 4 +- MAC/APL/PIC/TBBDriver/src/ResetCmd.cc | 163 +++++++++ MAC/APL/PIC/TBBDriver/src/ResetCmd.h | 86 +++++ MAC/APL/PIC/TBBDriver/src/SizeCmd.cc | 167 +++++++++ MAC/APL/PIC/TBBDriver/src/SizeCmd.h | 87 +++++ MAC/APL/PIC/TBBDriver/src/StationSettings.cc | 12 +- MAC/APL/PIC/TBBDriver/src/StationSettings.h | 11 +- MAC/APL/PIC/TBBDriver/src/StopCmd.cc | 164 +++++++++ MAC/APL/PIC/TBBDriver/src/StopCmd.h | 86 +++++ MAC/APL/PIC/TBBDriver/src/TBBDriver.cc | 327 ++++++++++++------ MAC/APL/PIC/TBBDriver/src/TBBDriver.conf.in | 41 +-- MAC/APL/PIC/TBBDriver/src/TBBDriver.h | 39 ++- .../PIC/TBBDriver/src/TBBDriverPorts.conf.in | 10 +- MAC/APL/PIC/TBBDriver/src/TP_Protocol.prot | 122 ++++++- MAC/APL/PIC/TBBDriver/src/TrigclrCmd.cc | 164 +++++++++ MAC/APL/PIC/TBBDriver/src/TrigclrCmd.h | 86 +++++ MAC/APL/PIC/TBBDriver/src/UdpCmd.cc | 172 +++++++++ MAC/APL/PIC/TBBDriver/src/UdpCmd.h | 86 +++++ MAC/APL/PIC/TBBDriver/src/VersionCmd.cc | 190 ++++++---- MAC/APL/PIC/TBBDriver/src/VersionCmd.h | 29 +- MAC/APL/PIC/TBBDriver/src/WritefCmd.cc | 173 +++++++++ MAC/APL/PIC/TBBDriver/src/WritefCmd.h | 88 +++++ 45 files changed, 4295 insertions(+), 393 deletions(-) create mode 100644 MAC/APL/PIC/TBBDriver/src/AllocCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/AllocCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/ClearCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/ClearCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/ConfigCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/ConfigCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/ErasefCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/ErasefCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/FreeCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/FreeCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/ReadCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/ReadCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/ReadfCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/ReadfCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/RecordCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/RecordCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/ResetCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/ResetCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/SizeCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/SizeCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/StopCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/StopCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/TrigclrCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/TrigclrCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/UdpCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/UdpCmd.h create mode 100644 MAC/APL/PIC/TBBDriver/src/WritefCmd.cc create mode 100644 MAC/APL/PIC/TBBDriver/src/WritefCmd.h diff --git a/MAC/APL/PIC/TBBDriver/src/AllocCmd.cc b/MAC/APL/PIC/TBBDriver/src/AllocCmd.cc new file mode 100644 index 00000000000..dc94eb9d153 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/AllocCmd.cc @@ -0,0 +1,166 @@ +//# AllocCmd.cc: implementation of the AllocCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "AllocCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a AllocCmd object.---------------------------------------- +AllocCmd::AllocCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPAllocEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBAllocackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + } +} + +//--Destructor for AllocCmd.--------------------------------------------------- +AllocCmd::~AllocCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool AllocCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_ALLOC)||(event.signal == TP_ALLOC)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void AllocCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBAllocEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPALLOC; + itsTPE->status = 0; + itsTPE->channel = itsTBBE->channel; + itsTPE->pageaddr = itsTBBE->pageaddr; + itsTPE->pagelength = itsTBBE->pagelength; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void AllocCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void AllocCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPAllocEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + LOG_DEBUG_STR(formatString("Received AllocAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void AllocCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void AllocCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 AllocCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 AllocCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool AllocCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool AllocCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/AllocCmd.h b/MAC/APL/PIC/TBBDriver/src/AllocCmd.h new file mode 100644 index 00000000000..baef1b46eaf --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/AllocCmd.h @@ -0,0 +1,85 @@ +//# -*- mode: c++ -*- +//# +//# AllocCmd.h: Allocate memmory +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef ALLOCCMD_H_ +#define ALLOCCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class AllocCmd : public Command + { + public: + // Constructors for a AllocCmd object. + AllocCmd(); + + // Destructor for AllocCmd. + virtual ~AllocCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPAllocEvent *itsTPE; + TPAllocEvent *itsTPackE; + TBBAllocEvent *itsTBBE; + TBBAllocackEvent *itsTBBackE; + + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* ALLOCCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/BoardCmdHandler.cc b/MAC/APL/PIC/TBBDriver/src/BoardCmdHandler.cc index 4216328dc4f..97fb7b4674c 100644 --- a/MAC/APL/PIC/TBBDriver/src/BoardCmdHandler.cc +++ b/MAC/APL/PIC/TBBDriver/src/BoardCmdHandler.cc @@ -23,19 +23,29 @@ #include <lofar_config.h> #include <Common/LofarLogger.h> +#include <APL/TBB_Protocol/TBB_Protocol.ph> #include "BoardCmdHandler.h" namespace LOFAR { + using namespace TBB_Protocol; namespace TBB { -#define N_RETRIES 10 - -BoardCmdHandler::BoardCmdHandler(GCFPortInterface* board_ports) - : GCFFsm((State)&BoardCmdHandler::send_state), - itsRetries(0), - itsNrOfBoards(12) +BoardCmdHandler::BoardCmdHandler() + : GCFFsm((State)&BoardCmdHandler::send_state) { - itsBoardPorts = board_ports; // save address of boards array + itsRetries = 10; + itsNrOfBoards = 12; + itsMaxBoards = 12; + itsTimeOut = 0.2; + itsCmdDone = true; + itsClientPort = 0; + itsBoardPorts = 0; + + for (int boardnr = 0; boardnr < itsMaxBoards; boardnr++) { + itsBoardRetries[boardnr] = 0; + } + + itsCmd = 0; } BoardCmdHandler::~BoardCmdHandler() @@ -48,21 +58,48 @@ GCFEvent::TResult BoardCmdHandler::send_state(GCFEvent& event, GCFPortInterface& GCFEvent::TResult status = GCFEvent::HANDLED; switch (event.signal) { + + case F_INIT: { + } break; + case F_ENTRY: { - } break; - + for (int boardnr = 0; boardnr < itsMaxBoards; boardnr++) { + itsBoardRetries[boardnr] = 0; + } + } break; + + case F_EXIT: { + } break; + default: { - if(itsCmd->isValid(event)) { // isValid returns true if event is a valid cmd + if(itsCmd && itsCmd->isValid(event)) { // isValid returns true if event is a valid cmd itsClientPort = &port; - itsCmd->saveTbbEvent(event); - itsCmd->makeTpEvent(); + itsCmd->saveTbbEvent(event,itsNrOfBoards); - for(int boardid = 0;boardid < itsNrOfBoards;boardid++) { - if((1 << boardid) & itsCmd->getSendMask()) { - itsCmd->sendTpEvent(itsBoardPorts[boardid]); + if(itsCmd->getSendMask()) { + itsCmdDone = false; + for(int boardid = 0;boardid < itsNrOfBoards;boardid++) { + if((1 << boardid) & itsCmd->getSendMask()) { + if(itsBoardPorts[boardid].isConnected()) { + itsCmd->sendTpEvent(itsBoardPorts[boardid]); + if(itsCmd->waitAck()) + itsBoardPorts[boardid].setTimer(itsTimeOut); + } + else { + itsCmd->portError(boardid); + } + itsBoardRetries[boardid]++; + } } } - TRAN(BoardCmdHandler::waitack_state); + if(itsCmd->waitAck()) { + TRAN(BoardCmdHandler::waitack_state); + } + else { + itsCmd->sendTbbAckEvent(itsClientPort); + itsCmdDone = true; + itsCmd = 0; + } } else { status = GCFEvent::NOT_HANDLED; @@ -78,21 +115,37 @@ GCFEvent::TResult BoardCmdHandler::waitack_state(GCFEvent& event, GCFPortInterfa GCFEvent::TResult status = GCFEvent::HANDLED; switch(event.signal) { + case F_INIT: { + } break; + case F_ENTRY: { + if(itsCmd->done()) { + itsCmd->sendTbbAckEvent(itsClientPort); + itsCmdDone = true; + itsCmd = 0; + TRAN(BoardCmdHandler::send_state); + } } break; case F_TIMER: { // time-out, retry - if(itsBoardRetries[PortToBoardNr(port)] < N_RETRIES) { - itsCmd->sendTpEvent(port); + if(itsBoardRetries[portToBoardNr(port)] < itsRetries) { + if(port.isConnected()) { + itsCmd->sendTpEvent(port); + port.setTimer(itsTimeOut); + } + itsBoardRetries[portToBoardNr(port)]++; + LOG_DEBUG_STR(formatString("itsRetries[%d] = %d", portToBoardNr(port), itsBoardRetries[portToBoardNr(port)])); } else { // max retries, save zero's - itsCmd->saveTpAckEvent(event,PortToBoardNr(port)); + itsCmd->saveTpAckEvent(event,portToBoardNr(port)); } if(itsCmd->done()) { itsCmd->sendTbbAckEvent(itsClientPort); + itsCmdDone = true; + itsCmd = 0; TRAN(BoardCmdHandler::send_state); } } break; @@ -102,11 +155,13 @@ GCFEvent::TResult BoardCmdHandler::waitack_state(GCFEvent& event, GCFPortInterfa default: { if(itsCmd->isValid(event)) { - itsBoardPorts[PortToBoardNr(port)].cancelAllTimers(); - itsCmd->saveTpAckEvent(event,PortToBoardNr(port)); + port.cancelAllTimers(); + itsCmd->saveTpAckEvent(event,portToBoardNr(port)); if(itsCmd->done()) { itsCmd->sendTbbAckEvent(itsClientPort); + itsCmdDone = true; + itsCmd = 0; TRAN(BoardCmdHandler::send_state); } } @@ -118,19 +173,44 @@ GCFEvent::TResult BoardCmdHandler::waitack_state(GCFEvent& event, GCFPortInterfa return status; } -void BoardCmdHandler::SetCmd(Command *cmd) +void BoardCmdHandler::setBoardPorts(GCFPortInterface* board_ports) +{ + itsBoardPorts = board_ports; // save address of boards array +} + +void BoardCmdHandler::setTpCmd(Command *cmd) { itsCmd = cmd; } -bool BoardCmdHandler::done() +void BoardCmdHandler::setTpRetries(int32 Retries) { - return itsCmd->done(); + itsRetries = Retries; } -int BoardCmdHandler::PortToBoardNr(GCFPortInterface& port) +void BoardCmdHandler::setNrOfTbbBoards(int32 NrOfBoards) { - int boardnr; + itsNrOfBoards = NrOfBoards; +} + +void BoardCmdHandler::setMaxTbbBoards(int32 MaxBoards) +{ + itsMaxBoards = MaxBoards; +} + +void BoardCmdHandler::setTpTimeOut(double TimeOut) +{ + itsTimeOut = TimeOut; +} + +bool BoardCmdHandler::tpCmdDone() +{ + return itsCmdDone; +} + +int32 BoardCmdHandler::portToBoardNr(GCFPortInterface& port) +{ + int32 boardnr; for(boardnr = 0;boardnr < itsNrOfBoards;boardnr++) { if(&port == &itsBoardPorts[boardnr]) { @@ -139,6 +219,6 @@ int BoardCmdHandler::PortToBoardNr(GCFPortInterface& port) } return -1; } - } // end TBB namespace -} // end LOFAR namespace - + + } // end namespace TBB +} // end namespace LOFAR diff --git a/MAC/APL/PIC/TBBDriver/src/BoardCmdHandler.h b/MAC/APL/PIC/TBBDriver/src/BoardCmdHandler.h index eccde515c55..0ab4bd2fd8c 100644 --- a/MAC/APL/PIC/TBBDriver/src/BoardCmdHandler.h +++ b/MAC/APL/PIC/TBBDriver/src/BoardCmdHandler.h @@ -47,10 +47,9 @@ namespace LOFAR { { public: - Command* itsCmd; // command to use // Constructors for a SyncAction object. // Default direction is read. - BoardCmdHandler(GCFPortInterface* board_ports); + BoardCmdHandler(); // Destructor for SyncAction. */ ~BoardCmdHandler(); @@ -59,26 +58,35 @@ namespace LOFAR { GCFEvent::TResult send_state(GCFEvent& event, GCFPortInterface& port); GCFEvent::TResult waitack_state(GCFEvent& event, GCFPortInterface& port); - void SetCmd(Command *cmd); + void setBoardPorts(GCFPortInterface* board_ports); + void setTpCmd(Command *cmd); + void setTpRetries(int32 Retries); + void setNrOfTbbBoards(int32 NrOfBoards); + void setMaxTbbBoards(int32 MaxBoards); + void setTpTimeOut(double TimeOut); - bool done(); + bool tpCmdDone(); protected: private: // convert port to portnr, used in the port-array - int PortToBoardNr(GCFPortInterface& port); + int portToBoardNr(GCFPortInterface& port); private: - int itsRetries; // max number of retries - int itsNrOfBoards; // numnber of boards installed + int32 itsRetries; // max number of retries + int32 itsNrOfBoards; + int32 itsMaxBoards; + double itsTimeOut; + bool itsCmdDone; + GCFPortInterface* itsClientPort; // return port of the actual commmand GCFPortInterface* itsBoardPorts; // array of tbb board ports - int itsBoardRetries[MAX_N_TBBBOARDS]; - + int32 itsBoardRetries[MAX_N_TBBBOARDS]; + Command* itsCmd; // command to use }; } // end TBB namespace diff --git a/MAC/APL/PIC/TBBDriver/src/ClearCmd.cc b/MAC/APL/PIC/TBBDriver/src/ClearCmd.cc new file mode 100644 index 00000000000..cece6523188 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ClearCmd.cc @@ -0,0 +1,163 @@ +//# ClearCmd.cc: implementation of the ClearCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "ClearCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a ClearCmd object.---------------------------------------- +ClearCmd::ClearCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPClearEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBClearackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + } +} + +//--Destructor for ClearCmd.--------------------------------------------------- +ClearCmd::~ClearCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool ClearCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_CLEAR)||(event.signal == TP_CLEAR)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void ClearCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBClearEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPCLEAR; + itsTPE->status = 0; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void ClearCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void ClearCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPClearEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + + LOG_DEBUG_STR(formatString("Received ClearAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void ClearCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void ClearCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 ClearCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 ClearCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool ClearCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool ClearCmd::waitAck() +{ + return false; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/ClearCmd.h b/MAC/APL/PIC/TBBDriver/src/ClearCmd.h new file mode 100644 index 00000000000..49c47929ce5 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ClearCmd.h @@ -0,0 +1,86 @@ +//# -*- mode: c++ -*- +//# +//# ClearCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef CLEARCMD_H_ +#define CLEARCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class ClearCmd : public Command + { + public: + // Constructors for a ClearCmd object. + ClearCmd(); + + // Destructor for ClearCmd. + virtual ~ClearCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPClearEvent *itsTPE; + TPClearEvent *itsTPackE; + TBBClearEvent *itsTBBE; + TBBClearackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* CLEARCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/ClientMsgHandler.cc b/MAC/APL/PIC/TBBDriver/src/ClientMsgHandler.cc index 2ad045bd994..4cc8afa7551 100644 --- a/MAC/APL/PIC/TBBDriver/src/ClientMsgHandler.cc +++ b/MAC/APL/PIC/TBBDriver/src/ClientMsgHandler.cc @@ -103,5 +103,6 @@ void ClientMsgHandler::SetMessage(Message *msg) { itsMsg = msg; } - } // end TBB namespace -} // end LOFAR namespace \ No newline at end of file + + } // end namespace TBB +} // end namespace LOFAR diff --git a/MAC/APL/PIC/TBBDriver/src/Command.h b/MAC/APL/PIC/TBBDriver/src/Command.h index b5603170686..8f0612bd642 100644 --- a/MAC/APL/PIC/TBBDriver/src/Command.h +++ b/MAC/APL/PIC/TBBDriver/src/Command.h @@ -31,9 +31,6 @@ namespace LOFAR { namespace TBB { - static const int MAX_N_TBBBOARDS = 12; - static const double TIME_OUT = 0.5; - class Command { public: @@ -46,21 +43,23 @@ namespace LOFAR { virtual bool isValid(GCFEvent& event) = 0; - virtual void saveTbbEvent(GCFEvent& event) = 0; - - virtual void makeTpEvent() = 0; - + virtual void saveTbbEvent(GCFEvent& event, int32 boards) = 0; + virtual void sendTpEvent(GCFPortInterface& port) = 0; - virtual void saveTpAckEvent(GCFEvent& event, int boardnr) = 0; + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr) = 0; virtual void sendTbbAckEvent(GCFPortInterface* clientport) = 0; + virtual void portError(int32 boardnr) = 0; + virtual uint32 getSendMask() = 0; virtual uint32 getRecvMask() = 0; - virtual uint32 done() = 0; + virtual bool done() = 0; + + virtual bool waitAck() = 0; private: diff --git a/MAC/APL/PIC/TBBDriver/src/ConfigCmd.cc b/MAC/APL/PIC/TBBDriver/src/ConfigCmd.cc new file mode 100644 index 00000000000..44cadf1a485 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ConfigCmd.cc @@ -0,0 +1,164 @@ +//# ConfigCmd.cc: implementation of the ConfigCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "ConfigCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a ConfigCmd object.---------------------------------------- +ConfigCmd::ConfigCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPConfigEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBConfigackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + } +} + +//--Destructor for ConfigCmd.--------------------------------------------------- +ConfigCmd::~ConfigCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool ConfigCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_CONFIG)||(event.signal == TP_CONFIG)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void ConfigCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBConfigEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPCONFIG; + itsTPE->status = 0; + itsTPE->image = itsTBBE->image; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void ConfigCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void ConfigCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPConfigEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + + LOG_DEBUG_STR(formatString("Received ConfigAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void ConfigCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void ConfigCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 ConfigCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 ConfigCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool ConfigCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool ConfigCmd::waitAck() +{ + return false; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/ConfigCmd.h b/MAC/APL/PIC/TBBDriver/src/ConfigCmd.h new file mode 100644 index 00000000000..2bd1a03958e --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ConfigCmd.h @@ -0,0 +1,86 @@ +//# -*- mode: c++ -*- +//# +//# ConfigCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef CONFIGCMD_H_ +#define CONFIGCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class ConfigCmd : public Command + { + public: + // Constructors for a ConfigCmd object. + ConfigCmd(); + + // Destructor for ConfigCmd. + virtual ~ConfigCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPConfigEvent *itsTPE; + TPConfigEvent *itsTPackE; + TBBConfigEvent *itsTBBE; + TBBConfigackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* CONFIGCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/ErasefCmd.cc b/MAC/APL/PIC/TBBDriver/src/ErasefCmd.cc new file mode 100644 index 00000000000..bca1b720460 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ErasefCmd.cc @@ -0,0 +1,164 @@ +//# ErasefCmd.cc: implementation of the ErasefCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "ErasefCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a ErasefCmd object.---------------------------------------- +ErasefCmd::ErasefCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPErasefEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBErasefackEvent(); + + itsBoardStatus = 0; + itsAddr = 0; +} + +//--Destructor for ErasefCmd.--------------------------------------------------- +ErasefCmd::~ErasefCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool ErasefCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_ERASEF)||(event.signal == TP_ERASEF)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void ErasefCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBErasefEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPERASEF; + itsTPE->status = 0; + itsTPE->addr = itsTBBE->addr; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void ErasefCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void ErasefCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPErasefEvent(event); + + itsBoardStatus = itsTPackE->status; + itsAddr = itsTPackE->addr; + + LOG_DEBUG_STR(formatString("Received ErasefAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void ErasefCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + itsTBBackE->boardstatus = itsBoardStatus; + itsTBBackE->addr = itsAddr; + + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void ErasefCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 ErasefCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 ErasefCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool ErasefCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool ErasefCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/ErasefCmd.h b/MAC/APL/PIC/TBBDriver/src/ErasefCmd.h new file mode 100644 index 00000000000..3886ec4e699 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ErasefCmd.h @@ -0,0 +1,87 @@ +//# -*- mode: c++ -*- +//# +//# ErasefCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef ERASEFCMD_H_ +#define ERASEFCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class ErasefCmd : public Command + { + public: + // Constructors for a ErasefCmd object. + ErasefCmd(); + + // Destructor for ErasefCmd. + virtual ~ErasefCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPErasefEvent *itsTPE; + TPErasefEvent *itsTPackE; + TBBErasefEvent *itsTBBE; + TBBErasefackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus; + uint32 itsAddr; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* ERASEFCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/FreeCmd.cc b/MAC/APL/PIC/TBBDriver/src/FreeCmd.cc new file mode 100644 index 00000000000..ad82e662748 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/FreeCmd.cc @@ -0,0 +1,163 @@ +//# FreeCmd.cc: implementation of the FreeCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "FreeCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a FreeCmd object.---------------------------------------- +FreeCmd::FreeCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPFreeEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBFreeackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + } +} + +//--Destructor for FreeCmd.--------------------------------------------------- +FreeCmd::~FreeCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool FreeCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_FREE)||(event.signal == TP_FREE)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void FreeCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBFreeEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPFREE; + itsTPE->status = 0; + itsTPE->channel = itsTBBE->channel; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void FreeCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void FreeCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPFreeEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + LOG_DEBUG_STR(formatString("Received FreeAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void FreeCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void FreeCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 FreeCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 FreeCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool FreeCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool FreeCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/FreeCmd.h b/MAC/APL/PIC/TBBDriver/src/FreeCmd.h new file mode 100644 index 00000000000..26c029ca67c --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/FreeCmd.h @@ -0,0 +1,85 @@ +//# -*- mode: c++ -*- +//# +//# FreeCmd.h: Discard the buffer settings and disable the input channel "channel" +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef FREECMD_H_ +#define FREECMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class FreeCmd : public Command + { + public: + // Constructors for a FreeCmd object. + FreeCmd(); + + // Destructor for FreeCmd. + virtual ~FreeCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPFreeEvent *itsTPE; + TPFreeEvent *itsTPackE; + TBBFreeEvent *itsTBBE; + TBBFreeackEvent *itsTBBackE; + + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* FREECMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/Makefile.am b/MAC/APL/PIC/TBBDriver/src/Makefile.am index a43371231fc..4d5b910d6a7 100644 --- a/MAC/APL/PIC/TBBDriver/src/Makefile.am +++ b/MAC/APL/PIC/TBBDriver/src/Makefile.am @@ -1,6 +1,7 @@ # if HAVE_SHMEM # SUBDIRS = shmem . # endif +# SUBDIRS = test AM_CPPFLAGS = \ -I$(top_builddir)/include @@ -13,34 +14,77 @@ SUFFIXES = .ph %.ph: %.prot $(AUTOGEN) --writable -L $(datadir)/GCF/TM $< cp $*.ph $(top_builddir)/include/TBBDriver/TP_Protocol + +BUILT_SOURCES = \ + TBBDriver.conf \ + RemoteStation.conf \ + tbbctl.conf + +sysconf_DATA = \ + TBBDriver.conf \ + RemoteStation.conf \ + tbbctl.conf +%.conf: %.conf.in + cp $< $@ -lib_LTLIBRARIES = libtbbdriver.la +lib_LTLIBRARIES = \ + libtbbdriver.la \ + libtp_protocol.la EXTRA_DIST = \ + $(BUILT_SOURCES) \ TP_Protocol.prot -libtbbdriver_la_SOURCES = \ - $(NOINST_HEADERS) \ - TP_Protocol.cc \ - StationSettings.cc \ - RawEvent.cc \ - BoardCmdHandler.cc \ - ClientMsgHandler.cc \ - VersionCmd.cc - -NOINST_HEADERS = \ +libtp_protocol_la_SOURCES = \ TP_Protocol.ph \ - StationSettings.h \ + TP_Protocol.cc \ RawEvent.h \ + RawEvent.cc + +libtbbdriver_la_SOURCES = \ + $(noinst_HEADERS) \ + BoardCmdHandler.cc \ + ClientMsgHandler.cc \ + AllocCmd.cc \ + FreeCmd.cc \ + RecordCmd.cc \ + StopCmd.cc \ + TrigclrCmd.cc \ + ReadCmd.cc \ + UdpCmd.cc \ + VersionCmd.cc \ + SizeCmd.cc \ + ClearCmd.cc \ + ResetCmd.cc \ + ConfigCmd.cc \ + ErasefCmd.cc \ + ReadfCmd.cc \ + WritefCmd.cc + +noinst_HEADERS = \ BoardCmdHandler.h \ ClientMsgHandler.h \ Message.h \ Command.h \ - VersionCmd.h - -NOINSTdir = + AllocCmd.h \ + FreeCmd.h \ + RecordCmd.h \ + StopCmd.h \ + TrigclrCmd.h \ + ReadCmd.h \ + UdpCmd.h \ + VersionCmd.h \ + SizeCmd.h \ + ClearCmd.h \ + ResetCmd.h \ + ConfigCmd.h \ + ErasefCmd.h \ + ReadfCmd.h \ + WritefCmd.h + +#NOINSTdir = # AM_YFLAGS = -d -p KeyParse # AM_LFLAGS = -PKeyTokenize @@ -61,8 +105,14 @@ TBBDriver_SOURCES = \ TBBDriver.h \ TBBDriver.cc -TBBDriver_LDADD = libtbbdriver.la -TBBDriver_DEPENDENCIES = libtbbdriver.la $(LOFAR_DEPEND) +TBBDriver_LDADD = \ + libtbbdriver.la \ + libtp_protocol.la + +TBBDriver_DEPENDENCIES = \ + libtbbdriver.la \ + libtp_protocol.la \ + $(LOFAR_DEPEND) glishdir = $(libexecdir)/glish dist_glish_SCRIPTS = diff --git a/MAC/APL/PIC/TBBDriver/src/RawEvent.cc b/MAC/APL/PIC/TBBDriver/src/RawEvent.cc index adff32da1b1..d115085097c 100644 --- a/MAC/APL/PIC/TBBDriver/src/RawEvent.cc +++ b/MAC/APL/PIC/TBBDriver/src/RawEvent.cc @@ -30,9 +30,9 @@ #include "RawEvent.h" namespace LOFAR { - using namespace TP_Protocol; + using namespace TP_Protocol; namespace TBB { - + static const uint8 OPCODE_LEN = 4; @@ -42,7 +42,7 @@ static const uint8 OPCODE_LEN = 4; typedef struct { GCFEvent event; uint32 opcode; - uint8 payload[ETH_DATA_LEN-4]; + uint8 payload[ETH_DATA_LEN - sizeof(uint32)]; } RawFrame; static RawFrame buf; @@ -53,13 +53,14 @@ GCFEvent::TResult RawEvent::dispatch(GCFTask& task, GCFPortInterface& port) GCFEvent::TResult status = GCFEvent::NOT_HANDLED; // Receive a raw packet - ssize_t size = port.recv(buf.payload, ETH_DATA_LEN); + //ssize_t size = port.recv(buf.payload, ETH_DATA_LEN); + ssize_t size = port.recv(&buf.opcode, ETH_DATA_LEN); // at least 4 bytes if (size < OPCODE_LEN) return GCFEvent::NOT_HANDLED; - LOG_DEBUG(formatString("F_DATAIN: Opcode=0x%04x",buf.opcode)); + LOG_DEBUG(formatString("in RawEvent::F_DATAIN: Opcode=0x%08x",buf.opcode)); // // If no error, lookup buf.opcode number, else assign ACK_ERROR buf.event.signal number @@ -68,79 +69,79 @@ GCFEvent::TResult RawEvent::dispatch(GCFTask& task, GCFPortInterface& port) { case TPALLOC: buf.event.signal = TP_ALLOC; - buf.event.length = 16; + buf.event.length = 20; break; case TPFREE: buf.event.signal = TP_FREE; - buf.event.length = 8; + buf.event.length = 12; break; case TPRECORD: buf.event.signal = TP_RECORD; - buf.event.length = 8; + buf.event.length = 12; break; case TPSTOP: buf.event.signal = TP_RECORD; - buf.event.length = 8; + buf.event.length = 12; break; case TPTRIGGER: buf.event.signal = TP_TRIGGER; - buf.event.length = 16; + buf.event.length = 20; break; case TPTRIGCLR: buf.event.signal = TP_TRIGCLR; - buf.event.length = 8; + buf.event.length = 12; break; case TPREAD: buf.event.signal = TP_READ; - buf.event.length = 16; + buf.event.length = 20; break; case TPUDP: buf.event.signal = TP_UDP; - buf.event.length = 40; + buf.event.length = 44; break; case TPVERSION: buf.event.signal = TP_VERSION; - buf.event.length = 36; + buf.event.length = 40; break; case TPSIZE: buf.event.signal = TP_SIZE; - buf.event.length = 8; + buf.event.length = 12; break; case TPERROR: buf.event.signal = TP_ERROR; - buf.event.length = 8; + buf.event.length = 12; break; case TPCLEAR: buf.event.signal = TP_CLEAR; - buf.event.length = 4; + buf.event.length = 8; break; case TPRESET: buf.event.signal = TP_RESET; - buf.event.length = 4; + buf.event.length = 8; break; case TPCONFIG: buf.event.signal = TP_CONFIG; - buf.event.length = 8; + buf.event.length = 12; break; case TPERASEF: buf.event.signal = TP_ERASEF; - buf.event.length = 8; + buf.event.length = 12; break; case TPREADF: buf.event.signal = TP_READF; - buf.event.length = 1028; + buf.event.length = 1032; break; case TPWRITEF: buf.event.signal = TP_WRITEF; - buf.event.length = 1028; + buf.event.length = 1032; break; case TPREADW: buf.event.signal = TP_READW; - buf.event.length = 20; + buf.event.length = 24; break; case TPWRITEW: buf.event.signal = TP_WRITEW; - buf.event.length = 20; + buf.event.length = 24; break; default: buf.event.signal = 0; @@ -149,10 +150,7 @@ GCFEvent::TResult RawEvent::dispatch(GCFTask& task, GCFPortInterface& port) } if (buf.event.signal) // buf.event.signal == 0 indicates unrecognised or invalid MEP message - { - - (void)new((void*)&buf.event) GCFEvent(buf.event.signal); // placement new does in place construction - + { // // Print debugging info // @@ -173,5 +171,6 @@ GCFEvent::TResult RawEvent::dispatch(GCFTask& task, GCFPortInterface& port) return status; } - } // end TBB namespace -} // end LOFAR namespace + + } // end namespace TBB +} // end namespace LOFAR diff --git a/MAC/APL/PIC/TBBDriver/src/RawEvent.h b/MAC/APL/PIC/TBBDriver/src/RawEvent.h index 3b3c060b346..130a99ceaf4 100644 --- a/MAC/APL/PIC/TBBDriver/src/RawEvent.h +++ b/MAC/APL/PIC/TBBDriver/src/RawEvent.h @@ -28,47 +28,14 @@ #include <GCF/TM/GCF_Control.h> namespace LOFAR { - using namespace TP_Protocol; namespace TBB { - - - // TP Command Opcode's - // Data Recording - static const uint32 TPALLOC = 0x00000100; // OUT allocate buffer space to a certain input channel - static const uint32 TPFREE = 0x00000101; // OUT free buffer settings and disable input channel - static const uint32 TPRECORD = 0x00000102; // OUT record channel - static const uint32 TPSTOP = 0x00000103; // OUT freeze channel - // Triggering - static const uint32 TPTRIGGER = 0x00000200; // IN trigger detected - static const uint32 TPTRIGCLR = 0x00000201; // OUT clear trigger flag - // Data reading - static const uint32 TPREAD = 0x00000300; // OUT send recorded data to CEP - static const uint32 TPUDP = 0x00000301; // OUT configure UDP and IP header - // Board information - static const uint32 TPVERSION = 0x00000701; // IN/OUT returns board version - static const uint32 TPSIZE = 0x00000702; // IN/OUT returns TBB memory size - // Board status - static const uint32 TPERROR = 0x00000703; // IN error on TBB board - // Board control - static const uint32 TPCLEAR = 0x00000710; // OUT clear registers - static const uint32 TPRESET = 0x00000711; // OUT reset to facory image - static const uint32 TPCONFIG = 0x00000712; // OUT reconfigure image - // Remote system update - static const uint32 TPERASEF = 0x00000720; // OUT erase flash memory - static const uint32 TPREADF = 0x00000721; // IN/OUT read flash memory - static const uint32 TPWRITEF = 0x00000722; // OUT write flash memory - // DDR2 acces - static const uint32 TPREADW = 0x00000730; // IN/OUT read 64bit word from mp - static const uint32 TPWRITEW = 0x00000731; // OUT write 64bit wort to mp - // Direct register acces - static const uint32 TPREADR = 0x00000740; // IN/OUT read register(direct access), for debug purpose - static const uint32 TPWRITER = 0x00000741; // OUT write register(direct access), for debug purpose class RawEvent { public: - static LOFAR::GCF::TM::GCFEvent::TResult dispatch(LOFAR::GCF::TM::GCFTask& task, - LOFAR::GCF::TM::GCFPortInterface& port); + //static LOFAR::GCF::TM::GCFEvent::TResult dispatch(LOFAR::GCF::TM::GCFTask& task, + // LOFAR::GCF::TM::GCFPortInterface& port); + static GCFEvent::TResult dispatch(GCFTask& task, GCFPortInterface& port); }; } // end TBB namespace } // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/ReadCmd.cc b/MAC/APL/PIC/TBBDriver/src/ReadCmd.cc new file mode 100644 index 00000000000..f3ac2bb5f54 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ReadCmd.cc @@ -0,0 +1,166 @@ +//# ReadCmd.cc: implementation of the ReadCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "ReadCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a ReadCmd object.---------------------------------------- +ReadCmd::ReadCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPReadEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBReadackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + } +} + +//--Destructor for ReadCmd.--------------------------------------------------- +ReadCmd::~ReadCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool ReadCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_READ)||(event.signal == TP_READ)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void ReadCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBReadEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPREAD; + itsTPE->status = 0; + itsTPE->channel = itsTBBE->channel; + itsTPE->time = itsTBBE->time; + itsTPE->period = itsTBBE->period; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void ReadCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void ReadCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPReadEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + + LOG_DEBUG_STR(formatString("Received ReadAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void ReadCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void ReadCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 ReadCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 ReadCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool ReadCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool ReadCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/ReadCmd.h b/MAC/APL/PIC/TBBDriver/src/ReadCmd.h new file mode 100644 index 00000000000..d1f3a584ce6 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ReadCmd.h @@ -0,0 +1,86 @@ +//# -*- mode: c++ -*- +//# +//# ReadCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef READCMD_H_ +#define READCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class ReadCmd : public Command + { + public: + // Constructors for a ReadCmd object. + ReadCmd(); + + // Destructor for ReadCmd. + virtual ~ReadCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPReadEvent *itsTPE; + TPReadEvent *itsTPackE; + TBBReadEvent *itsTBBE; + TBBReadackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* READCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/ReadfCmd.cc b/MAC/APL/PIC/TBBDriver/src/ReadfCmd.cc new file mode 100644 index 00000000000..66124b37f91 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ReadfCmd.cc @@ -0,0 +1,174 @@ +//# ReadfCmd.cc: implementation of the ReadfCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "ReadfCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a ReadfCmd object.---------------------------------------- +ReadfCmd::ReadfCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPReadfEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBReadfackEvent(); + + itsBoardStatus = 0; + itsAddr = 0; + + for(int an = 0; an < 256;an++) { + itsData[an] = 0; + } +} + +//--Destructor for ReadfCmd.--------------------------------------------------- +ReadfCmd::~ReadfCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool ReadfCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_READF)||(event.signal == TP_READF)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void ReadfCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBReadfEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPREADF; + itsTPE->status = 0; + itsTPE->addr = itsTBBE->addr; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void ReadfCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void ReadfCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPReadfEvent(event); + + itsBoardStatus = itsTPackE->status; + itsAddr = itsTPackE->addr; + for(int an=0; an < 256; an++) { + itsData[an] = itsTPackE->data[an]; + } + + LOG_DEBUG_STR(formatString("Received ReadfAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void ReadfCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + itsTBBackE->boardstatus = itsBoardStatus; + itsTBBackE->addr = itsAddr; + for(int an=0; an < 256; an++) { + itsTBBackE->data[an] = itsData[an]; + } + + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void ReadfCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 ReadfCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 ReadfCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool ReadfCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool ReadfCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/ReadfCmd.h b/MAC/APL/PIC/TBBDriver/src/ReadfCmd.h new file mode 100644 index 00000000000..333540bbda5 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ReadfCmd.h @@ -0,0 +1,88 @@ +//# -*- mode: c++ -*- +//# +//# ReadfCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef READFCMD_H_ +#define READFCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class ReadfCmd : public Command + { + public: + // Constructors for a ReadfCmd object. + ReadfCmd(); + + // Destructor for ReadfCmd. + virtual ~ReadfCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPReadfEvent *itsTPE; + TPReadfEvent *itsTPackE; + TBBReadfEvent *itsTBBE; + TBBReadfackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus; + uint32 itsAddr; + uint32 itsData[256]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* READFCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/RecordCmd.cc b/MAC/APL/PIC/TBBDriver/src/RecordCmd.cc new file mode 100644 index 00000000000..4c7fe728874 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/RecordCmd.cc @@ -0,0 +1,164 @@ +//# RecordCmd.cc: implementation of the RecordCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "RecordCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a RecordCmd object.---------------------------------------- +RecordCmd::RecordCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPRecordEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBRecordackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + } +} + +//--Destructor for RecordCmd.--------------------------------------------------- +RecordCmd::~RecordCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool RecordCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_RECORD)||(event.signal == TP_RECORD)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void RecordCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBRecordEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPRECORD; + itsTPE->status = 0; + itsTPE->channel = itsTBBE->channel; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void RecordCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void RecordCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPRecordEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + + LOG_DEBUG_STR(formatString("Received RecordAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void RecordCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void RecordCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 RecordCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 RecordCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool RecordCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool RecordCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/RecordCmd.h b/MAC/APL/PIC/TBBDriver/src/RecordCmd.h new file mode 100644 index 00000000000..1d9a76ab4fd --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/RecordCmd.h @@ -0,0 +1,86 @@ +//# -*- mode: c++ -*- +//# +//# RecordCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef RECORDCMD_H_ +#define RECORDCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class RecordCmd : public Command + { + public: + // Constructors for a RecordCmd object. + RecordCmd(); + + // Destructor for RecordCmd. + virtual ~RecordCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPRecordEvent *itsTPE; + TPRecordEvent *itsTPackE; + TBBRecordEvent *itsTBBE; + TBBRecordackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* RECORDCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/RemoteStation.conf.in b/MAC/APL/PIC/TBBDriver/src/RemoteStation.conf.in index e64034adc37..569c26be7a0 100644 --- a/MAC/APL/PIC/TBBDriver/src/RemoteStation.conf.in +++ b/MAC/APL/PIC/TBBDriver/src/RemoteStation.conf.in @@ -3,9 +3,9 @@ # # -# Number of TBB boards, normal 12 +# Number of TBB boards installed, normal 12 +# Maximum number of boards = 12, read Information.txt how to change it. # -RS.MAX_TBBBOARDS=12 RS.N_TBBBOARDS=1 diff --git a/MAC/APL/PIC/TBBDriver/src/ResetCmd.cc b/MAC/APL/PIC/TBBDriver/src/ResetCmd.cc new file mode 100644 index 00000000000..079c807b9a0 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ResetCmd.cc @@ -0,0 +1,163 @@ +//# ResetCmd.cc: implementation of the ResetCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "ResetCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a ResetCmd object.---------------------------------------- +ResetCmd::ResetCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPResetEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBResetackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + } +} + +//--Destructor for ResetCmd.--------------------------------------------------- +ResetCmd::~ResetCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool ResetCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_RESET)||(event.signal == TP_RESET)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void ResetCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBResetEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPRESET; + itsTPE->status = 0; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void ResetCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void ResetCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPResetEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + + LOG_DEBUG_STR(formatString("Received ResetAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void ResetCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void ResetCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 ResetCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 ResetCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool ResetCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool ResetCmd::waitAck() +{ + return false; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/ResetCmd.h b/MAC/APL/PIC/TBBDriver/src/ResetCmd.h new file mode 100644 index 00000000000..af3154d3cac --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/ResetCmd.h @@ -0,0 +1,86 @@ +//# -*- mode: c++ -*- +//# +//# ResetCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef RESETCMD_H_ +#define RESETCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class ResetCmd : public Command + { + public: + // Constructors for a ResetCmd object. + ResetCmd(); + + // Destructor for ResetCmd. + virtual ~ResetCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPResetEvent *itsTPE; + TPResetEvent *itsTPackE; + TBBResetEvent *itsTBBE; + TBBResetackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* RESETCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/SizeCmd.cc b/MAC/APL/PIC/TBBDriver/src/SizeCmd.cc new file mode 100644 index 00000000000..b235082571b --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/SizeCmd.cc @@ -0,0 +1,167 @@ +//# SizeCmd.cc: implementation of the SizeCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "SizeCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a SizeCmd object.---------------------------------------- +SizeCmd::SizeCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPSizeEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBSizeackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + itsSize[boardnr] = 0; + } +} + +//--Destructor for SizeCmd.--------------------------------------------------- +SizeCmd::~SizeCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool SizeCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_SIZE)||(event.signal == TP_SIZE)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void SizeCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBSizeEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPSIZE; + itsTPE->status = 0; + itsTPE->size = 0; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void SizeCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void SizeCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPSizeEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + itsSize[boardnr] = itsTPackE->size; + + LOG_DEBUG_STR(formatString("Received SizeAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void SizeCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + itsTBBackE->size[boardnr] = itsSize[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void SizeCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 SizeCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 SizeCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool SizeCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool SizeCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/SizeCmd.h b/MAC/APL/PIC/TBBDriver/src/SizeCmd.h new file mode 100644 index 00000000000..3424ebecf50 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/SizeCmd.h @@ -0,0 +1,87 @@ +//# -*- mode: c++ -*- +//# +//# SizeCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef SIZECMD_H_ +#define SIZECMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class SizeCmd : public Command + { + public: + // Constructors for a SizeCmd object. + SizeCmd(); + + // Destructor for SizeCmd. + virtual ~SizeCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPSizeEvent *itsTPE; + TPSizeEvent *itsTPackE; + TBBSizeEvent *itsTBBE; + TBBSizeackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + uint32 itsSize[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* SIZECMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/StationSettings.cc b/MAC/APL/PIC/TBBDriver/src/StationSettings.cc index 41813dc91c8..bcf01b1a557 100644 --- a/MAC/APL/PIC/TBBDriver/src/StationSettings.cc +++ b/MAC/APL/PIC/TBBDriver/src/StationSettings.cc @@ -28,7 +28,7 @@ #include "StationSettings.h" namespace LOFAR { - namespace TBB { + namespace TBB { // // Initialize singleton @@ -48,8 +48,7 @@ StationSettings* StationSettings::instance() // StationSettings::StationSettings() : itsMaxTbbBoards(0), - itsNrTbbBoards(0), - itsNrMpsPerBoard(4) + itsNrTbbBoards(0) { } @@ -74,8 +73,5 @@ void StationSettings::setNrTbbBoards (int32 nrOfBoards) itsNrTbbBoards, itsMaxTbbBoards)); } - - - - } // end TBB namespace -} // end LOFAR namespace + } // end namespace TBB +} // end namespace LOFAR diff --git a/MAC/APL/PIC/TBBDriver/src/StationSettings.h b/MAC/APL/PIC/TBBDriver/src/StationSettings.h index 04fdcb0b72c..f1793417b5c 100644 --- a/MAC/APL/PIC/TBBDriver/src/StationSettings.h +++ b/MAC/APL/PIC/TBBDriver/src/StationSettings.h @@ -52,14 +52,12 @@ public: int32 nrTbbBoards(); // RS.N_TBBBOARDS - int32 nrMpsPerBoard(); // const 4 - friend class TBBDriver; protected: // note TBBDriver must be able to set them void setMaxTbbBoards(int32 maxBoards); void setNrTbbBoards(int32 nrOfBoards); - + //void setNrTpRetries(int32 nrOfBoards); private: @@ -70,17 +68,14 @@ private: //# --- Datamembers --- int32 itsMaxTbbBoards; // max posible boards int32 itsNrTbbBoards; // nr of installed boards - int32 itsNrMpsPerBoard; // nr of Memmory Proccessors on one board - - - + //int32 itsNrTpRetries; + static StationSettings* theirStationSettings; }; //# --- inline functions --- inline int32 StationSettings::maxTbbBoards() { return (itsMaxTbbBoards); } inline int32 StationSettings::nrTbbBoards() { return (itsNrTbbBoards); } -inline int32 StationSettings::nrMpsPerBoard() { return (itsNrMpsPerBoard); } } // end TBB namespace } // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/StopCmd.cc b/MAC/APL/PIC/TBBDriver/src/StopCmd.cc new file mode 100644 index 00000000000..ca7ae29771a --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/StopCmd.cc @@ -0,0 +1,164 @@ +//# StopCmd.cc: implementation of the StopCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "StopCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a StopCmd object.---------------------------------------- +StopCmd::StopCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPStopEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBStopackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + } +} + +//--Destructor for StopCmd.--------------------------------------------------- +StopCmd::~StopCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool StopCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_STOP)||(event.signal == TP_STOP)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void StopCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBStopEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPSTOP; + itsTPE->status = 0; + itsTPE->channel = itsTBBE->channel; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void StopCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void StopCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPStopEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + + LOG_DEBUG_STR(formatString("Received StopAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void StopCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void StopCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 StopCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 StopCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool StopCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool StopCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/StopCmd.h b/MAC/APL/PIC/TBBDriver/src/StopCmd.h new file mode 100644 index 00000000000..111d904fc1b --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/StopCmd.h @@ -0,0 +1,86 @@ +//# -*- mode: c++ -*- +//# +//# StopCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef STOPCMD_H_ +#define STOPCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class StopCmd : public Command + { + public: + // Constructors for a StopCmd object. + StopCmd(); + + // Destructor for StopCmd. + virtual ~StopCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPStopEvent *itsTPE; + TPStopEvent *itsTPackE; + TBBStopEvent *itsTBBE; + TBBStopackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* STOPCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/TBBDriver.cc b/MAC/APL/PIC/TBBDriver/src/TBBDriver.cc index ee0e54089d8..301946b5d50 100644 --- a/MAC/APL/PIC/TBBDriver/src/TBBDriver.cc +++ b/MAC/APL/PIC/TBBDriver/src/TBBDriver.cc @@ -23,44 +23,41 @@ //# Always #include <lofar_config.h> first! #include <lofar_config.h> #include <Common/LofarLogger.h> - -//# Includes - +#include <Common/LofarLocators.h> #include <APS/ParameterSet.h> +#include <GCF/GCF_ServiceInfo.h> #include "TBBDriver.h" -#include "StationSettings.h" - #include "RawEvent.h" // include all cmd and msg classes -// #include <AllocCmd.h> -// #include <FreeCmd.h> -// #include <RecordCmd.h> -// #include <Stop.h> -// #include <TrigclrCmd.h> -// #include <ReadCmd.h> -// #include <UdpCmd.h> +#include "AllocCmd.h" +#include "FreeCmd.h" +#include <RecordCmd.h> +#include <StopCmd.h> +#include <TrigclrCmd.h> +#include <ReadCmd.h> +#include <UdpCmd.h> #include "VersionCmd.h" -// #include <SizeCmd.h> -// #include <ClearCmd.h> -// #include <ResetCmd.h> -// #include <ConfigCmd.h> -// #include <ErasefCmd.h> -// #include <ReadfCmd.h> -// #include <WritefCmd.h> +#include <SizeCmd.h> +#include <ClearCmd.h> +#include <ResetCmd.h> +#include <ConfigCmd.h> +#include <ErasefCmd.h> +#include <ReadfCmd.h> +#include <WritefCmd.h> // #include <ReadwCmd.h> // #include <WritewCmd.h> // #include <TriggerMsg.h> // #include <ErrorMsg.h> -#define ETHERTYPE_TP 0x10FA // first 4 letters of LOFAr +#define ETHERTYPE_TP 0x7BB0 // letters of TBB - -namespace LOFAR { - using namespace ACC::APS; - namespace TBB { +using namespace LOFAR; +using namespace GCFCommon; +using namespace ACC::APS; +using namespace TBB; static int32 g_instancenr = -1; @@ -106,15 +103,9 @@ void parseOptions(int argc, char** argv) } */ TBBDriver::TBBDriver(string name) - : GCFTask((State)&TBBDriver::idle_state, name) + : GCFTask((State)&TBBDriver::init_state, name) { - // first initialize the global settins - LOG_DEBUG("Setting up station settings"); - StationSettings* tbb_ss = StationSettings::instance(); - tbb_ss->setMaxTbbBoards (globalParameterSet()->getInt32("RS.MAX_TBBBOARDS")); - tbb_ss->setNrTbbBoards (globalParameterSet()->getInt32("RS.N_TBBBOARDS")); - - //LOG_DEBUG_STR (*tbb_ss); + cmd = 0; // tell broker we are here LOG_DEBUG("Registering protocols"); @@ -127,11 +118,12 @@ TBBDriver::TBBDriver(string name) if (g_instancenr>=0) { acceptorID = formatString("(%d)", g_instancenr); } - itsAcceptor.init(*this, "acceptor_v3"+acceptorID, GCFPortInterface::MSPP, TBB_PROTOCOL); + itsAcceptor.init(*this, MAC_SVCMASK_TBBDRIVER + acceptorID, GCFPortInterface::MSPP, TBB_PROTOCOL); // open port with TBB board LOG_DEBUG("Connecting to TBB boards"); - itsBoard = new GCFETHRawPort[StationSettings::instance()->nrTbbBoards()]; + itsBoard = new GCFETHRawPort[globalParameterSet()->getInt32("RS.N_TBBBOARDS")]; + //itsBoard = new GCFETHRawPort[tbb_ss->nrTbbBoards()]; ASSERT(itsBoard); itsMsgPort.init(*this, "MsgPort", GCFPortInterface::SAP, TBB_PROTOCOL); @@ -153,7 +145,7 @@ TBBDriver::TBBDriver(string name) char boardname[64]; char paramname[64]; char macaddrstr[64]; - for (int boardid = 0; boardid < StationSettings::instance()->nrTbbBoards(); boardid++) { + for (int boardid = 0; boardid < globalParameterSet()->getInt32("RS.N_TBBBOARDS"); boardid++) { snprintf(boardname, 64, "board%d", boardid); if (bUseMAC_BASE) { @@ -168,23 +160,107 @@ TBBDriver::TBBDriver(string name) itsBoard[boardid].init(*this, boardname, GCFPortInterface::SAP, TP_PROTOCOL,true /*raw*/); itsBoard[boardid].setAddr(globalParameterSet()->getString("TBBDriver.IF_NAME").c_str(), macaddrstr); - // set ethertype to 0x10FA so Ethereal can decode EPA messages + // set ethertype to 0x7BB0 so Ethereal can decode TBB messages itsBoard[boardid].setEtherType(ETHERTYPE_TP); - } + } // create cmd & msg handler - cmdhandler = new BoardCmdHandler(itsBoard); + LOG_DEBUG_STR("initializing handlers"); + cmdhandler = new BoardCmdHandler(); msghandler = new ClientMsgHandler(itsMsgPort); - + + cmdhandler->setBoardPorts(itsBoard); + cmdhandler->setMaxTbbBoards(MAX_N_TBBBOARDS); + cmdhandler->setNrOfTbbBoards(globalParameterSet()->getInt32("RS.N_TBBBOARDS")); + cmdhandler->setTpRetries(globalParameterSet()->getInt32("TBBDriver.TP_RETRIES")); + cmdhandler->setTpTimeOut(globalParameterSet()->getDouble("TBBDriver.TP_TIMEOUT")); + // set Tbb queue + LOG_DEBUG_STR("initializing TbbQueue"); itsTbbQueue = new deque<TbbEvent>(100); + itsTbbQueue->clear(); } TBBDriver::~TBBDriver() { - //delete cmdhandler; // delete BoardCmdHandler + delete cmdhandler; + delete msghandler; +} + + +void TBBDriver::undertaker() +{ + for (list<GCFPortInterface*>::iterator it = itsDeadClients.begin(); + it != itsDeadClients.end(); + it++) + { + delete (*it); + } + itsDeadClients.clear(); +} + +// +// openBoards() +// +void TBBDriver::openBoards() +{ + LOG_DEBUG_STR("opening boards"); + for (int boardid = 0; boardid < globalParameterSet()->getInt32("RS.N_TBBBOARDS"); boardid++) + { + if (!itsBoard[boardid].isConnected()) itsBoard[boardid].open(); + } +} + +// +// isEnabled() +// +bool TBBDriver::isEnabled() +{ + bool enabled = true; + for (int boardid = 0; boardid < globalParameterSet()->getInt32("RS.N_TBBBOARDS"); boardid++) + { + if (!itsBoard[boardid].isConnected()) + { + enabled = false; + break; + } + } + return enabled; +} + + +GCFEvent::TResult TBBDriver::init_state(GCFEvent& event, GCFPortInterface& port) +{ + GCFEvent::TResult status = GCFEvent::HANDLED; + + switch(event.signal) { + case F_INIT: { + } break; + + case F_ENTRY: { + openBoards(); + } break; + + case F_CONNECTED: { + LOG_INFO(formatString("CONNECTED: port '%s'", port.getName().c_str())); + + if (isEnabled()) { + // All board ports are open, start waiting for clients + if (!itsAcceptor.isConnected()) + itsAcceptor.open(); + } + if (itsAcceptor.isConnected()) + TRAN(TBBDriver::idle_state); + } break; + + default: { + status = GCFEvent::NOT_HANDLED; + } break; + } + return status; } + // // idle(event, port) @@ -192,27 +268,26 @@ TBBDriver::~TBBDriver() GCFEvent::TResult TBBDriver::idle_state(GCFEvent& event, GCFPortInterface& port) { GCFEvent::TResult status = GCFEvent::HANDLED; + undertaker(); switch(event.signal) { - case F_INIT: { } break; + case F_INIT: { + } break; case F_ENTRY: { - // look if there is an Tbb command in queue + if(!itsTbbQueue->empty()) { - GCFEvent event; - TbbEvent* tbbevent; - *tbbevent = itsTbbQueue->front(); + GCFEvent e; - event.signal = tbbevent->signal; + e.signal = itsTbbQueue->front().signal; //tbbevent->signal; - SetTbbCommand(tbbevent->signal); + SetTbbCommand(itsTbbQueue->front().signal); - status = cmdhandler->dispatch(event,*tbbevent->port); + status = cmdhandler->dispatch(e,*itsTbbQueue->front().port); itsTbbQueue->pop_front(); TRAN(TBBDriver::busy_state); - } } break; @@ -220,6 +295,30 @@ GCFEvent::TResult TBBDriver::idle_state(GCFEvent& event, GCFPortInterface& port) LOG_INFO(formatString("CONNECTED: port '%s'", port.getName().c_str())); } break; + case F_DISCONNECTED: { + + LOG_INFO(formatString("DISCONNECTED: port '%s'", port.getName().c_str())); + port.close(); + + if (&port == &itsAcceptor) { + LOG_FATAL("Failed to start listening for client connections."); + exit(EXIT_FAILURE); + } + else { + itsClientList.remove(&port); + itsDeadClients.push_back(&port); + } + } break; + + case F_ACCEPT_REQ: { + GCFTCPPort* client = new GCFTCPPort(); + client->init(*this, "client", GCFPortInterface::SPP, TBB_PROTOCOL); + itsAcceptor.accept(*client); + itsClientList.push_back(client); + + LOG_INFO(formatString("NEW CLIENT CONNECTED: %d clients connected", itsClientList.size())); + } break; + case F_DATAIN: { status = RawEvent::dispatch(*this, port); } break; @@ -232,7 +331,7 @@ GCFEvent::TResult TBBDriver::idle_state(GCFEvent& event, GCFPortInterface& port) } // if it is not a Tbb event, look for Tp event else if(SetTpCommand(event.signal)) { - status = cmdhandler->dispatch(event,port); + status = msghandler->dispatch(event,port); TRAN(TBBDriver::busy_state); } // if not a Tbb or Tp event, return not-handled @@ -251,6 +350,9 @@ GCFEvent::TResult TBBDriver::busy_state(GCFEvent& event, GCFPortInterface& port) GCFEvent::TResult status = GCFEvent::HANDLED; switch(event.signal) { + case F_INIT: { + } break; + case F_ENTRY: { } break; @@ -265,6 +367,7 @@ GCFEvent::TResult TBBDriver::busy_state(GCFEvent& event, GCFPortInterface& port) } break; case F_DISCONNECTED: { + TRAN(TBBDriver::idle_state); } break; case F_EXIT: { @@ -301,7 +404,7 @@ GCFEvent::TResult TBBDriver::busy_state(GCFEvent& event, GCFPortInterface& port) case TP_WRITEW: { status = cmdhandler->dispatch(event,port); // dispatch ack from boards - if(cmdhandler->done()){ + if(cmdhandler->tpCmdDone()){ TRAN(TBBDriver::idle_state); } } break; @@ -313,12 +416,15 @@ GCFEvent::TResult TBBDriver::busy_state(GCFEvent& event, GCFPortInterface& port) } break; default: { + if(cmdhandler->tpCmdDone()){ + TRAN(TBBDriver::idle_state); + } // put event on the queue TbbEvent tbbevent; tbbevent.signal = event.signal; tbbevent.port = &port; itsTbbQueue->push_back(tbbevent); - //status = GCFEvent::NOT_HANDLED; + status = GCFEvent::NOT_HANDLED; } break; } return status; @@ -327,96 +433,111 @@ GCFEvent::TResult TBBDriver::busy_state(GCFEvent& event, GCFPortInterface& port) bool TBBDriver::SetTbbCommand(unsigned short signal) { + if(cmd) delete cmd; switch(signal) { - /* + case TBB_ALLOC: { - AllocCmd *cmd = AllocCmd(); - cmdhandler->SetCmd(cmd); + AllocCmd *cmd; + cmd = new AllocCmd(); + cmdhandler->setTpCmd(cmd); } break; - case TBB_FREE: { - FreeCmd *cmd = FreeCmd(); - cmdhandler->SetCmd(cmd); + case TBB_FREE: { + FreeCmd *cmd; + cmd = new FreeCmd(); + cmdhandler->setTpCmd(cmd); } break; - + /* case TBB_RECORD: { - RecordCmd *cmd = RecordCmd(); - cmdhandler->SetCmd(cmd); + RecordCmd *cmd; + cmd = new RecordCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_STOP: { - Stopcmd *cmd = StopCmd(); - cmdhandler->SetCmd(cmd); + Stopcmd *cmd; + cmd = new StopCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_TRIGCLR: { - TrigclrCmd *cmd = TrigclrCmd(); - cmdhandler->SetCmd(cmd); + TrigclrCmd *cmd; + cmd = new TrigclrCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_READ: { - ReadCmd *cmd = ReadCmd(); - cmdhandler->SetCmd(cmd); + ReadCmd *cmd; + cmd = new ReadCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_UDP: { - UdpCmd *cmd = UdpCmd(); - cmdhandler->SetCmd(cmd); + UdpCmd *cmd; + cmd = new UdpCmd(); + cmdhandler->setTpCmd(cmd); } break; */ case TBB_VERSION: { VersionCmd *cmd; - - cmd = new VersionCmd; - - cmdhandler->SetCmd(cmd); + cmd = new VersionCmd(); + cmdhandler->setTpCmd(cmd); } break; - /* + case TBB_SIZE: { - SizeCmd *cmd = SizeCmd(); - cmdhandler->SetCmd(cmd); + SizeCmd *cmd; + cmd = new SizeCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_CLEAR: { - ClearCmd *cmd = ClearCmd(); - cmdhandler->SetCmd(cmd); + ClearCmd *cmd; + cmd = new ClearCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_RESET: { - ResetCmd *cmd = ResetCmd(); - cmdhandler->SetCmd(cmd); + ResetCmd *cmd; + cmd = new ResetCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_CONFIG: { - ConfigCmd *cmd = ConfigCmd(); - cmdhandler->SetCmd(cmd); + ConfigCmd *cmd; + cmd = new ConfigCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_ERASEF: { - ErasefCmd *cmd = ErasefCmd(); - cmdhandler->SetCmd(cmd); + ErasefCmd *cmd; + cmd = new ErasefCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_READF: { - ReadfCmd *cmd = ReadfCmd(); - cmdhandler->SetCmd(cmd); + ReadfCmd *cmd; + cmd = new ReadfCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_WRITEF: { - WritefCmd *cmd = WritefCmd(); - cmdhandler->SetCmd(cmd); + WritefCmd *cmd; + cmd = new WritefCmd(); + cmdhandler->setTpCmd(cmd); } break; - + /* case TBB_READW: { - ReadwCmd *cmd = ReadwCmd(); - cmdhandler->SetCmd(cmd); + ReadwCmd *cmd; + cmd = new ReadwCmd(); + cmdhandler->setTpCmd(cmd); } break; case TBB_WRITEW: { - WritewCmd *cmd = WritewCmd(); - cmdhandler->SetCmd(cmd); + WritewCmd *cmd; + cmd = new WritewCmd(); + cmdhandler->setTpCmd(cmd); } break; */ default: { @@ -433,12 +554,12 @@ bool TBBDriver::SetTpCommand(unsigned short signal) /* case TP_TRIGGER: { TriggerMsg *msg = TriggerMsg(); - msghandler->SetCmd(msg); + msghandler->SetTBBMsg(msg); } break; case TP_ERROR: { ErrorMsg *msg = ErrorMsg(); - msghandler->SetCmd(msg); + msghandler->SetTBBMsg(msg); } break; */ default: { @@ -448,15 +569,16 @@ bool TBBDriver::SetTpCommand(unsigned short signal) return true; } - } // namespace TBB -} // namespace LOFAR + //} // end namespace TBB +//} // end namespace LOFAR + // // main (argc, argv) // int main(int argc, char** argv) { - GCFTask::init(argc, argv); // initializes log system + LOFAR::GCF::TM::GCFTask::init(argc, argv); // initializes log system /* LOG_INFO(formatString("Starting up %s", argv[0])); @@ -475,8 +597,9 @@ int main(int argc, char** argv) */ LOG_DEBUG ("Reading configuration files"); try { - LOFAR::ACC::APS::globalParameterSet()->adoptFile("TBBDriverPorts.conf"); - LOFAR::ACC::APS::globalParameterSet()->adoptFile("RemoteStation.conf"); + LOFAR::ConfigLocator cl; + LOFAR::ACC::APS::globalParameterSet()->adoptFile(cl.locate("RemoteStation.conf")); + LOFAR::ACC::APS::globalParameterSet()->adoptFile(cl.locate("TBBDriver.conf")); } catch (LOFAR::Exception e) { LOG_ERROR_STR("Failed to load configuration files: " << e.text()); @@ -491,8 +614,8 @@ int main(int argc, char** argv) LOFAR::GCF::TM::GCFTask::run(); } catch (LOFAR::Exception e) { - //LOG_ERROR_STR("Exception: " << e.text()); - //exit(EXIT_FAILURE); + LOG_ERROR_STR("Exception: " << e.text()); + exit(EXIT_FAILURE); } LOG_INFO("Normal termination of program"); diff --git a/MAC/APL/PIC/TBBDriver/src/TBBDriver.conf.in b/MAC/APL/PIC/TBBDriver/src/TBBDriver.conf.in index 548e2fd556d..c1b32e8c309 100644 --- a/MAC/APL/PIC/TBBDriver/src/TBBDriver.conf.in +++ b/MAC/APL/PIC/TBBDriver/src/TBBDriver.conf.in @@ -3,19 +3,10 @@ # # -# Specify the base index of the TBB board ethernet MAC address -# The TBB boards addresses will be numbered consecutively. +# Specify the MAC addresses of all TBB boards # -# Start from address: 10:FA:00:00:MAC_BASE:02 -# TBBDriver.MAC_BASE=1 - -# -# Instead of specifying MAC_BASE, one can specify all MAC -# addresses explicitly as MAC_ADDR0..MAC_ADDR11 -# In this case you must leave TBBDriver.MAC_BASE unspecified -# - -TBBDriver.MAC_ADDR_0=10:FA:00:00:00:02 +TBBDriver.MAC_ADDR_0=00:30:48:2D:82:F7 +#TBBDriver.MAC_ADDR_0=10:FA:00:00:00:02 TBBDriver.MAC_ADDR_1=10:FA:00:00:01:02 TBBDriver.MAC_ADDR_2=10:FA:00:00:02:02 TBBDriver.MAC_ADDR_3=10:FA:00:00:03:02 @@ -28,14 +19,6 @@ TBBDriver.MAC_ADDR_9=10:FA:00:00:09:02 TBBDriver.MAC_ADDR_10=10:FA:00:00:0A:02 TBBDriver.MAC_ADDR_11=10:FA:00:00:0B:02 -# -# Data output payload size. -# Should eventually be computed dynamically -# based on settings. -# -TBBDriver.OUTPUT_PAYLOAD_SIZE=736 - - # # Ethernet interface on which to contact the TBB boards. # This interface would normally be connected to the switch. @@ -43,22 +26,8 @@ TBBDriver.OUTPUT_PAYLOAD_SIZE=736 TBBDriver.IF_NAME=eth1 # -# Select LOOPBACK_MODE mode # -# If LOOPBACK_MODE == 0, the WRITE is done first. -# In this mode the TBBDriver checks that what was -# written is correctly read back from the board. This can -# be used to check that the RSP board or the EPAStub -# functions correctly. Read results are not stored in -# the TBBDriver cache. # -# If LOOPBACK_MODE == 1, the READ is done first. -# In this mode you can check with Ethereal that what was -# read from the RSP board or EPAStub is written back in -# the same way. This is used to check whether the TBBDriver -# stores the information at the correct location in its cache. -# Of course in this mode reads results are stored in the -# TBBDriver cache. # -TBBDriver.LOOPBACK_MODE=0 - +TBBDriver.TP_RETRIES=10 +TBBDriver.TP_TIMEOUT=0.2 diff --git a/MAC/APL/PIC/TBBDriver/src/TBBDriver.h b/MAC/APL/PIC/TBBDriver/src/TBBDriver.h index 7f007cd656e..632a27e5c71 100644 --- a/MAC/APL/PIC/TBBDriver/src/TBBDriver.h +++ b/MAC/APL/PIC/TBBDriver/src/TBBDriver.h @@ -51,7 +51,21 @@ namespace LOFAR{ // GTMTopologyService classes. TBBDriver(string name); ~TBBDriver(); - + + // open all board ports + void openBoards(); + + // check if all boardports are open + bool isEnabled(); + + + // The init state. + // This state is used to wait for events from the client + // and board ports. When a event is received the command is executed + // and transition to the busy state is made. + GCFEvent::TResult init_state(GCFEvent& event, GCFPortInterface &port); + + // The idle state. // This state is used to wait for events from the client // and board ports. When a event is received the command is executed @@ -63,7 +77,8 @@ namespace LOFAR{ // but they will be put on the que. // All TPEvent will be transmittted imediallie GCFEvent::TResult busy_state(GCFEvent& event, GCFPortInterface &port); - + + void undertaker(); private: // Copying is not allowed ?? @@ -74,22 +89,22 @@ namespace LOFAR{ bool SetTpCommand(unsigned short signal); // define some constants - // mode of operation - BoardCmdHandler* cmdhandler; - ClientMsgHandler* msghandler; - + BoardCmdHandler *cmdhandler; + ClientMsgHandler *msghandler; + Command *cmd; struct TbbEvent{ - unsigned short signal; - GCFPortInterface* port; + unsigned short signal; + GCFPortInterface *port; }; - deque<TbbEvent>* itsTbbQueue; + deque<TbbEvent> *itsTbbQueue; GCFTCPPort itsAcceptor; // listen for clients on this port GCFTCPPort itsMsgPort; // send messages to this port - GCFETHRawPort* itsBoard; // array of ports, one for each TBB board - //std::list<GCFPortInterface*> itsclient_list; // list of clients - //std::list<GCFPortInterface*> itsdead_clients; // list of clients to cleanup + GCFETHRawPort *itsBoard; // array of ports, one for each TBB board + + std::list<GCFPortInterface*> itsClientList; // list of clients + std::list<GCFPortInterface*> itsDeadClients; // list of clients to cleanup }; } // end TBB namespace } // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/TBBDriverPorts.conf.in b/MAC/APL/PIC/TBBDriver/src/TBBDriverPorts.conf.in index 307d80228eb..e8f3809bbff 100644 --- a/MAC/APL/PIC/TBBDriver/src/TBBDriverPorts.conf.in +++ b/MAC/APL/PIC/TBBDriver/src/TBBDriverPorts.conf.in @@ -5,13 +5,13 @@ # # TBBDriver configuration # -mac.ns.TBBDriver.server.type=TCP +#mac.ns.TBBDriver.server.type=TCP #mac.ns.TBBDriver.spid.port=0 -mac.ns.TBBDriver.spid.deviceName=/dev/spid0 -mac.ns.TBBDriver.acceptor_v3.type=TCP +#mac.ns.TBBDriver.spid.deviceName=/dev/spid0 +#mac.ns.TBBDriver.acceptor_v3.type=TCP # # TBBTest configuration # -mac.ns.TBBTest.server.type=TCP -mac.top.TBBTest.server.remoteservice=TBBDriver:acceptor_v3 +#mac.ns.TBBTest.server.type=TCP +#mac.top.TBBTest.server.remoteservice=TBBDriver:acceptor_v3 diff --git a/MAC/APL/PIC/TBBDriver/src/TP_Protocol.prot b/MAC/APL/PIC/TBBDriver/src/TP_Protocol.prot index 73433f36e21..be966a2c575 100644 --- a/MAC/APL/PIC/TBBDriver/src/TP_Protocol.prot +++ b/MAC/APL/PIC/TBBDriver/src/TP_Protocol.prot @@ -11,16 +11,45 @@ id = "(LOFAR::GCF::TM::F_APL_PROTOCOL+15)"; // e.g. include = '<sys/time.h>'; include = '<linux/types.h>'; -include = '<bitset>'; +//include = '<bitset>'; include = '<Common/LofarTypes.h>'; -include = '<APL/RTCCommon/Timestamp.h>'; +//include = '<APL/RTCCommon/Timestamp.h>'; prelude = << PRELUDE_END - static const int MAX_N_TBBBOARDS = 12; - static const int SUCCESS = 1; - static const int FAILURE = 0; + + // TP Command Opcode's + // Data Recording + static const uint32 TPALLOC = 0x00000100; // OUT allocate buffer space to a certain input channel + static const uint32 TPFREE = 0x00000101; // OUT free buffer settings and disable input channel + static const uint32 TPRECORD = 0x00000102; // OUT record channel + static const uint32 TPSTOP = 0x00000103; // OUT freeze channel + // Triggering + static const uint32 TPTRIGGER = 0x00000200; // IN trigger detected + static const uint32 TPTRIGCLR = 0x00000201; // OUT clear trigger flag + // Data reading + static const uint32 TPREAD = 0x00000300; // OUT send recorded data to CEP + static const uint32 TPUDP = 0x00000301; // OUT configure UDP and IP header + // Board information + static const uint32 TPVERSION = 0x00000700; // IN/OUT returns board version + static const uint32 TPSIZE = 0x00000702; // IN/OUT returns TBB memory size + // Board status + static const uint32 TPERROR = 0x00000703; // IN error on TBB board + // Board control + static const uint32 TPCLEAR = 0x00000710; // OUT clear registers + static const uint32 TPRESET = 0x00000711; // OUT reset to facory image + static const uint32 TPCONFIG = 0x00000712; // OUT reconfigure image + // Remote system update + static const uint32 TPERASEF = 0x00000720; // OUT erase flash memory + static const uint32 TPREADF = 0x00000721; // IN/OUT read flash memory + static const uint32 TPWRITEF = 0x00000722; // OUT write flash memory + // DDR2 acces + static const uint32 TPREADW = 0x00000730; // IN/OUT read 64bit word from mp + static const uint32 TPWRITEW = 0x00000731; // OUT write 64bit wort to mp + // Direct register acces + static const uint32 TPREADR = 0x00000740; // IN/OUT read register(direct access), for debug purpose + static const uint32 TPWRITER = 0x00000741; // OUT write register(direct access), for debug purpose PRELUDE_END; @@ -45,6 +74,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; param = { name = "channel"; type = "uint32"; @@ -67,6 +100,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; param = { name = "channel"; type = "uint32"; @@ -81,6 +118,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; param = { name = "channel"; type = "uint32"; @@ -95,6 +136,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; param = { name = "channel"; type = "uint32"; @@ -110,6 +155,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; param = { name = "channel"; type = "uint32"; @@ -132,6 +181,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; param = { name = "channel"; type = "uint32"; @@ -147,6 +200,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; param = { name = "channel"; type = "uint32"; @@ -170,6 +227,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; param = { name = "udp"; type = "uint32[2]"; @@ -193,6 +254,10 @@ event = { param = { name = "opcode"; type = "uint32"; + }; + param = { + name = "status"; + type = "uint32"; }; param = { name = "boardid"; @@ -211,19 +276,19 @@ event = { type = "uint32"; }; param = { - name = "mp1version"; + name = "mp0version"; type = "uint32"; }; param = { - name = "mp2version"; + name = "mp1version"; type = "uint32"; }; param = { - name = "mp3version"; + name = "mp2version"; type = "uint32"; }; param = { - name = "mp4version"; + name = "mp3version"; type = "uint32"; }; }; @@ -237,6 +302,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; param = { name = "size"; type = "uint32"; @@ -251,6 +320,9 @@ event = { param = { name = "opcode"; type = "uint32"; + };param = { + name = "status"; + type = "uint32"; }; param = { name = "code"; @@ -267,6 +339,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; }; event = { @@ -277,6 +353,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; }; event = { @@ -291,6 +371,10 @@ event = { name = "image"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; }; // Remote system update @@ -302,6 +386,10 @@ event = { name = "opcode"; type = "uint32"; }; + param = { + name = "status"; + type = "uint32"; + }; param = { name = "addr"; type = "uint32"; @@ -315,6 +403,10 @@ event = { param = { name = "opcode"; type = "uint32"; + }; + param = { + name = "status"; + type = "uint32"; }; param = { name = "addr"; @@ -333,6 +425,10 @@ event = { param = { name = "opcode"; type = "uint32"; + }; + param = { + name = "status"; + type = "uint32"; }; param = { name = "addr"; @@ -352,6 +448,10 @@ event = { param = { name = "opcode"; type = "uint32"; + }; + param = { + name = "status"; + type = "uint32"; }; param = { name = "mp"; @@ -378,6 +478,10 @@ event = { param = { name = "opcode"; type = "uint32"; + }; + param = { + name = "status"; + type = "uint32"; }; param = { name = "mp"; diff --git a/MAC/APL/PIC/TBBDriver/src/TrigclrCmd.cc b/MAC/APL/PIC/TBBDriver/src/TrigclrCmd.cc new file mode 100644 index 00000000000..9cd726e688a --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/TrigclrCmd.cc @@ -0,0 +1,164 @@ +//# TrigclrCmd.cc: implementation of the TrigclrCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "TrigclrCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a TrigclrCmd object.---------------------------------------- +TrigclrCmd::TrigclrCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPTrigclrEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBTrigclrackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + } +} + +//--Destructor for TrigclrCmd.--------------------------------------------------- +TrigclrCmd::~TrigclrCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool TrigclrCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_TRIGCLR)||(event.signal == TP_TRIGCLR)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void TrigclrCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBTrigclrEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPTRIGCLR; + itsTPE->status = 0; + itsTPE->channel = itsTBBE->channel; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void TrigclrCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void TrigclrCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPTrigclrEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + + LOG_DEBUG_STR(formatString("Received TrigclrAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void TrigclrCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void TrigclrCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 TrigclrCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 TrigclrCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool TrigclrCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool TrigclrCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/TrigclrCmd.h b/MAC/APL/PIC/TBBDriver/src/TrigclrCmd.h new file mode 100644 index 00000000000..62c56f84da8 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/TrigclrCmd.h @@ -0,0 +1,86 @@ +//# -*- mode: c++ -*- +//# +//# TrigclrCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef TRIGCLRCMD_H_ +#define TRIGCLRCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class TrigclrCmd : public Command + { + public: + // Constructors for a TrigclrCmd object. + TrigclrCmd(); + + // Destructor for TrigclrCmd. + virtual ~TrigclrCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPTrigclrEvent *itsTPE; + TPTrigclrEvent *itsTPackE; + TBBTrigclrEvent *itsTBBE; + TBBTrigclrackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* TRIGCLRCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/UdpCmd.cc b/MAC/APL/PIC/TBBDriver/src/UdpCmd.cc new file mode 100644 index 00000000000..4c02e0fc38d --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/UdpCmd.cc @@ -0,0 +1,172 @@ +//# UdpCmd.cc: implementation of the UdpCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "UdpCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a UdpCmd object.---------------------------------------- +UdpCmd::UdpCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPUdpEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBUdpackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + } +} + +//--Destructor for UdpCmd.--------------------------------------------------- +UdpCmd::~UdpCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool UdpCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_UDP)||(event.signal == TP_UDP)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void UdpCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBUdpEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPUDP; + itsTPE->status = 0; + itsTPE->udp[0] = itsTBBE->udp[0]; + itsTPE->udp[1] = itsTBBE->udp[1]; + itsTPE->ip[0] = itsTBBE->ip[0]; + itsTPE->ip[1] = itsTBBE->ip[1]; + itsTPE->ip[2] = itsTBBE->ip[2]; + itsTPE->ip[3] = itsTBBE->ip[3]; + itsTPE->ip[4] = itsTBBE->ip[4]; + itsTPE->mac[0] = itsTBBE->mac[0]; + itsTPE->mac[1] = itsTBBE->mac[1]; + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void UdpCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void UdpCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPUdpEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + + LOG_DEBUG_STR(formatString("Received UdpAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void UdpCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + } + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void UdpCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 UdpCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 UdpCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool UdpCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool UdpCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/UdpCmd.h b/MAC/APL/PIC/TBBDriver/src/UdpCmd.h new file mode 100644 index 00000000000..bf3d5bf9e97 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/UdpCmd.h @@ -0,0 +1,86 @@ +//# -*- mode: c++ -*- +//# +//# UdpCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef UDPCMD_H_ +#define UDPCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class UdpCmd : public Command + { + public: + // Constructors for a UdpCmd object. + UdpCmd(); + + // Destructor for UdpCmd. + virtual ~UdpCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPUdpEvent *itsTPE; + TPUdpEvent *itsTPackE; + TBBUdpEvent *itsTBBE; + TBBUdpackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* UDPCMD_H_ */ diff --git a/MAC/APL/PIC/TBBDriver/src/VersionCmd.cc b/MAC/APL/PIC/TBBDriver/src/VersionCmd.cc index 7d0687f5914..514401c0c70 100644 --- a/MAC/APL/PIC/TBBDriver/src/VersionCmd.cc +++ b/MAC/APL/PIC/TBBDriver/src/VersionCmd.cc @@ -1,4 +1,4 @@ -//# GetVersions.cc: implementation of the GetVersions class +//# VersionCmd.cc: implementation of the VersionsCmd class //# //# Copyright (C) 2002-2004 //# ASTRON (Netherlands Foundation for Research in Astronomy) @@ -23,9 +23,6 @@ #include <lofar_config.h> #include <Common/LofarLogger.h> -#include <APL/TBB_Protocol/TBB_Protocol.ph> -#include "TP_Protocol.ph" - #include "VersionCmd.h" namespace LOFAR { @@ -33,19 +30,35 @@ namespace LOFAR { using namespace TP_Protocol; namespace TBB { - -// Constructors for a GetVersions object. +//--Constructors for a VersionCmd object.-------------------------------------- VersionCmd::VersionCmd(): - itsSendMask(0),itsRecvMask(0),itsErrorMask(0) + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) { - + itsTPE = new TPVersionEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBVersionackEvent(); + + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsBoardStatus[boardnr] = 0; + itsBoardId[boardnr] = 0; + itsSwVersion[boardnr] = 0; + itsBoardVersion[boardnr] = 0; + itsTpVersion[boardnr] = 0; + itsMp0Version[boardnr] = 0; + itsMp1Version[boardnr] = 0; + itsMp2Version[boardnr] = 0; + itsMp3Version[boardnr] = 0; + } } - -// Destructor for GetVersions. + +//--Destructor for GetVersions.------------------------------------------------ VersionCmd::~VersionCmd() { - + delete itsTPE; + delete itsTBBackE; } + // ---------------------------------------------------------------------------- bool VersionCmd::isValid(GCFEvent& event) { @@ -56,86 +69,116 @@ bool VersionCmd::isValid(GCFEvent& event) } // ---------------------------------------------------------------------------- -void VersionCmd::saveTbbEvent(GCFEvent& event) +void VersionCmd::saveTbbEvent(GCFEvent& event, int32 boards) { - TBBVersionEvent tbbe(event); + itsTBBE = new TBBVersionEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } - itsSendMask = tbbe.tbbmask; // for some commands board-id is used ??? - itsRecvMask = 0; - itsErrorMask = 0; -} - -// ---------------------------------------------------------------------------- -void VersionCmd::makeTpEvent() -{ - itsVersionEvent.opcode = 0x00000701; - itsVersionEvent.boardid = 0; - itsVersionEvent.swversion = 0; - itsVersionEvent.boardversion = 0; - itsVersionEvent.tpversion = 0; - itsVersionEvent.mp1version = 0; - itsVersionEvent.mp2version = 0; - itsVersionEvent.mp3version = 0; - itsVersionEvent.mp4version = 0; + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // fill TP command, to send + itsTPE->opcode = TPVERSION; + itsTPE->status = 0; + itsTPE->boardid = 0; + itsTPE->swversion = 0; + itsTPE->boardversion = 0; + itsTPE->tpversion = 0; + itsTPE->mp0version = 0; + itsTPE->mp1version = 0; + itsTPE->mp2version = 0; + itsTPE->mp3version = 0; + + delete itsTBBE; } // ---------------------------------------------------------------------------- void VersionCmd::sendTpEvent(GCFPortInterface& port) { - port.send(itsVersionEvent); - port.setTimer(TIME_OUT); + port.send(*itsTPE); } // ---------------------------------------------------------------------------- -void VersionCmd::saveTpAckEvent(GCFEvent& event, int boardnr) +void VersionCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) { itsRecvMask |= (1 << boardnr); - // in case of a time-out, save alle zero's + // in case of a time-out, set error mask if(event.signal == F_TIMER) { itsErrorMask |= (1 << boardnr); - itsBoardId[boardnr] = 0; - itsSwVersion[boardnr] = 0; - itsBoardVersion[boardnr]= 0; - itsTpVersion[boardnr] = 0; - itsMp1Version[boardnr] = 0; - itsMp2Version[boardnr] = 0; - itsMp3Version[boardnr] = 0; - itsMp4Version[boardnr] = 0; } else { - TPVersionEvent tpe(event); - itsBoardId[boardnr] = tpe.boardid; - itsSwVersion[boardnr] = tpe.swversion; - itsBoardVersion[boardnr]= tpe.boardversion; - itsTpVersion[boardnr] = tpe.tpversion; - itsMp1Version[boardnr] = tpe.mp1version; - itsMp2Version[boardnr] = tpe.mp2version; - itsMp3Version[boardnr] = tpe.mp3version; - itsMp4Version[boardnr] = tpe.mp4version; + //TPVersionEvent tpe(event); + itsTPackE = new TPVersionEvent(event); + + itsBoardStatus[boardnr] = itsTPackE->status; + itsBoardId[boardnr] = itsTPackE->boardid; + itsSwVersion[boardnr] = itsTPackE->swversion; + itsBoardVersion[boardnr]= itsTPackE->boardversion; + itsTpVersion[boardnr] = itsTPackE->tpversion; + itsMp0Version[boardnr] = itsTPackE->mp0version; + itsMp1Version[boardnr] = itsTPackE->mp1version; + itsMp2Version[boardnr] = itsTPackE->mp2version; + itsMp3Version[boardnr] = itsTPackE->mp3version; + + LOG_DEBUG_STR(formatString("Received VersionAck from boardnr[%d]", boardnr)); + /* + LOG_DEBUG_STR(formatString("opcode = 0X%08X", itsTPackE->opcode)); + LOG_DEBUG_STR(formatString("status = 0X%08X", itsTPackE->status)); + LOG_DEBUG_STR(formatString("boardid = 0X%08X", itsTPackE->boardid)); + LOG_DEBUG_STR(formatString("swversion = 0X%08X", itsTPackE->swversion)); + LOG_DEBUG_STR(formatString("boardversion = 0X%08X", itsTPackE->boardversion)); + LOG_DEBUG_STR(formatString("tpversion = 0X%08X", itsTPackE->tpversion)); + LOG_DEBUG_STR(formatString("mp0version = 0X%08X", itsTPackE->mp0version)); + LOG_DEBUG_STR(formatString("mp1version = 0X%08X", itsTPackE->mp1version)); + LOG_DEBUG_STR(formatString("mp2version = 0X%08X", itsTPackE->mp2version)); + LOG_DEBUG_STR(formatString("mp3version = 0X%08X", itsTPackE->mp3version)); + */ + delete itsTPackE; } } // ---------------------------------------------------------------------------- void VersionCmd::sendTbbAckEvent(GCFPortInterface* clientport) { - TBBVersionackEvent tbbe; - - tbbe.status = 0; + itsTBBackE->commstatus = SUCCESS; if(itsErrorMask) { - tbbe.status = 1; - tbbe.status |= (itsErrorMask << 16); + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); } - for(int boardnr = 0;boardnr < 12;boardnr++) { - tbbe.boardinfo[boardnr].boardid = itsBoardId[boardnr]; - tbbe.boardinfo[boardnr].swversion = itsSwVersion[boardnr]; - tbbe.boardinfo[boardnr].boardversion = itsBoardVersion[boardnr]; - tbbe.boardinfo[boardnr].tpversion = itsTpVersion[boardnr]; - tbbe.boardinfo[boardnr].mp1version = itsMp1Version[boardnr]; - tbbe.boardinfo[boardnr].mp2version = itsMp2Version[boardnr]; - tbbe.boardinfo[boardnr].mp3version = itsMp3Version[boardnr]; - tbbe.boardinfo[boardnr].mp4version = itsMp4Version[boardnr]; + // fill all the fields of the TBBackEvent + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsTBBackE->boardstatus[boardnr] = itsBoardStatus[boardnr]; + itsTBBackE->boardid[boardnr] = itsBoardId[boardnr]; + itsTBBackE->swversion[boardnr] = itsSwVersion[boardnr]; + itsTBBackE->boardversion[boardnr] = itsBoardVersion[boardnr]; + itsTBBackE->tpversion[boardnr] = itsTpVersion[boardnr]; + itsTBBackE->mp0version[boardnr] = itsMp0Version[boardnr]; + itsTBBackE->mp1version[boardnr] = itsMp1Version[boardnr]; + itsTBBackE->mp2version[boardnr] = itsMp2Version[boardnr]; + itsTBBackE->mp3version[boardnr] = itsMp3Version[boardnr]; } - clientport->send(tbbe); + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void VersionCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); } // ---------------------------------------------------------------------------- @@ -151,10 +194,17 @@ uint32 VersionCmd::getRecvMask() } // ---------------------------------------------------------------------------- -uint32 VersionCmd::done() +bool VersionCmd::done() +{ + if (itsRecvMask == itsSendMask) return true; + return false; +} + +// ---------------------------------------------------------------------------- +bool VersionCmd::waitAck() { - return (itsRecvMask == itsSendMask); + return true; } - } // end TBB namespace -} // end LOFAR namespace + } // end namespace TBB +} // end namespace LOFAR diff --git a/MAC/APL/PIC/TBBDriver/src/VersionCmd.h b/MAC/APL/PIC/TBBDriver/src/VersionCmd.h index c2dfe76219c..2ef68e8bba0 100644 --- a/MAC/APL/PIC/TBBDriver/src/VersionCmd.h +++ b/MAC/APL/PIC/TBBDriver/src/VersionCmd.h @@ -1,6 +1,6 @@ //# -*- mode: c++ -*- //# -//# VersionCmd.h: Get Tbb board versions +//# VersionCmd.h: Get TBB board versions //# //# Copyright (C) 2002-2004 //# ASTRON (Netherlands Foundation for Research in Astronomy) @@ -28,9 +28,13 @@ #include <Common/LofarTypes.h> #include <GCF/TM/GCF_Control.h> +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + #include "Command.h" namespace LOFAR { + using namespace TBB_Protocol; namespace TBB { class VersionCmd : public Command @@ -44,37 +48,44 @@ namespace LOFAR { virtual bool isValid(GCFEvent& event); - virtual void saveTbbEvent(GCFEvent& event); - - virtual void makeTpEvent(); - + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + virtual void sendTpEvent(GCFPortInterface& port); - virtual void saveTpAckEvent(GCFEvent& event, int boardnr); + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); virtual void sendTbbAckEvent(GCFPortInterface* clientport); + virtual void portError(int32 boardnr); + virtual uint32 getSendMask(); virtual uint32 getRecvMask(); - virtual uint32 done(); + virtual bool done(); + + virtual bool waitAck(); private: uint32 itsSendMask; // mask indicates the boards to communicate with uint32 itsRecvMask; // mask indicates the boards handled uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask - TPVersionEvent itsVersionEvent; + TPVersionEvent *itsTPE; + TPVersionEvent *itsTPackE; + TBBVersionEvent *itsTBBE; + TBBVersionackEvent *itsTBBackE; + uint32 itsBoardStatus[MAX_N_TBBBOARDS]; uint32 itsBoardId[MAX_N_TBBBOARDS]; uint32 itsSwVersion[MAX_N_TBBBOARDS]; uint32 itsBoardVersion[MAX_N_TBBBOARDS]; uint32 itsTpVersion[MAX_N_TBBBOARDS]; + uint32 itsMp0Version[MAX_N_TBBBOARDS]; uint32 itsMp1Version[MAX_N_TBBBOARDS]; uint32 itsMp2Version[MAX_N_TBBBOARDS]; uint32 itsMp3Version[MAX_N_TBBBOARDS]; - uint32 itsMp4Version[MAX_N_TBBBOARDS]; }; } // end TBB namespace } // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/WritefCmd.cc b/MAC/APL/PIC/TBBDriver/src/WritefCmd.cc new file mode 100644 index 00000000000..d3be10e5804 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/WritefCmd.cc @@ -0,0 +1,173 @@ +//# WritefCmd.cc: implementation of the WritefCmd class +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#include <lofar_config.h> +#include <Common/LofarLogger.h> + +#include "WritefCmd.h" + +namespace LOFAR { + using namespace TBB_Protocol; + using namespace TP_Protocol; + namespace TBB { + +//--Constructors for a WritefCmd object.---------------------------------------- +WritefCmd::WritefCmd(): + itsSendMask(0),itsRecvMask(0),itsErrorMask(0),itsBoardsMask(0) +{ + itsTPE = new TPWritefEvent(); + itsTPackE = 0; + itsTBBE = 0; + itsTBBackE = new TBBWritefackEvent(); + + itsBoardStatus = 0; + itsAddr = 0; + + for(int an = 0; an < 256;an++) { + itsData[an] = 0; + } +} + +//--Destructor for WritefCmd.--------------------------------------------------- +WritefCmd::~WritefCmd() +{ + delete itsTPE; + delete itsTBBackE; +} + +// ---------------------------------------------------------------------------- +bool WritefCmd::isValid(GCFEvent& event) +{ + if((event.signal == TBB_WRITEF)||(event.signal == TP_WRITEF)) { + return true; + } + return false; +} + +// ---------------------------------------------------------------------------- +void WritefCmd::saveTbbEvent(GCFEvent& event, int32 boards) +{ + itsTBBE = new TBBWritefEvent(event); + + itsSendMask = itsTBBE->tbbmask; // for some commands board-id is used ??? + // if SendMask = 0, select all boards + if(itsSendMask == 0) { + for(int boardnr = 0;boardnr < MAX_N_TBBBOARDS;boardnr++) { + itsSendMask |= (1 << boardnr); + } + } + + // mask for the installed boards + if(boards > MAX_N_TBBBOARDS) boards = MAX_N_TBBBOARDS; + for(int boardnr = 0;boardnr < boards;boardnr++) { + itsBoardsMask |= (1 << boardnr); + } + + // Send only commands to boards installed + itsErrorMask = itsSendMask & ~itsBoardsMask; + itsSendMask = itsSendMask & itsBoardsMask; + + // initialize TP send frame + itsTPE->opcode = TPWRITEF; + itsTPE->status = 0; + itsTPE->addr = itsTBBE->addr; + + for(int an = 0; an < 256;an++) { + itsTPE->data[an] = itsTBBE->data[an]; + } + + delete itsTBBE; +} + +// ---------------------------------------------------------------------------- +void WritefCmd::sendTpEvent(GCFPortInterface& port) +{ + port.send(*itsTPE); +} + +// ---------------------------------------------------------------------------- +void WritefCmd::saveTpAckEvent(GCFEvent& event, int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + // in case of a time-out, set error mask + if(event.signal == F_TIMER) { + itsErrorMask |= (1 << boardnr); + } + else { + itsTPackE = new TPWritefEvent(event); + + itsBoardStatus = itsTPackE->status; + itsAddr = itsTPackE->addr; + + LOG_DEBUG_STR(formatString("Received WritefAck from boardnr[%d]", boardnr)); + delete itsTPackE; + } +} + +// ---------------------------------------------------------------------------- +void WritefCmd::sendTbbAckEvent(GCFPortInterface* clientport) +{ + itsTBBackE->commstatus = SUCCESS; + if(itsErrorMask) { + itsTBBackE->commstatus = FAILURE; + itsTBBackE->commstatus |= (itsErrorMask << 16); + } + + itsTBBackE->boardstatus = itsBoardStatus; + itsTBBackE->addr = itsAddr; + + clientport->send(*itsTBBackE); +} + +// ---------------------------------------------------------------------------- +void WritefCmd::portError(int32 boardnr) +{ + itsRecvMask |= (1 << boardnr); + itsErrorMask |= (1 << boardnr); +} + +// ---------------------------------------------------------------------------- +uint32 WritefCmd::getSendMask() +{ + return itsSendMask; +} + +// ---------------------------------------------------------------------------- +uint32 WritefCmd::getRecvMask() +{ + return itsRecvMask; +} + +// ---------------------------------------------------------------------------- +bool WritefCmd::done() +{ + return (itsRecvMask == itsSendMask); +} + +// ---------------------------------------------------------------------------- +bool WritefCmd::waitAck() +{ + return true; +} + + } // end TBB namespace +} // end LOFAR namespace diff --git a/MAC/APL/PIC/TBBDriver/src/WritefCmd.h b/MAC/APL/PIC/TBBDriver/src/WritefCmd.h new file mode 100644 index 00000000000..06430abce37 --- /dev/null +++ b/MAC/APL/PIC/TBBDriver/src/WritefCmd.h @@ -0,0 +1,88 @@ +//# -*- mode: c++ -*- +//# +//# WritefCmd.h: III +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef WRITEFCMD_H_ +#define WRITEFCMD_H_ + +#include <Common/LofarTypes.h> +#include <GCF/TM/GCF_Control.h> + +#include <APL/TBB_Protocol/TBB_Protocol.ph> +#include "TP_Protocol.ph" + +#include "Command.h" + +namespace LOFAR { + using namespace TBB_Protocol; + namespace TBB { + + class WritefCmd : public Command + { + public: + // Constructors for a WritefCmd object. + WritefCmd(); + + // Destructor for WritefCmd. + virtual ~WritefCmd(); + + virtual bool isValid(GCFEvent& event); + + virtual void saveTbbEvent(GCFEvent& event, int32 boards); + + virtual void sendTpEvent(GCFPortInterface& port); + + virtual void saveTpAckEvent(GCFEvent& event, int32 boardnr); + + virtual void sendTbbAckEvent(GCFPortInterface* clientport); + + virtual void portError(int32 boardnr); + + virtual uint32 getSendMask(); + + virtual uint32 getRecvMask(); + + virtual bool done(); + + virtual bool waitAck(); + + private: + uint32 itsSendMask; // mask indicates the boards to communicate with + uint32 itsRecvMask; // mask indicates the boards handled + uint32 itsErrorMask; // mask indicates the not responding boards + uint32 itsBoardsMask; // Installed boards mask + + TPWritefEvent *itsTPE; + TPWritefEvent *itsTPackE; + TBBWritefEvent *itsTBBE; + TBBWritefackEvent *itsTBBackE; + + // variables holding data from tp cmd + uint32 itsBoardStatus; + uint32 itsAddr; + uint32 itsData[256]; + }; + } // end TBB namespace +} // end LOFAR namespace + +#endif /* WRITEFCMD_H_ */ -- GitLab