Skip to content

Commit d60a43b

Browse files
Merge pull request #107 from MEAT-Inc/bugfix/SWRAP-106-sim-playback-issues
More fixes for simulation playback and updated configurations
2 parents 3351583 + bab164a commit d60a43b

17 files changed

Lines changed: 295 additions & 139 deletions

File tree

SharpAutoId/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
[assembly: Guid("73552094-035A-4DFB-BEC4-5116EC7993EF")]
2020

2121
// Version information
22-
[assembly: AssemblyVersion("0.4.4.156")]
23-
[assembly: AssemblyFileVersion("0.4.4.156")]
22+
[assembly: AssemblyVersion("0.4.4.162")]
23+
[assembly: AssemblyFileVersion("0.4.4.162")]
2424
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
2525

SharpAutoId/SharpAutoId.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<Version>2.7.8.334</Version>
6666
</PackageReference>
6767
<PackageReference Include="SharpWrapper">
68-
<Version>6.1.14.497</Version>
68+
<Version>6.2.3.507</Version>
6969
</PackageReference>
7070
</ItemGroup>
7171
<ItemGroup />

SharpExpressions/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
[assembly: Guid("73552094-035A-4DFB-BEC4-5116EC7993EF")]
2020

2121
// Version information
22-
[assembly: AssemblyVersion("0.5.15.396")]
23-
[assembly: AssemblyFileVersion("0.5.15.396")]
22+
[assembly: AssemblyVersion("0.5.15.449")]
23+
[assembly: AssemblyFileVersion("0.5.15.449")]
2424
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
2525

SharpExpressions/SharpExpressions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<Version>2.7.8.334</Version>
7979
</PackageReference>
8080
<PackageReference Include="SharpWrapper">
81-
<Version>6.1.14.497</Version>
81+
<Version>6.2.3.507</Version>
8282
</PackageReference>
8383
</ItemGroup>
8484
<ItemGroup />

SharpPipes/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
[assembly: Guid("73552094-035A-4DFB-BEC4-5116EC7993EF")]
2020

2121
// Version information
22-
[assembly: AssemblyVersion("0.2.4.50")]
23-
[assembly: AssemblyFileVersion("0.2.4.50")]
22+
[assembly: AssemblyVersion("0.2.4.55")]
23+
[assembly: AssemblyFileVersion("0.2.4.55")]
2424
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
2525

SharpSimulator/PassThruSimulationConfiguration.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
using SharpWrapper.J2534Objects;
88
using SharpWrapper.PassThruTypes;
99
using SharpLogging;
10+
using SharpSimulator.PassThruSimulationSupport;
1011

