mirror of
				https://github.com/gnss-sdr/gnss-sdr
				synced 2025-10-30 14:53:03 +00:00 
			
		
		
		
	Stop the Labsat_Signal_Source when the end of file is reached. This allows to use this source for automated testing.
Now the block also accepts directly *.ls2 names in filename parameter Remove samples parameter, it was not used. This source reads the full file(s). Make labsat23_source constructor private, so only the smart pointer wrapper can be called
This commit is contained in:
		| @@ -40,21 +40,20 @@ LabsatSignalSource::LabsatSignalSource(ConfigurationInterface* configuration, | ||||
|     const std::string& role, unsigned int in_stream, unsigned int out_stream, gr::msg_queue::sptr queue) : role_(role), in_stream_(in_stream), out_stream_(out_stream), queue_(std::move(queue)) | ||||
| { | ||||
|     std::string default_item_type = "gr_complex"; | ||||
|     std::string default_dump_file = "./data/source.bin"; | ||||
|     std::string default_dump_file = "./labsat_output.dat"; | ||||
|     item_type_ = configuration->property(role + ".item_type", default_item_type); | ||||
|     dump_ = configuration->property(role + ".dump", false); | ||||
|     dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); | ||||
|  | ||||
|     int channel_selector = configuration->property(role + ".selected_channel", 1); | ||||
|     std::string default_filename = "./example_capture.LS3"; | ||||
|  | ||||
|     samples_ = configuration->property(role + ".samples", 0); | ||||
|     std::string default_filename = "./example_capture.LS3"; | ||||
|     filename_ = configuration->property(role + ".filename", default_filename); | ||||
|  | ||||
|     if (item_type_ == "gr_complex") | ||||
|         { | ||||
|             item_size_ = sizeof(gr_complex); | ||||
|             labsat23_source_ = labsat23_make_source(filename_.c_str(), channel_selector); | ||||
|             labsat23_source_ = labsat23_make_source_sptr(filename_.c_str(), channel_selector, queue_); | ||||
|             DLOG(INFO) << "Item size " << item_size_; | ||||
|             DLOG(INFO) << "labsat23_source_(" << labsat23_source_->unique_id() << ")"; | ||||
|         } | ||||
|   | ||||
| @@ -81,7 +81,6 @@ private: | ||||
|     unsigned int out_stream_; | ||||
|     std::string item_type_; | ||||
|     size_t item_size_; | ||||
|     uint64_t samples_; | ||||
|     std::string filename_; | ||||
|     bool dump_; | ||||
|     std::string dump_filename_; | ||||
|   | ||||
| @@ -64,6 +64,7 @@ target_link_libraries(signal_source_gr_blocks | ||||
|         Gnuradio::runtime | ||||
|         signal_source_libs | ||||
|     PRIVATE | ||||
|         core_receiver | ||||
|         Gflags::gflags | ||||
|         Glog::glog | ||||
| ) | ||||
|   | ||||
| @@ -30,30 +30,25 @@ | ||||
|  | ||||
|  | ||||
| #include "labsat23_source.h" | ||||
| #include "control_message_factory.h" | ||||
| #include <gnuradio/io_signature.h> | ||||
| #include <exception> | ||||
| #include <iostream> | ||||
| #include <sstream> | ||||
|  | ||||
|  | ||||
| labsat23_source_sptr labsat23_make_source(const char *signal_file_basename, int channel_selector) | ||||
| labsat23_source_sptr labsat23_make_source_sptr(const char *signal_file_basename, int channel_selector, gr::msg_queue::sptr queue) | ||||
| { | ||||
|     return labsat23_source_sptr(new labsat23_source(signal_file_basename, channel_selector)); | ||||
| } | ||||
|  | ||||
|  | ||||
| std::string labsat23_source::generate_filename() | ||||
| { | ||||
|     std::ostringstream ss; | ||||
|     ss << std::setw(4) << std::setfill('0') << d_current_file_number; | ||||
|     return d_signal_file_basename + "_" + ss.str() + ".LS3"; | ||||
|     return labsat23_source_sptr(new labsat23_source(signal_file_basename, channel_selector, queue)); | ||||
| } | ||||
|  | ||||
|  | ||||
| labsat23_source::labsat23_source(const char *signal_file_basename, | ||||
|     int channel_selector) : gr::block("labsat23_source", | ||||
|     int channel_selector, | ||||
|     gr::msg_queue::sptr queue) : gr::block("labsat23_source", | ||||
|                                      gr::io_signature::make(0, 0, 0), | ||||
|                                 gr::io_signature::make(1, 1, sizeof(gr_complex))) | ||||
|                                      gr::io_signature::make(1, 1, sizeof(gr_complex))), | ||||
|                                  d_queue(queue) | ||||
| { | ||||
|     if (channel_selector < 1 or channel_selector > 2) | ||||
|         { | ||||
| @@ -108,6 +103,25 @@ labsat23_source::~labsat23_source() | ||||
| } | ||||
|  | ||||
|  | ||||
| std::string labsat23_source::generate_filename() | ||||
| { | ||||
|     if (d_signal_file_basename.substr(d_signal_file_basename.length() - 4, 4) == ".ls2" or d_signal_file_basename.substr(d_signal_file_basename.length() - 4, 4) == ".LS2") | ||||
|         { | ||||
|             if (d_current_file_number == 0) | ||||
|                 { | ||||
|                     return d_signal_file_basename; | ||||
|                 } | ||||
|             else | ||||
|                 { | ||||
|                     return std::string("donotexist");  // just to stop processing | ||||
|                 } | ||||
|         } | ||||
|     std::ostringstream ss; | ||||
|     ss << std::setw(4) << std::setfill('0') << d_current_file_number; | ||||
|     return d_signal_file_basename + "_" + ss.str() + ".LS3"; | ||||
| } | ||||
|  | ||||
|  | ||||
| int labsat23_source::getBit(uint8_t byte, int position) | ||||
| { | ||||
|     return (byte >> position) & 0x01; | ||||
| @@ -129,7 +143,7 @@ void labsat23_source::decode_samples_one_channel(int16_t input_short, gr_complex | ||||
|                 } | ||||
|             break; | ||||
|         case 4: | ||||
|             //four bits per sample, 4 samples per int16 | ||||
|             //  bits per sample, 4 samples per int16 | ||||
|             for (int i = 0; i < 4; i++) | ||||
|                 { | ||||
|                     out[i] = gr_complex(0.0, 0.0); | ||||
| @@ -388,7 +402,6 @@ int labsat23_source::general_work(int noutput_items, | ||||
|             return -1; | ||||
|         } | ||||
|  | ||||
|  | ||||
|     // ready to start reading samples | ||||
|     switch (d_bits_per_sample) | ||||
|         { | ||||
| @@ -419,8 +432,10 @@ int labsat23_source::general_work(int noutput_items, | ||||
|                                     } | ||||
|  | ||||
|                                 // trigger the read of the next file in the sequence | ||||
|                                 if (d_labsat_version == 3) | ||||
|                                     { | ||||
|                                         std::cout << "End of current file, reading the next Labsat file in sequence: " << generate_filename() << std::endl; | ||||
|  | ||||
|                                     } | ||||
|                                 d_current_file_number++; | ||||
|                                 binary_input_file->close(); | ||||
|                                 binary_input_file->open(generate_filename().c_str(), std::ios::in | std::ios::binary); | ||||
| @@ -429,8 +444,18 @@ int labsat23_source::general_work(int noutput_items, | ||||
|                                         std::cout << "Labsat file source is reading samples from " << generate_filename() << std::endl; | ||||
|                                     } | ||||
|                                 else | ||||
|                                     { | ||||
|                                         if (d_labsat_version == 3) | ||||
|                                             { | ||||
|                                                 std::cout << "Last file reached, LabSat source stop" << std::endl; | ||||
|                                             } | ||||
|                                         else | ||||
|                                             { | ||||
|                                                 std::cout << "End of file reached, LabSat source stop" << std::endl; | ||||
|                                             } | ||||
|                                         auto *cmf = new ControlMessageFactory(); | ||||
|                                         d_queue->handle(cmf->GetQueueMessage(200, 0)); | ||||
|                                         delete cmf; | ||||
|                                         return -1; | ||||
|                                     } | ||||
|                             } | ||||
| @@ -468,8 +493,10 @@ int labsat23_source::general_work(int noutput_items, | ||||
|                                     } | ||||
|  | ||||
|                                 // trigger the read of the next file in the sequence | ||||
|                                 if (d_labsat_version == 3) | ||||
|                                     { | ||||
|                                         std::cout << "End of current file, reading the next Labsat file in sequence: " << generate_filename() << std::endl; | ||||
|  | ||||
|                                     } | ||||
|                                 d_current_file_number++; | ||||
|                                 binary_input_file->close(); | ||||
|                                 binary_input_file->open(generate_filename().c_str(), std::ios::in | std::ios::binary); | ||||
| @@ -478,8 +505,18 @@ int labsat23_source::general_work(int noutput_items, | ||||
|                                         std::cout << "Labsat file source is reading samples from " << generate_filename() << std::endl; | ||||
|                                     } | ||||
|                                 else | ||||
|                                     { | ||||
|                                         if (d_labsat_version == 3) | ||||
|                                             { | ||||
|                                                 std::cout << "Last file reached, LabSat source stop" << std::endl; | ||||
|                                             } | ||||
|                                         else | ||||
|                                             { | ||||
|                                                 std::cout << "End of file reached, LabSat source stop" << std::endl; | ||||
|                                             } | ||||
|                                         auto *cmf = new ControlMessageFactory(); | ||||
|                                         d_queue->handle(cmf->GetQueueMessage(200, 0)); | ||||
|                                         delete cmf; | ||||
|                                         return -1; | ||||
|                                     } | ||||
|                             } | ||||
|   | ||||
| @@ -32,6 +32,7 @@ | ||||
| #define GNSS_SDR_LABSAT23_SOURCE_H | ||||
|  | ||||
| #include <gnuradio/block.h> | ||||
| #include <gnuradio/msg_queue.h>  // for msg_queue, msg_queue::sptr | ||||
| #include <cstdint> | ||||
| #include <fstream> | ||||
| #include <string> | ||||
| @@ -41,7 +42,7 @@ class labsat23_source; | ||||
|  | ||||
| using labsat23_source_sptr = boost::shared_ptr<labsat23_source>; | ||||
|  | ||||
| labsat23_source_sptr labsat23_make_source(const char *signal_file_basename, int channel_selector); | ||||
| labsat23_source_sptr labsat23_make_source_sptr(const char *signal_file_basename, int channel_selector, gr::msg_queue::sptr queue); | ||||
|  | ||||
| /*! | ||||
|  * \brief This class implements conversion between Labsat2 and 3 format byte packet samples to gr_complex | ||||
| @@ -49,7 +50,8 @@ labsat23_source_sptr labsat23_make_source(const char *signal_file_basename, int | ||||
| class labsat23_source : public gr::block | ||||
| { | ||||
| private: | ||||
|     friend labsat23_source_sptr labsat23_make_source_sptr(const char *signal_file_basename, int channel_selector); | ||||
|     friend labsat23_source_sptr labsat23_make_source_sptr(const char *signal_file_basename, int channel_selector, gr::msg_queue::sptr queue); | ||||
|     labsat23_source(const char *signal_file_basename, int channel_selector, gr::msg_queue::sptr queue); | ||||
|     std::string generate_filename(); | ||||
|     void decode_samples_one_channel(int16_t input_short, gr_complex *out, int type); | ||||
|     int getBit(uint8_t byte, int position); | ||||
| @@ -62,9 +64,9 @@ private: | ||||
|     std::ifstream *binary_input_file; | ||||
|     uint8_t d_ref_clock; | ||||
|     uint8_t d_bits_per_sample; | ||||
|     gr::msg_queue::sptr d_queue; | ||||
|  | ||||
| public: | ||||
|     labsat23_source(const char *signal_file_basename, int channel_selector); | ||||
|     ~labsat23_source(); | ||||
|     int general_work(int noutput_items, | ||||
|         gr_vector_int &ninput_items, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Carles Fernandez
					Carles Fernandez