#!/bin/bash if [ -d "$2$1" ]; then echo "$2$1 already exists... quitting." exit 1 fi if [ -z "$1" ] ; then echo "GenMOOSApp_AppCasting: usage: $0 [app-name] [prefix]" exit 0 fi if [ -z "$2" ] ; then echo "GenMOOSApp_AppCasting: usage: $0 [app-name] [prefix]" exit 0 fi #if [ -z "$3" ] ; then # $3="YOUR-NAME-HERE" #fi mkdir $2$1 cd $2$1 cat > CMakeLists.txt < ${1}.h < main.cpp < #include "MBUtils.h" #include "ColorParse.h" #include "${1}.h" #include "${1}_Info.h" using namespace std; int main(int argc, char *argv[]) { string mission_file; string run_command = argv[0]; for(int i=1; i $2${1}.moos < ${1}.cpp < #include "MBUtils.h" #include "ACTable.h" #include "${1}.h" using namespace std; //--------------------------------------------------------- // Constructor ${1}::${1}() { } //--------------------------------------------------------- // Destructor ${1}::~${1}() { } //--------------------------------------------------------- // Procedure: OnNewMail bool ${1}::OnNewMail(MOOSMSG_LIST &NewMail) { AppCastingMOOSApp::OnNewMail(NewMail); MOOSMSG_LIST::iterator p; for(p=NewMail.begin(); p!=NewMail.end(); p++) { CMOOSMsg &msg = *p; string key = msg.GetKey(); #if 0 // Keep these around just for template string comm = msg.GetCommunity(); double dval = msg.GetDouble(); string sval = msg.GetString(); string msrc = msg.GetSource(); double mtime = msg.GetTime(); bool mdbl = msg.IsDouble(); bool mstr = msg.IsString(); #endif if(key == "FOO") cout << "great!"; else if(key != "APPCAST_REQ") // handled by AppCastingMOOSApp reportRunWarning("Unhandled Mail: " + key); } return(true); } //--------------------------------------------------------- // Procedure: OnConnectToServer bool ${1}::OnConnectToServer() { registerVariables(); return(true); } //--------------------------------------------------------- // Procedure: Iterate() // happens AppTick times per second bool ${1}::Iterate() { AppCastingMOOSApp::Iterate(); // Do your thing here! AppCastingMOOSApp::PostReport(); return(true); } //--------------------------------------------------------- // Procedure: OnStartUp() // happens before connection is open bool ${1}::OnStartUp() { AppCastingMOOSApp::OnStartUp(); STRING_LIST sParams; m_MissionReader.EnableVerbatimQuoting(false); if(!m_MissionReader.GetConfiguration(GetAppName(), sParams)) reportConfigWarning("No config block found for " + GetAppName()); STRING_LIST::iterator p; for(p=sParams.begin(); p!=sParams.end(); p++) { string orig = *p; string line = *p; string param = toupper(biteStringX(line, '=')); string value = line; bool handled = false; if(param == "FOO") { handled = true; } else if(param == "BAR") { handled = true; } if(!handled) reportUnhandledConfigWarning(orig); } registerVariables(); return(true); } //--------------------------------------------------------- // Procedure: registerVariables void ${1}::registerVariables() { AppCastingMOOSApp::RegisterVariables(); // Register("FOOBAR", 0); } //------------------------------------------------------------ // Procedure: buildReport() bool ${1}::buildReport() { m_msgs << "============================================ \n"; m_msgs << "File: \n"; m_msgs << "============================================ \n"; ACTable actab(4); actab << "Alpha | Bravo | Charlie | Delta"; actab.addHeaderLines(); actab << "one" << "two" << "three" << "four"; m_msgs << actab.getFormattedString(); return(true); } EOF cat >> ${1}_Info.h <> ${1}_Info.cpp < #include #include "${1}_Info.h" #include "ColorParse.h" #include "ReleaseInfo.h" using namespace std; //---------------------------------------------------------------- // Procedure: showSynopsis void showSynopsis() { blk("SYNOPSIS: "); blk("------------------------------------ "); blk(" The ${2}${1} application is used for "); blk(" "); blk(" "); blk(" "); blk(" "); } //---------------------------------------------------------------- // Procedure: showHelpAndExit void showHelpAndExit() { blk(" "); blu("=============================================================== "); blu("Usage: ${2}${1} file.moos [OPTIONS] "); blu("=============================================================== "); blk(" "); showSynopsis(); blk(" "); blk("Options: "); mag(" --alias","= "); blk(" Launch ${2}${1} with the given process name "); blk(" rather than ${2}${1}. "); mag(" --example, -e "); blk(" Display example MOOS configuration block. "); mag(" --help, -h "); blk(" Display this help message. "); mag(" --interface, -i "); blk(" Display MOOS publications and subscriptions. "); mag(" --version,-v "); blk(" Display the release version of ${2}${1}. "); blk(" "); blk("Note: If argv[2] does not otherwise match a known option, "); blk(" then it will be interpreted as a run alias. This is "); blk(" to support pAntler launching conventions. "); blk(" "); exit(0); } //---------------------------------------------------------------- // Procedure: showExampleConfigAndExit void showExampleConfigAndExit() { blk(" "); blu("=============================================================== "); blu("${2}${1} Example MOOS Configuration "); blu("=============================================================== "); blk(" "); blk("ProcessConfig = ${2}${1} "); blk("{ "); blk(" AppTick = 4 "); blk(" CommsTick = 4 "); blk(" "); blk("} "); blk(" "); exit(0); } //---------------------------------------------------------------- // Procedure: showInterfaceAndExit void showInterfaceAndExit() { blk(" "); blu("=============================================================== "); blu("${2}${1} INTERFACE "); blu("=============================================================== "); blk(" "); showSynopsis(); blk(" "); blk("SUBSCRIPTIONS: "); blk("------------------------------------ "); blk(" NODE_MESSAGE = src_node=alpha,dest_node=bravo,var_name=FOO, "); blk(" string_val=BAR "); blk(" "); blk("PUBLICATIONS: "); blk("------------------------------------ "); blk(" Publications are determined by the node message content. "); blk(" "); exit(0); } //---------------------------------------------------------------- // Procedure: showReleaseInfoAndExit void showReleaseInfoAndExit() { showReleaseInfo("${2}${1}", "gpl"); exit(0); } EOF echo "$2${1} generated"