virtual const gnuradar::ResponseMessage Execute( gnuradar::ControlMessage& msg ){ gnuradar::ResponseMessage response_msg; try{ // reset any existing configuration producer_.reset(); consumer_.reset(); bufferManager_.reset(); hdf5_.reset(); array_.clear(); gnuradar::File* file = msg.mutable_file(); // standardizes units of input file. gr_helper::FormatFileFromMessage( file ); gnuradar::RadarParameters* rp = file->mutable_radarparameters(); // setup shared buffer header to assist in real-time processing header_ = SharedBufferHeaderPtr ( new ::yml::SharedBufferHeader ( constants::NUM_BUFFERS, rp->bytesperbuffer(), file->samplerate(), file->numchannels(), rp->prisperbuffer(), rp->samplesperbuffer() ) ); // setup gnuradar settings pointer GnuRadarSettingsPtr settings( new GnuRadarSettings() ); // read and parse configuration file-> GetSettings( settings, file ); // create a device to communicate with hardware GnuRadarDevicePtr gnuRadarDevice( new GnuRadarDevice( settings ) ); // make sure we don't have an existing data set if( gr_helper::HdfFileExists( file->basefilename() )) { throw std::runtime_error( "HDF5 File set " + fileName + " exists and cannot be overwritten. Change your " "base file set name and try again"); } // setup HDF5 attributes and file->set. hdf5_ = SetupHDF5( file ); // setup shared memory buffers CreateSharedBuffers( rp->bytesperbuffer() ); // setup the buffer manager bufferManager_ = SynchronizedBufferManagerPtr( new SynchronizedBufferManager( array_, constants::NUM_BUFFERS, rp->bytesperbuffer()) ); // setup table dimensions column = samples per ipp , row = IPP number std::vector<hsize_t> dims; dims.push_back(rp->prisperbuffer()); dims.push_back (static_cast<int> (rp->samplesperpri())); // setup producer thread producer_ = gnuradar::ProducerThreadPtr ( new ProducerThread ( bufferManager_, gnuRadarDevice ) ); // flush header information header_->Write(0,0,0); // setup consumer thread consumer_ = gnuradar::ConsumerThreadPtr( new ConsumerThread ( bufferManager_ , header_, hdf5_, dims ) ); // new model pcModel_->Initialize( bufferManager_, producer_, consumer_); // start producer thread pcModel_->Start(); response_msg.set_value(gnuradar::ResponseMessage::OK); response_msg.set_message("Data collection successfully started."); // Start status thread to broadcast status packets to any subscribers. if( statusServer_->IsActive() == false ) { statusServer_->Start(); } std::cout << "System is running..." << std::endl; } catch( std::runtime_error& e ){ response_msg.set_value(gnuradar::ResponseMessage::ERROR); response_msg.set_message(e.what()); } catch( H5::Exception& e ){ response_msg.set_value(gnuradar::ResponseMessage::ERROR); response_msg.set_message(e.getDetailMsg()); } return response_msg; }
virtual const std::string Execute( const xml::XmlPacketArgs& args ) { // reset any existing configuration producer_.reset(); consumer_.reset(); bufferManager_.reset(); hdf5_.reset(); array_.clear(); std::string response; std::string xml_data = command::ParseArg( "file", args ); // incoming "file" is self-contained xml data. bool data_is_xml = true; xml_data = xml::XmlPacket::DecodeXml( xml_data ); // parse configuration file ConfigFile configFile( xml_data, data_is_xml ); // create constants const int BUFFER_SIZE = configFile.BytesPerSecond(); const double SAMPLE_RATE = configFile.SampleRate(); const int NUM_CHANNELS = configFile.NumChannels(); const int IPPS_PER_BUFFER = static_cast<int>( ceil(1.0/configFile.IPP())); const int SAMPLES_PER_BUFFER = static_cast<int> ( configFile.SamplesPerIpp() * configFile.NumChannels() ); // setup shared buffer header to assist in real-time processing header_ = SharedBufferHeaderPtr( new ::xml::SharedBufferHeader( constants::NUM_BUFFERS, BUFFER_SIZE, SAMPLE_RATE, NUM_CHANNELS, IPPS_PER_BUFFER, SAMPLES_PER_BUFFER )); // create a response packet and return to requester std::string destination = command::ParseArg( "source", args ); xml::XmlPacketArgs responsePacket; responsePacket["destination"] = destination; responsePacket["type"] = "response"; gnuradar::xml::XmlPacket packet("gnuradar_server"); try{ // make sure we don't have an existing data set CheckForExistingFileSet ( configFile.DataFileBaseName() ) ; // setup HDF5 attributes and file set. hdf5_ = SetupHDF5( configFile ); // read and parse configuration file. GnuRadarSettingsPtr settings = GetSettings( configFile ); // create a device to communicate with hardware GnuRadarDevicePtr gnuRadarDevice( new GnuRadarDevice( settings ) ); // setup shared memory buffers CreateSharedBuffers( BUFFER_SIZE ); // setup the buffer manager bufferManager_ = SynchronizedBufferManagerPtr( new SynchronizedBufferManager( array_, constants::NUM_BUFFERS, BUFFER_SIZE) ); // setup table dimensions column = samples per ipp , row = IPP number vector<hsize_t> dims; dims.push_back( IPPS_PER_BUFFER ); dims.push_back ( static_cast<int> ( configFile.SamplesPerIpp() * configFile.NumChannels() ) ); // setup producer thread producer_ = gnuradar::ProducerThreadPtr ( new ProducerThread ( bufferManager_, gnuRadarDevice ) ); // flush header information header_->Close(); // setup consumer thread consumer_ = gnuradar::ConsumerThreadPtr( new ConsumerThread ( bufferManager_ , header_, hdf5_, dims ) ); // new model pcModel_->Initialize( bufferManager_, producer_, consumer_); // start producer thread pcModel_->Start(); responsePacket["value"] = "OK"; responsePacket["message"] = "Data collection successfully started."; response = packet.Format( responsePacket ); // Start status thread to broadcast status packets to any subscribers. statusThread_->Stop(); statusThread_->Start(); } catch( std::runtime_error& e ){ responsePacket["value"] = "ERROR"; responsePacket["message"] = e.what(); response = packet.Format( responsePacket ); } catch( H5::Exception& e ){ responsePacket["value"] = "ERROR"; responsePacket["message"] = e.getDetailMsg(); response = packet.Format( responsePacket ); } return response; }
Hdf5Ptr SetupHDF5( gnuradar::File* file ) throw( H5::Exception ) { Hdf5Ptr h5File_( new HDF5 ( file->basefilename() , hdf5::WRITE ) ); h5File_->Description ( "GnuRadar Software" + file->version() ); h5File_->WriteStrAttrib ( "START_TIME", currentTime.GetTime() ); h5File_->WriteStrAttrib ( "INSTRUMENT", file->receiver() ); h5File_->WriteAttrib<int> ( "CHANNELS", file->numchannels(), H5::PredType::NATIVE_INT, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "SAMPLE_RATE", file->samplerate(), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "BANDWIDTH", file->bandwidth(), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); h5File_->WriteAttrib<int> ( "DECIMATION", file->decimation(), H5::PredType::NATIVE_INT, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "OUTPUT_RATE", file->outputrate(), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "IPP", file->pri(), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "RF", file->txcarrier() , H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); for ( int i = 0; i < file->numchannels(); ++i ) { h5File_->WriteAttrib<double> ( "DDC" + lexical_cast<string> ( i ), file->channel(i).frequency(), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "PHASE" + lexical_cast<string> ( i ), file->channel(i).phase(), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); } h5File_->WriteAttrib<int> ( "SAMPLE_WINDOWS", file->window_size(), H5::PredType::NATIVE_INT, H5::DataSpace() ); for ( int i = 0; i < file->window_size(); ++i ) { // TODO: Window Renaming scheme - 10/19/2010 // Standardize window naming and add the user-defined // window name as a separate attribute. string idx = boost::lexical_cast<string> ( i ); h5File_->WriteAttrib<int> ( "RxWin"+ idx + "_START", file->window(i).start(), H5::PredType::NATIVE_INT, H5::DataSpace() ); h5File_->WriteAttrib<int> ( "RxWin" + idx + "_STOP", file->window(i).stop(), H5::PredType::NATIVE_INT, H5::DataSpace() ); // update gnuradar shared buffer header header_->AddWindow( file->window(i).name(), file->window(i).start(), file->window(i).stop() ); } return h5File_; }
Hdf5Ptr SetupHDF5( ConfigFile& configuration ) throw( H5::Exception ) { std::string fileSet = configuration.DataFileBaseName(); Hdf5Ptr h5File_( new HDF5 ( fileSet , hdf5::WRITE ) ); h5File_->Description ( "GnuRadar Software" + configuration.Version() ); h5File_->WriteStrAttrib ( "START_TIME", currentTime.GetTime() ); h5File_->WriteStrAttrib ( "INSTRUMENT", configuration.Receiver() ); h5File_->WriteAttrib<int> ( "CHANNELS", configuration.NumChannels(), H5::PredType::NATIVE_INT, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "SAMPLE_RATE", configuration.SampleRate(), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "BANDWIDTH", configuration.Bandwidth(), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); h5File_->WriteAttrib<int> ( "DECIMATION", configuration.Decimation(), H5::PredType::NATIVE_INT, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "OUTPUT_RATE", configuration.OutputRate(), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "IPP", configuration.IPP(), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "RF", configuration.TxCarrier() , H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); for ( int i = 0; i < configuration.NumChannels(); ++i ) { h5File_->WriteAttrib<double> ( "DDC" + lexical_cast<string> ( i ), configuration.DDC ( i ), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); h5File_->WriteAttrib<double> ( "PHASE" + lexical_cast<string> ( i ), configuration.Phase ( i ), H5::PredType::NATIVE_DOUBLE, H5::DataSpace() ); } h5File_->WriteAttrib<int> ( "SAMPLE_WINDOWS", configuration.NumWindows(), H5::PredType::NATIVE_INT, H5::DataSpace() ); for ( int i = 0; i < configuration.NumWindows(); ++i ) { // TODO: Window Renaming scheme - 10/19/2010 // Standardize window naming and add the user-defined // window name as a separate attribute. h5File_->WriteAttrib<int> ( configuration.WindowName ( i ) + "_START", configuration.WindowStart ( i ), H5::PredType::NATIVE_INT, H5::DataSpace() ); h5File_->WriteAttrib<int> ( configuration.WindowName ( i ) + "_STOP", configuration.WindowStop ( i ), H5::PredType::NATIVE_INT, H5::DataSpace() ); // update gnuradar shared buffer header header_->AddWindow( configuration.WindowName(i), configuration.WindowStart(i), configuration.WindowStop(i) ); } return h5File_; }