Ejemplo n.º 1
0
        public void TestNewDataSubscriber()
        {
            ConfigurationData config = new ConfigurationData();
            OBDDeviceCommunicatorAsync obd = new OBDDeviceCommunicatorAsync(null, config);

            string PIDreturn_engineLoad = "7E8 03 41 04 FF";
            // 0x03 bytes, mode (0x41 - 0x40) = 0x01, PID 0x04, message 0xFF = 0d255
            // betekenis: Calculated engine load value (%). Formule: A*100/255 = 255*100/255 = 100%
            string expectedAnswer = "100";
            int mode = 0x01;
            int sensor = 0x04;

            bool answered = false;
            string answer = "";
            PIDSensor loadValueSensor = config.GetSensor(mode, sensor);
            loadValueSensor.RaiseOBDSensorData += (object sender, OBDSensorDataEventArgs s) =>
            {
                answer = s.value;
                answered = true;
            };
            obd.cleanAndHandleResponses(PIDreturn_engineLoad);
            DateTime startWaiting = DateTime.Now;
            while (!answered && DateTime.Now > startWaiting.AddSeconds(1)) ;
            Assert.IsTrue(answered, "Event didn't raise within one second");
            Assert.IsTrue(answer == expectedAnswer, "Event value incorrect: is %s, should be %s", answer, expectedAnswer);

            // string PIDreturn_throttlePosition = "7E8 03 41 04 1B";
            // 0x03 bytes, mode (0x41 - 0x40) = 0x01, PID 0x11 = 0d17, message 0x26 = 0d38
            // betekenis: Throttle position (%). Formule: A*100/255 = 38*100/255 = 7%
        }
Ejemplo n.º 2
0
        public void TestInitPIDClass()
        {
            string   xmlSource = "<PIDList>\r\n  <SensorAvailability Mode=\"01\">\r\n    <PIDSensor PID=\"00\" bytes=\"04\" firstPID=\"01\" Description=\"PIDs supported [01 - 20]\">\r\n    </PIDSensor>\r\n  </SensorAvailability>\r\n</PIDList>";
            XElement dSource   = XElement.Parse(xmlSource, LoadOptions.None);


            Koos__OBD_Communicator.ConfigurationData testConfig = new Koos__OBD_Communicator.ConfigurationData(dSource);

            // There's only one availability mode in this example, so there is only one 'root' PID sensor
            Assert.IsTrue(testConfig.possibleSensors.Count == 1);

            // The mode should be written to the key of the dict:
            Assert.IsTrue(testConfig.possibleSensors.First().Key == 1);

            var sensor = testConfig.possibleSensors.First().Value;

            // The properties should have been recorded correctly:
            Assert.IsTrue(sensor.PID == 0);
            Assert.IsTrue(sensor.bytes == 4);
            // Assert.IsTrue(sensor.firstPID == 1); --> this is filtered in the config loading: whithout children, mentioning the range of children is useless.
            Assert.IsTrue(sensor.description == "PIDs supported [01 - 20]");

            // The sensor shouldn't have any descendants
            Assert.IsTrue(sensor.PIDSensors.Count == 0);
        }
Ejemplo n.º 3
0
        public void testModeNotFound()
        {
            string   PID00     = "    <PIDSensor PID=\"00\" bytes=\"04\" firstPID=\"01\" Description=\"PIDs supported [01 - 20]\">\r\n    </PIDSensor>\r\n";
            string   xmlSource = "<PIDList>\r\n  <SensorAvailability Mode=\"01\">\r\n" + PID00 + "  </SensorAvailability>\r\n</PIDList>";
            XElement dSource   = XElement.Parse(xmlSource, LoadOptions.None);

            Koos__OBD_Communicator.ConfigurationData testConfig = new Koos__OBD_Communicator.ConfigurationData(dSource);

            testConfig.GetSensor(15, 16);
        }
