Example #1
0
        public void HexToIntInvalid()
        {
            // NO exception
            var actual = ObdSupport.HexToInt("FFyF");

            Assert.AreEqual(0, (int)actual);
        }
Example #2
0
        public void TestGetMultilineCanString()
        {
            const string DataVin = "0140:4902013144341:475030305235352:42313233343536";
            var          actual  = ObdSupport.GetMultilineCanString(DataVin, "4902", 17);

            Assert.AreEqual("1D4GP00R55B123456", actual);

            const string DataEcu = "0170:490A0145434D1:002D456E67696E2:65436F6E74726F3:6C000000000000";

            actual = ObdSupport.GetMultilineCanString(DataEcu, "490A", 24);
            Assert.AreEqual("ECM-EngineControl", actual);
        }
Example #3
0
        public void TestGetEngineLoad()
        {
            var actual = ObdSupport.GetCalculatedEngineLoad("00");

            Assert.AreEqual(0, actual);

            actual = ObdSupport.GetCalculatedEngineLoad("80");
            Assert.AreEqual(50, actual);

            actual = ObdSupport.GetCalculatedEngineLoad("FF");
            Assert.AreEqual(100, actual);
        }
Example #4
0
        public void TestByteToHex()
        {
            var actual = ObdSupport.ByteToHex(0);

            Assert.AreEqual("00", actual);

            actual = ObdSupport.ByteToHex(0x55);
            Assert.AreEqual("55", actual);

            actual = ObdSupport.ByteToHex(255);
            Assert.AreEqual("FF", actual);
        }
Example #5
0
        public void TestGetChar()
        {
            var actual = ObdSupport.GetChar("00");

            Assert.AreEqual('\0', actual);

            actual = ObdSupport.GetChar(":1");
            Assert.AreEqual((char)0xff, actual);

            actual = ObdSupport.GetChar("30");
            Assert.AreEqual('0', actual);

            actual = ObdSupport.GetChar("41");
            Assert.AreEqual('A', actual);
        }
Example #6
0
        public void TestGetSupportedPidText()
        {
            var actual = ObdSupport.GetSupportedPidText(0x0, 0);

            Assert.AreEqual("None", actual);

            actual = ObdSupport.GetSupportedPidText(0x1, 0);
            Assert.AreEqual("0x20", actual);

            actual = ObdSupport.GetSupportedPidText(0x80000000, 0);
            Assert.AreEqual("0x01", actual);

            actual = ObdSupport.GetSupportedPidText(0xC0000001, 0);
            Assert.AreEqual("0x01, 0x02, 0x20", actual);
        }
Example #7
0
        public void TestInt16ToHex()
        {
            var actual = ObdSupport.Int16ToHex(0, false);

            Assert.AreEqual("0000", actual);

            actual = ObdSupport.Int16ToHex(0, true);
            Assert.AreEqual("00 00", actual);

            actual = ObdSupport.Int16ToHex(0x1234, false);
            Assert.AreEqual("1234", actual);

            actual = ObdSupport.Int16ToHex(0x1234, true);
            Assert.AreEqual("12 34", actual);
        }
Example #8
0
        public void TestInt32ToHex()
        {
            var actual = ObdSupport.Int32ToHex(0, false);

            Assert.AreEqual("00000000", actual);

            actual = ObdSupport.Int32ToHex(0, true);
            Assert.AreEqual("00 00 00 00", actual);

            actual = ObdSupport.Int32ToHex(0x76543210, false);
            Assert.AreEqual("76543210", actual);

            actual = ObdSupport.Int32ToHex(0x76543210, true);
            Assert.AreEqual("76 54 32 10", actual);
        }
Example #9
0
        public void TestGetOxygenSensorsPresentText()
        {
            var actual = ObdSupport.GetOxygenSensorsPresentText(0x00);

            Assert.AreEqual(string.Empty, actual);

            actual = ObdSupport.GetOxygenSensorsPresentText(0x08);
            Assert.AreEqual("Bank 1, sensors 4", actual);

            actual = ObdSupport.GetOxygenSensorsPresentText(0x09);
            Assert.AreEqual("Bank 1, sensors 1, 4", actual);

            actual = ObdSupport.GetOxygenSensorsPresentText(0x80);
            Assert.AreEqual("Bank 2, sensors 4", actual);

            actual = ObdSupport.GetOxygenSensorsPresentText(0xFE);
            Assert.AreEqual("Bank 1, sensors 2, 3, 4, Bank 2, sensors 1, 2, 3, 4", actual);
        }
