@@ -93,6 +93,7 @@ public class Decoder : MDCCRC
9393 */
9494 private double incr ; //
9595 private int frameCount ; // number of frames in MDC packet
96+ private bool inDouble ; //
9697
9798 private double [ ] th ; //
9899
@@ -393,6 +394,7 @@ private bool ProcessBits(int idx)
393394 this . shstate [ k ] = 0 ;
394395
395396 this . frameCount = 2 ;
397+ this . inDouble = false ;
396398 }
397399 else
398400 {
@@ -403,29 +405,38 @@ private bool ProcessBits(int idx)
403405 first . Argument = data [ 1 ] ;
404406 first . UnitID = ( ushort ) ( ( data [ 2 ] << 8 ) | data [ 3 ] ) ;
405407 crc = ( byte ) ( ( data [ 4 ] << 8 ) | data [ 5 ] ) ;
406-
407- // reset the states for all decoders
408- for ( int k = 0 ; k < MDC_ND ; k ++ )
409- this . shstate [ k ] = 0 ;
410408
411- // check if the operation code is for a "double" packet
412- switch ( data [ 0 ] )
409+ if ( ! inDouble )
413410 {
414- case OpType . DOUBLE_PACKET_TYPE1 :
415- case OpType . DOUBLE_PACKET_TYPE2 :
411+ // check if the operation code is for a "double" packet
412+ switch ( data [ 0 ] )
416413 {
417- // we have a double packet reset the frame count to 0
418- // and set the state to reflect a double packet
419- this . frameCount = 0 ;
420- this . shstate [ idx ] = 2 ;
421- this . shcount [ idx ] = 0 ;
414+ case OpType . DOUBLE_PACKET_TYPE1 :
415+ case OpType . DOUBLE_PACKET_TYPE2 :
416+ {
417+ // we have a double packet reset the frame count to 0
418+ // and set the state to reflect a double packet
419+ this . frameCount = 0 ;
420+ this . inDouble = true ;
421+ this . shstate [ idx ] = 2 ;
422+ this . shcount [ idx ] = 0 ;
423+
424+ ClearBits ( idx ) ;
425+ }
426+ break ;
422427
423- ClearBits ( idx ) ;
428+ default :
429+ // reset the states for all decoders
430+ for ( int k = 0 ; k < MDC_ND ; k ++ )
431+ this . shstate [ k ] = 0 ;
432+ break ;
424433 }
425- break ;
426-
427- default :
428- break ;
434+ }
435+ else
436+ {
437+ this . shstate [ idx ] = 2 ;
438+ this . shcount [ idx ] = 0 ;
439+ ClearBits ( idx ) ;
429440 }
430441 }
431442
@@ -435,6 +446,12 @@ private bool ProcessBits(int idx)
435446 Messages . Trace ( "Frame Count: " + frameCount ) ;
436447 Messages . Trace ( "MDC Frame 1 = " + ToString ( first ) ) ;
437448
449+ if ( inDouble && frameCount <= 1 )
450+ {
451+ this . frameCount = 0 ;
452+ return true ;
453+ }
454+
438455 // if we have a frame count of > 1 then display second packet data
439456 if ( this . frameCount > 1 )
440457 Messages . Trace ( "MDC Frame 2 = " + ToString ( second ) ) ;
@@ -447,6 +464,10 @@ private bool ProcessBits(int idx)
447464
448465 // reset frame count
449466 this . frameCount = 0 ;
467+
468+ // reset the states for all decoders
469+ for ( int k = 0 ; k < MDC_ND ; k ++ )
470+ this . shstate [ k ] = 0 ;
450471 }
451472
452473 return true ;
0 commit comments