Ejemplo n.º 4
0
        public void TestDecodingOfReturnMessage()
        {
            bool[] supported_shouldbe = new bool[] { true, false, true, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, true, true, false, false, false, false, false, false, false, true, false, false, false, true };
            int firstPID = 0x21;
            int lastPID = 0x40;
            int mode = 1;
            int base_pid = 0x20;
            //                               7E8064100BE 3F A8 11
            string returnMessage_cleansed = "7E8064120A007B011";
            // A0 07 B0 11 = 1010 0000 0000 0111 1011 0000 0001 0001

            string PID00 = "    <PIDSensor PID=\"" + base_pid.ToString("X") + "\" bytes=\"04\" firstPID=\"" + firstPID.ToString("X") + "\" Description=\"PIDs supported [01 - 20]\">\r\n";
            for (int nPID = firstPID; nPID <= lastPID; nPID++)
            {
                PID00 += "      <PIDSensor PID=\"" + nPID.ToString("X") + "\" bytes=\"02\" Description=\"Testje\" Formula=\"((A*256)+B) / 100\" />\r\n";
            }
            PID00 += "    </PIDSensor>\r\n";
            string xmlSource = "<PIDList>\r\n  <SensorAvailability Mode=\"01\">\r\n" + PID00 + "  </SensorAvailability>\r\n</PIDList>";

            var configTest = new ConfigurationData(XElement.Parse(xmlSource, LoadOptions.None));

            configTest.parseOBDResponse(returnMessage_cleansed);

            var availableSensors = configTest.availableSensors();

            for(int nPID = firstPID; nPID <= lastPID; nPID++)
            {
                var currentSensor = configTest.GetSensor(mode, nPID);
                if(supported_shouldbe[nPID - firstPID])
                {
                    // First, the availability on the sensor should be set to true
                    Assert.IsTrue(currentSensor.isAvailable);
                    // Secondly, the sensor should show up in the availability list
                    Assert.IsTrue(availableSensors.Contains(currentSensor));
                }
                else
                {
                    // First, the availability on the sensor should be set to false
                    Assert.IsFalse(currentSensor.isAvailable);

                    // Secondly, the sensor should not show up in the availability list
                    Assert.IsFalse(availableSensors.Contains(currentSensor));
                }
            }
        }
Ejemplo n.º 5
0
        public void testPIDSearch()
        {
            string   PID10     = "      <PIDSensor PID=\"10\" bytes=\"02\" Description=\"MAF air flow rate (grams / sec)\" Formula=\"((A*256)+B) / 100\" />\r\n";
            string   PID11     = "      <PIDSensor PID=\"11\" bytes=\"01\" Description=\"Throttle position (%)\" Formula=\"A*100/255\" />\r\n";
            string   PID00     = "    <PIDSensor PID=\"00\" bytes=\"04\" firstPID=\"01\" Description=\"PIDs supported [01 - 20]\">\r\n" + PID10 + PID11 + "    </PIDSensor>\r\n";
            string   xmlSource = "<PIDList>\r\n  <SensorAvailability Mode=\"01\">\r\n" + PID00 + "  </SensorAvailability>\r\n</PIDList>";
            XElement dSource   = XElement.Parse(xmlSource, LoadOptions.None);

            Koos__OBD_Communicator.ConfigurationData testConfig = new Koos__OBD_Communicator.ConfigurationData(dSource);

            var sensor      = testConfig.possibleSensors.First().Value;
            var PIDSensor10 = sensor.PIDSensors.First();
            var PIDSensor11 = sensor.PIDSensors.Last();

            Assert.IsTrue(testConfig.GetSensor(1, 0) == sensor);
            Assert.IsTrue(testConfig.GetSensor(1, 16) == PIDSensor10);
            Assert.IsTrue(testConfig.GetSensor(1, 17) == PIDSensor11);
        }