Example #10
0
        public void TestGetOxygenSensorsPresentSensorText()
        {
            var actual = ObdSupport.GetOxygenSensorsPresentSensorText(0x00);

            Assert.AreEqual(string.Empty, actual);

            actual = ObdSupport.GetOxygenSensorsPresentSensorText(0x01);
            Assert.AreEqual("1", actual);

            actual = ObdSupport.GetOxygenSensorsPresentSensorText(0x03);
            Assert.AreEqual("1, 2", actual);

            actual = ObdSupport.GetOxygenSensorsPresentSensorText(0x0F);
            Assert.AreEqual("1, 2, 3, 4", actual);

            actual = ObdSupport.GetOxygenSensorsPresentSensorText(0x09);
            Assert.AreEqual("1, 4", actual);
        }
Example #11
0
        public void TestGetOxygenSensorPid()
        {
            var actual = ObdSupport.GetOxygenSensorPid(1, 1);

            Assert.AreEqual(0x14, actual);

            actual = ObdSupport.GetOxygenSensorPid(1, 2);
            Assert.AreEqual(0x15, actual);

            actual = ObdSupport.GetOxygenSensorPid(1, 4);
            Assert.AreEqual(0x17, actual);

            actual = ObdSupport.GetOxygenSensorPid(2, 1);
            Assert.AreEqual(0x18, actual);

            actual = ObdSupport.GetOxygenSensorPid(2, 4);
            Assert.AreEqual(0x1B, actual);
        }
Example #12
0
        public void HexToInt()
        {
            var actual = ObdSupport.HexToInt("0");

            Assert.AreEqual(0, (int)actual);

            actual = ObdSupport.HexToInt("0000");
            Assert.AreEqual(0, (int)actual);

            actual = ObdSupport.HexToInt("12");
            Assert.AreEqual((uint)18, actual);

            actual = ObdSupport.HexToInt("FFFF");
            Assert.AreEqual((uint)65535, actual);

            actual = ObdSupport.HexToInt("FF FF FF");
            Assert.AreEqual((uint)0xffffff, actual);
        }
Example #13
0
        public void TestGetLastAnswer()
        {
            const string Test1  = "010C\r\n410C0fA0\r\n>";
            var          actual = ObdSupport.GetLastAnswer(Test1);

            Assert.AreEqual(Test1, actual);

            const string Test2 = "010C\r\n410C0fA0\r\n>010D\r\n410D0f\r\n>";

            actual = ObdSupport.GetLastAnswer(Test2);
            Assert.AreEqual("010D\r\n410D0f\r\n>", actual);

            actual = ObdSupport.GetLastAnswer(string.Empty);
            Assert.AreEqual(string.Empty, actual);

            actual = ObdSupport.GetLastAnswer(ObdBase.ElmPrompt);
            Assert.AreEqual(ObdBase.ElmPrompt, actual);

            actual = ObdSupport.GetLastAnswer("1>22>333>4444>");
            Assert.AreEqual("4444>", actual);
        }
Example #14
0
        public void TestGetDtcText()
        {
            var actual = ObdSupport.GetDtcText(0x0133);

            Assert.AreEqual("P0133", actual);

            actual = ObdSupport.GetDtcText(0x3133);
            Assert.AreEqual("P3133", actual);

            actual = ObdSupport.GetDtcText(0x4133);
            Assert.AreEqual("C0133", actual);

            actual = ObdSupport.GetDtcText(0x8133);
            Assert.AreEqual("B0133", actual);

            actual = ObdSupport.GetDtcText(0xC133);
            Assert.AreEqual("U0133", actual);

            actual = ObdSupport.GetDtcText(0xF369);
            Assert.AreEqual("U3369", actual);
        }
