bool CMOOSRemoteLite::MailLoop()
{
    m_bRunMailLoop = true;
    while(!m_bQuit)
    {
        MOOSPause(300);

        MOOSMSG_LIST MailIn;
        if(m_bRunMailLoop && m_Comms.Fetch(MailIn))
        {
            //process mail
            //simply write out
            MOOSMSG_LIST::iterator p;

            //make it in time order
            MailIn.sort();
            MailIn.reverse();

            for(p = MailIn.begin();p!=MailIn.end();p++)
            {

                if(p->IsSkewed(MOOSTime()))
                    continue;
                if(MOOSStrCmp(p->m_sKey,"NAV_SUMMARY"))
                {
                    DoNavSummary(*p);
                }
                else

                if(p->GetKey().find("DEBUG")!=string::npos)
                {
                    //we print MOOS_DEBUG messages to the screen
                    string sMsg = p->m_sVal;
                    MOOSRemoveChars(sMsg,"\r\n");

                    MOOSTrace(">%-10s @ %7.2f \"%s\"\n",
                        p->m_sSrc.c_str(),
                        p->m_dfTime-GetAppStartTime(),
                        sMsg.c_str());
                }

                else
                {
                    CUSTOMJOURNAL_MAP::iterator w = m_CustomJournals.find(p->GetKey());
                    if(w!=m_CustomJournals.end())
                    {
                        w->second.Add(p->GetAsString());
                    }

                }
            }


            UpdateMOOSVariables(MailIn);

        }

    }
    return true;
}
Beispiel #2
0
bool CMOOSLogger::OnNewMail(MOOSMSG_LIST &NewMail)
{
    //these three calls look through the incoming mail
    //and handle all appropriate logging
    DoAsyncLog(NewMail);

    UpdateMOOSVariables(NewMail);

    LogSystemMessages(NewMail);


    //here we look for more unusual things
    MOOSMSG_LIST::iterator q;

    for(q=NewMail.begin();q!=NewMail.end();q++)
    {

        if(q->IsSkewed(MOOSTime()))
            continue;

        //are we being asked to restart?
        if(MOOSStrCmp(q->GetKey(),"LOGGER_RESTART"))
        {
            OnLoggerRestart();
        }

    }

    return true;
}
Beispiel #3
0
//this is a mail callback - it is called as soon as mail arrives
bool OnMail(void *pParam){
	CMOOSCommClient* pC = reinterpret_cast<CMOOSCommClient*>(pParam);

	//grab all the held mail
	MOOSMSG_LIST M;
	pC->Fetch(M); //get the mail
	MOOSMSG_LIST::iterator q; //process it
	for(q=M.begin();q!=M.end();q++){
		q->Trace();//print it
	}
	return true;
}
Beispiel #4
0
bool OnMail (void * pParam)
{
	CMOOSCommClient* pC = reinterpret_cast<CMOOSCommClient*> (pParam);
	MOOSMSG_LIST M;
	pC->Fetch(M);

	MOOSMSG_LIST::iterator q;

	for(q=M.begin();q!=M.end();q++)
	{
		q->Trace();
	}
	return true;
}
Beispiel #5
0
bool CMOOSApp::LookForAndHandleAppCommand(MOOSMSG_LIST & NewMail)
{
    MOOSMSG_LIST::iterator q;
    bool bResult = true;
    for(q=NewMail.begin();q!=NewMail.end();q++)
    {
        if(MOOSStrCmp(q->GetKey(),GetCommandKey()))
        {
            //give a derived class a chance to respond
            bResult&= OnCommandMsg(*q);
        }
    }
    return bResult;
}
void moossafir::SimDriver::do_work()
{
    MOOSMSG_LIST msgs;
    if(moos_client_.Fetch(msgs))
    {
        for(MOOSMSG_LIST::iterator it = msgs.begin(),
                end = msgs.end(); it != end; ++it)
        {
            const std::string& in_moos_var = driver_cfg_.GetExtension(moossafir::Config::incoming_moos_var);
            if(it->GetKey() == in_moos_var)
            {
                const std::string& value = it->GetString();
                
                glog.is(DEBUG1) &&
                    glog << group(glog_in_group())  << in_moos_var << ": " << value  << std::endl;
                goby::acomms::protobuf::ModemRaw in_raw;
                in_raw.set_raw(value);
                ModemDriverBase::signal_raw_incoming(in_raw);

                try
                {
                    goby::acomms::protobuf::ModemTransmission m;
                    std::string data;
                    int id;
                    if(goby::moos::val_from_string(data, value, "data"))
                        m.add_frame(dccl::hex_decode(data));

                    if(!goby::moos::val_from_string(id, value, "modem_id"))
                        throw(std::runtime_error("No `modem_id` field"));

                    m.set_src(id);
                    receive_message(m);
                }
                catch(std::exception& e)
                {
                    glog.is(DEBUG1) &&
                        glog << group(glog_in_group())  << warn << "Failed to parse incoming  message: " << e.what() << std::endl;
                }                
            }            
        }
    }
} 
Beispiel #7
0
	bool OnNewMail(MOOSMSG_LIST & Mail){
		//process it
		MOOSMSG_LIST::iterator q;
		for(q=Mail.begin();q!=Mail.end();q++)
		{
			//are we a ponger
			if(q->GetKey()=="ex1010-ping")
				Notify("ex1010-pong",q->GetDouble());

			if(q->GetKey()=="ex1010-pong"){
				double latency =(MOOSLocalTime()-q->GetDouble())/2;
				mean_latency_+= latency;
				if(count_>2)//this simply removes case of stale data in DB
					max_latency_ = std::max(latency,max_latency_);
				if(count_<burstsize_-1)
					Notify("ex1010-ping",MOOSLocalTime());
			}
			count_++;
		}
		return true;
	}
