コード例 #1
0
ファイル: MessageHandlingTests.cs プロジェクト: vstrien/KOCus
        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));
                }
            }
        }
コード例 #2
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%
        }