Example #15
0
        } // BtnCreateRawReportClick()

        /// <summary>
        /// Handles the Click event of the <c>btnReadDtc</c> control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing
        /// the event data.</param>
        private async void BtnReadDtcClick(object sender, EventArgs e)
        {
            if (this.obdManager == null)
            {
                return;
            } // if

            try
            {
                var monitorStatus = await this.obdManager.GetMonitorStatus();

                var milOn = ((monitorStatus & ObdBase.B7) > 0);
                this.picMil.Image = milOn ? Resources.Check_Engine_70 : Resources.Check_Engine_gray_70;
                this.lblMil.Text  = string.Format("MIL (malfunction indicator lamp) is {0}", milOn ? "ON" : "OFF");
                var numDtcs = (monitorStatus & 0x7F000000) >> 24;
                if (numDtcs == 0)
                {
                    lblNumDtc.Text = "No DTCs";
                    return;
                } // if
                lblNumDtc.Text = string.Format("#DTC = {0}", numDtcs);

                var dtcList = await this.obdManager.GetDiagnosticTroubleCodes();

                this.listViewDtc.Items.Clear();
                foreach (var dtc in dtcList)
                {
                    var dtcText        = ObdSupport.GetDtcText(dtc);
                    var dtcDescription = DtcDatabase.GetDtcDescription(dtcText);
                    var item           = new ListViewItem(dtcText);
                    item.SubItems.Add(dtcDescription);
                    this.listViewDtc.Items.Add(item);
                } // foreach
            }
            catch (Exception ex)
            {
                log.Error("Error reading DTC data", ex);
            } // catch
        }     // BtnReadDtcClick()
Example #16
0
        public void TestIsPidSupported()
        {
            const uint SupportedPids = 0xBE1FA813;

            var actual = ObdSupport.IsPidSupported(SupportedPids, 1, 0);

            Assert.IsTrue(actual);

            actual = ObdSupport.IsPidSupported(SupportedPids, 2, 0);
            Assert.IsFalse(actual);

            actual = ObdSupport.IsPidSupported(SupportedPids, 8, 0);
            Assert.IsFalse(actual);

            actual = ObdSupport.IsPidSupported(SupportedPids, 0x1E, 0);
            Assert.IsFalse(actual);

            actual = ObdSupport.IsPidSupported(SupportedPids, 0x1F, 0);
            Assert.IsTrue(actual);

            actual = ObdSupport.IsPidSupported(SupportedPids, 0x20, 0);
            Assert.IsTrue(actual);
        } // TestIsPidSupported()
Example #17
0
        } // RefreshSensorData()

        /// <summary>
        /// Updates the sensor list.
        /// </summary>
        /// <param name="supportedPids">The supported PIDs.</param>
        private void UpdateSensorList(uint supportedPids)
        {
            try
            {
                this.listViewSensor.Items.Clear();

                ListViewItem item;
                if (ObdSupport.IsPidSupported(supportedPids, 4, 0))
                {
                    item = new ListViewItem("Engine load");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 5, 0))
                {
                    item = new ListViewItem("Engine coolant temperature");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                item = new ListViewItem("Battery Voltage");
                item.SubItems.Add("<No Value>");
                item.Checked = true;
                this.listViewSensor.Items.Add(item);

                if (ObdSupport.IsPidSupported(supportedPids, 0x0c, 0))
                {
                    item = new ListViewItem("Engine RPM");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x0d, 0))
                {
                    item = new ListViewItem("Vehicle Speed");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x0f, 0))
                {
                    item = new ListViewItem("Intake air temperature");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x11, 0))
                {
                    item = new ListViewItem("Throttle position");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x1F, 0))
                {
                    item = new ListViewItem("Run time since engine start");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x2F, 0x20))
                {
                    item = new ListViewItem("Fuel Level Input");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x33, 0x20))
                {
                    item = new ListViewItem("Barometric pressure");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x43, 0x40))
                {
                    item = new ListViewItem("Absolute load value");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x45, 0x40))
                {
                    item = new ListViewItem("Relative throttle position");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x46, 0x40))
                {
                    item = new ListViewItem("Ambient air temperature");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x47, 0x40))
                {
                    item = new ListViewItem("Absolute throttle position B");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if

                if (ObdSupport.IsPidSupported(supportedPids, 0x4C, 0x40))
                {
                    item = new ListViewItem("Commanded throttle actuator");
                    item.SubItems.Add("<No Value>");
                    item.Checked = true;
                    this.listViewSensor.Items.Add(item);
                } // if
            }
            catch (Exception ex)
            {
                log.Error("Error updating sensor list", ex);
            } // catch
        }     // UpdateSensorList()
