diff --git a/apps/flowgraphs/satellites/noaa_apt_decoder.grc b/apps/flowgraphs/satellites/noaa_apt_decoder.grc index ae59fce..0831399 100644 --- a/apps/flowgraphs/satellites/noaa_apt_decoder.grc +++ b/apps/flowgraphs/satellites/noaa_apt_decoder.grc @@ -1,5 +1,5 @@ - + Mon Apr 10 23:26:02 2017 @@ -72,6 +72,10 @@ run True + + sizing_mode + fixed + thread_safe_setters @@ -80,6 +84,10 @@ title NOAA APT Decoder + + placement + (0,0) + variable @@ -370,6 +378,10 @@ TX sampling rate short_id + + hide + none + type string @@ -492,6 +504,10 @@ TX sampling rate short_id + + hide + none + type eng_float @@ -578,6 +594,10 @@ TX sampling rate short_id + + hide + none + type string @@ -621,6 +641,10 @@ TX sampling rate short_id + + hide + none + type string @@ -664,6 +688,10 @@ TX sampling rate short_id + + hide + none + type intx @@ -707,6 +735,10 @@ TX sampling rate short_id + + hide + none + type intx @@ -809,6 +841,10 @@ TX sampling rate short_id + + hide + none + type string @@ -889,7 +925,7 @@ TX sampling rate _coordinate - (472, 716) + (312, 716) _rotation @@ -907,6 +943,10 @@ TX sampling rate short_id + + hide + none + type intx @@ -1060,6 +1100,10 @@ TX sampling rate short_id + + hide + none + type eng_float @@ -1103,6 +1147,10 @@ TX sampling rate short_id + + hide + none + type string @@ -1147,6 +1195,10 @@ we shift the LO a little further short_id + + hide + none + type eng_float @@ -2597,6 +2649,10 @@ we shift the LO a little further short_id + + hide + none + type intx @@ -2876,6 +2932,10 @@ we shift the LO a little further short_id + + hide + none + type eng_float @@ -2919,6 +2979,10 @@ we shift the LO a little further short_id + + hide + none + type intx @@ -2962,6 +3026,10 @@ we shift the LO a little further short_id + + hide + none + type eng_float @@ -3005,6 +3073,10 @@ we shift the LO a little further short_id + + hide + none + type string @@ -3034,7 +3106,7 @@ we shift the LO a little further _coordinate - (471, 119) + (464, 176) _rotation @@ -3148,16 +3220,12 @@ we shift the LO a little further height - 1500 + 1800 width 2080 - - split - bool(split_images) - sync bool(sync) @@ -3320,49 +3388,6 @@ we shift the LO a little further samp_rate_rx/ ( first_stage_decimation * int(samp_rate_rx/ first_stage_decimation / initial_bandwidth)) - - parameter - - alias - - - - comment - - - - _enabled - True - - - _coordinate - (304, 716) - - - _rotation - 0 - - - id - split_images - - - label - - - - short_id - - - - type - intx - - - value - 0 - - parameter @@ -3397,6 +3422,10 @@ we shift the LO a little further short_id + + hide + none + type intx @@ -3440,6 +3469,10 @@ we shift the LO a little further short_id + + hide + none + type string diff --git a/apps/flowgraphs/satellites/satnogs_noaa_apt_decoder.py b/apps/flowgraphs/satellites/satnogs_noaa_apt_decoder.py index 5b3ac59..e6a2a5c 100755 --- a/apps/flowgraphs/satellites/satnogs_noaa_apt_decoder.py +++ b/apps/flowgraphs/satellites/satnogs_noaa_apt_decoder.py @@ -5,7 +5,7 @@ # Title: NOAA APT Decoder # Author: Manolis Surligas, George Vardakis # Description: A NOAA APT Decoder with automatic image synchronization -# Generated: Fri Jan 19 21:55:37 2018 +# Generated: Fri Feb 2 16:19:42 2018 ################################################## from gnuradio import analog @@ -23,7 +23,7 @@ import time class satnogs_noaa_apt_decoder(gr.top_block): - def __init__(self, antenna=satnogs.not_set_antenna, bb_gain=satnogs.not_set_rx_bb_gain, decoded_data_file_path='/tmp/.satnogs/data/noaa', dev_args=satnogs.not_set_dev_args, doppler_correction_per_sec=20, enable_iq_dump=0, file_path='/tmp/test.ogg', flip_images=0, if_gain=satnogs.not_set_rx_if_gain, iq_file_path='/tmp/iq.dat', lo_offset=100e3, ppm=0, rf_gain=satnogs.not_set_rx_rf_gain, rigctl_port=4532, rx_freq=90.4e6, rx_sdr_device='usrpb200', split_images=0, sync=1, waterfall_file_path='/tmp/waterfall.dat'): + def __init__(self, antenna=satnogs.not_set_antenna, bb_gain=satnogs.not_set_rx_bb_gain, decoded_data_file_path='/tmp/.satnogs/data/noaa', dev_args=satnogs.not_set_dev_args, doppler_correction_per_sec=20, enable_iq_dump=0, file_path='/tmp/test.ogg', flip_images=0, if_gain=satnogs.not_set_rx_if_gain, iq_file_path='/tmp/iq.dat', lo_offset=100e3, ppm=0, rf_gain=satnogs.not_set_rx_rf_gain, rigctl_port=4532, rx_freq=90.4e6, rx_sdr_device='usrpb200', sync=1, waterfall_file_path='/tmp/waterfall.dat'): gr.top_block.__init__(self, "NOAA APT Decoder") ################################################## @@ -45,7 +45,6 @@ class satnogs_noaa_apt_decoder(gr.top_block): self.rigctl_port = rigctl_port self.rx_freq = rx_freq self.rx_sdr_device = rx_sdr_device - self.split_images = split_images self.sync = sync self.waterfall_file_path = waterfall_file_path @@ -69,7 +68,7 @@ class satnogs_noaa_apt_decoder(gr.top_block): self.satnogs_waterfall_sink_0 = satnogs.waterfall_sink(samp_rate_rx/ ( first_stage_decimation * int(samp_rate_rx/ first_stage_decimation / initial_bandwidth)), 0.0, 8, 1024, waterfall_file_path, 0) self.satnogs_tcp_rigctl_msg_source_0 = satnogs.tcp_rigctl_msg_source("127.0.0.1", rigctl_port, False, 1000/doppler_correction_per_sec, 1500) self.satnogs_ogg_encoder_0 = satnogs.ogg_encoder(file_path, 48000, 0.8) - self.satnogs_noaa_apt_sink_0 = satnogs.noaa_apt_sink(decoded_data_file_path, 2080, 1500, bool(split_images), bool(sync), bool(flip_images)) + self.satnogs_noaa_apt_sink_0 = satnogs.noaa_apt_sink(decoded_data_file_path, 2080, 1800, bool(sync), bool(flip_images)) self.satnogs_iq_sink_0 = satnogs.iq_sink(32767, iq_file_path, False, enable_iq_dump) self.satnogs_coarse_doppler_correction_cc_0 = satnogs.coarse_doppler_correction_cc(rx_freq, samp_rate_rx /first_stage_decimation) self.rational_resampler_xxx_2 = filter.rational_resampler_ccc( @@ -123,6 +122,8 @@ class satnogs_noaa_apt_decoder(gr.top_block): audio_decimation=audio_decimation, ) + + ################################################## # Connections ################################################## @@ -254,12 +255,6 @@ class satnogs_noaa_apt_decoder(gr.top_block): self.osmosdr_source_0.set_bb_gain(satnogs.handle_rx_bb_gain(self.rx_sdr_device, self.bb_gain), 0) self.osmosdr_source_0.set_antenna(satnogs.handle_rx_antenna(self.rx_sdr_device, self.antenna), 0) - def get_split_images(self): - return self.split_images - - def set_split_images(self, split_images): - self.split_images = split_images - def get_sync(self): return self.sync @@ -368,9 +363,6 @@ def argument_parser(): parser.add_option( "", "--rx-sdr-device", dest="rx_sdr_device", type="string", default='usrpb200', help="Set rx_sdr_device [default=%default]") - parser.add_option( - "", "--split-images", dest="split_images", type="intx", default=0, - help="Set split_images [default=%default]") parser.add_option( "", "--sync", dest="sync", type="intx", default=1, help="Set sync [default=%default]") @@ -384,7 +376,7 @@ def main(top_block_cls=satnogs_noaa_apt_decoder, options=None): if options is None: options, _ = argument_parser().parse_args() - tb = top_block_cls(antenna=options.antenna, bb_gain=options.bb_gain, decoded_data_file_path=options.decoded_data_file_path, dev_args=options.dev_args, doppler_correction_per_sec=options.doppler_correction_per_sec, enable_iq_dump=options.enable_iq_dump, file_path=options.file_path, flip_images=options.flip_images, if_gain=options.if_gain, iq_file_path=options.iq_file_path, lo_offset=options.lo_offset, ppm=options.ppm, rf_gain=options.rf_gain, rigctl_port=options.rigctl_port, rx_freq=options.rx_freq, rx_sdr_device=options.rx_sdr_device, split_images=options.split_images, sync=options.sync, waterfall_file_path=options.waterfall_file_path) + tb = top_block_cls(antenna=options.antenna, bb_gain=options.bb_gain, decoded_data_file_path=options.decoded_data_file_path, dev_args=options.dev_args, doppler_correction_per_sec=options.doppler_correction_per_sec, enable_iq_dump=options.enable_iq_dump, file_path=options.file_path, flip_images=options.flip_images, if_gain=options.if_gain, iq_file_path=options.iq_file_path, lo_offset=options.lo_offset, ppm=options.ppm, rf_gain=options.rf_gain, rigctl_port=options.rigctl_port, rx_freq=options.rx_freq, rx_sdr_device=options.rx_sdr_device, sync=options.sync, waterfall_file_path=options.waterfall_file_path) tb.start() tb.wait() diff --git a/grc/satnogs_noaa_apt_sink.xml b/grc/satnogs_noaa_apt_sink.xml index 7797482..81e7745 100644 --- a/grc/satnogs_noaa_apt_sink.xml +++ b/grc/satnogs_noaa_apt_sink.xml @@ -4,7 +4,7 @@ satnogs_noaa_apt_sink [SatNOGS] import satnogs - satnogs.noaa_apt_sink($*filename_png, $width, $height, $split, $sync, $flip) + satnogs.noaa_apt_sink($*filename_png, $width, $height, $sync, $flip) Output PNG Filename filename_png @@ -22,21 +22,7 @@ height 1500 int - - - Split Images - split - False - bool - - - + Synchronize sync diff --git a/grc/satnogs_noaa_apt_sync.xml b/grc/satnogs_noaa_apt_sync.xml deleted file mode 100644 index 2bf68a0..0000000 --- a/grc/satnogs_noaa_apt_sync.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - noaa_apt_sync - satnogs_noaa_apt_sync - [SatNOGS] - import satnogs - satnogs.noaa_apt_sync($*filename,$*filename_png, $width, $height, $split) - - Output Data Filename - filename - - file_save - - - Output PNG Filename - filename_png - - file_save - - - PNG width - width - int - - - PNG height - height - int - - - Split Images - split - False - bool - part - - - - - in - float - - - diff --git a/include/satnogs/noaa_apt_sink.h b/include/satnogs/noaa_apt_sink.h index 4a931d1..779d083 100644 --- a/include/satnogs/noaa_apt_sink.h +++ b/include/satnogs/noaa_apt_sink.h @@ -68,7 +68,7 @@ namespace gr * */ static sptr - make (const char *filename_png, size_t width, size_t height, bool split, + make (const char *filename_png, size_t width, size_t height, bool sync, bool flip); }; diff --git a/lib/noaa_apt_sink_impl.cc b/lib/noaa_apt_sink_impl.cc index 45f627b..b2b4d6e 100644 --- a/lib/noaa_apt_sink_impl.cc +++ b/lib/noaa_apt_sink_impl.cc @@ -60,10 +60,10 @@ namespace gr noaa_apt_sink::sptr noaa_apt_sink::make (const char *filename_png, size_t width, size_t height, - bool split, bool sync, bool flip) + bool sync, bool flip) { return gnuradio::get_initial_sptr ( - new noaa_apt_sink_impl (filename_png, width, height, split, sync, + new noaa_apt_sink_impl (filename_png, width, height, sync, flip)); } @@ -73,20 +73,19 @@ namespace gr */ noaa_apt_sink_impl::noaa_apt_sink_impl (const char *filename_png, size_t width, size_t height, - bool split, bool sync, bool flip) : + bool sync, bool flip) : gr::sync_block ("noaa_apt_sink", gr::io_signature::make (1, 1, sizeof(float)), gr::io_signature::make (0, 0, 0)), f_average_alpha (0.25), - d_row_write_threshold (250), d_filename_png (filename_png), d_width (width), d_height (height), - d_split (split), d_synchronize_opt (sync), d_flip (flip), d_history_length (40), d_has_sync (false), + d_image_received(false), d_current_x (0), d_current_y (0), d_num_images (0), @@ -95,35 +94,9 @@ namespace gr f_average(0.0) { set_history(d_history_length); - init_images(); + d_full_image = png::image(d_width, d_height); } - - void - noaa_apt_sink_impl::init_images () { - // Split the filename option into path + filename and extension - - - // Construct numbered filename for the full image - d_full_filename = d_filename_png + std::to_string(d_num_images); - // Create a new empty png - d_full_image = png::image(d_width, d_height); - - - if(d_split) { - // In case split images are requested construct filenames for those as well - d_left_filename = d_filename_png + std::to_string(d_num_images) - + "_left"; - d_right_filename = d_filename_png + std::to_string(d_num_images) - + "_right"; - - // Create new empty pngs for the split images - d_left_image = png::image(d_width/2, d_height); - d_right_image = png::image(d_width/2, d_height); - } - } - - void noaa_apt_sink_impl::write_image (png::image image, std::string filename) @@ -153,48 +126,10 @@ namespace gr } } - - void - noaa_apt_sink_impl::write_images () { - // Write out the full image - write_image(d_full_image, d_full_filename); - - if(d_split) { - // Write out the split images if the split option is enabled - write_image(d_left_image, d_left_filename); - write_image(d_right_image, d_right_filename); - } - } - - noaa_apt_sink_impl::~noaa_apt_sink_impl () { - // Nothing happens here - } - - bool - noaa_apt_sink_impl::stop () { - // As a teardown action, the remaining pngs - //should be cropped to the correct size and written to disk - - // Grab the buffers from the fullsize pngs - png::image::pixbuf buf_full_image = d_full_image.get_pixbuf(); - png::image::pixbuf buf_left_image = d_left_image.get_pixbuf(); - png::image::pixbuf buf_right_image = d_right_image.get_pixbuf(); - - // Create new smaller pngs using the old buffers - d_full_image = png::image(d_width, d_current_y + 1); - d_full_image.set_pixbuf(buf_full_image); - - d_left_image = png::image(d_width/2, d_current_y + 1); - d_left_image .set_pixbuf(buf_left_image); - - d_right_image = png::image(d_width/2, d_current_y + 1); - d_right_image.set_pixbuf(buf_right_image); - - // Write the smaller images to disk - write_images(); - - return true; + if(!d_image_received){ + write_image(d_full_image, d_filename_png); + } } @@ -203,21 +138,8 @@ namespace gr sample = (sample - f_min_level) / (f_max_level - f_min_level) * 255; // Set the pixel in the full image d_full_image.set_pixel(x, y, sample); - - // Id the split otions is set - if(d_split) { - // Set the pixel in the right image, - // depending on its coordinate - if(x < d_width / 2) { - d_left_image.set_pixel(x, y, sample); - } - else { - d_right_image.set_pixel(x - d_width / 2, y, sample); - } - } } - void noaa_apt_sink_impl::skip_to (size_t new_x, size_t pos, const float *samples) { // Check if the skip is forward or backward @@ -255,8 +177,6 @@ namespace gr if((sample > 0 && syncb_seq[i]) || (sample < 0 && !syncb_seq[i])) { count_b += 1; } - - } // Prefer sync pattern a as it is detected more reliable @@ -278,6 +198,10 @@ namespace gr gr_vector_void_star &output_items) { const float *in = (const float *) input_items[0]; + /* If we have already produced one image, ignore the remaining observation*/ + if(d_image_received){ + return noutput_items; + } // Structure of in[]: // - d_history_length many historical samples @@ -336,17 +260,13 @@ namespace gr // Reset x position to line start d_current_x = 0; - // If there are enough lines decoded write the image to disk - if(d_current_y % d_row_write_threshold == 0) { - write_images(); - } - // Split the image if there are enough lines decoded if(d_current_y >= d_height) { d_current_y = 0; d_num_images += 1; - write_images(); - init_images(); + // Write out the full image + write_image(d_full_image, d_filename_png); + d_image_received = true; } } } diff --git a/lib/noaa_apt_sink_impl.h b/lib/noaa_apt_sink_impl.h index 6eb45e0..182faf2 100644 --- a/lib/noaa_apt_sink_impl.h +++ b/lib/noaa_apt_sink_impl.h @@ -40,23 +40,17 @@ namespace gr // Factor exponential smoothing average, // which is used for sync pattern detection const float f_average_alpha; - - // The images are written to disk every d_row_write_threshold lines - // so in case something goes horribly wrong, partial images will be available - const size_t d_row_write_threshold; - - static const bool synca_seq[]; static const bool syncb_seq[]; std::string d_filename_png; size_t d_width; size_t d_height; - bool d_split; bool d_synchronize_opt; bool d_flip; size_t d_history_length; bool d_has_sync; + bool d_image_received; png::image d_full_image; png::image d_left_image; @@ -75,7 +69,7 @@ namespace gr public: noaa_apt_sink_impl (const char *filename_png, size_t width, size_t height, - bool split, bool sync, bool flip); + bool sync, bool flip); ~noaa_apt_sink_impl (); // Where all the action really happens @@ -83,14 +77,8 @@ namespace gr work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); - // For teardown actions, like writing the remaining images to disk - bool - stop (); private: - // Generates new empty images and the filenames for them - void - init_images (); /* * Checks if the history portion of the input contains a sync marker. @@ -110,10 +98,6 @@ namespace gr void skip_to (size_t new_x, size_t pos, const float *samples); - // Writes all images to disk - void - write_images (); - // Writes a single image to disk, also takes care of flipping void write_image (png::image image, std::string filename);