Ejemplo n.º 6
0
        public void TestInitPIDClassWithChildren()
        {
            string   PID10     = "      <PIDSensor PID=\"10\" bytes=\"02\" Description=\"MAF air flow rate (grams / sec)\" Formula=\"((A*256)+B) / 100\" />\r\n";
            string   PID11     = "      <PIDSensor PID=\"11\" bytes=\"01\" Description=\"Throttle position (%)\" Formula=\"A*100/255\" />\r\n";
            string   PID00     = "    <PIDSensor PID=\"00\" bytes=\"04\" firstPID=\"01\" Description=\"PIDs supported [01 - 20]\">\r\n" + PID10 + PID11 + "    </PIDSensor>\r\n";
            string   xmlSource = "<PIDList>\r\n  <SensorAvailability Mode=\"01\">\r\n" + PID00 + "  </SensorAvailability>\r\n</PIDList>";
            XElement dSource   = XElement.Parse(xmlSource, LoadOptions.None);

            Koos__OBD_Communicator.ConfigurationData testConfig = new Koos__OBD_Communicator.ConfigurationData(dSource);

            // There's only one availability mode in this example, so there is only one 'root' PID sensor
            Assert.IsTrue(testConfig.possibleSensors.Count == 1);

            // The mode should be written to the key of the dict:
            Assert.IsTrue(testConfig.possibleSensors.First().Key == 1);

            var sensor = testConfig.possibleSensors.First().Value;

            // The properties of PID 0 should have been recorded correctly:
            Assert.IsTrue(sensor.PID == 0);
            Assert.IsTrue(sensor.bytes == 4);
            Assert.IsTrue(sensor.firstPID == 1);
            Assert.IsTrue(sensor.description == "PIDs supported [01 - 20]");

            // The sensor should have two descendants
            Assert.IsTrue(sensor.PIDSensors.Count == 2);

            // The descendants should have been loaded correctly
            var PIDSensor10 = sensor.PIDSensors.First();
            var PIDSensor11 = sensor.PIDSensors.Last();

            Assert.IsTrue(PIDSensor10.PID == 16); // 16 = 10 hex
            Assert.IsTrue(PIDSensor11.PID == 17); // 17 = 11 hex
            Assert.IsTrue(PIDSensor10.bytes == 2);
            Assert.IsTrue(PIDSensor11.bytes == 1);
            Assert.IsTrue(PIDSensor10.description == "MAF air flow rate (grams / sec)");
            Assert.IsTrue(PIDSensor11.description == "Throttle position (%)");
            Assert.IsTrue(PIDSensor10.formula == "((A*256)+B) / 100");
            Assert.IsTrue(PIDSensor11.formula == "A*100/255");
            Assert.IsTrue(PIDSensor10.highestFormulaCharacter == 'B');
            Assert.IsTrue(PIDSensor11.highestFormulaCharacter == 'A');
            Assert.IsTrue(PIDSensor10.highestFormulaCharacterNumber == 1);
            Assert.IsTrue(PIDSensor11.highestFormulaCharacterNumber == 0);
        }
Ejemplo n.º 7
0
        public void TestInitPIDClassWithChildren()
        {
            string PID10 = "      <PIDSensor PID=\"10\" bytes=\"02\" Description=\"MAF air flow rate (grams / sec)\" Formula=\"((A*256)+B) / 100\" />\r\n";
            string PID11 = "      <PIDSensor PID=\"11\" bytes=\"01\" Description=\"Throttle position (%)\" Formula=\"A*100/255\" />\r\n";
            string PID00 = "    <PIDSensor PID=\"00\" bytes=\"04\" firstPID=\"01\" Description=\"PIDs supported [01 - 20]\">\r\n" + PID10 + PID11 + "    </PIDSensor>\r\n";
            string xmlSource = "<PIDList>\r\n  <SensorAvailability Mode=\"01\">\r\n" + PID00 + "  </SensorAvailability>\r\n</PIDList>";
            XElement dSource = XElement.Parse(xmlSource, LoadOptions.None);
            Koos__OBD_Communicator.ConfigurationData testConfig = new Koos__OBD_Communicator.ConfigurationData(dSource);

            // There's only one availability mode in this example, so there is only one 'root' PID sensor
            Assert.IsTrue(testConfig.possibleSensors.Count == 1);

            // The mode should be written to the key of the dict:
            Assert.IsTrue(testConfig.possibleSensors.First().Key == 1);

            var sensor = testConfig.possibleSensors.First().Value;
            // The properties of PID 0 should have been recorded correctly:
            Assert.IsTrue(sensor.PID == 0);
            Assert.IsTrue(sensor.bytes == 4);
            Assert.IsTrue(sensor.firstPID == 1);
            Assert.IsTrue(sensor.description == "PIDs supported [01 - 20]");

            // The sensor should have two descendants
            Assert.IsTrue(sensor.PIDSensors.Count == 2);

            // The descendants should have been loaded correctly
            var PIDSensor10 = sensor.PIDSensors.First();
            var PIDSensor11 = sensor.PIDSensors.Last();
            Assert.IsTrue(PIDSensor10.PID == 16); // 16 = 10 hex
            Assert.IsTrue(PIDSensor11.PID == 17); // 17 = 11 hex
            Assert.IsTrue(PIDSensor10.bytes == 2);
            Assert.IsTrue(PIDSensor11.bytes == 1);
            Assert.IsTrue(PIDSensor10.description == "MAF air flow rate (grams / sec)");
            Assert.IsTrue(PIDSensor11.description == "Throttle position (%)");
            Assert.IsTrue(PIDSensor10.formula == "((A*256)+B) / 100");
            Assert.IsTrue(PIDSensor11.formula == "A*100/255");
            Assert.IsTrue(PIDSensor10.highestFormulaCharacter == 'B');
            Assert.IsTrue(PIDSensor11.highestFormulaCharacter == 'A');
            Assert.IsTrue(PIDSensor10.highestFormulaCharacterNumber == 1);
            Assert.IsTrue(PIDSensor11.highestFormulaCharacterNumber == 0);
        }
