/// <summary> /// Create a log profile from the application's configuration settings /// </summary> private LogProfile CreateLogProfile() { Trace.WriteLine("CreateLogProfile"); LogProfile profile = LogProfile.CreateInstance(); for (int i = 0; i < 6; i++) { string combined = ConfigurationManager.AppSettings[i.ToString()]; string[] idAndUnits = combined.Split(','); if (idAndUnits.Length != 2) { throw new ApplicationException("Parameter " + i.ToString() + "is not of the form \"P12,units\"." + Environment.NewLine + "Please fix this in TreeHugger.exe.config and try again"); } string id = idAndUnits[0]; string units = idAndUnits[1]; this.AddParameter(profile, id, units); } return(profile); }
/// <summary> /// Call this after the user has changed the set of parameters to log. /// </summary> public void SelectedProfileSettingsChanged() { if (this.logger == null) { Trace("Lumberjack.SelectedProfileSettingsChanged: this.logger is null - assuming this is startup time"); return; } if (this.ignoreProfileSettingsChangeNotifications) { Trace("Lumberjack.SelectedProfileSettingsChanged: ignoring"); return; } Trace("Lumberjack.SelectedProfileSettingsChanged: creating new profile"); LogProfile profile = LogProfile.CreateInstance(); this.ui.GetNewProfileSettings(profile); this.ui.SetSaveButtonState(true); this.logger.SetProfile(profile); this.logger.StartLogging(); this.currentProfileIsChanged = true; this.SetTitle(); }
public void BasicLoggerAddressesDuplicates() { MockEcuStream stream = MockEcuStream.CreateInstance(); this.logger = SsmBasicLogger.GetInstance(Environment.CurrentDirectory, stream); IAsyncResult result = logger.BeginConnect(null, null); result.AsyncWaitHandle.WaitOne(); ParameterSource source = logger.EndConnect(result); ParameterDatabase database = ParameterDatabase.GetInstance(); database.Add(source); LogProfile profile = LogProfile.CreateInstance(); Parameter parameter; database.TryGetParameterById("P8", out parameter); // engine speed (14) profile.Add(parameter, parameter.Conversions[0]); database.TryGetParameterById("P201", out parameter); // IDC, requires engine speed (14), IPW (32) profile.Add(parameter, parameter.Conversions[0]); database.TryGetParameterById("P202", out parameter); // MRP(corrected), requires MAP (13), Atmo (35) profile.Add(parameter, parameter.Conversions[0]); database.TryGetParameterById("P7", out parameter); // MAP (13) profile.Add(parameter, parameter.Conversions[0]); // IPW is not in the resulting set of addresses, why? this.logger.SetProfile(profile, database); List <int> addresses = this.logger.Addresses; Assert.AreEqual(5, addresses.Count); int[] expected = new int[] { 14, 15, 13, 32, 35 }; Utility.CompareArrays("Address arrays", expected, addresses.ToArray()); }
public void LoggerAddressesDuplicates() { this.logger = SsmLogger.GetInstance(Environment.CurrentDirectory, MockEcuStream.PortName); IAsyncResult result = logger.BeginConnect(null, null); result.AsyncWaitHandle.WaitOne(); ParameterSource source = logger.EndConnect(result); ParameterDatabase database = ParameterDatabase.GetInstance(); database.Add(source); LogProfile profile = LogProfile.CreateInstance(); Parameter parameter; database.TryGetParameterById("P8", out parameter); profile.Add(parameter, parameter.Conversions[0]); database.TryGetParameterById("P201", out parameter); profile.Add(parameter, parameter.Conversions[0]); database.TryGetParameterById("P202", out parameter); profile.Add(parameter, parameter.Conversions[0]); database.TryGetParameterById("P7", out parameter); profile.Add(parameter, parameter.Conversions[0]); this.logger.SetProfile(profile, database); List <int> addresses = this.logger.Addresses; Assert.AreEqual(5, addresses.Count); int[] expected = new int[] { 14, 15, 13, 32, 35 }; Utility.CompareArrays("Address arrays", expected, addresses.ToArray()); }
public void LoggerManualLoggingChangeProfile() { ManualLoggingTest(delegate(ParameterDatabase database) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.1)); int entriesBefore = this.logEntryCalls; LogProfile newProfile = LogProfile.CreateInstance(); foreach (SsmParameter parameter in database.Parameters) { switch (parameter.Name) { case "Injector Duty Cycle": case "Manifold Rel. Pressure (Corrected)": newProfile.Add(parameter, parameter.Conversions[0]); break; } } this.logger.SetProfile(newProfile, database); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.5)); int entriesAfter = this.logEntryCalls; this.logEntryCallsAfterChange = entriesAfter - entriesBefore; }); Console.WriteLine("LogEntry calls: " + this.logEntryCalls); Assert.AreEqual(2, this.logStartCalls, "LogStart calls"); Assert.IsTrue(this.logEntryCalls > 1, "LogEntry calls > 1"); Assert.IsTrue(this.logEntryCallsAfterChange > 3, "LogEntry calls after change"); Assert.AreEqual(2, this.logEndCalls, "LogEnd calls"); Assert.AreEqual(0, this.logErrorCalls, "LogError calls"); }
public void LoggerSuspendResume() { this.logger = SsmLogger.GetInstance(Environment.CurrentDirectory, MockEcuStream.PortName); IAsyncResult result = logger.BeginConnect(null, null); result.AsyncWaitHandle.WaitOne(); ParameterSource source = logger.EndConnect(result); ParameterDatabase database = ParameterDatabase.GetInstance(); database.Add(source); LogProfile profile = LogProfile.CreateInstance(); foreach (SsmParameter parameter in database.Parameters) { profile.Add(parameter, parameter.Conversions[0]); if (profile.Columns.Count > 3) { break; } } this.logStartCalls = 0; this.logEntryCalls = 0; this.logEndCalls = 0; this.logErrorCalls = 0; this.logger.SetProfile(profile, database); this.logger.LogStart += this.LogStart; this.logger.LogEntry += this.LogEntry; this.logger.LogStop += this.LogStop; this.logger.LogError += this.LogError; this.logger.StartLogging(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.25)); this.logger.Suspend(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.25)); int entriesBeforeSuspend = this.logEntryCalls; Debug.WriteLine("Entries before suspend: " + entriesBeforeSuspend.ToString()); this.logger.Resume(TimeSpan.FromMilliseconds(250)); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.5)); int entriesAfterSuspend = this.logEntryCalls; Debug.WriteLine("Entries after suspend: " + entriesAfterSuspend.ToString()); this.logger.BeginStopLogging(NoOp, null); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.1)); Assert.IsTrue(entriesAfterSuspend > entriesBeforeSuspend, "Resumed logging after suspend/resume."); }
public void InternalLogProfileNoParameters() { ParameterDatabase database = ParameterDatabase.GetInstance(); MockParameterSource source = new MockParameterSource(); database.Add(source); LogProfile publicProfile = LogProfile.CreateInstance(); InternalLogProfile internalProfile = InternalLogProfile.GetInstance(publicProfile, database); Assert.AreEqual(0, internalProfile.Addresses.Count); }
public void BasicLoggerDependencyConversions() { MockEcuStream stream = MockEcuStream.CreateInstance(); this.logger = SsmBasicLogger.GetInstance(Environment.CurrentDirectory, stream); IAsyncResult result = logger.BeginConnect(null, null); result.AsyncWaitHandle.WaitOne(); ParameterSource source = logger.EndConnect(result); ParameterDatabase database = ParameterDatabase.GetInstance(); database.Add(source); LogProfile baseParameters = LogProfile.CreateInstance(); foreach (SsmParameter parameter in database.Parameters) { if (parameter.Id == "P201") { baseParameters.Add(parameter, parameter.Conversions[0]); } if (parameter.Id == "P202") { baseParameters.Add(parameter, parameter.Conversions[0]); break; } } this.logger.SetProfile(baseParameters, database); LogEventArgs args = this.logger.GetOneRow(); Utility.AssertColumnParameterId(args, 0, "P201"); Utility.AssertColumnParameterId(args, 1, "P202"); Utility.AssertColumnParameterId(args, 2, "P8"); Utility.AssertColumnParameterId(args, 3, "P21"); Utility.AssertColumnParameterId(args, 4, "P7"); Utility.AssertColumnParameterId(args, 5, "P24"); Assert.AreEqual(6, args.Row.Columns.Count); List <int> addresses = this.logger.Addresses; Assert.AreEqual(5, addresses.Count); int[] expected = new int[] { 14, 15, 32, 13, 35 }; Utility.CompareArrays("Address arrays", expected, addresses.ToArray()); // Values from observation... Assert.AreEqual("2.08", args.Row.Columns[0].ValueAsString); Assert.AreEqual("1.02", args.Row.Columns[1].ValueAsString); }
/// <summary> /// Call this when the user wants to create a new profile. /// </summary> public void ProfileNew() { Trace("Lumberjack.ProfileNew"); LogProfile empty = LogProfile.CreateInstance(); this.logger.SetProfile(empty); this.Settings.LastProfilePath = null; this.ShowNewProfileSettings(); this.ui.SelectProfile(null); this.ui.SetSaveButtonState(false); this.currentProfileIsChanged = false; this.SetTitle(); }
public void InternalLogProfileMockParameters() { ParameterDatabase database = ParameterDatabase.GetInstance(); MockParameterSource source = new MockParameterSource(); database.Add(source); LogProfile publicProfile = LogProfile.CreateInstance(); publicProfile.Add(database.Parameters[0], database.Parameters[0].Conversions[0]); publicProfile.Add(database.Parameters[1], database.Parameters[1].Conversions[0]); InternalLogProfile internalProfile = InternalLogProfile.GetInstance(publicProfile, database); Assert.AreEqual(0, internalProfile.Addresses.Count); Assert.AreEqual(2, internalProfile.LogEventArgs.Row.Columns.Count); }
/// <summary> /// Second half of LoadSelectedProfile /// </summary> private void ContinueLoadSelectedProfile(IAsyncResult asyncResult) { Trace("Lumberjack.ContinueLoadSelectedProfile"); string profilePath = (string)asyncResult.AsyncState; this.ui.Invoke(delegate { Trace("Lumberjack.ContinueLoadSelectedProfile (UI thread)"); LogProfile profile; if (profilePath == null) { Trace("Lumberjack.ContinueLoadSelectedProfile: creating trivial profile"); profile = LogProfile.CreateInstance(); /* foreach (SsmParameter parameter in this.logger.Database.Parameters) * { * // Add the RPM parameter and nothing else. * if (parameter.Id == "P8") * { * profile.Add(parameter, parameter.Conversions[0]); * break; * } * } */ } else { Trace("Lumberjack.ContinueLoadSelectedProfile: loading " + profilePath); profile = LogProfile.Load(profilePath, this.database); } this.logger.SetProfile(profile); this.logger.StartLogging(); this.Settings.LastProfilePath = profilePath; this.Settings.Save(); this.ignoreProfileSettingsChangeNotifications = true; this.ui.ShowNewProfileSettings(this.logger.CurrentProfile); this.ui.SelectProfile(this.Settings.LastProfilePath); this.ignoreProfileSettingsChangeNotifications = false; this.currentProfileIsChanged = false; this.ui.SetSaveButtonState(true); this.SetTitle(); }); }
private LogProfile GenerateProfile() { LogProfile profile = LogProfile.CreateInstance(); this.AddScreenParameters(profile, this.currentScreen); foreach (SawMillScreen screen in this.screens) { if ((screen.ForegroundOnly) || (screen == this.currentScreen)) { continue; } AddScreenParameters(profile, screen); } profile.Add("P200", "g/rev", this.database); return(profile); }
/// <summary> /// Create a LogProfile, using parameters passed to ctor and the given SsmLogger's database. /// </summary> public LogProfile GetProfile(ParameterDatabase database) { if (database == null) { throw new ArgumentNullException("database"); } if (this.profile != null) { return(this.profile); } this.profile = LogProfile.CreateInstance(); foreach (string combined in this.parameters) { string[] idAndUnits = combined.Split(','); if (idAndUnits.Length != 2) { continue; } string id = idAndUnits[0]; string units = idAndUnits[1]; try { profile.Add(id, units, database); } catch (ArgumentException) { MessageBox.Show("Parameter " + id + " is not supported for your car." + Environment.NewLine + "The " + this.name + " screen will not work."); } } if (this.profile.UserData != null) { System.Diagnostics.Debugger.Break(); } this.profile.UserData = this; return(this.profile); }
public void ManualLoggingTest(Action <ParameterDatabase> callback) { MockEcuStream stream = MockEcuStream.CreateInstance(); FragmentedStream fragStream = FragmentedStream.GetInstance(stream); this.logger = SsmBasicLogger.GetInstance(Environment.CurrentDirectory, fragStream); IAsyncResult result = logger.BeginConnect(null, null); result.AsyncWaitHandle.WaitOne(); ParameterSource source = logger.EndConnect(result); ParameterDatabase database = ParameterDatabase.GetInstance(); database.Add(source); LogProfile Profile = LogProfile.CreateInstance(); foreach (SsmParameter parameter in database.Parameters) { Profile.Add(parameter, parameter.Conversions[0]); if (Profile.Columns.Count > 3) { break; } } this.logStartCalls = 0; this.logEntryCalls = 0; this.logEndCalls = 0; this.logErrorCalls = 0; this.logger.SetProfile(Profile, database); this.logger.LogStart += this.LogStart; this.logger.LogEntry += this.LogEntry; this.logger.LogStop += this.LogStop; this.logger.LogError += this.LogError; this.logger.StartLogging(); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.25)); callback(database); this.logger.BeginStopLogging(NoOp, null); System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.1)); }
public void BasicLoggerAddresses() { MockEcuStream stream = MockEcuStream.CreateInstance(); SsmBasicLogger logger = SsmBasicLogger.GetInstance(Environment.CurrentDirectory, stream); IAsyncResult result = logger.BeginConnect(null, null); result.AsyncWaitHandle.WaitOne(); ParameterSource source = logger.EndConnect(result); ParameterDatabase database = ParameterDatabase.GetInstance(); database.Add(source); LogProfile profile = LogProfile.CreateInstance(); foreach (SsmParameter parameter in database.Parameters) { profile.Add(parameter, parameter.Conversions[0]); if (profile.Columns.Count == 8) { break; } } logger.SetProfile(profile, database); IList <int> actual = logger.Addresses; // Note that parameters get re-ordered alphabetically IList <int> expected = new int[] { // 9, 10, 8, 14, 15, 17, 18, 13, 16, 8, 9, 10, 13, 14, 15, 16, 17, 18, }; Assert.AreEqual(expected.Count, actual.Count, "Addresses.Length"); for (int i = 0; i < expected.Count; i++) { Assert.AreEqual(expected[i], actual[i], "Addresses[" + i + "]"); } }
public void LoggerUserData() { SsmLogger logger = SsmLogger.GetInstance(Environment.CurrentDirectory, MockEcuStream.PortName); IAsyncResult result = logger.BeginConnect(null, null); result.AsyncWaitHandle.WaitOne(); ParameterSource source = logger.EndConnect(result); ParameterDatabase database = ParameterDatabase.GetInstance(); database.Add(source); LogProfile profile = LogProfile.CreateInstance(); foreach (SsmParameter parameter in database.Parameters) { profile.Add(parameter, parameter.Conversions[0]); if (profile.Columns.Count == 8) { break; } } string userData = "UserData"; profile.UserData = userData; logger.SetProfile(profile, database); logger.LogStart += this.LoggerUserDataLogStart; logger.LogEntry += this.LoggerUserDataLogEntry; logger.LogStop += this.LoggerUserDataLogStop; logger.StartLogging(); System.Threading.Thread.Sleep(500); IAsyncResult stopResult = logger.BeginStopLogging(null, null); stopResult.AsyncWaitHandle.WaitOne(); logger.EndStopLogging(stopResult); Assert.AreSame(userData, userDataFromLogStart); Assert.AreSame(userData, userDataFromLogEntry); Assert.AreSame(userData, userDataFromLogStop); }
public void LogProfileSaveAndReload() { ParameterDatabase database = this.InitializeLogger(); LogProfile expectedProfile = LogProfile.CreateInstance(); foreach (SsmParameter parameter in database.Parameters) { expectedProfile.Add(parameter, parameter.Conversions[0]); if (expectedProfile.Columns.Count > 3) { break; } } this.logger.SetProfile(expectedProfile, database); expectedProfile.Save("profile.xml"); LogProfile emptyProfile = LogProfile.CreateInstance(); this.logger.SetProfile(emptyProfile, database); LogProfile loadedProfile = LogProfile.Load("profile.xml", database); this.logger.SetProfile(loadedProfile, database); LogProfile actualProfile = this.logger.CurrentProfile; foreach (LogColumn column in actualProfile.Columns) { Assert.IsTrue(expectedProfile.Contains(column.Parameter)); } foreach (LogColumn column in expectedProfile.Columns) { Assert.IsTrue(actualProfile.Contains(column.Parameter)); } }
public void BasicLoggerProfile() { MockEcuStream stream = MockEcuStream.CreateInstance(); this.logger = SsmBasicLogger.GetInstance(Environment.CurrentDirectory, stream); IAsyncResult result = logger.BeginConnect(null, null); result.AsyncWaitHandle.WaitOne(); ParameterSource source = logger.EndConnect(result); ParameterDatabase database = ParameterDatabase.GetInstance(); database.Add(source); LogProfile expectedProfile = LogProfile.CreateInstance(); foreach (SsmParameter parameter in database.Parameters) { expectedProfile.Add(parameter, parameter.Conversions[0]); if (expectedProfile.Columns.Count > 3) { break; } } logger.SetProfile(expectedProfile, database); LogProfile actualProfile = logger.CurrentProfile; Assert.AreEqual(expectedProfile.Columns.Count, actualProfile.Columns.Count, "Actual count and expected count"); foreach (LogColumn expectedColumn in expectedProfile.Columns) { Assert.IsTrue(actualProfile.Contains(expectedColumn.Parameter), "Actual expected parameter set is missing something"); } foreach (LogColumn actualColumn in actualProfile.Columns) { Assert.IsTrue(expectedProfile.Contains(actualColumn.Parameter), "Actual expected parameter set contains something extra"); } }
public void LumberjackLoadNewClose() { MockUserInterface mui = new MockUserInterface(); Lumberjack lumberjack = new Lumberjack(mui); mui.Lumberjack = lumberjack; lumberjack.Load(); Thread.Sleep(loadSleep); lumberjack.ProfileNew(); Thread.Sleep(actionSleep); mui.Profile = LogProfile.CreateInstance(); mui.Profile.Add("P8", "rpm", lumberjack.Database); lumberjack.SelectedProfileSettingsChanged(); Thread.Sleep(actionSleep); bool cancel = false; lumberjack.Closing(ref cancel); Thread.Sleep(actionSleep); string record = mui.ToString(); AssertRecordingStart(); AssertRecorded(ref record, "SetTitle"); AssertRecorded(ref record, "ShowNewProfileSettings"); AssertRecorded(ref record, "SaveButtonEnabled: False"); AssertRecorded(ref record, "SetTitle: Lumberjack - Mock ECU - new profile"); //AssertRecorded(ref record, "RenderLogEntry"); AssertRecorded(ref record, "GetNewProfileSettings"); AssertRecorded(ref record, "SaveButtonEnabled: True"); AssertRecorded(ref record, "SetTitle: Lumberjack - Mock ECU - new profile*"); //AssertRecorded(ref record, "New Profile.profile"); //AssertRecorded(ref record, "Close"); Assert.Inconclusive("This test needs more work."); }
public void InternalLogProfileSsmAddressesOneParameter() { ParameterDatabase database = ParameterDatabase.GetInstance(); SsmParameterSource source = SsmParameterSource.GetInstance( Environment.CurrentDirectory, SsmParameterSourceTest.EcuIdentifier, SsmParameterSourceTest.CompatibilityMap); database.Add(source); LogProfile publicProfile = LogProfile.CreateInstance(); SsmParameter parameter = database.Parameters[0] as SsmParameter; publicProfile.Add(parameter, parameter.Conversions[0]); InternalLogProfile internalProfile = InternalLogProfile.GetInstance(publicProfile, database); Assert.AreEqual(1, internalProfile.Addresses.Count); Assert.AreEqual(parameter.Address, internalProfile.Addresses[0]); Assert.AreEqual(1, internalProfile.LogEventArgs.Row.Columns.Count); LogColumn column = internalProfile.LogEventArgs.Row.Columns[0]; Assert.AreEqual(column.PropertyBag[InternalLogProfile.ColumnAddressIndex], 0); }