Example #18
0
        } // GetStatisticsHeader()

        /// <summary>
        /// Refreshes the sensor data.
        /// </summary>
        private async void RefreshSensorData()
        {
            if (this.obdManager == null)
            {
                return;
            } // if

            // Torque seems to write only
            // - Speed, Coolant, Throttle, RPM
            // => proposed: real time stamp, engine load
            // NOT: Battery Voltage, Throttle position, Fuel Level Input, Barometric pressure
            // Absolute load value, Relative throttle position, Absolute throttle position B,
            // Commanded throttle actuator
            var watch = new Stopwatch();

            watch.Start();
            try
            {
                var sb = new StringBuilder(200);
                sb.AppendFormat("{0};", DateTime.Now.ToString("u"));

                var supportedPids = await this.obdManager.GetSupportedPids20();

                if (this.listViewSensor.Items.Count == 0)
                {
                    this.UpdateSensorList(supportedPids);
                } // if

                var itemCount = 0;
                if ((ObdSupport.IsPidSupported(supportedPids, 4, 0)) && this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetCalculatedEngineLoad();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture, "{0}%", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 5, 0)) && this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetEngineCoolantTemperature();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0}°C", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if (this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetBatteryVoltage();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0}V", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x0C, 0)) && this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetEngineRpm();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0} rpm", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x0d, 0)) && this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetVehicleSpeed();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0} km/h", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x0f, 0)) && this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetIntakeAirTemperature();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0}°C", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x11, 0)) && this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetThrottlePosition();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0:N}%", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x1f, 0)) && this.listViewSensor.Items[itemCount].Checked)
                {
                    var totalseconds = await this.obdManager.GetRuntimeSinceEngineStart();

                    var hours   = totalseconds / 3600;
                    var minutes = (totalseconds - (hours * 3600)) / 60;
                    var seconds = totalseconds - (hours * 3600) - (minutes * 60);

                    var time = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0:D2}:{1:D2}:{2:D2}", hours, minutes, seconds);

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = time;
                    sb.AppendFormat("{0};", time);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x2f, 0x20)) &&
                    this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetFuelLevelInput();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0:N2}%", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x33, 0x20)) &&
                    this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetBarometricPressure();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0} kPa", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x43, 0x40)) &&
                    this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetAbsoluteLoadValue();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0:N}%", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x45, 0x40)) &&
                    this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetRelativeThrottlePosition();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0:N}%", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x46, 0x40)) &&
                    this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetAmbientAirTemperature();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0}°C", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x47, 0x40)) &&
                    this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetAbsoluteThrottlePositionB();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0:N}%", val);
                    sb.AppendFormat("{0};", val);
                } // if

                itemCount++;
                if ((ObdSupport.IsPidSupported(supportedPids, 0x4C, 0x40)) &&
                    this.listViewSensor.Items[itemCount].Checked)
                {
                    var val = await this.obdManager.GetCommandedThrottleActuator();

                    this.listViewSensor.Items[itemCount].SubItems[1].Text = string.Format(
                        CultureInfo.CurrentCulture,
                        "{0:N}%", val);
                    sb.AppendFormat("{0};", val);
                } // if

                this.lblLastUpdate.Text = DateTime.Now.ToLongTimeString();

                if (this.streamwriter != null)
                {
                    this.WriteToStatisticsFile(sb.ToString());
                } // if
            }
            catch (Exception ex)
            {
                log.Error("Error refreshing sensor data", ex);
            } // catch

            watch.Stop();

            // cycle time = approx 100ms with simulator
            ////log.InfoFormat("Cycle time = {0} ms", watch.ElapsedMilliseconds);
        } // RefreshSensorData()