示例#1
0
/** 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
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;
                }                
            }            
        }
    }
}