Beispiel #1
0
        public static bool Configure_PICkitSerial_For_LINSlave_Mode(byte p_array_byte_count, ref byte[] p_profile_array, ref string p_result_str, bool p_autobaud, ref int p_error_code)
        {
            bool flag = false;

            byte[] array  = new byte[65];
            byte[] array2 = new byte[255];
            byte[] array3 = new byte[65];
            bool   result = false;
            byte   b      = 0;
            byte   b2     = 0;
            string text   = "";

            p_error_code = 0;
            Array.Clear(array, 0, array.Length);
            Array.Clear(array3, 0, array3.Length);
            byte b3 = LIN.Number_Of_Bytes_In_CBUF3(ref b, ref b2);

            if (p_array_byte_count > b3)
            {
                p_result_str = string.Format("Byte count of {0} greater than allowed value of {1}.", p_array_byte_count, b3);
                p_error_code = 1;
                return(flag);
            }
            USBWrite.Clear_CBUF(3);
            if (p_autobaud)
            {
                Mode.update_status_packet_data(10, ref array3);
            }
            else
            {
                Mode.update_status_packet_data(19, ref array3);
            }
            USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array3);
            USBWrite.Send_Cold_Reset_Cmd();
            flag = USBWrite.Send_Data_Packet_To_PICkitS(ref array);
            USBWrite.Send_Warm_Reset_Cmd();
            Array.Clear(array2, 0, array2.Length);
            array2[0] = 0;
            array2[1] = 5;
            array2[2] = p_array_byte_count;
            for (int i = 3; i < (int)(p_array_byte_count + 3); i++)
            {
                array2[i] = p_profile_array[i - 3];
            }
            USBWrite.Send_Script_To_PICkitS(ref array2);
            byte[] expr_F9_cp_0 = array3;
            int    expr_F9_cp_1 = 23;

            expr_F9_cp_0[expr_F9_cp_1] |= 32;
            USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array3);
            flag = USBWrite.Send_Data_Packet_To_PICkitS(ref array);
            if (flag)
            {
                if (USBWrite.Update_Status_Packet())
                {
                    Utilities.m_flags.g_status_packet_mutex.WaitOne();
                    int j;
                    for (j = 7; j < 31; j++)
                    {
                        if (Constants.STATUS_PACKET_DATA[j] != array[j - 5])
                        {
                            p_error_code = 3;
                            p_result_str = string.Format("Byte {0} failed verification in config block write.\n Value reads {1:X2}, but should be {2:X2}.", j - 7, Constants.STATUS_PACKET_DATA[j], array[j - 5]);
                            break;
                        }
                    }
                    if (j == 31)
                    {
                        result       = true;
                        p_result_str = string.Format("PICkit Serial Analyzer correctly updated.", new object[0]);
                    }
                    Utilities.m_flags.g_status_packet_mutex.ReleaseMutex();
                }
                else
                {
                    p_result_str = string.Format("Error requesting config verification - Config Block may not be updated correctly", new object[0]);
                }
            }
            else
            {
                p_error_code = 2;
                p_result_str = string.Format("Error sending config packet - Config Block may not be updated correctly", new object[0]);
            }
            return(result);
        }