MOOS

CMOOSApp Class Reference

#include <MOOSApp.h>

Inheritance diagram for CMOOSApp:

CMOOSInstrument List of all members.

Public Member Functions

bool Run (char *sName, char *sMissionFile)
virtual bool OnConnectToServer ()
virtual bool OnDisconnectFromServer ()
void OnDisconnectToServerPrivate ()
void OnConnectToServerPrivate ()

Protected Member Functions

virtual bool Iterate ()
virtual bool OnNewMail (MOOSMSG_LIST &NewMail)
virtual bool OnCommandMsg (CMOOSMsg Msg)
virtual std::string MakeStatusString ()
void SetCommsFreq (unsigned int nFreq)
void SetAppFreq (double dfFreq)
double GetAppStartTime ()
void SetServer (const char *sServerHost="LOCALHOST", long lPort=9000)
bool UseMOOSComms (bool bUse)
bool MOOSDebugWrite (const std::string &sTxt)
void EnableCommandMessageFiltering (bool bEnable)
bool LookForAndHandleAppCommand (MOOSMSG_LIST &NewMail)
std::string GetAppName ()
std::string GetMissionFileName ()
bool AddMOOSVariable (std::string sName, std::string sSubscribeName, std::string sPublishName, double dfCommsTime)
CMOOSVariable * GetMOOSVar (std::string sName)
bool RegisterMOOSVariables ()
bool UpdateMOOSVariables (MOOSMSG_LIST &NewMail)
bool SetMOOSVar (const std::string &sName, const std::string &sVal, double dfTime)
bool SetMOOSVar (const std::string &sVarName, double dfVal, double dfTime)
bool PublishFreshMOOSVariables ()
bool IsSimulateMode ()
virtual bool OnStartUp ()
bool ConfigureComms ()
double GetTimeSinceIterate ()
double GetLastIterateTime ()
int GetIterateCount ()
std::string GetCommandKey ()
bool IsDebug ()

Protected Attributes

CMOOSCommClient m_Comms
CProcessConfigReader m_MissionReader
MOOSVARMAP m_MOOSVars
bool m_bSimMode
long m_lServerPort
std::string m_sServerHost
std::string m_sServerPort
bool m_bServerSet
bool m_bUseMOOSComms
std::string m_sAppName
int m_nCommsFreq
double m_dfFreq
std::string m_sMissionFile
bool m_bCommandMessageFiltering
double m_dfAppStartTime
double m_dfLastRunTime
bool m_bDebug

Detailed Description

This is a class from which all MOOS component applications can be derived main() will typically end with a call to MOOSAppDerivedClass::Run(). It provides automatic connection to the MOOSDB, provides slots for Mail Processing and application work, callbacks for connection/disconnection to MOOSDB, Configuration file reading and dynamic (runtime) variables. Definately worth getting to know.


Member Function Documentation

bool CMOOSApp::AddMOOSVariable std::string  sName,
std::string  sSubscribeName,
std::string  sPublishName,
double  dfCommsTime
[protected]
 

Add a dynamic (run time) variable

Parameters:
sName name of the variable
sSubscribeName if you call RegisterMOOSVariables() the variable will be updated with mail called <sSubscribeName> if and when you call UpdateMOOSVariables()
sPublishName if you call PublishFreshMOOSVariables() (and you've written to the dynamic varible since the last call) the variable will be published under this name.
CommsTime - if sSubscribeName is not empty this is the minimum time between updates which you are interested in knowing about, so if CommsTime=0.1 then the maximum update rate you will see on the variable from the DB is 10HZ.

bool CMOOSApp::ConfigureComms  )  [protected]
 

start up the comms

void CMOOSApp::EnableCommandMessageFiltering bool  bEnable  )  [protected]
 

enable/disable the behind the scenes search for command messages

string CMOOSApp::GetAppName  )  [protected]
 

return the application name

double CMOOSApp::GetAppStartTime  )  [protected]
 

return the boot time of the App

std::string CMOOSApp::GetCommandKey  )  [protected]
 

returns the string which constitutes a command string for this application. if CommandFiltering is enabled (see EnableCommandMessageFiltering() ) the application will filter incoming mail and Call OnCommandMsg() (which can be overiden) if a message with this command string as a name is received. Command strings look like APPNAME_CMD

int CMOOSApp::GetIterateCount  )  [protected]
 

return number of times iterate has been called

double CMOOSApp::GetLastIterateTime  )  [protected]
 

Return time at which the Run loop last ran (called Iterate)

std::string CMOOSApp::GetMissionFileName  )  [protected]
 

return the application mission file name

CMOOSVariable* CMOOSApp::GetMOOSVar std::string  sName  )  [protected]
 

return a pointer to a named variable

double CMOOSApp::GetTimeSinceIterate  )  [protected]
 

Time since last iterate was called

bool CMOOSApp::IsSimulateMode  )  [protected]
 

Returns true if Simulate = true is found in the mission/configuration file (a global flag) - the mission file is not re-read on each call

bool CMOOSApp::Iterate  )  [protected, virtual]
 

called when the application should iterate. Overload this function in a derived class and within it write all the application specific code. It will be called at approximately nFreq = 1/AppTick Hz

bool CMOOSApp::LookForAndHandleAppCommand MOOSMSG_LIST &  NewMail  )  [protected]
 

dispatching function for OnCommandMsg

std::string CMOOSApp::MakeStatusString  )  [protected, virtual]
 

make a status string - overload this in a derived class if you want to modify or what the statuts string looks like

bool CMOOSApp::MOOSDebugWrite const std::string &  sTxt  )  [protected]
 

Call this to write a debug string to the DB under the name "MOOS_DEBUG"

bool CMOOSApp::OnCommandMsg CMOOSMsg  Msg  )  [protected, virtual]
 