Ejemplo n.º 8
0
        public void TestInitPIDClass()
        {
            string xmlSource = "<PIDList>\r\n  <SensorAvailability Mode=\"01\">\r\n    <PIDSensor PID=\"00\" bytes=\"04\" firstPID=\"01\" Description=\"PIDs supported [01 - 20]\">\r\n    </PIDSensor>\r\n  </SensorAvailability>\r\n</PIDList>";
            XElement dSource = XElement.Parse(xmlSource, LoadOptions.None);

            Koos__OBD_Communicator.ConfigurationData testConfig = new Koos__OBD_Communicator.ConfigurationData(dSource);

            // There's only one availability mode in this example, so there is only one 'root' PID sensor
            Assert.IsTrue(testConfig.possibleSensors.Count == 1);

            // The mode should be written to the key of the dict:
            Assert.IsTrue(testConfig.possibleSensors.First().Key == 1);

            var sensor = testConfig.possibleSensors.First().Value;
            // The properties should have been recorded correctly:
            Assert.IsTrue(sensor.PID == 0);
            Assert.IsTrue(sensor.bytes == 4);
            // Assert.IsTrue(sensor.firstPID == 1); --> this is filtered in the config loading: whithout children, mentioning the range of children is useless.
            Assert.IsTrue(sensor.description == "PIDs supported [01 - 20]");

            // The sensor shouldn't have any descendants
            Assert.IsTrue(sensor.PIDSensors.Count == 0);
        }
Ejemplo n.º 9
0
        public void testModeNotFound()
        {
            string PID00 = "    <PIDSensor PID=\"00\" bytes=\"04\" firstPID=\"01\" Description=\"PIDs supported [01 - 20]\">\r\n    </PIDSensor>\r\n";
            string xmlSource = "<PIDList>\r\n  <SensorAvailability Mode=\"01\">\r\n" + PID00 + "  </SensorAvailability>\r\n</PIDList>";
            XElement dSource = XElement.Parse(xmlSource, LoadOptions.None);
            Koos__OBD_Communicator.ConfigurationData testConfig = new Koos__OBD_Communicator.ConfigurationData(dSource);

            testConfig.GetSensor(15, 16);
        }
Ejemplo n.º 10
0
        public void testPIDSearch()
        {
            string PID10 = "      <PIDSensor PID=\"10\" bytes=\"02\" Description=\"MAF air flow rate (grams / sec)\" Formula=\"((A*256)+B) / 100\" />\r\n";
            string PID11 = "      <PIDSensor PID=\"11\" bytes=\"01\" Description=\"Throttle position (%)\" Formula=\"A*100/255\" />\r\n";
            string PID00 = "    <PIDSensor PID=\"00\" bytes=\"04\" firstPID=\"01\" Description=\"PIDs supported [01 - 20]\">\r\n" + PID10 + PID11 + "    </PIDSensor>\r\n";
            string xmlSource = "<PIDList>\r\n  <SensorAvailability Mode=\"01\">\r\n" + PID00 + "  </SensorAvailability>\r\n</PIDList>";
            XElement dSource = XElement.Parse(xmlSource, LoadOptions.None);
            Koos__OBD_Communicator.ConfigurationData testConfig = new Koos__OBD_Communicator.ConfigurationData(dSource);

            var sensor = testConfig.possibleSensors.First().Value;
            var PIDSensor10 = sensor.PIDSensors.First();
            var PIDSensor11 = sensor.PIDSensors.Last();

            Assert.IsTrue(testConfig.GetSensor(1, 0) == sensor);
            Assert.IsTrue(testConfig.GetSensor(1, 16) == PIDSensor10);
            Assert.IsTrue(testConfig.GetSensor(1, 17) == PIDSensor11);
        }