MOOS 0.2375
|
#include <MOOSApp.h>
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.
CMOOSApp::CMOOSApp | ( | ) |
Definition at line 109 of file MOOSApp.cpp.
CMOOSApp::~CMOOSApp | ( | ) | [virtual] |
Definition at line 133 of file MOOSApp.cpp.
bool CMOOSApp::AddMOOSVariable | ( | std::string | sName, |
std::string | sSubscribeName, | ||
std::string | sPublishName, | ||
double | dfCommsTime | ||
) | [protected] |
Add a dynamic (run time) variable
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. |
Definition at line 550 of file MOOSApp.cpp.
bool CMOOSApp::CanIterateWithoutComms | ( | ) | [protected] |
returns true if we can iterate without comms
Definition at line 687 of file MOOSApp.cpp.
bool CMOOSApp::ConfigureComms | ( | ) | [protected, virtual] |
start up the comms
Definition at line 461 of file MOOSApp.cpp.
bool CMOOSApp::DoRunWork | ( | ) | [protected] |
A function which Run eventually calls which itself calls on NewMail and Iterate
Definition at line 294 of file MOOSApp.cpp.
void CMOOSApp::EnableCommandMessageFiltering | ( | bool | bEnable | ) | [protected] |
enable/disable the behind the scenes search for command messages
Definition at line 764 of file MOOSApp.cpp.
void CMOOSApp::EnableIterateWithoutComms | ( | bool | bEnable | ) | [protected] |
Allow ::Iterate to be called without a connection to a DB
Definition at line 692 of file MOOSApp.cpp.
string CMOOSApp::GetAppName | ( | ) | [protected] |
return the application name
Definition at line 715 of file MOOSApp.cpp.
double CMOOSApp::GetAppStartTime | ( | ) | [protected] |
return the boot time of the App
Definition at line 522 of file MOOSApp.cpp.
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
Definition at line 741 of file MOOSApp.cpp.
int CMOOSApp::GetIterateCount | ( | ) | [protected] |
return number of times iterate has been called
Definition at line 517 of file MOOSApp.cpp.
double CMOOSApp::GetLastIterateTime | ( | ) | [protected] |
Return time at which the Run loop last ran (called Iterate) - this is a local time - you need to add GetMOOSSKew to produce a unified system time
Definition at line 704 of file MOOSApp.cpp.
std::string CMOOSApp::GetMissionFileName | ( | ) | [protected] |
return the application mission file name
Definition at line 710 of file MOOSApp.cpp.
CMOOSVariable * CMOOSApp::GetMOOSVar | ( | std::string | sName | ) | [protected] |
return a pointer to a named variable
Definition at line 727 of file MOOSApp.cpp.
double CMOOSApp::GetTimeSinceIterate | ( | ) | [protected] |
Time since last iterate was called
Definition at line 699 of file MOOSApp.cpp.
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
Definition at line 545 of file MOOSApp.cpp.
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
Reimplemented in CB, CSimpleApp, CSimpleApp, CSimulator, CSimulator, CMessager, CMOOSLogger, CMOOSScheduler, CGPSInstrument, CMOOSActuation, CADVInstrument, CBatteryInstrument, CCompassInstrument, CDepthInstrument, CDVLInstrument, CINSInstrument, CMOOSJanitor, CLBLInstrument, CRelayBoard, CHelmApp, CMOOSNavigator, and CMVSim.
Definition at line 426 of file MOOSApp.cpp.
bool CMOOSApp::LookForAndHandleAppCommand | ( | MOOSMSG_LIST & | NewMail | ) | [protected] |
dispatching function for ::OnCommandMsg
Definition at line 748 of file MOOSApp.cpp.
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
Reimplemented in CMOOSLogger.
Definition at line 780 of file MOOSApp.cpp.
bool CMOOSApp::MOOSDebugWrite | ( | const std::string & | sTxt | ) | [protected] |
Call this to write a debug string to the DB under the name "MOOS_DEBUG"
Definition at line 674 of file MOOSApp.cpp.
optionally (see ::EnableCommandMessageFiltering() ) called when a command message (<MOOSNAME>_CMD) is recieved by the application.
a | copy of CmdMsg the message purporting to be a "command" - i.e. has the name <MOOSNAME>_CMD |
Reimplemented in CMOOSLogger.
Definition at line 454 of file MOOSApp.cpp.
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
Reimplemented in CSimpleApp, CSimpleApp, CSimulator, CSimulator, CMessager, CMOOSLogger, CMOOSScheduler, CGPSInstrument, CMOOSActuation, CADVInstrument, CBatteryInstrument, CCompassInstrument, CDepthInstrument, CDVLInstrument, CINSInstrument, CMOOSJanitor, CLBLInstrument, CRelayBoard, CMOOSRemote, CHelmApp, CMOOSNavigator, and CMVSim.
Definition at line 435 of file MOOSApp.cpp.
void CMOOSApp::OnConnectToServerPrivate | ( | ) |
Definition at line 811 of file MOOSApp.cpp.
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
Definition at line 442 of file MOOSApp.cpp.
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
Definition at line 805 of file MOOSApp.cpp.
bool CMOOSApp::OnMailCallBack | ( | ) |
this is a call back from MOOSComms and its use is specialised (not for general consumption)
Definition at line 449 of file MOOSApp.cpp.
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.
NewMail | a list of new mail messages |
Reimplemented in CSimpleApp, CSimpleApp, CSimulator, CSimulator, CMessager, CMOOSLogger, CMOOSScheduler, CGPSInstrument, CMOOSActuation, CADVInstrument, CBatteryInstrument, CCompassInstrument, CDepthInstrument, CDVLInstrument, CINSInstrument, CMOOSJanitor, CLBLInstrument, CRelayBoard, CHelmApp, CMOOSNavigator, and CMVSim.
Definition at line 421 of file MOOSApp.cpp.
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
over load this if you want to do something fancy at statup...
Reimplemented in CMOOSInstrument, CSimpleApp, CSimpleApp, CSimulator, CSimulator, CMOOSLogger, CMOOSScheduler, CGPSInstrument, CMOOSActuation, CADVInstrument, CBatteryInstrument, CCompassInstrument, CDepthInstrument, CDVLInstrument, CINSInstrument, CMOOSJanitor, CLBLInstrument, CRelayBoard, CMOOSRemote, CHelmApp, CMOOSNavigator, and CMVSim.
Definition at line 512 of file MOOSApp.cpp.
bool CMOOSApp::PublishFreshMOOSVariables | ( | ) | [protected] |
Send any variables (under their sPublishName see AddMOOSVariable) which been written too since the last call of PublishFreshMOOSVariables()
Definition at line 565 of file MOOSApp.cpp.
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
Definition at line 650 of file MOOSApp.cpp.
bool CMOOSApp::RequestQuit | ( | ) |
requests the MOOSApp to quit (i.e return from Run)
Definition at line 288 of file MOOSApp.cpp.
bool CMOOSApp::Run | ( | const char * | sName, |
const char * | sMissionFile | ||
) |
let derivatives do stuff before execution
Reimplemented in CMOOSRemote.
Definition at line 147 of file MOOSApp.cpp.
bool CMOOSApp::Run | ( | const char * | sName, |
const char * | sMissionFile, | ||
const char * | sSubscribeName | ||
) |
called to start the application
sName | The name of this application (used to read configuration from a mission file and if sSubscribeName is NULL, to register with the MOOSDB) |
the | name of the mission file |
the | subscribe name of the application. If NULL then sName |
Definition at line 139 of file MOOSApp.cpp.
void CMOOSApp::SetAppError | ( | bool | bFlag, |
const std::string & | sReason | ||
) | [protected] |
sets the error state of the app and a comment - this is published as a field in <PROCNAME>_STATUS
Definition at line 402 of file MOOSApp.cpp.
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
Definition at line 527 of file MOOSApp.cpp.
bool 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
Definition at line 535 of file MOOSApp.cpp.
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 CMOOSVariable & | MOOSVar | ) | [protected] |
Sets the value of a previously added dynamic variable to the given CMOOSVariable.
true
if the variable's type and value were set, false
otherwise. Definition at line 616 of file MOOSApp.cpp.
bool CMOOSApp::SetMOOSVar | ( | const std::string & | sName, |
const std::string & | sVal, | ||
double | dfTime | ||
) | [protected] |
Set value in a dynamic variable if the variable is of type double (type is set on first write )
void CMOOSApp::SetQuitOnFailedIterate | ( | bool | bQuit | ) | [inline, protected] |
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)
sServerHost | name of the machine hosting the MOOSDB application |
lPort | port nuymber that MOOSDB listens on |
Definition at line 377 of file MOOSApp.cpp.
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
Definition at line 628 of file MOOSApp.cpp.
bool CMOOSApp::UseMailCallBack | ( | ) |
Definition at line 410 of file MOOSApp.cpp.
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
Definition at line 720 of file MOOSApp.cpp.
bool CMOOSApp::m_bAppError [protected] |
flag specifying the error state of the App - set via SetAppError()
bool CMOOSApp::m_bCommandMessageFiltering [protected] |
bool CMOOSApp::m_bDebug [protected] |
bool CMOOSApp::m_bQuitOnIterateFail [protected] |
bool CMOOSApp::m_bServerSet [protected] |
bool CMOOSApp::m_bSimMode [protected] |
bool CMOOSApp::m_bSortMailByTime [protected] |
bool CMOOSApp::m_bUseMOOSComms [protected] |
CMOOSCommClient CMOOSApp::m_Comms [protected] |
double CMOOSApp::m_dfAppStartTime [protected] |
double CMOOSApp::m_dfFreq [protected] |
double CMOOSApp::m_dfLastRunTime [protected] |
long CMOOSApp::m_lServerPort [protected] |
CProcessConfigReader CMOOSApp::m_MissionReader [protected] |
MOOSVARMAP CMOOSApp::m_MOOSVars [protected] |
int CMOOSApp::m_nCommsFreq [protected] |
std::string CMOOSApp::m_sAppError [protected] |
std::string CMOOSApp::m_sAppName [protected] |
std::string CMOOSApp::m_sMissionFile [protected] |
std::string CMOOSApp::m_sMOOSName [protected] |
std::string CMOOSApp::m_sServerHost [protected] |
std::string CMOOSApp::m_sServerPort [protected] |