Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Releasing new SharpWrapper configurations #99

Merged
merged 18 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SharpAutoId/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
[assembly: Guid("73552094-035A-4DFB-BEC4-5116EC7993EF")]

// Version information
[assembly: AssemblyVersion("0.4.4.137")]
[assembly: AssemblyFileVersion("0.4.4.137")]
[assembly: AssemblyVersion("0.4.4.140")]
[assembly: AssemblyFileVersion("0.4.4.140")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]

2 changes: 1 addition & 1 deletion SharpAutoId/SharpAutoId.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<Version>2.7.8.334</Version>
</PackageReference>
<PackageReference Include="SharpWrapper">
<Version>6.1.11.469</Version>
<Version>6.1.11.472</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
Expand Down
19 changes: 16 additions & 3 deletions SharpExpressions/PassThruExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using SharpExpressions.PassThruExpressions;
using SharpLogging;

Expand Down Expand Up @@ -113,9 +114,21 @@ public override string ToString()
.ToArray();

// Store string to replace and build new list of strings
var NewLines = new List<string>() { SplitString }; NewLines.Add("\r");
NewLines.AddRange(this.SplitCommandLines.Select(LineObj => " " + LineObj.Trim()));
NewLines.Add("\n");
var NewLines = new List<string>() { SplitString, "\r" };
foreach (string CommandLine in this.SplitCommandLines)
{
// Clean out starting newlines from commands if needed
string CleanedCommandLine = CommandLine;
if (CleanedCommandLine.StartsWith("\n")) CleanedCommandLine = CommandLine.Substring(1);

// If we're looking at a command line, make sure we tab it over accordingly
string[] SplitCommandLine = CleanedCommandLine.Replace(" ", " ").Split(' ').ToArray();
bool IsCommandData = !CleanedCommandLine.Contains("\\__") && SplitCommandLine.All(BytePart => BytePart.Length == 2);
NewLines.Add((IsCommandData ? "\t " : " ") + CleanedCommandLine);
}

// NOTE: Removed to fix formatting for output content
// NewLines.Add("\n");

