Пример #1
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());
        }
Пример #2
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);
        }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 private void CreateLogger(string configurationDirectory, string ssmPortName)
 {
     this.logger            = SsmLogger.GetInstance(configurationDirectory, ssmPortName);
     this.logger.LogEntry  += this.OnLogEntry;
     this.logger.LogError  += this.OnLogError;
     this.logger.Exception += this.OnLoggerException;
 }
Пример #4
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.");
        }
Пример #5
0
        public void LoggerConnect()
        {
            MockEcuStream mock = MockEcuStream.CreateInstance();

            this.logger = SsmLogger.GetInstance(Environment.CurrentDirectory, MockEcuStream.PortName);
            IAsyncResult result = logger.BeginConnect(ConnectCallback, null);

            result.AsyncWaitHandle.WaitOne();
            ParameterSource   source   = logger.EndConnect(result);
            ParameterDatabase database = ParameterDatabase.GetInstance();

            database.Add(source);

            Assert.AreEqual("2F12785206", this.logger.EcuIdentifier, "EcuIdentifier");
            Assert.IsNotNull(database);
            Assert.IsNotNull(database.Parameters);
            Assert.AreEqual(database.Parameters.Count, 178);
        }
Пример #6
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);
        }
Пример #7
0
        public void ManualLoggingTest(Action <ParameterDatabase> callback)
        {
            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));
            callback(database);
            this.logger.BeginStopLogging(NoOp, null);
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(0.1));
        }
Пример #8
0
        public void LoggerAddresses()
        {
            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;
                }
            }
            logger.SetProfile(profile, database);
            IList <int> actual   = logger.Addresses;
            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 + "]");
            }
        }
Пример #9
0
        public void LoggerProfile()
        {
            this.logger = SsmLogger.GetInstance(Environment.CurrentDirectory, MockEcuStream.PortName);
            IAsyncResult result = logger.BeginConnect(ConnectCallback, 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");
            }
        }
Пример #10
0
        private static void ConnectCallback(IAsyncResult asyncResult)
        {
            SsmLogger logger = (SsmLogger)asyncResult.AsyncState;

            logger.EndConnect(asyncResult);
        }