optionally (see EnableCommandMessageFiltering() ) called when a command message (<MOOSNAME>_CMD) is recieved by the application.

Parameters:
a copy of CmdMsg the message purporting to be a "command" - i.e. has the name <MOOSNAME>_CMD

bool CMOOSApp::OnConnectToServer  )  [virtual]
 

Called when the class has succesully connected to the server. Overload this function and place use it to register for notification when variables of interest change

bool CMOOSApp::OnDisconnectFromServer  )  [virtual]
 

Called when the class has disconnects from the server. Put code you want to run when this happens in a virtual version of this method

void CMOOSApp::OnDisconnectToServerPrivate  ) 
 

these two functions are used to handle private MOOSApp work that need to occur on behalf of derived classes at the same time as the overloaded OnConnectToServer and OnDisconnectFromServer methods are called. They are public to allow their invokation from a call back. They are not interesting to the casual user

bool CMOOSApp::OnNewMail MOOSMSG_LIST &  NewMail  )  [protected, virtual]
 

called when new mail has arrived. Overload this method in a derived class to process new mail. It will be called at approximately 1/CommsTick Hz. In this function you'll most likely interate over the collection of mail message received or call a m_Comms::PeekMail() to look for a specific named message.

Parameters:
NewMail a list of new mail messages

bool CMOOSApp::OnStartUp  )  [protected, virtual]
 

called just before the main app loop is entered. Specific initialisation code can be written in an overloaded version of this function

Reimplemented in CMOOSInstrument.

bool CMOOSApp::PublishFreshMOOSVariables  )  [protected]
 

Send any variables (under their sPublishName see AddMOOSVariable) which been written too since the last call of PublishFreshMOOSVariables()

bool CMOOSApp::RegisterMOOSVariables  )  [protected]
 

Register with the DB to be mailed about any changes to any dynamic variables which were created with non-empty sSubscribeName fields

bool CMOOSApp::Run char *  sName,
char *  sMissionFile
 

called to start the application

Parameters:
sName The name of this application (must be unique amoungst MOOS components
the name of the mission file

void CMOOSApp::SetAppFreq double  dfFreq  )  [protected]
 

Set the time between calls of Iterate (which is where you'll probably do Application work)- can be set using the AppTick flag in the config file

void CMOOSApp::SetCommsFreq unsigned int  nFreq  )  [protected]
 

Set the time between calls into the DB - can be set using the CommsTick flag in the config file

bool CMOOSApp::SetMOOSVar const std::string &  sVarName,
double  dfVal,
double  dfTime
[protected]
 

Set value in a dynamic variable if the variable is of type string (type is set on first write )

bool CMOOSApp::SetMOOSVar const std::string &  sName,
const std::string &  sVal,
double  dfTime
[protected]
 

Set value in a dynamic variable if teh variable is of type double (type is set on first write )

void CMOOSApp::SetServer const char *  sServerHost = "LOCALHOST",
long  lPort = 9000
[protected]
 

Called to set the MOOS server info used rarely usually this info will be picked up by the MOOSApp automatically when it Run is called specifying the configuration file (which contains the DB's coordinates)

Parameters:
sServerHost name of the machine hosting the MOOSDB application
lPort port nuymber that MOOSDB listens on

bool CMOOSApp::UpdateMOOSVariables MOOSMSG_LIST &  NewMail  )  [protected]
 

Pass mail (usually collected in OnNewMail) to the set of dynamic variables. If they are interested (mail name matches their subscribe name) they will update themselves automatically

bool CMOOSApp::UseMOOSComms bool  bUse  )  [protected]
 

By default MOOSDB comms are on - but you may want to use the structuire of MOOSApp as a standalone application - if so call this function with a false parameter


Member Data Documentation

bool CMOOSApp::m_bCommandMessageFiltering [protected]
 

flag specifying whether command message fitlering is enabled

bool CMOOSApp::m_bServerSet [protected]
 

true if the server has been set

bool CMOOSApp::m_bSimMode [protected]
 

flag saying whether MOOS is running with a simulator can be set by registering for SIMULATION_MODE variable

bool CMOOSApp::m_bUseMOOSComms [protected]
 

true if we want to use MOOS comms

CMOOSCommClient CMOOSApp::m_Comms [protected]
 

The MOOSComms node. All communications happens by way of this object. You'll often do things like m_Comms.Notify("VARIABLE_X","STRING_DATA",dfTime) top send data

double CMOOSApp::m_dfAppStartTime [protected]
 

The start time of the application

double CMOOSApp::m_dfFreq [protected]
 

frequency at which this application will iterate

double CMOOSApp::m_dfLastRunTime [protected]
 

Time at which the Run loop last ran (called Iterate)

long CMOOSApp::m_lServerPort [protected]
 

Port on which server application listens for new connection

CProcessConfigReader CMOOSApp::m_MissionReader [protected]
 

a very useful object that lets us retrieve configuration information from the mission file using calls like GetConfigurationParam()

MOOSVARMAP CMOOSApp::m_MOOSVars [protected]
 

a map of dynamic/run time moos variables that may be set by comms - avoid messy long if else if statements

int CMOOSApp::m_nCommsFreq [protected]
 

frequency at which server will be contacted

std::string CMOOSApp::m_sAppName [protected]
 

name of this application

std::string CMOOSApp::m_sMissionFile [protected]
 

std::string name of mission file

std::string CMOOSApp::m_sServerHost [protected]
 

name of machine on which MOOS Server resides

std::string CMOOSApp::m_sServerPort [protected]
 

std::string version of m_lServerPort


The documentation for this class was generated from the following files:
Generated on Fri Sep 28 20:14:20 2007 for MOOSLIB by  doxygen 1.4.6