// Add our breakdown contents here.
NewLines.Add(SplitTable[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,31 @@ public PassThruReadMessagesExpression(string CommandInput) : base(CommandInput,

// If we failed to pull our read count just send out ? and ?. If it's a complete read count, then we know we're passed so just do 0/0
if (!PtReadMsgsResult) this._expressionLogger.WriteLog($"FAILED TO REGEX OPERATE ON ONE OR MORE TYPES FOR EXPRESSION TYPE {this.GetType().Name}!");
if (!MessagesReadResult) MessagesReadStrings = CommandInput.Contains("PTReadMsgs() complete") || CommandInput.Contains("Zero messages received")
? new[] { "Read 0/0", "0", "0" }
: new[] { "Read ? of ? messages", "?", "?" };


// Find our values to store here and add them to our list of values.
List<string> StringsToApply = new List<string> { PassThruReadMsgsStrings[0] };
StringsToApply.AddRange(this.PtReadMessagesRegex.ExpressionValueGroups
.Where(NextIndex => NextIndex <= PassThruReadMsgsStrings.Length)
.Select(NextIndex => PassThruReadMsgsStrings[NextIndex]));

// Find the properties of our message objects here
this.FindMessageContents(out this.MessageProperties);
if (!MessagesReadResult) MessagesReadStrings = CommandInput.Contains("PTReadMsgs() complete") || CommandInput.Contains("Zero messages received")
? new[] { "Read 0/0", "0", "0" }
: new[]
{
// Build a new read count status string based on the requested message count and property list
$"Read {this.MessageProperties.Count} of {PassThruReadMsgsStrings[4]} messages",
$"{this.MessageProperties.Count}",
$"{PassThruReadMsgsStrings[4]}"
};

// Store our message read contents here after manual assignment for failed regex routines
StringsToApply.AddRange(this.MessagesReadRegex.ExpressionValueGroups
.Where(NextIndex => NextIndex <= MessagesReadStrings.Length)
.Select(NextIndex => MessagesReadStrings[NextIndex]));

// Now apply values using base method and exit out of this routine
this.FindMessageContents(out this.MessageProperties);
if (!this.SetExpressionProperties(FieldsToSet, StringsToApply.ToArray()))
throw new InvalidOperationException($"FAILED TO SET CLASS VALUES FOR EXPRESSION OBJECT OF TYPE {this.GetType().Name}!");
}
Expand Down
4 changes: 2 additions & 2 deletions SharpExpressions/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
[assembly: Guid("73552094-035A-4DFB-BEC4-5116EC7993EF")]

// Version information
[assembly: AssemblyVersion("0.5.12.220")]
[assembly: AssemblyFileVersion("0.5.12.220")]
[assembly: AssemblyVersion("0.5.13.290")]
[assembly: AssemblyFileVersion("0.5.13.290")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]

2 changes: 1 addition & 1 deletion SharpExpressions/SharpExpressions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<Version>2.7.8.334</Version>
</PackageReference>
<PackageReference Include="SharpWrapper">
<Version>6.1.11.469</Version>
<Version>6.1.11.472</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
Expand Down
2 changes: 2 additions & 0 deletions SharpSimulator/PassThruSimulationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public PassThruSimulationChannel[] GenerateLogSimulation()
.Cast<PassThruStartMessageFilterExpression>()
.GroupBy(FilterObj => new
{
// Only include unique filters here and don't include invalid ones
FilterMask = FilterObj.MessageFilterContents[0].Last(),
FilterPattern = FilterObj.MessageFilterContents[1].Last(),
FilterFlow = FilterObj.MessageFilterContents.Count >= 3
Expand Down Expand Up @@ -382,6 +383,7 @@ public string SaveSimulationFile(string BaseFileName = "", string OutputLogFileF
_simulationLogger.WriteLog("CONVERTING TO STRINGS NOW...", LogType.WarnLog);
Tuple<uint, PassThruSimulationChannel>[] ChannelsConstructed = this.SimulationChannels
.Select(SimChannel => new Tuple<uint, PassThruSimulationChannel>(SimChannel.ChannelId, SimChannel))
.OrderBy(SimChannel => SimChannel.Item1)
.ToArray();

// Log information and write output.
Expand Down
72 changes: 70 additions & 2 deletions SharpSimulator/PassThruSimulationPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SharpLogging;
using SharpWrapper;
using SharpWrapper.J2534Objects;
Expand Down Expand Up @@ -286,12 +289,55 @@ public PassThruSimulationPlayer(IEnumerable<PassThruSimulationChannel> SimChanne

// ------------------------------------------------------------------------------------------------------------------------------------------

/// <summary>
/// Loads a simulation file into the playback helper by parsing the JSON contents of the provided file
/// </summary>
/// <param name="SimulationFile">Full path to the simulation file we're looking to play back</param>
/// <returns>True if the simulation is loaded. False if it is not</returns>
public bool LoadSimulationFile(string SimulationFile)
{
// Load the file and parse all the JSON contents from it to build our channels
int FailedCounter = 0;
var PulledChannels = JArray.Parse(File.ReadAllText(SimulationFile));
this._simPlayingLogger.WriteLog($"LOADING AND PARSING SIMULATION FILE {SimulationFile} NOW...", LogType.WarnLog);

// Iterate all the channels loaded in the JSON file and parse them
foreach (var ChannelInstance in PulledChannels.Children())
{
try
{
// Try and build our channel here
JToken ChannelToken = ChannelInstance.Last;
if (ChannelToken == null)
throw new InvalidDataException("Error! Input channel was seen to be an invalid layout!");

// Now using the JSON Converter, unwrap the channel into a simulation object and store it on our player
PassThruSimulationChannel BuiltChannel = ChannelToken.First.ToObject<PassThruSimulationChannel>();
this._simulationChannels.Add(BuiltChannel);
}
catch (Exception ConvertEx)
{
// Log failures out here
FailedCounter++;
this._simPlayingLogger.WriteLog("FAILED TO CONVERT SIMULATION CHANNEL FROM JSON TO OBJECT!", LogType.ErrorLog);
this._simPlayingLogger.WriteLog("EXCEPTION AND CHANNEL OBJECT ARE BEING LOGGED BELOW...", LogType.WarnLog);
this._simPlayingLogger.WriteLog($"SIM CHANNEL JSON:\n{ChannelInstance.ToString(Formatting.Indented)}", LogType.TraceLog);
this._simPlayingLogger.WriteException("EXCEPTION THROWN:", ConvertEx);
}
}

// Log out that we're loaded up and return out true once done
this._simPlayingLogger.WriteLog($"IMPORTED SIMULATION FILE {SimulationFile} CORRECTLY!", LogType.InfoLog);
this._simPlayingLogger.WriteLog($"PULLED IN A TOTAL OF {this._simulationChannels.Count} INPUT SIMULATION CHANNELS INTO OUR LOADER WITHOUT FAILURE!", LogType.InfoLog);
this._simPlayingLogger.WriteLog($"ENCOUNTERED A TOTAL OF {FailedCounter} FAILURES WHILE LOADING CHANNELS!", LogType.InfoLog);
return true;
}
/// <summary>
/// Appends a new simulation channel into our loader using an input channel object
/// </summary>
/// <param name="ChannelToAdd">Channel to store on our loader</param>
/// <returns>The index of the channel added</returns>
public int AddSimulationChannel(PassThruSimulationChannel ChannelToAdd)
public bool AddSimulationChannel(PassThruSimulationChannel ChannelToAdd)
{
// Store all values of our channel here
this._simulationChannels = this.SimulationChannels
Expand All @@ -300,7 +346,7 @@ public int AddSimulationChannel(PassThruSimulationChannel ChannelToAdd)

// Find new index and return it. Check the min index of the filters and the channels then the messages.
this._simPlayingLogger.WriteLog($"ADDED NEW VALUES FOR A SIMULATION CHANNEL {ChannelToAdd.ChannelId} WITHOUT ISSUES!", LogType.InfoLog);
return PairedSimulationMessages.Length - 1;
return this._simulationChannels.Contains(ChannelToAdd);
}
/// <summary>
/// Removes a channel by the ID value passed in
Expand Down Expand Up @@ -339,6 +385,28 @@ public bool RemoveSimulationChannel(PassThruSimulationChannel ChannelToRemove)

// ------------------------------------------------------------------------------------------------------------------------------------------

/// <summary>
/// Applies an entire simulation configuration onto the simulation player
/// </summary>
/// <param name="SimConfiguration">The configuration we're looking to set on the playback helper</param>
public void SetPlaybackConfiguration(PassThruSimulationConfiguration SimConfiguration)
{
// Log out the configuration we're setting and apply the values
this._simPlayingLogger. WriteLog($"APPLYING CONFIGURATION {SimConfiguration.ConfigurationName} TO SIMULATION PLAYER NOW...");
this.SetDefaultConfigurations(SimConfiguration.ReaderConfigs);
this.SetDefaultMessageFilters(SimConfiguration.ReaderFilters);
this.SetDefaultConnectionType(
SimConfiguration.ReaderProtocol,
SimConfiguration.ReaderChannelFlags,
SimConfiguration.ReaderBaudRate);
this.SetDefaultMessageValues(
SimConfiguration.ReaderTimeout,
SimConfiguration.ReaderMsgCount,
SimConfiguration.ResponseTimeout);

// Log out that our configuration has been set and exit out
this._simPlayingLogger.WriteLog($"APPLIED ALL CONFIGURATION VALUES FOR CONFIGURATION {SimConfiguration.ConfigurationName} CORRECTLY!", LogType.InfoLog);
}
/// <summary>
/// Toggles if we allow responses to our messages or not.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions SharpSimulator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
[assembly: Guid("183F7A6A-E107-4209-8A11-044A08DEAEE4")]

// Version information
[assembly: AssemblyVersion("0.12.5.253")]
[assembly: AssemblyFileVersion("0.12.5.253")]
[assembly: AssemblyVersion("0.12.7.260")]
[assembly: AssemblyFileVersion("0.12.7.260")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]

Loading