1112
namespace SharpSimulator
1213
{
1314
/// <summary>
1415
/// Default simulation configuration layout
1516
/// </summary>
17+
// TODO: Configure JSON Converter for the configuration objects
18+
// [JsonConverter(typeof(PassThruSimConfigJsonConverter))]
1619
public class PassThruSimulationConfiguration
1720
{
1821
#region Custom Events
@@ -36,6 +39,7 @@ public class PassThruSimulationConfiguration
3639
public uint ReaderTimeout { get; set; } // Timeout for each read routine
3740
public uint ReaderMsgCount { get; set; } // The number of messages to read
3841
public uint ResponseTimeout { get; set; } // The timeout for sending responses
42+
public uint ResponseAttempts { get; set; } // The number of attempts for responses
3943

4044
// Basic Channel Configurations
4145
public BaudRate ReaderBaudRate { get; set; } // Baudrate for the current channel
@@ -58,14 +62,25 @@ public class PassThruSimulationConfiguration
5862
// ------------------------------------------------------------------------------------------------------------------------------------------
5963

6064
/// <summary>
61-
/// Default CTOR for a configuration object. Used to build a configuration step by step
65+
/// Default CTOR for a configuration object. Used mainly by JSON converter
6266
/// </summary>
63-
public PassThruSimulationConfiguration()
67+
[JsonConstructor]
68+
internal PassThruSimulationConfiguration()
6469
{
6570
// Setup a new configuration logger if possible
6671
_configurationLogger ??= new SharpLogger(LoggerActions.UniversalLogger);
6772
}
6873
/// <summary>
74+
/// Builds a new configuration object. Used to build a configuration step by step
75+
/// </summary>
76+
/// <param name="ConfigurationName">Optional name of our configuration</param>
77+
public PassThruSimulationConfiguration(string ConfigurationName)
78+
{
79+
// Setup a new configuration logger if possible and store the name of the configuration
80+
this.ConfigurationName = ConfigurationName;
81+
_configurationLogger ??= new SharpLogger(LoggerActions.UniversalLogger);
82+
}
83+
/// <summary>
6984
/// Builds a new configuration object and sets defaults to null/empty
7085
/// </summary>
7186
/// <param name="ProtocolInUse">Protocol for the configuration</param>

SharpSimulator/PassThruSimulationPlayer.cs

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

SharpSimulator/PassThruSimulationSupport/PassThruSimChannelExtensions.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,17 +417,24 @@ public static PassThruStructs.PassThruMsg[] ConvertReadExpression(this PassThruR
417417
// Now restore message values
418418
MessageData = string.Join(" ", SplitData);
419419
}
420-
421-
// If it's not a frame pad message, add to our simulation
420+
421+
// Pull out the protocol, message data content, and parse the Rx Status value
422422
var ProtocolId = (ProtocolId)Enum.Parse(typeof(ProtocolId), MessageSet[2].Split(':')[0]);
423423
MessageData = MessageData.Replace("0x", string.Empty).Replace(" ", " ");
424424
RxStatus MsgRxStatus = (RxStatus)uint.Parse(MessageSet[4].Replace("RxS=", string.Empty), NumberStyles.HexNumber);
425-
TxFlags MsgTxFlags = ProtocolId == ProtocolId.ISO15765 && MsgRxStatus == RxStatus.NO_RX_STATUS
426-
? TxFlags.ISO15765_FRAME_PAD
427-
: TxFlags.NO_TX_FLAGS;
428425

429-
// If this message is a framepad identifier, skip it
426+
// Configure message TxFlags here
427+
TxFlags MsgTxFlags = TxFlags.NO_TX_FLAGS;
428+
if (ProtocolId == ProtocolId.ISO15765)
429+
{
430+
// Check the length of the message here
431+
int DataSize = MessageData.Split(' ').Length;
432+
if (DataSize <= 12) MsgTxFlags = TxFlags.ISO15765_FRAME_PAD;
433+
}
434+
435+
// If this message was read in as part of a flow control operation, skip it
430436
if (MsgRxStatus.HasFlag(RxStatus.TX_MSG_TYPE)) continue;
437+
if (MsgRxStatus.HasFlag(RxStatus.START_OF_MESSAGE)) continue;
431438

432439
// Build a message and then return it. Store the needed RxStatus values for it if needed
433440
var NextMessage = J2534Device.CreatePTMsgFromString(ProtocolId, (uint)MsgTxFlags, (uint)MsgRxStatus, MessageData);

SharpSimulator/PassThruSimulationSupport/PassThruSimChannelJsonConverter.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ internal class PassThruSimChannelJsonConverter: JsonConverter
2020
public override bool CanConvert(Type ObjectType) { return ObjectType == typeof(PassThruSimulationChannel); }
2121

2222
/// <summary>
23-
/// Writes a J2534 Filter object to JSON
23+
/// Writes a simulation channel object to JSON
2424
/// </summary>
25-
/// <param name="JWriter"></param>
26-
/// <param name="ValueObject"></param>
27-
/// <param name="JSerializer"></param>
25+
/// <param name="JWriter">JSON Writer to build output</param>
26+
/// <param name="ValueObject">The configuration object we're converting</param>
27+
/// <param name="JSerializer">JSON serialization settings for conversion</param>
2828
public override void WriteJson(JsonWriter JWriter, object? ValueObject, JsonSerializer JSerializer)
2929
{
3030
// Check if value object is null. Build output
@@ -57,11 +57,11 @@ public override void WriteJson(JsonWriter JWriter, object? ValueObject, JsonSeri
5757
/// <summary>
5858
/// Reads a J2534 object from JSON
5959
/// </summary>
60-
/// <param name="JReader"></param>
61-
/// <param name="ObjectType"></param>
62-
/// <param name="ExistingValue"></param>
63-
/// <param name="JSerializer"></param>
64-
/// <returns></returns>
60+
/// <param name="JReader">JSON reader reading the input JSON contents</param>
61+
/// <param name="ObjectType">The type of object we're converting</param>
62+
/// <param name="ExistingValue">An existing object we're trying to provide context with</param>
63+
/// <param name="JSerializer">JSON serialization settings for conversion</param>
64+
/// <returns>The built simulation channel object from the JSON input</returns>
6565
public override object? ReadJson(JsonReader JReader, Type ObjectType, object? ExistingValue, JsonSerializer JSerializer)
6666
{
6767
// Check if input is null. Build object from it.

0 commit comments

Comments
 (0)