/** * Convert a list of strings to a list of doubles. Any values within the * string list which are non-numeric will not be added to the double list. */ void strListToDblList(std::list<std::string> strList, std::list<double> &dblList) { for (std::list<std::string>::iterator it = strList.begin(); it != strList.end(); it++) { if (MOOSIsNumeric(*it)) dblList.push_back(MOOS::StringToDouble(*it)); } } /* strListToDblList */
bool CProcessConfigReader::GetConfigurationParam(std::string sAppName, std::string sParam, bool & bVal) { std::string sVal; if (GetConfigurationParam(sAppName, sParam, sVal)) { // jckerken 10/24/04 : made bin 0,1 also work // bVal = MOOSStrCmp(sVal,"TRUE"); bVal = (MOOSStrCmp(sVal, "TRUE") || (MOOSIsNumeric(sVal) && atof(sVal.c_str()) > 0)); return true; } return false; }
IPV4Address::IPV4Address(const std::string & host_and_port) { std::string tmp(host_and_port); if(tmp.find(':')==std::string::npos) throw std::runtime_error("IPV4Address::IPV4Address "+tmp+" is not of host:port format"); host_ = MOOS::Chomp(tmp,":"); if(host_.empty() || tmp.empty() ) throw std::runtime_error("IPV4Address::IPV4Address "+tmp+" is not of host:port format"); if(!MOOSIsNumeric(tmp)) throw std::runtime_error("IPV4Address::IPV4Address "+tmp+" is not of host:port format"); port_ = atoi(tmp.c_str()); }
bool CProcessConfigReader::GetConfigurationParam(std::string sParam, bool & bVal) { if(!m_sAppName.empty()) { std::string sVal; if(GetConfigurationParam(m_sAppName,sParam, sVal)) { bVal = (MOOSStrCmp(sVal, "TRUE") || (MOOSIsNumeric(sVal) && atof(sVal.c_str()) > 0)); return true; } } else { MOOSTrace("App Name not set in CProcessConfigReader::GetConfigurationParam()\n"); } return false; }
bool Joystick::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()); int inputId = -1; int inputType = -1; float ratio = 1.; float axis_min = -1.; float axis_max = 1.; ControlMode inputMode = Value; 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 == "DEVICE_NAME") { mJoystickControl.mDeviceName = value; handled = true; } else if(param == "MODE") { if (tolower(value) == "value") inputMode = Value; else if (tolower(value) == "increment") inputMode = Increment; else if (tolower(value) == "switch") inputMode = Switch; handled = true; } else if(param == "MIN") { if(!MOOSIsNumeric(value)) reportConfigWarning(orig); else axis_min = atof(value.c_str()); handled = true; } else if(param == "MAX") { if(!MOOSIsNumeric(value)) reportConfigWarning(orig); else axis_max = atof(value.c_str()); handled = true; } else if(param == "BUTTON") { if(!MOOSIsNumeric(value)) reportConfigWarning(orig); else { inputId = atoi(value.c_str()); inputType = JS_EVENT_BUTTON; } handled = true; } else if(param == "AXIS") { if(!MOOSIsNumeric(value)) reportConfigWarning(orig); else { inputId = atoi(value.c_str()); inputType = JS_EVENT_AXIS; } handled = true; } else if(param == "SCALE") { if(!MOOSIsNumeric(value)) reportConfigWarning(orig); else { axis_max = atof(value.c_str()); axis_min = -axis_max; } handled = true; } else if(param == "SCALE_RATIO") { if(!MOOSIsNumeric(value)) reportConfigWarning(orig); else ratio = atof(value.c_str()); handled = true; } else if(param == "MOOS_DEST_VAR") { value = toupper(value); if(inputId >= 0) { mControlsVariables[make_pair(inputType, inputId)] = pair<string, JoystickControlState>(value, JoystickControlState()); double offset = ratio*axis_min; double gain = (ratio*axis_max - offset); mJoystickControl.setState(inputType, inputId, inputMode, gain, offset); handled = true; } } if(!handled) reportUnhandledConfigWarning(orig); } if(!mJoystickControl.OpenPort()) MOOSFail("Cannot open the joystick device '%s'.\n", mJoystickControl.mDeviceName.c_str()); registerVariables(); return(true); }
bool CMOOSPlayBackV2::MessageFromLine(const std::string & sLine, CMOOSMsg &Msg) { int n = 0; std::string sTime,sKey,sSrc; m_ALog.GetNextToken(sLine,n,sTime); m_ALog.GetNextToken(sLine,n,sKey); m_ALog.GetNextToken(sLine,n,sSrc); size_t nData = sLine.find_first_not_of(" \t",n); if(nData==string::npos) return false; std::string sData = sLine.substr(nData,sLine.size()-nData); Msg.m_dfTime = MOOSTime(); if(MOOSIsNumeric(sData)) { Msg.m_dfVal = atof(sData.c_str()); Msg.m_cDataType = MOOS_DOUBLE; Msg.m_sVal = ""; } else { Msg.m_dfVal = 0.0; if(sData.find("<MOOS_BINARY>") !=std::string::npos) { //Msg.MarkAsBinary(); long long nOffset; if(!MOOSValFromString(nOffset,sData,"Offset")) return MOOSFail("badly formed MOOS_BINARY indicator - missing \"Offset=xyz\""); std::string sFile; if(!MOOSValFromString(sFile,sData,"File")) return MOOSFail("badly formed MOOS_BINARY indicator - missing \"File=XYZ\""); int nBytes; if(!MOOSValFromString(nBytes,sData,"Bytes")) return MOOSFail("badly formed MOOS_BINARY indicator - missing \"Bytes=xyz\""); //corner case of binary file changing half way through a log....(Why this might happen //I don't know but catch it anyway.... if(sFile != m_sBinaryFileName && m_BinaryFile.is_open() ) { m_BinaryFile.close(); } m_sBinaryFileName = sFile; if(!m_BinaryFile.is_open()) { //open the file with the correct name //here we need to point the file towards the full path - the blog file should be sitting next //to teh alog being played /** splits a fully qualified path into parts -path, filestem and extension */ std::string sPath,sFileName,sExtension; if(!MOOSFileParts(m_ALog.GetFileName(),sPath,sFileName,sExtension)) return MOOSFail("failed to parse alog file into file parts %s",MOOSHERE); std::string sFullBinaryLogPath = sPath+"/"+m_sBinaryFileName; MOOSTrace("opening binary file %s\n",sFullBinaryLogPath.c_str()); m_BinaryFile.open(sFullBinaryLogPath.c_str(),std::ios::binary); if(!m_BinaryFile) { return MOOSFail("unable to open binary file called %s", m_sBinaryFileName.c_str()); } } //move to the right place in the file m_BinaryFile.seekg(nOffset); //make space char * pBD = new char[nBytes]; //read the right number of bytes m_BinaryFile.read(pBD,nBytes); //copy data Msg.m_sVal.assign(pBD,nBytes); //delete temporary space delete [] pBD; Msg.MarkAsBinary(); } else { Msg.m_dfVal = 0.0; Msg.m_cDataType = MOOS_STRING; Msg.m_sVal = sData; } } //fill in standard aspects Msg.m_sSrc = sSrc; Msg.m_sKey = sKey; Msg.m_cMsgType = MOOS_NOTIFY; return true; }