/*******************************************************************************
* Control.h Control process
* T.Barnaby, BEAM Ltd, 2007-02-07
*******************************************************************************
*/
#ifndef Control_H
#define Control_H 1
#include <stdint.h>
#include <BError.h>
#include <BThread.h>
#include <TmsPuApi.h>
#include <TmsC.h>
#include <TmsEventServerList.h>
#include <Pupe.h>
#include <BMutex.h>
#include <BRWLock.h>
#include <main.h>
class Control;
class CycleParams {
public:
CycleParams(BString cycleType, CycleParam& params);
BString cycleType; // The Cycle type name
BList<CycleParam> params; // Parameters for channels
};
/// A resource test class. this implements a simple timer operated function called every second, that can be used to check on system resources.
class ControlTimer : public BThread {
public:
ControlTimer(Control& control);
void* function();
private:
Control& ocontrol;
};
/// The main system control class
class Control {
public:
Control(int dbFixed);
~Control();
BError init(int number); ///< Initialise the system
// Main functionality
BError initCmd();
BError configure(ConfigInfo configInfo); ///< Configure the system for use. This includes mapping the individual physical PickUp channels to logical pickup channels.
BError test(BList<BError>& errors);
BError getStatus(BList<NameValue>& statusList);
BError getStatistics(BList<NameValue>& statsList);
BError addEventServer(BString name);
BError delEventServer(BString name);
BError setControlInfo(CycleParam params);
BError setNextCycle(UInt32 cycleNumber, BString cycleType);
BError getStatus(PuChannel puChannel, PuStatus& puStatus);
BError getData(PuChannel puChannel, DataInfo dataInfo, Data& data);
BError requestData(PuChannel puChannel, DataInfo dataInfo);
BError setTestMode(PuChannel puChannel, UInt32 testOutput, UInt32 timingDisableMask);
BError setTimingSignals(PuChannel puChannel, UInt32 timingSignals);
BError captureTestData(PuChannel puChannel, TestCaptureInfo captureInfo, BArray<UInt64>& data);
BError setTestData(PuChannel puChannel, Int32 on, BArray<UInt32> data); ///< This function will set a PU channel to sample data from memory rather than the ADC's
BError setPupeConfig(PuChannel puPhysChannel, PupeConfig pupeConfig);
void run(); ///< Start the system running
// System utilities
void timer();
void cycleStart(UInt32 cycleNumber); ///< The CYCLE_START event has occured
void cycleStop(UInt32 cycleNumber); ///< The CYCLE_STOP event has occured
void cycleError(UInt32 cycleNumber, BError error); ///< A Cycle error occurred
BError getPuChannel(PuChannel puPhysChannel, UInt32& puChannel);
BError getPuPhysChannel(UInt32 puChannel, PuChannel& puPhysChannel);
int moduleNum(); ///< Returns the module controller number
public:
// General data
int osimulate; ///< Simulation mode
int osimulateTiming; ///< Simulate timing inputs
private:
// Low level bits
BError initPupeEngines();
BError setPupeControlInfo(BString cycleType);
// Control data
int odebugFixed; ///< Fixed debug level from command line
int onum; ///< The Module controller number
int oinitialised; ///< The system has been initialised
BMutex olock; ///< Lock for data access
ControlTimer otimer;
BString oserverName; ///< The BOAP Servers host name
BoapServer oboapServer; ///< The overal Boap server class
PuControlServer opuControlServer; ///< The PuControl API interface
PuProcessServer opuProcessServer; ///< The PuProcess API interface
ConfigInfo oconfigInfo; ///< The configuration of PickUp channels
BMutex oconfigInfoLock;
BList<Pupe*> opupeEngines; ///< The list of PUPE engines
BRWLock opupeEnginesLock;
TmsEventServerList oeventServers; ///< The list of event servers
BList<CycleParams> ocycleParms; ///< The table of cycle parameters
UInt32 ocycleNumber; ///< The current cycle number
BString ocycleType; ///< The current cycle type
UInt32 ocycleNumberNext; ///< The next cycle number
BString ocycleTypeNext; ///< The next cycle type
UInt32 oprocessingCycle; ///< We are processing a cycle
// Statistics
double ostartTime; ///< The start time
UInt64 ocycleProcessed; ///< The number of cycles processed
};
#endif