Beispiel #8
0
bool NodeManager::OnNewMail(MOOSMSG_LIST &NewMail)
{
  MOOSMSG_LIST::iterator p;

  for(p=NewMail.begin(); p!=NewMail.end(); p++) {
    CMOOSMsg &msg = *p;

    if (msg.GetKey() == "NAV_LAT") {
      m_node_lat = msg.GetDouble();
      m_lat_set = true;
    } else if (msg.GetKey() == "NAV_LONG") {
      m_node_lon = msg.GetDouble();
      m_lon_set = true;
    } else if (msg.GetKey() == "MSEASOCEANMODEL_RETURN") {
      int num_values = p->GetBinaryDataSize()/sizeof(double);
      int num_rows = num_values;
      Matrix a(num_rows, 1);
      double *a_data = a.fortran_vec();
      memcpy(a_data, p->GetBinaryData(), p->GetBinaryDataSize());
      m_model_values_return = a;
      double drift_x = m_model_values_return(0)/100;  //MSEAS model velocity data is in cm/s
      double drift_y = m_model_values_return(1)/100;
      m_Comms.Notify("DRIFT_X", drift_x);
      m_Comms.Notify("DRIFT_Y", drift_y);
    }

#if 0 // Keep these around just for template
    string key   = msg.GetKey();
    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
   }

   return(true);
}
/** OnNewMail */
bool CImageGrabberApp::OnNewMail(MOOSMSG_LIST &NewMail)
{
	std::string cad;
	for(MOOSMSG_LIST::iterator i = NewMail.begin(); i != NewMail.end(); ++i)
	{
		if( (i->GetName()=="SHUTDOWN") && (MOOSStrCmp(i->GetString(),"true")) )
		{
			// Disconnect comms:
			MOOSTrace("Closing Module \n");
			this->RequestQuit();
		}
		if( (i->GetName()=="IMG_GRABBER_CMD") )	// process command to the grabber, typically: start or stop to grab
		{
			VERBOSE_LEVEL(2) << "[pImageGrabber -- INFO] Received Command: " << i->GetString().c_str() << endl;

			std::deque<std::string> lista;
			mrpt::system::tokenize( i->GetString(), " ", lista );

			cad = MOOSToLower( lista[0].c_str() );
			if( MOOSStrCmp(cad,"start") )
			{
				if( !m_start_grabbing )
				{
					m_grabbed_images_counter = 0;	// reset counter of grabbed images
					m_start_grabbing = true;
					VERBOSE_LEVEL(1) << "[pImageGrabber -- INFO] Image recording started." << endl;
				} // end-start-grabbing
			}
			else if( MOOSStrCmp(cad,"stop") )
			{
				if( m_start_grabbing )
				{
					m_start_grabbing = false;
					VERBOSE_LEVEL(1) << "[pImageGrabber -- INFO] Image recording stopped." << endl;
				} // end-stop-grabbing
			}
			else VERBOSE_LEVEL(0) << "[pImageGrabber -- INFO] Command not recognized: " << cad << endl;
		}
	}
    UpdateMOOSVariables(NewMail);
    return true;
} // end-OnNewMail
bool CMOOSCommClient::DispatchInBoxToActiveThreads()
{


	//here we dispatch to special callbacks managed by threads

	MOOS::ScopedLock L(ActiveQueuesLock_);


	//before we start we can see if we have a default queue installed...
	std::map<std::string, std::set<std::string> >::iterator q;

	MOOSMSG_LIST::iterator t = m_InBox.begin();

	//iterate over all pending messages.
	while(t!=m_InBox.end())
	{

//	    std::cerr<<"Inbox size:"<<m_InBox.size()<<"\n";
//	    t->Trace();

		//does this message have a active queue mapping?
		q= Msg2ActiveQueueName_.find(t->GetKey());

		//have we ever checked this message against the wildcard queues?
		std::set<std::string>::iterator u  =  WildcardCheckSet_.find(t->GetKey());

		if(q==Msg2ActiveQueueName_.end() || u==WildcardCheckSet_.end() )
		{
			//maybe the wildcard queues are interested?
			//or maybe this is a new message whihc has not been seen by wildcard queues

			//each element is a <nickname,pattern> string pair;
			std::map<std::string, std::string  >::iterator w;

			bool bFoundWCMatch = false;
			for(w = WildcardQueuePatterns_.begin();w!=WildcardQueuePatterns_.end();w++)
			{
				std::string sPattern = w->second;
				//build a list of all wc queues that match this message
				//add these queues to the list of queues pointed to by this message
				if(MOOSWildCmp(sPattern,t->GetKey()))
				{
//				    std::cerr<<"found wildcard match adding queue  "<<w->first
//				            <<" to routing for "<<t->GetKey()<<"\n";

					Msg2ActiveQueueName_[t->GetKey()].insert(w->first);
					bFoundWCMatch = true;
				}
			}

			//remember all messages that have been received...
			//we do it here because at this point wild card queue have been given
			//the option to register their interest....
			//but what to do if a wc queue in installed at run time...?
			WildcardCheckSet_.insert(t->GetKey());

			//std::cerr<<"added key"<<t->GetKey()<<" to wildcard chacek set\n";

			//if we found a least one mapping simply go again without
			//incrementing t...smart
			if(bFoundWCMatch)
			{
			    continue;
			}
			else
			{
			    if(q==Msg2ActiveQueueName_.end())
			    {
			        //wildcard queues are not interested
			        //no standard queue is interested
			        //nothing to do....
			        return true;
			    }
			}
		}

		//now we know which queue(s) are relevant for us.
		//there namaes are in a string list.
		std::set<std::string>::iterator r;

		bool bPickedUpByActiveQueue = false;
		for(r = q->second.begin();r!=q->second.end();r++)
		{

//		    std::cerr<<"found queue that is relevent "<<*r<<"\n";

		    //for each named queue find a pointer to
			//the actual active queue
			std::map<std::string,MOOS::ActiveMailQueue*>::iterator v;
			v = ActiveQueueMap_.find(*r);
			if(v!=ActiveQueueMap_.end())
			{
				//and now we have checked it exists push this message to that
				//queue
                MOOS::ActiveMailQueue* pQ = v->second;
//                std::cerr<<"pushing to queue: "<<(void*)pQ<<"\n";
                bPickedUpByActiveQueue = true;
				pQ->Push(*t);
			}
			else
			{
				//this is bad news - we have be told to use a queue
				//which does not exist.
			    //std::cerr<<"WTF\n";
				throw std::runtime_error("active queue "+*r+" not found");
			}
		}


		if(bPickedUpByActiveQueue)
		{
	        //we have now handled this message remove it from the Inbox.
		    MOOSMSG_LIST::iterator to_erase = t;
		    ++t;
		    m_InBox.erase(to_erase);
		}
		else
		{
		    ++t;
		}
	}

	return true;
}