#!/bin/bash if [ -d "$2$1" ]; then echo "$2$1 already exists... quitting." exit 1 fi if [ -z "$1" ] ; then echo "GenMOOSApp_AppCasting_Multi: usage: $0 [app-name] [prefix]" exit 0 fi if [ -z "$2" ] ; then echo "GenMOOSApp_AppCasting_Multi: 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 < m_node_rec_map; std::set m_contacts; }; #endif EOF cat > 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 ${1}.cpp < #include "MBUtils.h" #include "ACTable.h" #include "${1}.h" using namespace std; //--------------------------------------------------------- // Constructor() ${1}::${1}() { m_nav_x = 0.0; m_nav_y = 0.0; m_nav_hdg = 0.0; m_vname = ""; m_curr_option = ""; } //--------------------------------------------------------- // 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 == "NODE_REPORT") || (key == "NODE_REPORT_LOCAL")) { if ( !handleNodeReport(msg.GetString()) ) reportRunWarning("Unhandled Mail: " + key); } else if (key == "NAV_X") { m_nav_x = msg.GetDouble(); } else if (key == "NAV_Y") { m_nav_y = msg.GetDouble(); } else if (key == "NAV_HEADING") { m_nav_hdg = msg.GetDouble(); } else if (key == "NAV_SPEED") { m_nav_spd = msg.GetDouble(); } else if (key == "CONTACTS_LIST") { if ( !handleContactsList(msg.GetString()) ) reportRunWarning("Unhandled Mail: " + key); } else if (key == "OPTION"){ if (msg.GetString() != ""){ m_curr_option = tolower(msg.GetString()); } else reportRunWarning("Unhandled Mail: " + key); } } return(true); } //--------------------------------------------------------- // Procedure: OnConnectToServer() bool ${1}::OnConnectToServer() { //registerVariables(); // commented out to reduce redundancy 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 = tolower(biteStringX(line, '=')); string value = line; bool handled = false; if(param == "foo") { handled = true; } else if(param == "bar") { handled = true; } if(!handled) reportUnhandledConfigWarning(orig); } // The vehicle name is the host community m_vname = m_host_community; registerVariables(); return(true); } //--------------------------------------------------------- // Procedure: registerVariables() void ${1}::registerVariables() { AppCastingMOOSApp::RegisterVariables(); Register("NODE_REPORT", 0); Register("NODE_REPORT_LOCAL", 0); Register("CONTACTS_LIST", 0); Register("OPTION",0); Register("NAV_X", 0); Register("NAV_Y", 0); Register("NAV_HEADING", 0); Register("NAV_SPEED", 0); } //----------------------------------------------------- // handleNodeReport(std::string msg) // bool ${1}::handleNodeReport(std::string msg) { // process incoming node record NodeRecord newNodeRecord; newNodeRecord = string2NodeRecord(msg); if (!newNodeRecord.valid()) return(false); // Only keep contacts that are alive: if ( m_contacts.count(newNodeRecord.getName()) || (newNodeRecord.getName() == m_vname) ) m_node_rec_map[newNodeRecord.getName()] = newNodeRecord; return(true); } //----------------------------------------------------- // Procedure: handleContactsList(std::string msg) // bool ${1}::handleContactsList(std::string msg) { // parse message std::set new_contact_set; std::vector svector = parseString(msg, ','); for (unsigned int i=0; i::iterator it; for (it = m_node_rec_map.begin(); it != m_node_rec_map.end();){ if ( m_contacts.count(it->first) || (m_vname == it->first) ) { ++it; } else { m_node_rec_map.erase(it++); } } return(true); } //------------------------------------------------------------ // Procedure: buildReport() bool ${1}::buildReport() { m_msgs << "============================================" << endl; m_msgs << " " << endl; m_msgs << "= Node Reports ==========================================" << endl; m_msgs << "===========================================================" << endl; std::map::iterator it; for (it = m_node_rec_map.begin(); it != m_node_rec_map.end(); it++){ m_msgs << " <- " << it->second.getSpec() << endl; } /* 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(" Ego vehicle state: "); blk(" NAV_X, NAV_Y, NAV_SPEED, NAV_HEADING (all doubles) "); blk(" "); blk(" Multi-agent related: "); blk(" NODE_REPORT (NODE_REPORT_LOCAL): Standard message from "); blk(" pNodeReporter "); blk(" "); blk(" CONTACTS_LIST: Standard message from "); blk(" pContactMgr "); blk(" "); blk(" OPTION: Standard message from "); blk(" pOptionMgr "); 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"