@@ -94,6 +94,11 @@ std::map<int, float> ndr358_551_ddc_map = {
9494 { 40 , 128e6 }
9595};
9696
97+ std::map<int , int > ndr358_551_timestamp_diffs = {
98+ {40 , 2048 } , {39 , 4096 } , {38 , 8192 } , {37 , 8192 } , {36 , 16384 },
99+ {35 , 16384 }, {34 , 16384 }, {33 , 32768 }, {32 , 32768 }
100+ };
101+
97102void raise_error (std::string tag, int sock)
98103{
99104 // see http://www.club.cc.cmu.edu/~cmccabe/blog_strerror.html for problems with
@@ -176,6 +181,7 @@ namespace gr {
176181 d_first_packet(true ),
177182 d_packetCounter(0 ),
178183 d_buffer(),
184+ d_frac_last_timestamp( 0 ),
179185 d_use_vector_output( vector_output )
180186 {
181187 if ( this ->d_use_vector_output )
@@ -390,12 +396,20 @@ namespace gr {
390396 *******************************************************************************/
391397 auto vita_udp_rx_impl::tag_packet (int stream, int offset) -> void
392398 {
399+ uint32_t __ddc_filter = 0 ;
393400 if (d_tag_packets) {
394401 auto hdr = reinterpret_cast <V49_0_Header*>(d_buffer.data ());
395402
396403 uint64_t tag_item = nitems_written (0 ) + offset;
397404
398405 // Note if we setup byte swap, it's already been done in place
406+ {
407+ // Moved so I have the information for DDC Rate
408+ auto ddc_filter = ((hdr->ddc_2 >> 20 ) & 0x0FFF );
409+ auto tag = pmt::from_float (ndr358_551_ddc_map.at (ddc_filter));
410+ add_item_tag (stream, tag_item, pmt::mp (" ddc_rate" ), tag);
411+ __ddc_filter = ddc_filter;
412+ }
399413
400414 // timestamp
401415 {
@@ -405,6 +419,27 @@ namespace gr {
405419 auto tag = pmt::cons (pmt::from_long (hdr->int_timestamp ),
406420 pmt::from_uint64 (fractionalTs));
407421 add_item_tag (stream, tag_item, pmt::mp (" timestamp" ), tag);
422+
423+ if ( d_first_packet )
424+ {
425+ d_frac_last_timestamp = fractionalTs;
426+ } else {
427+ uint32_t expected_diff = ndr358_551_timestamp_diffs.at (__ddc_filter);
428+ // wrapping at 1second.
429+ uint32_t diff = 0 ;
430+ if ( fractionalTs < d_frac_last_timestamp ) {
431+ diff = (256000000ull - d_frac_last_timestamp) + fractionalTs;
432+ }
433+ else {
434+ diff = fractionalTs - d_frac_last_timestamp;
435+ }
436+ if ( diff != expected_diff ) {
437+ txStatusMsg ();
438+ d_logger->warn (" gr::CyberRadio::vita_udp_rx_impl: packet loss detected: expected {}, recieved {}" ,
439+ expected_diff, diff);
440+ }
441+ d_frac_last_timestamp = fractionalTs;
442+ }
408443 }
409444
410445 // stream id
@@ -431,12 +466,6 @@ namespace gr {
431466 }
432467 }
433468
434- {
435- auto ddc_filter = ((hdr->ddc_2 >> 20 ) & 0x0FFF );
436- auto tag = pmt::from_float (ndr358_551_ddc_map.at (ddc_filter));
437- add_item_tag (stream, tag_item, pmt::mp (" ddc_rate" ), tag);
438- }
439-
440469 {
441470 auto tag = pmt::from_long ((hdr->ddc_2 >> 0 ) & 0x0001FFFF );
442471 add_item_tag (stream, tag_item, pmt::mp (" delay_time" ), tag);
@@ -480,8 +509,13 @@ namespace gr {
480509 }
481510
482511 {
483- auto tag = pmt::from_long (((hdr->ddc_4 >> 0 ) & 0x000007FF ));
512+ uint16_t valid_data_samples = ((hdr->ddc_4 >> 0 ) & 0x000007FF );
513+ auto tag = pmt::from_long (valid_data_samples);
484514 add_item_tag (stream, tag_item, pmt::mp (" valid_data_count" ), tag);
515+ if ( d_samples_per_packet != valid_data_samples ) {
516+ auto msg = pmt::cons (pmt::mp (" valid data count < d_samples_per_packet" ), pmt::PMT_NIL);
517+ message_port_pub (status_port, msg);
518+ }
485519 }
486520
487521 {
@@ -526,8 +560,7 @@ namespace gr {
526560 *******************************************************************************/
527561 void vita_udp_rx_impl::rxControlMsg (pmt::pmt_t msg)
528562 {
529- std::cout << " **** vita_udp_rx_impl::rxControlMsg: " << msg << " ****"
530- << std::endl;
563+ d_logger->debug (" vita_udp_rx_impl::rxControlMsg \" {}\" " , pmt::symbol_to_string (msg));
531564 // What did we receive?
532565 pmt::pmt_t msgId = pmt::car (msg);
533566 pmt::pmt_t content = pmt::cdr (msg);
0 commit comments