Example #1
0
        private void Scan_DTC_from_UI(KWP_2000_Process kwp2000)
        {
            // CheckBox lut of UI must be listed accroding to its byte/bit index.

            uint byte_bit_index;

            byte_bit_index = 0;
            foreach (var item in abs_lut)
            {
                if (item.Checked == true)
                {
                    // If CheckBox is checked, treat it as Lamp_ON_Failure_Set
                    kwp2000.ABS_DTC_Queue_Add(ABS_DTC_Table.Find_ABS_DTC((byte_bit_index / 8), (byte_bit_index % 8)), KWP_2000_Process.Lamp_ON_Failure_Set);
                }
                byte_bit_index++;
            }

            byte_bit_index = 0;
            foreach (var item in obd_lut)
            {
                if (item.Checked == true)
                {
                    // If CheckBox is checked, treat it as Lamp_ON_Failure_Set
                    kwp2000.OBD_DTC_Queue_Add(OBD_DTC_Table.Find_OBD_DTC((byte_bit_index / 8), (byte_bit_index % 8)), KWP_2000_Process.Lamp_ON_Failure_Set);
                }
                byte_bit_index++;
            }
        }
Example #2
0
 private void Use_Fixed_DTC_from_HQ(KWP_2000_Process kwp2000)
 {
     // byte[] fixed_response_data_abs = { 0x04, 0x50, 0x43, 0xE0, 0x50, 0x45, 0xE0, 0x50, 0x52, 0xA0, 0x50, 0x53, 0xA0 };
     kwp2000.ABS_DTC_Queue_Add(0x50, 0x43, 0xE0);
     kwp2000.ABS_DTC_Queue_Add(0x50, 0x45, 0xE0);
     kwp2000.ABS_DTC_Queue_Add(0x50, 0x52, 0xA0);
     kwp2000.ABS_DTC_Queue_Add(0x50, 0x53, 0xA0);
     // byte[] fixed_response_data_obd = { 0x04, 0x01, 0x15, 0x61, 0x40, 0x85, 0x62, 0x02, 0x30, 0x62, 0xC4, 0x86, 0x62 };
     // P0115: 0x0115
     // C0085: 0x4085
     // P0230: 0x0230
     // U0486: 0xC486
     kwp2000.OBD_DTC_Queue_Add(0x01, 0x15, 0x61);
     kwp2000.OBD_DTC_Queue_Add(0x40, 0x85, 0x62);
     kwp2000.OBD_DTC_Queue_Add(0x02, 0x30, 0x62);
     kwp2000.OBD_DTC_Queue_Add(0xC4, 0x86, 0x62);
 }
Example #3
0
        private void Tmr_FetchingUARTInput_Tick(object sender, EventArgs e)
        {
            // Regularly polling request message
            while (MySerialPort.KLineBlockMessageList.Count() > 0)
            {
                // Pop 1st KLine Block Message
                BlockMessage in_message = MySerialPort.KLineBlockMessageList[0];
                MySerialPort.KLineBlockMessageList.RemoveAt(0);

                // Display debug message on RichTextBox
                String raw_data_in_string = MySerialPort.KLineRawDataInStringList[0];
                MySerialPort.KLineRawDataInStringList.RemoveAt(0);
                DisplayKLineBlockMessage(rtbKLineData, "raw_input: " + raw_data_in_string);
                DisplayKLineBlockMessage(rtbKLineData, "In - " + in_message.GenerateDebugString());

                // Process input Kline message and generate output KLine message
                KWP_2000_Process kwp_2000_process = new KWP_2000_Process();
                BlockMessage     out_message      = new BlockMessage();

                //Use_Random_DTC(kwp_2000_process);  // Random Test
                //Use_Fixed_DTC_from_HQ(kwp_2000_process);  // Simulate response from a ECU device
                Scan_DTC_from_UI(kwp_2000_process);  // Scan Checkbox status and add DTC into queue

                // Generate output block message according to input message and DTC codes
                kwp_2000_process.ProcessMessage(in_message, ref out_message);

                // Convert output block message to List<byte> so that it can be sent via UART
                List <byte> output_data;
                out_message.GenerateSerialOutput(out output_data);

                // NOTE: because we will also receive all data sent by us, we need to tell UART to skip all data to be sent by SendToSerial
                MySerialPort.Add_ECU_Filtering_Data(output_data);
                MySerialPort.Enable_ECU_Filtering(true);
                // Send output KLine message via UART (after some delay)
                Thread.Sleep((KWP_2000_Process.min_delay_before_response - 1));
                MySerialPort.SendToSerial(output_data.ToArray());

                // Show output KLine message for debug purpose
                DisplayKLineBlockMessage(rtbKLineData, "Out - " + out_message.GenerateDebugString());
            }
        }
Example #4
0
        //
        private void Use_Random_DTC(KWP_2000_Process kwp2000)
        {
            Random rs = new Random();
            Byte   DTC_no;

            DTC_no = (byte)(rs.Next(10));
            DTC_no = (byte)((DTC_no <= KWP_2000_Process.ReadDiagnosticCodesByStatus_MaxNumberOfDTC) ? DTC_no : 0);
            for (int no = 0; no < DTC_no; no++)
            {
                CMD_E_ABS_DTC random_dtc = ABS_DTC_Table.Find_ABS_DTC(rs.Next(ABS_DTC_Table.Count()));
                kwp2000.ABS_DTC_Queue_Add(random_dtc, (byte)kwp2000.dtc_status_table[rs.Next(kwp2000.dtc_status_table.Length)]);
            }
            // for OBD
            DTC_no = (byte)(rs.Next(10));
            DTC_no = (byte)((DTC_no <= KWP_2000_Process.ReadDiagnosticCodesByStatus_MaxNumberOfDTC) ? DTC_no : 0);
            for (int no = 0; no < DTC_no; no++)
            {
                CMD_F_OBD_DTC random_dtc = OBD_DTC_Table.Find_OBD_DTC(rs.Next(OBD_DTC_Table.Count()));
                kwp2000.OBD_DTC_Queue_Add(random_dtc, (byte)kwp2000.dtc_status_table_for_obd[rs.Next(kwp2000.dtc_status_table_for_obd.Length)]);
            }
        }