@@ -70,6 +70,7 @@ protected virtual void SimMessageReceived(SimMessageEventArgs MessageArgs)
7070 public uint ReaderTimeout { get ; private set ; }
7171 public uint ReaderMessageCount { get ; private set ; }
7272 public uint SenderResponseTimeout { get ; private set ; }
73+ public uint SenderRetryAttempts { get ; private set ; }
7374
7475 // Other Reader Configuration Values and States
7576 public bool SimulationReading { get ; private set ; }
@@ -342,7 +343,7 @@ public bool LoadSimulationFile(JArray SimulationChannels)
342343 }
343344
344345 // Log out that we're loaded up and return out true once done
345- this . _simPlayingLogger . WriteLog ( $ "IMPORTED SIMULATION FILE { SimulationChannels } CORRECTLY!", LogType . InfoLog ) ;
346+ this . _simPlayingLogger . WriteLog ( $ "IMPORTED SIMULATION FILE CORRECTLY!", LogType . InfoLog ) ;
346347 this . _simPlayingLogger . WriteLog ( $ "PULLED IN A TOTAL OF { this . _simulationChannels . Count } INPUT SIMULATION CHANNELS INTO OUR LOADER WITHOUT FAILURE!", LogType . InfoLog ) ;
347348 this . _simPlayingLogger . WriteLog ( $ "ENCOUNTERED A TOTAL OF { FailedCounter } FAILURES WHILE LOADING CHANNELS!", LogType . InfoLog ) ;
348349 return true ;
@@ -417,7 +418,8 @@ public void SetPlaybackConfiguration(PassThruSimulationConfiguration SimConfigur
417418 this . SetDefaultMessageValues (
418419 SimConfiguration . ReaderTimeout ,
419420 SimConfiguration . ReaderMsgCount ,
420- SimConfiguration . ResponseTimeout ) ;
421+ SimConfiguration . ResponseTimeout ,
422+ SimConfiguration . ResponseAttempts ) ;
421423
422424 // Log out that our configuration has been set and exit out
423425 this . _simPlayingLogger . WriteLog ( $ "APPLIED ALL CONFIGURATION VALUES FOR CONFIGURATION { SimConfiguration . ConfigurationName } CORRECTLY!", LogType . InfoLog ) ;
@@ -435,20 +437,24 @@ public void SetResponsesEnabled(bool ResponsesEnabled)
435437 /// <summary>
436438 /// Stores new values for our reader configuration on our output
437439 /// </summary>
438- /// <param name="TimeoutValue ">Timeout on each read command</param>
440+ /// <param name="ReadTimeoutValue ">Timeout on each read command</param>
439441 /// <param name="MessageCount">Messages to read</param>
440- public void SetDefaultMessageValues ( uint ReadTimeoutValue = 100 , uint MessageCount = 10 , uint SenderTimeoutValue = 500 )
442+ /// <param name="SenderTimeoutValue">Timeout on each send response command</param>
443+ /// <param name="SenderRetryAttempts">Number of tries to send messages back out</param>
444+ public void SetDefaultMessageValues ( uint ReadTimeoutValue = 100 , uint MessageCount = 10 , uint SenderTimeoutValue = 500 , uint SenderRetryAttempts = 5 )
441445 {
442446 // Store new values here and log them out
443447 this . ReaderTimeout = ReadTimeoutValue ;
444448 this . ReaderMessageCount = MessageCount ;
445449 this . SenderResponseTimeout = SenderTimeoutValue ;
450+ this . SenderRetryAttempts = SenderRetryAttempts ;
446451
447452 // Log our stored values out as trace log.
448453 this . _simPlayingLogger . WriteLog ( $ "STORED NEW READER CONFIGURATION! VALUES SET:\n " +
449454 $ "{ this . ReaderMessageCount } MESSAGES TO READ\n " +
450455 $ "{ this . ReaderTimeout } TIMEOUT ON EACH READ COMMAND\n " +
451- $ "{ this . SenderResponseTimeout } TIMEOUT ON EACH RESPONSE COMMAND",
456+ $ "{ this . SenderResponseTimeout } TIMEOUT ON EACH RESPONSE COMMAND\n " +
457+ $ "{ this . SenderRetryAttempts } ATTEMPTS ALLOWED FOR EACH RESPONSE",
452458 LogType . TraceLog
453459 ) ;
454460 }
@@ -723,13 +729,7 @@ private void _processSimulationMessages()
723729 this . _simPlayingLogger . WriteLog ( $ "EXCEPTION THROWN: { RespEx } ") ;
724730
725731 // Return passed and setup a base channel object again
726- if ( ! this . InitializeSimReader ( ) )
727- throw new Exception (
728- "SETUP_READER_EXCEPTION" ,
729- new InvalidOperationException ( "FAILED TO RECONFIGURE READER CHANNEL!" )
730- ) ;
731-
732- // Return passed and move onto next configuration
732+ if ( ! this . InitializeSimReader ( ) ) throw RespEx ;
733733 return ;
734734 }
735735 }
@@ -768,14 +768,18 @@ private bool _generateResponseChannel(int IndexOfMessageSet, int IndexOfMessageF
768768 // Try and set each filter for the channel. Skip duplicate filters
769769 try
770770 {
771+ // Apply the filter and break this loop once we've configured it
771772 this . PhysicalChannel . StartMessageFilter ( ChannelFilter ) ;
772- this . _simPlayingLogger . WriteLog ( $ "Started Filter: { ChannelFilter . FilterMask } | { ChannelFilter . FilterPattern } | { ChannelFilter . FilterFlowCtl } ", LogType . ErrorLog ) ;
773+ this . _simPlayingLogger . WriteLog ( $ "STARTED FILTER: { ChannelFilter . FilterMask } | { ChannelFilter . FilterPattern } | { ChannelFilter . FilterFlowCtl } ", LogType . ErrorLog ) ;
774+
775+ // Break out if we've configured a perfect filter for this message instance
776+ if ( CanMatchFilter ) break ;
773777 }
774778 catch
775779 {
776780 // Log out what our duplicate/invalid filter was
777- this . _simPlayingLogger . WriteLog ( $ "Error! Filter was unable to be set for requested simulation channel !", LogType . ErrorLog ) ;
778- this . _simPlayingLogger . WriteLog ( $ "Filter : { ChannelFilter . FilterMask } | { ChannelFilter . FilterPattern } | { ChannelFilter . FilterFlowCtl } ", LogType . ErrorLog ) ;
781+ this . _simPlayingLogger . WriteLog ( $ "ERROR! COULD NOT SET FILTER FOR SIMULATION CHANNEL !", LogType . ErrorLog ) ;
782+ this . _simPlayingLogger . WriteLog ( $ "FILTER : { ChannelFilter . FilterMask } | { ChannelFilter . FilterPattern } | { ChannelFilter . FilterFlowCtl } ", LogType . ErrorLog ) ;
779783 }
780784 }
781785
@@ -796,41 +800,51 @@ private bool _generateSimulationResponses(int IndexOfMessageSet, int IndexOfMess
796800
797801 // Log message contents out and then log the responses out if we are going to be sending them
798802 this . _simPlayingLogger . WriteLog ( $ "--> READ MESSAGE [0]: { BitConverter . ToString ( PulledMessages . MessageRead . Data ) } ", LogType . InfoLog ) ;
799- if ( ! ResponsesEnabled )
803+ if ( ! this . ResponsesEnabled )
800804 {
801805 // Fake a reply output event and disconnect our channel
802806 this . SimulationSession . PTDisconnect ( 0 ) ;
803807 this . SimMessageReceived ( new SimMessageEventArgs ( this . SimulationSession , false , PulledMessages . MessageRead , PulledMessages . MessageResponses ) ) ;
804808 return true ;
805809 }
806810
807- try
811+ // Try and send our message as many times as our configuration requests.
812+ for ( int RetryCount = 0 ; RetryCount < this . SenderRetryAttempts ; RetryCount ++ )
808813 {
809- // Try and send the message, indicate passed sending routine
810- this . PhysicalChannel . PTWriteMessages ( PulledMessages . MessageResponses , this . SenderResponseTimeout ) ;
811- this . SimulationSession . PTDisconnect ( 0 ) ;
814+ try
815+ {
816+ // Try and send the message, indicate passed sending routine
817+ this . PhysicalChannel . PTWriteMessages ( PulledMessages . MessageResponses , this . SenderResponseTimeout ) ;
818+ this . SimulationSession . PTDisconnect ( 0 ) ;
812819
813- // Attempt to send output events in a task to stop hanging our response operations
814- this . SimMessageReceived ( new SimMessageEventArgs ( this . SimulationSession , true , PulledMessages . MessageRead , PulledMessages . MessageResponses ) ) ;
815- for ( int RespIndex = 0 ; RespIndex < PulledMessages . MessageResponses . Length ; RespIndex += 1 )
816- this . _simPlayingLogger . WriteLog ( $ " --> SENT MESSAGE [{ RespIndex } ]: { BitConverter . ToString ( PulledMessages . MessageResponses [ RespIndex ] . Data ) } ") ;
820+ // Attempt to send output events in a task to stop hanging our response operations
821+ this . SimMessageReceived ( new SimMessageEventArgs ( this . SimulationSession , true , PulledMessages . MessageRead , PulledMessages . MessageResponses ) ) ;
822+ for ( int RespIndex = 0 ; RespIndex < PulledMessages . MessageResponses . Length ; RespIndex += 1 )
823+ this . _simPlayingLogger . WriteLog ( $ " --> SENT MESSAGE [{ RespIndex } ]: { BitConverter . ToString ( PulledMessages . MessageResponses [ RespIndex ] . Data ) } ") ;
817824
818- // Return passed sending output
819- return true ;
820- }
821- catch ( Exception SendResponseException )
822- {
823- // Disconnect our channel and exit this routine
824- this . SimulationSession . PTDisconnect ( 0 ) ;
825-
826- // Log failed to send output, set sending failed.
827- this . _simPlayingLogger . WriteLog ( $ "ATTEMPT TO SEND MESSAGE RESPONSE FAILED!", LogType . ErrorLog ) ;
828- this . _simPlayingLogger . WriteException ( "EXCEPTION IS BEING LOGGED BELOW" , SendResponseException ) ;
829- this . SimMessageReceived ( new SimMessageEventArgs ( this . SimulationSession , false , PulledMessages . MessageRead , PulledMessages . MessageResponses ) ) ;
825+ // Return passed sending output
826+ return true ;
827+ }
828+ catch ( Exception SendResponseException )
829+ {
830+ // If we're able to keep trying, do so here
831+ if ( RetryCount < this . SenderRetryAttempts - 1 ) continue ;
832+
833+ // Disconnect our channel and exit this routine
834+ this . SimulationSession . PTDisconnect ( 0 ) ;
835+
836+ // Log failed to send output, set sending failed.
837+ this . _simPlayingLogger . WriteLog ( $ "ATTEMPT TO SEND MESSAGE RESPONSE FAILED!", LogType . ErrorLog ) ;
838+ this . _simPlayingLogger . WriteException ( "EXCEPTION IS BEING LOGGED BELOW" , SendResponseException ) ;
839+ this . SimMessageReceived ( new SimMessageEventArgs ( this . SimulationSession , false , PulledMessages . MessageRead , PulledMessages . MessageResponses ) ) ;
830840
831- // Return failed sending output
832- return false ;
841+ // Return failed sending output
842+ return false ;
843+ }
833844 }
845+
846+ // Return false at this point if we're unable to send messages
847+ return false ;
834848 }
835849 }
836850}
0 commit comments