示例#1
0
        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());
        }
示例#2
0
        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());
        }
示例#3
0
        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);
        }
示例#4
0
        static void ManualLoggingTest(Stream ecuStream, SerialPort port)
        {
            SsmLogger    logger      = SsmLogger.GetInstance(Environment.CurrentDirectory, ecuStream);
            IAsyncResult asyncResult = logger.BeginConnect(ConnectCallback, logger);

            asyncResult.AsyncWaitHandle.WaitOne();

            LogProfile profile = LogProfile.GetInstance();

            foreach (SsmParameter parameter in logger.Database.Parameters)
            {
                switch (parameter.Name)
                {
                case "Engine Load":
                case "Manifold Relative Pressure":
                case "Engine Speed":
                    profile.Add(parameter, parameter.Conversions[0]);
                    break;
                }
            }

            logger.SetProfile(profile);
            logger.LogStart += LogStart;
            logger.LogEntry += LogEntry;
            logger.LogStop  += LogEnd;
            logger.StartLogging();
            for (int i = 0; i < 100000 && !Console.KeyAvailable; i++)
            {
                Thread.Sleep(1);
            }
            logger.StopLogging();
            Thread.Sleep(500);
        }
示例#5
0
        /// <summary>
        /// Get log profile settings from the UI
        /// </summary>
        /// <param name="profile">log profile</param>
        void IUserInterface.GetNewProfileSettings(LogProfile profile)
        {
            Trace("MainForm.GetNewProfileSettings");

            foreach (DataGridViewRow row in this.parameterGrid.Rows)
            {
                if ((bool)row.Cells[(int)GridColumns.Enabled].Value)
                {
                    DataGridViewComboBoxCell conversionCell = (DataGridViewComboBoxCell)row.Cells[(int)GridColumns.Conversions];
                    Conversion conversion = null;
                    foreach (Conversion candidate in conversionCell.Items)
                    {
                        // The cell.Value can be a string.  WTF?
                        if ((candidate.Units == conversionCell.Value as string) ||
                            (candidate == conversionCell.Value as Conversion))
                        {
                            conversion = candidate;
                            break;
                        }
                    }

                    if (conversion != null)
                    {
                        Parameter parameter = (Parameter)row.Cells[(int)GridColumns.Parameter].Value;
                        profile.Add(parameter, conversion);
                    }
                    else
                    {
                        // TODO: apologize to user?
                    }
                }
            }
        }
        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);
        }
示例#7
0
        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");
        }
示例#8
0
        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.");
        }
示例#9
0
        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);
        }
示例#10
0
        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));
        }
示例#11
0
        /// <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);
        }
示例#12
0
        private void AddScreenParameters(LogProfile profile, SawMillScreen screen)
        {
            if (this.database == null)
            {
                throw new InvalidOperationException("Logger must be connected and database must be initialized before calling AddScreenParameters");
            }

            LogProfile screenProfile = screen.GetProfile(this.database);

            foreach (LogColumn column in screenProfile.Columns)
            {
                Parameter          parameter   = column.Parameter;
                IList <Conversion> conversions = screenProfile.GetConversions(parameter);
                foreach (Conversion conversion in conversions)
                {
                    profile.Add(parameter, conversion);
                }
            }
        }
示例#13
0
        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);
        }
示例#14
0
        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 + "]");
            }
        }
示例#15
0
        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));
            }
        }
示例#16
0
        /// <summary>
        /// Add a parameter to the log profile
        /// </summary>
        private void AddParameter(LogProfile profile, string id, string units)
        {
            foreach (SsmParameter parameter in this.database.Parameters)
            {
                if (parameter.Id == id)
                {
                    foreach (Conversion conversion in parameter.Conversions)
                    {
                        if (conversion.Units == units)
                        {
                            profile.Add(parameter, conversion);
                            return;
                        }
                    }

                    throw new ApplicationException(
                              "Conversion " + units + " not found for parameter " + id);
                }
            }

            throw new ApplicationException(
                      "Parameter " + id + " not found.");
        }
示例#17
0
        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");
            }
        }
示例#18
0
        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);
        }