/// READ STRINGS bool CProcessConfigReader::GetConfigurationParam(std::string sAppName,std::string sParam, std::string &sVal) { Reset(); //remember all names we were asked for.... std::string sl = sParam; MOOSToLower(sl); m_Audit[sAppName].insert(sl); STRING_LIST sParams; if(GetConfigurationAndPreserveSpace( sAppName, sParams)) { STRING_LIST::iterator p; for(p = sParams.begin(); p!=sParams.end(); p++) { std::string sTmp = *p; std::string sTok = MOOSChomp(sTmp,"="); MOOSTrimWhiteSpace(sTok); if (sTmp.empty()) return false; if(MOOSStrCmp(sTok,sParam)) { MOOSTrimWhiteSpace(sTmp); sVal=sTmp; return true; } } } return false; }
bool CMOOSRemoteLite::MakeCustomSummary() { STRING_LIST sParams; if(m_MissionReader.GetConfiguration(GetAppName(),sParams)) { STRING_LIST::iterator p; for(p = sParams.begin();p!=sParams.end();p++) { string sLine = *p; string sTok,sVal; m_MissionReader.GetTokenValPair(sLine,sTok,sVal); if(MOOSStrCmp(sTok,"CUSTOMSUMMARY")) { m_CustomSummaryList.push_front(sVal); AddMOOSVariable(sVal,sVal,"",0.2); } } } RegisterMOOSVariables(); return true; }
bool CHelmApp::OnPreIterate() { TASK_LIST::iterator p; STRING_LIST NewResources; STRING_LIST::iterator q; for(p = m_Tasks.begin();p!=m_Tasks.end();p++) { CMOOSBehaviour* pBehaviour = *p; if(pBehaviour->HasNewRegistration()) { NewResources.clear(); pBehaviour->GetRegistrations(NewResources); for(q = NewResources.begin();q!=NewResources.end();q++) { if(m_Comms.IsConnected()) { m_Comms.Register(*q,UPDATE_INTERVAL); } } } } return true; }
bool CMOOSDB::OnProcessSummaryRequested(CMOOSMsg &Msg, MOOSMSG_LIST &MsgTxList) { DBVAR_MAP::iterator p; STRING_LIST::iterator q; STRING_LIST Clients; m_pCommServer->GetClientNames(Clients); for(q=Clients.begin();q!=Clients.end();q++) { string sWho = *q; string sPublished= "PUBLISHED="; string sSubscribed = "SUBSCRIBED="; for(p=m_VarMap.begin();p!=m_VarMap.end();p++) { CMOOSDBVar & rVar = p->second; if(rVar.m_Writers.find(sWho)!=rVar.m_Writers.end()) { if(!sPublished.empty()) { sPublished+=","; } sPublished+=rVar.m_sName; } if(rVar.m_Subscribers.find(sWho)!=rVar.m_Subscribers.end()) { if(!sSubscribed.empty()) { sSubscribed+=","; } sSubscribed+=rVar.m_sName; } } CMOOSMsg MsgReply; MsgReply.m_nID = Msg.m_nID; MsgReply.m_cMsgType = MOOS_NOTIFY; MsgReply.m_cDataType = MOOS_STRING; MsgReply.m_dfTime = MOOSTime()-m_dfStartTime; //for display MsgReply.m_sSrc = m_sDBName; MsgReply.m_sKey = "PROC_SUMMARY"; MsgReply.m_sVal = sWho+":"+sSubscribed+","+sPublished; MsgReply.m_dfVal = -1; MsgTxList.push_front(MsgReply); } return true; }
bool SonarFilter::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 == "FILTERLEN") { m_filter_len = atoi(value.c_str()); handled = true; } else if(param == "STDEVLIMIT") { m_std_limit = atof(value.c_str()); handled = true; } else if (param == "SIMSWATHANGLE") { // Convert the angle to radians m_sim_swath_angle = atof(value.c_str()) * M_PI / 180; handled = true; } else if (param == "SONARTYPE") { } if(!handled) reportUnhandledConfigWarning(orig); } AddMOOSVariable("X", "NAV_X", "", 0); AddMOOSVariable("Y", "NAV_Y", "", 0); AddMOOSVariable("Heading", "NAV_HEADING", "", 0); AddMOOSVariable("Depth", "SONAR_DEPTH_M", "", 0); AddMOOSVariable("Depth_Stbd", "SONAR_DEPTH_STBD_M", "", 0); AddMOOSVariable("Depth_Port", "SONAR_DEPTH_PORT_M", "", 0); AddMOOSVariable("SonarWidth", "SONAR_WIDTH", "", 0); AddMOOSVariable("Swath", "", "SWATH_WIDTH", 0); m_nadir_filter = StDevFilter(m_filter_len, m_std_limit, 1/GetAppFreq()); m_port_filter = StDevFilter(m_filter_len, m_std_limit, 1/GetAppFreq()); m_stbd_filter = StDevFilter(m_filter_len, m_std_limit, 1/GetAppFreq()); registerVariables(); return(true); }
bool CMOOSNavEngine::SetUpSensorChannels(STRING_LIST sParams,string sToken) { //ok we need to load up rejection settings STRING_LIST::iterator p; for(p = sParams.begin();p!=sParams.end();p++) { string sLine = *p; if(sLine.find(sToken)!=string::npos) { MOOSRemoveChars(sLine," \t"); MOOSChomp(sLine,"="); //LSQ_REJECTION = TheAvtrak : Reject = 3, History = 5,Fail = 0.001 CMOOSSensorChannel NewChannel; string sSensor = MOOSChomp(sLine,":"); string sHistory = MOOSChomp(sLine,","); string sFail = MOOSChomp(sLine,","); MOOSChomp(sHistory,"="); MOOSChomp(sFail,"="); if(sFail.empty() ||sHistory.empty()) { MOOSTrace("error in %s line!\n",sToken.c_str()); return false; } int nDepth = atoi(sHistory.c_str()); if(nDepth>0) { NewChannel.SetHistoryDepth(nDepth); } double dfFail = atof(sFail.c_str()); if(dfFail>0) { NewChannel.SetNoiseLimit(dfFail); } NewChannel.SetName(sSensor); m_SensorChannelMap[sSensor]=NewChannel; } } return true; }
bool CMOOSRemoteLite::MakeCustomKeys() { STRING_LIST sParams; if(m_MissionReader.GetConfiguration(GetAppName(),sParams)) { STRING_LIST::iterator p; for(p = sParams.begin();p!=sParams.end();p++) { string sLine = *p; string sTok,sVal; m_MissionReader.GetTokenValPair(sLine,sTok,sVal); if(MOOSStrCmp(sTok,"CUSTOMKEY")) { MOOSRemoveChars(sVal," "); string sChar = MOOSChomp(sVal,":"); string sKey = MOOSChomp(sVal,"@"); MOOSRemoveChars(sVal,"\""); string sTx = MOOSChomp(sVal,"$"); bool bIsNumeric = MOOSIsNumeric(sTx); bool bAskToConfirm = (sVal == "confirm"); if(!sChar.empty()) { CCustomKey NewKey; NewKey.m_cChar = sChar[0]; NewKey.m_sKey = sKey; NewKey.m_sVal = sTx; NewKey.bIsNumeric = bIsNumeric; NewKey.bAskToConfirm = bAskToConfirm; if(isdigit(NewKey.m_cChar)) { m_CustomKeys[NewKey.m_cChar] = NewKey; } else { MOOSTrace("CMOOSRemote: can only bind custom keys to numeric characters!\n"); } } } } } return true; }
bool DeadManPost::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 == "heartbeat_var") { if(!strContainsWhite(value)) { m_heart_var = value; handled = true; } } else if(param == "deadflag") { string varname = biteStringX(value, '='); string varval = value; if(!strContainsWhite(varname) && (varval != "")) { VarDataPair pair(varname, varval, "auto"); m_deadflags.push_back(pair); handled = true; } } else if(param == "post_policy") { string val = tolower(value); if((val=="once") || (val=="repeat") || (val=="reset")) { m_post_policy = val; handled = true; } } else if((param == "max_noheart") && isNumber(value)) { m_max_noheart = atof(value.c_str()); handled = true; } else if(param == "active_at_start") handled = setBooleanOnString(m_active_at_start, value); if(!handled) reportUnhandledConfigWarning(orig); } registerVariables(); return(true); }
bool HazardMgr::OnStartUp() { AppCastingMOOSApp::OnStartUp(); STRING_LIST sParams; m_MissionReader.EnableVerbatimQuoting(true); 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 == "swath_width") && isNumber(value)) { m_swath_width_desired = atof(value.c_str()); handled = true; } else if(((param == "sensor_pd") || (param == "pd")) && isNumber(value)) { m_pd_desired = atof(value.c_str()); handled = true; } else if(param == "report_name") { value = stripQuotes(value); m_report_name = value; handled = true; } else if(param == "region") { XYPolygon poly = string2Poly(value); if(poly.is_convex()) m_search_region = poly; handled = true; } if(!handled) reportUnhandledConfigWarning(orig); } m_hazard_set.setSource(m_host_community); m_hazard_set.setName(m_report_name); m_hazard_set.setRegion(m_search_region); m_voted_hazard_set.setSource(m_host_community); m_voted_hazard_set.setName(m_report_name); m_voted_hazard_set.setRegion(m_search_region); registerVariables(); return(true); }
void CMOOSDB::UpdateDBClientsVar() { STRING_LIST Clients; m_pCommServer->GetClientNames(Clients); std::ostringstream ss; std::copy(Clients.begin(),Clients.end(),ostream_iterator<std::string>(ss,",")); CMOOSMsg DBC(MOOS_NOTIFY,"DB_CLIENTS",ss.str()); DBC.m_sOriginatingCommunity = m_sCommunityName; DBC.m_sSrc = m_sDBName; OnNotify(DBC); }
bool GPS::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 == "SERIAL_PORT") { m_uart_port = value.c_str(); handled = true; } if (param == "UART_BAUD_RATE") { m_uart_baud_rate = atoi(value.c_str()); handled = true; } if (!handled) reportUnhandledConfigWarning(orig); } registerVariables(); // Init GPS connection m_error = m_serial.open(m_uart_port,m_error); if (m_error.value() != 0.0) { // No error from asio read reportConfigWarning("Serial open error"); } else m_serial.set_option(boost::asio::serial_port_base::baud_rate(m_uart_baud_rate)); //serial.set_option(boost::asio::serial_port_base::character_size()); //serial.set_option(boost::asio::serial_port_base::flow_control()); //serial.set_option(boost::asio::serial_port_base::parity()); //serial.set_option(boost::asio::serial_port_base::stop_bits()); if(!m_serial.is_open()){ reportConfigWarning("Serial port not open"); } return (true); }
bool CMOOSRemoteLite::DoCustomJournal(char cCmd) { CUSTOMJOURNAL_MAP::iterator p; for(p = m_CustomJournals.begin();p!=m_CustomJournals.end();p++) { if(p->second.m_cKey==cCmd) { MOOSTrace("\nJournal Entries for \"%s\" :\n ",p->first.c_str()); STRING_LIST Cpy = p->second.m_Entries; std::copy(Cpy.begin(),Cpy.end(),std::ostream_iterator<std::string>(std::cout,"\n ")); return true; } } return false; }
Triggerconf::ATTRIBUTE_MAP Triggerconf::getConfigItemAttributes (string module, string submodule, string configitem) { ATTRIBUTE_MAP ret; STRING_LIST names = getConfigAttributeNames (module, submodule, configitem); STRING_LIST_ITERATOR begin = names.begin(); STRING_LIST_ITERATOR end = names.end(); for ( ; begin != end; begin++) { string value = getConfigAttributeValue (module, submodule, configitem, *begin); ret.insert (ATTRIBUTE_PAIR (*begin, value)); } // for ( ; begin != end; begin++) return ret; }
string Triggerconf::untokenize (STRING_LIST path) { STRING_LIST::iterator begin = path.begin(); STRING_LIST::iterator end = path.end(); string ret; for ( ; begin != end; begin++) { if (ret.length () == 0) ret += *begin; else ret += (PATH_DELIMITER + *begin); } return ret; }
void CMOOSDB::UpdateReadWriteSummaryVar() { std::map<std::string,std::list<std::string> > Pub; std::map<std::string,std::list<std::string> > Sub; DBVAR_MAP::iterator p; for(p=m_VarMap.begin();p!=m_VarMap.end();p++) { CMOOSDBVar & rVar = p->second; STRING_SET::iterator w; REGISTER_INFO_MAP::iterator v; std::stringstream ss; for(v = rVar.m_Subscribers.begin();v!=rVar.m_Subscribers.end();v++) Sub[v->second.m_sClientName].push_back(rVar.m_sName); for(w = rVar.m_Writers.begin();w!=rVar.m_Writers.end();w++) Pub[*w].push_back(rVar.m_sName); } STRING_LIST Clients; m_pCommServer->GetClientNames(Clients); STRING_LIST::iterator q; std::ostringstream ss; for(q=Clients.begin();q!=Clients.end();) { ss<<*q<<"="; PrintCollection(Sub[*q],ss,":"); ss<<"&"; PrintCollection(Pub[*q],ss,":"); if(++q!=Clients.end()) ss<<","; } CMOOSMsg DBS(MOOS_NOTIFY,"DB_RWSUMMARY",ss.str()); DBS.m_sSrc = m_sDBName; DBS.m_sOriginatingCommunity = m_sCommunityName; OnNotify(DBS); }
bool Gps::OnStartUp() { AppCastingMOOSApp::OnStartUp(); STRING_LIST sParams; m_MissionReader.EnableVerbatimQuoting(false); if (!m_MissionReader.GetValue("GPS_SERIAL_PORT",m_uart_port)) reportConfigWarning("No GPS_SERIAL_PORT config found for " + GetAppName() + "(previously iGps)"); 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 == "UART_BAUD_RATE") { m_uart_baud_rate = atoi(value.c_str()); handled = true; } if (!handled) reportUnhandledConfigWarning(orig); } registerVariables(); // Init GPS connection // if(serial.is_open()){ // serial.close(); // } m_serial.open(m_uart_port); m_serial.set_option(boost::asio::serial_port_base::baud_rate(m_uart_baud_rate)); //serial.set_option(boost::asio::serial_port_base::character_size()); //serial.set_option(boost::asio::serial_port_base::flow_control()); //serial.set_option(boost::asio::serial_port_base::parity()); //serial.set_option(boost::asio::serial_port_base::stop_bits()); return (true); }
bool SensorViewer::OnStartUp() { AppCastingMOOSApp::OnStartUp(); STRING_LIST sParams; m_MissionReader.EnableVerbatimQuoting(false); 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 == "SONAR_CONTRAST") { m_sonar_contrast = atof(value.c_str()); handled = true; } else if (param == "SONAR_CONTRAST_MINIKING") { m_sonar_contrast_miniking = atof(value.c_str()); handled = true; } else if (param == "SONAR_CONTRAST_MICRON") { m_sonar_contrast_micron = atof(value.c_str()); handled = true; } if (!handled) reportUnhandledConfigWarning(orig); } registerVariables(); namedWindow("CAMERA SIDE", WINDOW_NORMAL); namedWindow("CAMERA BOTTOM", WINDOW_NORMAL); // namedWindow("SONAR MINIKING", WINDOW_NORMAL); namedWindow("SONAR MICRON", WINDOW_NORMAL); //namedWindow("SONAR", WINDOW_NORMAL); namedWindow("WALL MICRON", WINDOW_NORMAL); // namedWindow("WALL MINIKING", WINDOW_NORMAL); return(true); }
bool LoadWatch::OnStartUp() { string directives = "must_have_moosblock=false"; AppCastingMOOSApp::OnStartUpDirectives(directives); STRING_LIST sParams; m_MissionReader.EnableVerbatimQuoting(false); if(!m_MissionReader.GetConfiguration(GetAppName(), sParams)) return(true); 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; // THRESH = app=pHelmIvP, gapthresh=1.5 // BREACH_TRIGGER = 1 if(param == "thresh") { handled = handleConfigThresh(value); } else if((param == "breach_trigger") && isNumber(value)) { double dval = atof(value.c_str()); if(dval < 0) dval = 0; m_breach_trigger = (unsigned int)(dval); handled = true; } if(!handled) reportUnhandledConfigWarning(orig); } registerVariables(); return(true); }
BOOL Language::GetAllValueMap(VALUE_MAP &valueMap) const { STRING_LIST nameList; if(GetSectionNames(nameList)) { for(STRING_LIST::iterator ite=nameList.begin();ite!=nameList.end();ite++) { CString strSection = *ite; VALUE_MAP tmpMap; if(GetSectionValueMap(strSection, tmpMap)) { VALUE_MAP::iterator itor_b = tmpMap.begin(); VALUE_MAP::iterator itor_e = tmpMap.end(); for (; itor_b != itor_e; itor_b++) { (void)valueMap.insert(std::make_pair(itor_b->first, itor_b->second)); } } } } return TRUE; }
bool CHelmApp::CTransaction::HasPermissions(string sRequest) { MOOSToUpper(sRequest); STRING_LIST AllowableTasks = m_PermissionsMap[m_sTransactingClient]; STRING_LIST::iterator q; for(q = AllowableTasks.begin(); q != AllowableTasks.end(); q++) { //now see if the sRequest the m_sTransactingClient //wants to accomplish is within its list of permissable //tasks to spawn string sAllowedTask = *q; if(MOOSStrCmp(sRequest,sAllowedTask)) { return true; } } //the requesting client's task is not allowed to be launched by them return false; }
bool NodeBroker::OnStartUp() { AppCastingMOOSApp::OnStartUp(); // host_community info grabbed and stored at AppCastingMOOSApp level m_node_host_record.setCommunity(m_host_community); STRING_LIST sParams; 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 == "TRY_SHORE_HOST") handled = handleConfigTryShoreHost(value); else if(param == "BRIDGE") handled = handleConfigBridge(value); if(!handled) reportUnhandledConfigWarning(orig); } //Temporary fix for command messages //m_Comms.Advertise("PSHARE_CMD"); registerVariables(); registerPingBridges(); return(true); }
bool Rad2Degree::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; sParams.reverse(); 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; }
void CMOOSDB::UpdateDBClientsVar() { #define CLIENT_LIST_PUBLISH_PERIOD 2 static double dfLastTime = MOOSTime(); double dfNow = MOOSTime(); if(dfNow-dfLastTime>CLIENT_LIST_PUBLISH_PERIOD) { STRING_LIST Clients; m_CommServer.GetClientNames(Clients); std::ostringstream ss; std::copy(Clients.begin(),Clients.end(),ostream_iterator<std::string>(ss,",")); CMOOSMsg DBC(MOOS_NOTIFY,"DB_CLIENTS",ss.str()); DBC.m_sOriginatingCommunity = m_sCommunityName; DBC.m_sSrc = m_sDBName; OnNotify(DBC); dfLastTime = dfNow; } }
bool USM_MOOSApp::OnStartUp() { AppCastingMOOSApp::OnStartUp(); m_model.resetTime(m_curr_time); STRING_LIST sParams; 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; double dval = atof(value.c_str()); // Handle and warn of deprecated configuration parameters. param = handleConfigDeprecations(param); bool handled = false; if((param == "START_X") && isNumber(value)) handled = m_model.setParam(param, dval); else if((param == "START_Y") && isNumber(value)) handled = m_model.setParam(param, dval); else if((param == "START_HEADING") && isNumber(value)) handled = m_model.setParam(param, dval); else if((param == "START_SPEED") && isNumber(value)) handled = m_model.setParam(param, dval); else if((param == "START_DEPTH") && isNumber(value)) handled = m_model.setParam(param, dval); else if((param == "BUOYANCY_RATE") && isNumber(value)) handled = m_model.setParam(param, dval); else if((param == "DRIFT_X") && isNumber(value)) handled = m_model.setParam("drift_x", dval); else if((param == "DRIFT_Y") && isNumber(value)) handled = m_model.setParam("drift_y", dval); else if((param == "ROTATE_SPEED") && isNumber(value)) handled = m_model.setParam("rotate_speed", dval); else if((param == "MAX_ACCELERATION") && isNumber(value)) handled = m_model.setParam("max_acceleration", dval); else if((param == "MAX_DECELERATION") && isNumber(value)) handled = m_model.setParam("max_deceleration", dval); else if((param == "MAX_DEPTH_RATE") && isNumber(value)) handled = m_model.setParam("max_depth_rate", dval); else if((param == "MAX_DEPTH_RATE_SPEED") && isNumber(value)) handled = m_model.setParam("max_depth_rate_speed", dval); else if((param == "MAX_RUDDER_DEGS_PER_SEC") && isNumber(value)) handled = m_model.setMaxRudderDegreesPerSec(dval); else if((param == "PREFIX") && !strContainsWhite(value)) { m_sim_prefix = value; handled = true; } else if(param == "DRIFT_VECTOR") handled = m_model.setDriftVector(value); else if((param == "SIM_PAUSE") && isBoolean(value)) { m_model.setPaused(tolower(value) == "true"); handled = true; } else if((param == "DUAL_STATE") && isBoolean(value)) { m_model.setDualState(tolower(value) == "true"); handled = true; } else if(param == "START_POS") handled = m_model.initPosition(value); else if((param == "THRUST_REFLECT") && isBoolean(value)) { m_model.setThrustReflect(tolower(value)=="true"); handled = true; } else if((param == "THRUST_FACTOR") && isNumber(value)) m_model.setThrustFactor(dval); else if(param == "THRUST_MAP") handled = handleThrustMapping(value); else if((param == "TURN_RATE") && isNumber(value)) handled = m_model.setParam("turn_rate", dval); else if((param == "DEFAULT_WATER_DEPTH") && isNumber(value)) handled = m_model.setParam("water_depth", dval); else if((param == "TRIM_TOLERANCE") && isNumber(value)) { pitch_tolerance = dval; handled = true; } else if((param == "MAX_TRIM_DELAY") && isNumber(value)) { max_trim_delay = dval; handled = true; } if(!handled) reportUnhandledConfigWarning(orig); } // look for latitude, longitude global variables double latOrigin, longOrigin; if(!m_MissionReader.GetValue("LatOrigin", latOrigin)) { MOOSTrace("uSimMarine: LatOrigin not set in *.moos file.\n"); m_geo_ok = false; } else if(!m_MissionReader.GetValue("LongOrigin", longOrigin)) { MOOSTrace("uSimMarine: LongOrigin not set in *.moos file\n"); m_geo_ok = false; } else { m_geo_ok = true; // initialize m_geodesy if(!m_geodesy.Initialise(latOrigin, longOrigin)) { MOOSTrace("uSimMarine: Geodesy init failed.\n"); m_geo_ok = false; } } cacheStartingInfo(); registerVariables(); MOOSTrace("uSimMarine started \n"); return(true); }
bool MoveEvent::configureEvent(xmlNodePtr p) { std::string str; int intValue; if(readXMLString(p, "event", str)){ if(asLowerCaseString(str) == "stepin"){ m_eventType = MOVE_EVENT_STEP_IN; } else if(asLowerCaseString(str) == "stepout"){ m_eventType = MOVE_EVENT_STEP_OUT; } else if(asLowerCaseString(str) == "equip"){ m_eventType = MOVE_EVENT_EQUIP; } else if(asLowerCaseString(str) == "deequip"){ m_eventType = MOVE_EVENT_DEEQUIP; } else if(asLowerCaseString(str) == "additem"){ m_eventType = MOVE_EVENT_ADD_ITEM; } else if(asLowerCaseString(str) == "removeitem"){ m_eventType = MOVE_EVENT_REMOVE_ITEM; } else{ std::cout << "Error: [MoveEvent::configureMoveEvent] No valid event name " << str << std::endl; return false; } if(m_eventType == MOVE_EVENT_EQUIP || m_eventType == MOVE_EVENT_DEEQUIP){ if(readXMLString(p, "slot", str)){ if(asLowerCaseString(str) == "head"){ slot = SLOT_HEAD; } else if(asLowerCaseString(str) == "necklace"){ slot = SLOT_NECKLACE; } else if(asLowerCaseString(str) == "backpack"){ slot = SLOT_BACKPACK; } else if(asLowerCaseString(str) == "armor"){ slot = SLOT_ARMOR; } else if(asLowerCaseString(str) == "right-hand"){ slot = SLOT_RIGHT; } else if(asLowerCaseString(str) == "left-hand"){ slot = SLOT_LEFT; } else if(asLowerCaseString(str) == "legs"){ slot = SLOT_LEGS; } else if(asLowerCaseString(str) == "feet"){ slot = SLOT_FEET; } else if(asLowerCaseString(str) == "ring"){ slot = SLOT_RING; } else if(asLowerCaseString(str) == "ammo"){ slot = SLOT_AMMO; } else{ std::cout << "Warning: [MoveEvent::configureMoveEvent] " << "Unknown slot type " << str << std::endl; } } wieldInfo = 0; if(readXMLInteger(p, "lvl", intValue) || readXMLInteger(p, "level", intValue)){ reqLevel = intValue; if(reqLevel > 0){ wieldInfo |= WIELDINFO_LEVEL; } } if(readXMLInteger(p, "maglv", intValue) || readXMLInteger(p, "maglevel", intValue)){ reqMagLevel = intValue; if(reqMagLevel > 0){ wieldInfo |= WIELDINFO_MAGLV; } } if(readXMLInteger(p, "prem", intValue) || readXMLInteger(p, "premium", intValue)){ premium = (intValue != 0); if(premium){ wieldInfo |= WIELDINFO_PREMIUM; } } //Gather vocation information typedef std::list<std::string> STRING_LIST; STRING_LIST vocStringList; xmlNodePtr vocationNode = p->children; while(vocationNode){ if(xmlStrcmp(vocationNode->name,(const xmlChar*)"vocation") == 0){ if(readXMLString(vocationNode, "name", str)){ int32_t vocationId = g_vocations.getVocationId(str); if(vocationId != -1){ vocEquipMap[vocationId] = true; intValue = 1; readXMLInteger(vocationNode, "showInDescription", intValue); if(intValue != 0){ toLowerCaseString(str); vocStringList.push_back(str); } } } } vocationNode = vocationNode->next; } if(!vocStringList.empty()){ for(STRING_LIST::iterator it = vocStringList.begin(); it != vocStringList.end(); ++it){ if(*it != vocStringList.front()){ if(*it != vocStringList.back()){ vocationString += ", "; } else{ vocationString += " and "; } } vocationString += *it; vocationString += "s"; } wieldInfo |= WIELDINFO_VOCREQ; } } } else{ std::cout << "Error: [MoveEvent::configureMoveEvent] No event found." << std::endl; return false; } return true; }
bool OpiDetection::OnStartUp() { AppCastingMOOSApp::OnStartUp(); setlocale(LC_ALL, "C"); STRING_LIST sParams; m_MissionReader.EnableVerbatimQuoting(false); if(!m_MissionReader.GetConfiguration(GetAppName(), sParams)) reportConfigWarning("No config block found for " + GetAppName()); STRING_LIST::iterator p; sParams.reverse(); 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 == "VARIABLE_IMAGE_NAME") { image_name = value; handled = true; } else if(param == "VARIABLE_WHEN_FOUND") { message_name = value; handled = true; } else if(param == "SHOW_PROCESS") { show_process = (value == "true"); handled = true; } else if(param == "IMAGE_NAME_PATTERN") { image_name_pattern = "/" + value; handled = true; } else if(param == "FOLDER_NAME_PATTERN") { folder_name_pattern = "/" + value; handled = true; } else if(param == "SAVE_IN_FOLDER") { path_save = value; handled = true; } if(!handled) reportUnhandledConfigWarning(orig); } char folder_name[80]; time_t now = time(0); struct tm tstruct; tstruct = *localtime(&now); // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime // for more information about date/time format strftime(folder_name, sizeof(folder_name), folder_name_pattern.c_str(), &tstruct); path_save += folder_name; mkdir(path_save.c_str(),S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); registerVariables(); return true; }
bool MarinePID::OnStartUp() { cout << "pMarinePID starting...." << endl; m_start_time = MOOSTime(); STRING_LIST sParams; m_MissionReader.GetConfiguration(GetAppName(), sParams); STRING_LIST::iterator p; for(p=sParams.begin(); p!=sParams.end(); p++) { string sLine = *p; string param = toupper(biteStringX(sLine, '=')); string value = sLine; double dval = atof(value.c_str()); if(param == "DRAG_MAP") m_drag_map.setPoints(value); else if(param == "HEADING_LIMIT") m_heading_limit = dval; else if(param == "SPD_PID_ACTIVE") { if(sLine == "true") m_spdPID_active = true; else m_spdPID_active = false; } else if(param == "TARDY_HELM_THRESHOLD") m_tardy_helm_thresh = vclip_min(dval, 0); else if(param == "TARDY_NAV_THRESHOLD") m_tardy_nav_thresh = vclip_min(dval, 0); else if(param == "ACTIVE_START") setBooleanOnString(m_has_control, value); else if(param == "VERBOSE") { if((sLine == "true") || (sLine == "verbose")) m_verbose = "verbose"; if(sLine == "terse") m_verbose = "terse"; if(sLine == "quiet") m_verbose = "quiet"; } } bool ok_yaw = handleYawSettings(); bool ok_spd = handleSpeedSettings(); bool ok_dep = handleDepthSettings(); if(!ok_yaw || !ok_spd || !ok_dep) { cout << "Improper PID Settings" << endl; return(false); } if(m_depth_control) cout << "Depth Control is ON" << endl; else cout << "Depth Control is OFF" << endl; registerVariables(); return(true); }
bool XSensINS::OnStartUp() { AppCastingMOOSApp::OnStartUp(); // XSens Configuration Array XsOutputConfigurationArray configArray; // MOOS parser STRING_LIST sParams; m_MissionReader.EnableVerbatimQuoting(false); if (!m_MissionReader.GetConfiguration(GetAppName(), sParams)) reportConfigWarning("No config block found for " + GetAppName()); STRING_LIST::iterator p; sParams.reverse(); 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 == "UART_BAUD_RATE") { m_uart_baud_rate = atoi(value.c_str()); handled = true; } else if (param == "SERIAL_PORT") { m_uart_port = value; handled = true; } else if (param == "XDI_EULERANGLES"){ XsOutputConfiguration config(XDI_EulerAngles, atoi(value.c_str())); configArray.push_back(config); handled = true; } else if (param == "XDI_ACCELERATION"){ XsOutputConfiguration config(XDI_Acceleration, atoi(value.c_str())); configArray.push_back(config); handled = true; } else if (param == "XDI_RATEOFTURN"){ XsOutputConfiguration config(XDI_RateOfTurn, atoi(value.c_str())); configArray.push_back(config); handled = true; } else if (param == "XDI_MAGNETICFIELD"){ XsOutputConfiguration config(XDI_MagneticField, atoi(value.c_str())); configArray.push_back(config); handled = true; } else if (param == "XDI_LATLON"){ XsOutputConfiguration config(XDI_LatLon, atoi(value.c_str())); configArray.push_back(config); handled = true; } else if (param == "XDI_VELOCITYXYZ"){ XsOutputConfiguration config(XDI_VelocityXYZ, atoi(value.c_str())); configArray.push_back(config); handled = true; } if(!handled) reportUnhandledConfigWarning(orig); } registerVariables(); //------ OPEN INS ---------------// XsPortInfo mtPort(m_uart_port, XsBaud::numericToRate(m_uart_baud_rate)); if (!m_device.openPort(mtPort)) { cout << "CANNOT OPEN THE PORT : " << m_uart_port << '\n'; reportRunWarning("Could not open the COM port" + m_uart_port); } //------ CONFIGURE INS ---------------// // Put the device into configuration mode before configuring the device if (!m_device.gotoConfig()) { reportRunWarning("Could not begin the config mode"); } // Save INS Config if (!m_device.setOutputConfiguration(configArray)) { reportRunWarning("Could not save config"); } //------ START INS ---------------// if (!m_device.gotoMeasurement()) { reportRunWarning("Could not start the INS"); } return true; }
bool CMOOSLogger::ConfigureLogging() { //figure out what we are required to log.... //here we read in what we want to log from the mission file.. STRING_LIST Params; bool bHasMissionFile = true; if(m_MissionReader.GetConfiguration(m_sAppName,Params)) { //this will make columns in sync log in order they //were declared in *.moos file Params.reverse(); STRING_LIST::iterator p; for(p=Params.begin();p!=Params.end();p++) { string sParam = *p; string sWhat = MOOSChomp(sParam,"="); if(MOOSStrCmp(sWhat,"LOG")) { std::string sNewVar; HandleLogRequest(sParam,sNewVar); } } } else { bHasMissionFile = false; MOOSTrace("Warning:\n\tNo Configuration block was read - unusual but not terminal\n"); } //are we allowing dynamic logging of variables is via PLOGGER_CMD message? int nNumDynamicVariables = m_MissionReader.IsOpen() ? 0 : 10; //this won't touch nNumDynamicVariables if mission file isn't open. m_MissionReader.GetConfigurationParam("DynamicSyncLogColumns",nNumDynamicVariables); if(nNumDynamicVariables>0) { MOOSTrace("Comment:\n\tReserving space for %d dynamic variables in slog\n",nNumDynamicVariables); for(int i = 0; i<nNumDynamicVariables;i++) { m_UnusedDynamicVariables.push_back(MOOSFormat("DYNAMIC_%d",i)); } } //and generally turn on command message filtering at the CMOOSApp level EnableCommandMessageFiltering(true); //do we want wildcard logging - ie have the logger log every change... m_bWildCardLogging = false; if(bHasMissionFile) { m_MissionReader.GetConfigurationParam("WildcardLogging",m_bWildCardLogging); } else { m_bWildCardLogging = true; } //what sort of things do we want to wild card log if(m_bWildCardLogging ) { //we never want to log mission files sent between communities - this is done elsewhere m_sWildCardOmitted.push_back("MISSION_FILE"); //there was a request to allow multiple statements of the these patterns...hence the //more complicated parsing here STRING_LIST sList; if(m_MissionReader.GetConfiguration(GetAppName(), sList)) { STRING_LIST::iterator q; for(q = sList.begin();q!=sList.end();q++) { //are we being told exactly what accept and what not to accept std::string sTok,sVal; if(!CMOOSFileReader::GetTokenValPair(*q, sTok,sVal)) continue; if(MOOSStrCmp("WildCardPattern",sTok)) { while(!sVal.empty()) { m_sWildCardAccepted.push_back(MOOSChomp(sVal,",")); } } else if(MOOSStrCmp("WildCardOmitPattern",sTok)) { while(!sVal.empty()) { m_sWildCardOmitted.push_back(MOOSChomp(sVal)); } } } } m_bAsynchronousLog = true; } //ok so now lets register our interest in all these MOOS vars! if(!RegisterMOOSVariables()) MOOSDebugWrite("Variable subscription is still pending - not terminal, but unusual"); return true; }
bool Weapon::configureEvent(xmlNodePtr p) { int32_t intValue; std::string strValue; if (readXMLInteger(p, "id", intValue)) { id = intValue; } else { std::cout << "Error: [Weapon::configureEvent] Weapon without id." << std::endl; return false; } if (readXMLInteger(p, "lvl", intValue) || readXMLInteger(p, "level", intValue)) { level = intValue; } if (readXMLInteger(p, "maglv", intValue) || readXMLInteger(p, "maglevel", intValue)) { magLevel = intValue; } if (readXMLInteger(p, "mana", intValue)) { mana = intValue; } if (readXMLInteger(p, "manapercent", intValue)) { manaPercent = intValue; } if (readXMLInteger(p, "soul", intValue)) { soul = intValue; } if (readXMLInteger(p, "exhaustion", intValue)) { exhaustion = intValue; } if (readXMLInteger(p, "prem", intValue)) { premium = (intValue == 1); } if (readXMLInteger(p, "enabled", intValue)) { enabled = (intValue == 1); } if (readXMLInteger(p, "unproperly", intValue)) { wieldUnproperly = (intValue == 1); } if (readXMLString(p, "ammo", strValue)) { std::cout << "Warning: ammo is not longer used in weapons.xml." << std::endl; } typedef std::list<std::string> STRING_LIST; STRING_LIST vocStringList; xmlNodePtr vocationNode = p->children; while (vocationNode) { if (xmlStrcmp(vocationNode->name, (const xmlChar*)"vocation") == 0) { if (readXMLString(vocationNode, "name", strValue)) { int32_t vocationId = g_vocations.getVocationId(strValue); if (vocationId != -1) { vocWeaponMap[vocationId] = true; int32_t promotedVocation = g_vocations.getPromotedVocation(vocationId); if (promotedVocation != 0) { vocWeaponMap[promotedVocation] = true; } readXMLInteger(vocationNode, "showInDescription", intValue); if (intValue != 0) { toLowerCaseString(strValue); vocStringList.push_back(strValue); } } } } vocationNode = vocationNode->next; } range = Item::items[id].shootRange; std::string vocationString; if (!vocStringList.empty()) { for (STRING_LIST::iterator it = vocStringList.begin(); it != vocStringList.end(); ++it) { if (*it != vocStringList.front()) { if (*it != vocStringList.back()) { vocationString += ", "; } else { vocationString += " and "; } } vocationString += *it; vocationString += "s"; } } uint32_t wieldInfo = 0; if (getReqLevel() > 0) { wieldInfo |= WIELDINFO_LEVEL; } if (getReqMagLv() > 0) { wieldInfo |= WIELDINFO_MAGLV; } if (!vocationString.empty()) { wieldInfo |= WIELDINFO_VOCREQ; } if (isPremium()) { wieldInfo |= WIELDINFO_PREMIUM; } if (wieldInfo != 0) { ItemType& it = Item::items.getItemType(id); it.wieldInfo = wieldInfo; it.vocationString = vocationString; it.minReqLevel = getReqLevel(); it.minReqMagicLevel = getReqMagLv(); } if (configureWeapon(Item::items[getID()])) { return true; } return false; }