internal static void finalize_working_frame() { if (!LIN.m_we_are_finishing_a_frame) { LIN.finish_this_frame(); } }
public static bool Change_LIN_BAUD_Rate(ushort Baud) { bool flag = false; string text = ""; string text2 = ""; byte[] array = new byte[65]; byte[] array2 = new byte[65]; if (Utilities.m_flags.HID_DeviceReady != false) //(Utilities.m_flags.HID_read_handle != IntPtr.Zero) { Array.Clear(array, 0, array.Length); Array.Clear(array2, 0, array2.Length); if (!Basic.Get_Status_Packet(ref array2)) { return(false); } int num = (int)Math.Round(20000000.0 / (double)Baud / 4.0) - 1; array2[29] = (byte)num; array2[30] = (byte)(num >> 8); USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array2); flag = USBWrite.write_and_verify_LIN_config_block(ref array, ref text2, true, ref text); } if (flag) { LIN.Get_LIN_BAUD_Rate(); } return(flag); }
public static bool Write_Slave_Profile(byte p_masterid, ref byte[] p_data, byte p_byte_count, ref byte p_error_code) { bool result = false; p_error_code = 0; byte[] array = new byte[255]; byte[] array2 = new byte[255]; byte b = 0; byte b2 = 0; if (p_byte_count > 244) { p_error_code = 3; return(false); } Array.Clear(array, 0, array.Length); array[0] = 0; array[1] = 3; array[2] = (byte)(p_byte_count + 5); array[3] = 134; array[4] = p_masterid; array[5] = p_byte_count; byte b3; for (b3 = 0; b3 < p_byte_count; b3 += 1) { array[(int)(6 + b3)] = p_data[(int)b3]; } array[(int)(b3 + 6)] = 31; array[(int)(b3 + 7)] = 119; array[(int)(b3 + 8)] = 0; bool flag = USBWrite.Send_Script_To_PICkitS(ref array); if (flag) { if (!LIN.Read_Slave_Profile(p_masterid, ref array2, p_byte_count, ref b2, ref b)) { p_error_code = 1; } else { for (b3 = 0; b3 < p_byte_count; b3 += 1) { if (array2[(int)b3] != p_data[(int)b3]) { p_error_code = 1; return(false); } } result = true; } } else { p_error_code = 2; } return(result); }
public static bool Configure_PICkitSerial_For_LIN_No_Autobaud() { bool result = false; if (Basic.Configure_PICkitSerial(19, true)) { LIN.Get_LIN_BAUD_Rate(); result = true; } return(result); }
private static bool set_OnReceive_timeout_from_baud_rate() { byte[] array = new byte[65]; if (Utilities.m_flags.HID_DeviceReady != false) //(Utilities.m_flags.HID_read_handle != IntPtr.Zero) { Array.Clear(array, 0, array.Length); if (!Basic.Get_Status_Packet(ref array)) { return(false); } int p_baud = (int)LIN.calculate_baud_rate((ushort)((int)array[50] + ((int)array[51] << 8))); LIN.calculate_new_baud_dependent_onreceive_timeout(p_baud); } return(true); }
internal static void initialize_LIN_frames() { LIN.m_stopwatch = new Stopwatch(); LIN.m_opmode = LIN.OPMODE.LISTEN; LIN.m_working_frame.FrameInfo.FrameData = new byte[9]; LIN.reset_working_frame(); LIN.Reset_LIN_Frame_Buffers(); LIN.m_FrameStartTimer = new Timer(new TimerCallback(LIN.frame_has_timed_out), null, -1, -1); LIN.m_working_frame.BuildState.we_have_transmitted = false; LIN.m_working_frame.BuildState.transmit_data_byte_count_zero = false; LIN.m_working_frame_is_done = new AutoResetEvent(false); LIN.m_slave_profile_id_read = new AutoResetEvent(false); LIN.m_slave_profile_id.ByteCount = 0; LIN.m_slave_profile_id.FrameID = 0; LIN.m_slave_profile_id.Data = new byte[255]; }
public static bool Set_OnReceive_Timeout(int Timeout) { if (Timeout != 65535) { LIN.m_use_baud_rate_timeout = false; LIN.FRAME_TIMEOUT = Timeout; return(true); } if (LIN.set_OnReceive_timeout_from_baud_rate()) { LIN.m_use_baud_rate_timeout = true; return(true); } Timeout = 0; return(false); }
public static ushort Get_LIN_BAUD_Rate() { byte[] array = new byte[65]; ushort num = 0; if (Utilities.m_flags.HID_DeviceReady != false) //(Utilities.m_flags.HID_read_handle != IntPtr.Zero) { Array.Clear(array, 0, array.Length); if (Basic.Get_Status_Packet(ref array)) { num = LIN.calculate_baud_rate((ushort)((int)array[50] + ((int)array[51] << 8))); LIN.m_last_master_baud_rate = num; } } return(num); }
private static void frame_has_timed_out(object state) { while (LIN.m_stopwatch.ElapsedMilliseconds < (long)LIN.FRAME_TIMEOUT) { Thread.Sleep(10); } LIN.m_working_frame.FrameInfo.frame_timeout_time = LIN.m_stopwatch.ElapsedMilliseconds; if (!LIN.m_we_are_finishing_a_frame) { if (LIN.m_working_frame.FrameInfo.FrameID == 0) { byte arg_5C_0 = USBRead.m_raw_cbuf2_data_array[(int)((UIntPtr)USBRead.m_cb2_array_tag_index)]; } LIN.m_working_frame.BuildState.we_timed_out = true; LIN.finish_this_frame(); } }
private static bool Toggle_AutoBaud_Set(bool p_turn_autobaudset_on, ref ushort p_baud, ref string p_error_detail) { bool flag = false; int num = 0; string text = ""; string text2 = ""; byte[] array = new byte[65]; byte[] array2 = new byte[65]; p_error_detail = ""; if (Utilities.m_flags.HID_DeviceReady != false) //(Utilities.m_flags.HID_read_handle != IntPtr.Zero) { Array.Clear(array, 0, array.Length); Array.Clear(array2, 0, array2.Length); if (!Basic.Get_Status_Packet(ref array2)) { p_error_detail = "Could not poll PKSA for status."; return(false); } p_baud = LIN.calculate_baud_rate((ushort)((int)array2[29] + ((int)array2[30] << 8))); if (p_turn_autobaudset_on) { byte[] expr_8F_cp_0 = array2; int expr_8F_cp_1 = 23; expr_8F_cp_0[expr_8F_cp_1] |= 128; } else { byte[] expr_AC_cp_0 = array2; int expr_AC_cp_1 = 23; expr_AC_cp_0[expr_AC_cp_1] &= 127; } USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array2); while (!flag && num < 3) { num++; flag = USBWrite.write_and_verify_LIN_config_block(ref array, ref text2, false, ref text); p_error_detail += text2; } } return(flag); }
public static bool Get_This_Device(ushort p_VendorID, ushort p_PoductID, ushort p_index, ref IntPtr p_ReadHandle, ref IntPtr p_WriteHandle, ref string p_devicepath, bool p_pass_ptr_to_handle, ref Guid p_HidGuid, ref ushort p_num_devices_attached) { SP_DEVICE_INTERFACE_DATA sp_device_interface_data; SP_DEVICE_INTERFACE_DETAIL_DATA sp_device_interface_detail_data; HIDD_ATTRIBUTES hidd_attributes; Utilities.InitializeParams(); LIN.initialize_LIN_frames(); IntPtr zero = IntPtr.Zero; IntPtr preparsedData = IntPtr.Zero; HIDP_CAPS capabilities = new HIDP_CAPS(); ushort num2 = 0; IntPtr hidDeviceObject = IntPtr.Zero; int requiredSize = 0; SECURITY_ATTRIBUTES structure = new SECURITY_ATTRIBUTES(); IntPtr ptr4 = new IntPtr(-1); structure.lpSecurityDescriptor = 0; structure.bInheritHandle = Convert.ToInt32(true); structure.nLength = Marshal.SizeOf(structure); Guid empty = Guid.Empty; sp_device_interface_data.cbSize = 0; sp_device_interface_data.Flags = 0; sp_device_interface_data.InterfaceClassGuid = Guid.Empty; sp_device_interface_data.Reserved = 0; sp_device_interface_detail_data.cbSize = 0; sp_device_interface_detail_data.DevicePath = ""; hidd_attributes.ProductID = 0; hidd_attributes.Size = 0; hidd_attributes.VendorID = 0; hidd_attributes.VersionNumber = 0; bool flag = false; structure.lpSecurityDescriptor = 0; structure.bInheritHandle = Convert.ToInt32(true); structure.nLength = Marshal.SizeOf(structure); HidD_GetHidGuid(ref empty); zero = SetupDiGetClassDevs(ref empty, null, 0, 0x12); sp_device_interface_data.cbSize = Marshal.SizeOf(sp_device_interface_data); for (int i = 0; i < 30; i++) { if (SetupDiEnumDeviceInterfaces(zero, 0, ref empty, i, ref sp_device_interface_data) != 0) { SetupDiGetDeviceInterfaceDetail(zero, ref sp_device_interface_data, IntPtr.Zero, 0, ref requiredSize, IntPtr.Zero); sp_device_interface_detail_data.cbSize = Marshal.SizeOf(sp_device_interface_detail_data); IntPtr ptr = Marshal.AllocHGlobal(requiredSize); Marshal.WriteInt32(ptr, 4 + Marshal.SystemDefaultCharSize); SetupDiGetDeviceInterfaceDetail(zero, ref sp_device_interface_data, ptr, requiredSize, ref requiredSize, IntPtr.Zero); IntPtr ptr6 = new IntPtr(ptr.ToInt32() + 4); string lpFileName = Marshal.PtrToStringAuto(ptr6); hidDeviceObject = CreateFile(lpFileName, 0xc0000000, 3, ref structure, 3, 0, 0); if (hidDeviceObject != ptr4) { hidd_attributes.Size = Marshal.SizeOf(hidd_attributes); if (HidD_GetAttributes(hidDeviceObject, ref hidd_attributes) != 0) { if ((hidd_attributes.VendorID == p_VendorID) && (hidd_attributes.ProductID == p_PoductID)) { if (num2 == p_index) { flag = true; if (p_pass_ptr_to_handle) { p_WriteHandle = hidDeviceObject; } p_devicepath = lpFileName; p_HidGuid = empty; Utilities.m_flags.HID_write_handle = hidDeviceObject; HidD_GetPreparsedData(hidDeviceObject, ref preparsedData); HidP_GetCaps(preparsedData, ref capabilities); Utilities.m_flags.irbl = (ushort)capabilities.InputReportByteLength; Utilities.m_flags.HID_read_handle = CreateFile(lpFileName, 0xc0000000, 3, ref structure, 3, 0, 0); if (p_pass_ptr_to_handle) { p_ReadHandle = Utilities.m_flags.HID_read_handle; } HidD_FreePreparsedData(ref preparsedData); break; } num2 = (ushort)(num2 + 1); } else { flag = false; CloseHandle(hidDeviceObject); } } else { flag = false; CloseHandle(hidDeviceObject); } } } } SetupDiDestroyDeviceInfoList(zero); p_num_devices_attached = num2; return(flag); }
private static void process_lin_data(ref bool p_error) { switch (m_raw_cbuf2_data_array[m_cb2_array_tag_index]) { case 0x80: if ((m_raw_cbuf2_data_array_index - m_cb2_array_tag_index) < 2) { m_we_need_next_packet_to_continue = true; return; } m_cb2_array_tag_index += 2; return; case 0x81: if ((m_raw_cbuf2_data_array_index - m_cb2_array_tag_index) < 2) { m_we_need_next_packet_to_continue = true; return; } m_cb2_array_tag_index += 2; return; case 130: LIN.m_working_frame.BuildState.we_had_a_status_error = true; if (!LIN.m_working_frame.BuildState.we_timed_out) { LIN.finalize_working_frame(); Device.Clear_Status_Errors(); } if ((m_raw_cbuf2_data_array_index - m_cb2_array_tag_index) >= 2) { m_cb2_array_tag_index += 2; return; } m_we_need_next_packet_to_continue = true; return; case 0x83: if (!LIN.m_working_frame.BuildState.we_timed_out) { if (LIN.m_working_frame.BuildState.we_are_building_a_frame) { LIN.m_working_frame.BuildState.next_frame_header_received = true; LIN.finalize_working_frame(); } LIN.m_working_frame.BuildState.we_are_building_a_frame = true; m_grab_next_time_marker = true; LIN.reset_LIN_timeout(); } m_cb2_array_tag_index++; return; case 0x84: m_cb2_array_tag_index++; return; case 0x85: if (LIN.m_working_frame.BuildState.we_are_building_a_frame) { LIN.m_working_frame.FrameInfo.baud = (ushort)(m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 1))] + (m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 2))] << 8)); if (LIN.m_use_baud_rate_timeout) { LIN.calculate_new_baud_dependent_onreceive_timeout(LIN.m_working_frame.FrameInfo.baud); } } if ((m_raw_cbuf2_data_array_index - m_cb2_array_tag_index) >= 3) { m_cb2_array_tag_index += 3; return; } m_we_need_next_packet_to_continue = true; return; case 0x86: if ((m_raw_cbuf2_data_array_index - m_cb2_array_tag_index) < 2) { m_we_need_next_packet_to_continue = true; return; } m_cb2_array_tag_index += 2; return; case 0x87: if ((m_raw_cbuf2_data_array_index - m_cb2_array_tag_index) < 2) { m_we_need_next_packet_to_continue = true; return; } m_cb2_array_tag_index += 2; return; case 0x88: LIN.m_slave_profile_id.FrameID = m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 1))]; LIN.m_slave_profile_id.ByteCount = m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 2))]; for (int i = 0; i < LIN.m_slave_profile_id.ByteCount; i++) { LIN.m_slave_profile_id.Data[i] = m_raw_cbuf2_data_array[(int)((IntPtr)((m_cb2_array_tag_index + 3) + i))]; } m_cb2_array_tag_index += (uint)(m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 2))] + 3); LIN.m_slave_profile_id_read.Set(); return; } p_error = true; }
private static void process_common_data(ref bool p_error) { switch (m_raw_cbuf2_data_array[m_cb2_array_tag_index]) { case 0x10: case 0x12: case 0x1a: case 0x1c: if ((m_raw_cbuf2_data_array_index - m_cb2_array_tag_index) < 2) { m_we_need_next_packet_to_continue = true; return; } switch (m_raw_cbuf2_data_array[m_cb2_array_tag_index]) { case 0x10: add_data_to_cbuf2_data_array(ref m_raw_cbuf2_data_array, m_cb2_array_tag_index + 1, 1); if (((Utilities.g_comm_mode == Utilities.COMM_MODE.LIN) && !LIN.m_working_frame.BuildState.we_timed_out) && LIN.m_working_frame.BuildState.we_are_building_a_frame) { if (!LIN.m_working_frame.BuildState.we_have_an_id) { LIN.m_working_frame.FrameInfo.FrameID = m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 1))]; LIN.m_working_frame.BuildState.we_have_an_id = true; } else { if (LIN.m_working_frame.FrameInfo.bytecount < 9) { byte num4; LIN.m_working_frame.FrameInfo.bytecount = (byte)((num4 = LIN.m_working_frame.FrameInfo.bytecount) + 1); LIN.m_working_frame.FrameInfo.FrameData[num4] = m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 1))]; } if (LIN.m_working_frame.FrameInfo.bytecount == 9) { LIN.finalize_working_frame(); } } } goto Label_01C3; case 0x1c: if (m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 1))] == 0x77) { Utilities.m_flags.g_PKSA_has_completed_script.Set(); } goto Label_01C3; } break; case 0x11: if (((m_raw_cbuf2_data_array_index - m_cb2_array_tag_index) - 2) < m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 1))]) { m_we_need_next_packet_to_continue = true; return; } add_data_to_cbuf2_data_array(ref m_raw_cbuf2_data_array, m_cb2_array_tag_index + 2, m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 1))]); m_cb2_array_tag_index += (uint)(2 + m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 1))]); return; case 0x13: if ((m_raw_cbuf2_data_array_index - m_cb2_array_tag_index) < 3) { m_we_need_next_packet_to_continue = true; return; } if (((Utilities.g_comm_mode == Utilities.COMM_MODE.LIN) && LIN.m_working_frame.BuildState.we_are_building_a_frame) && m_grab_next_time_marker) { double num = ((m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 2))] << 8) + m_raw_cbuf2_data_array[(int)((IntPtr)(m_cb2_array_tag_index + 1))]) * m_EVENT_TIME_CONSTANT; m_RUNNING_TIME = m_EVENT_TIME_ROLLOVER + num; LIN.m_working_frame.FrameInfo.time = m_RUNNING_TIME; m_grab_next_time_marker = false; } m_cb2_array_tag_index += 3; return; case 20: m_EVENT_TIME_ROLLOVER += m_EVENT_TIME_ROLLOVER_CONSTANT; m_cb2_array_tag_index++; return; case 0x15: if ((m_raw_cbuf2_data_array_index - m_cb2_array_tag_index) < 3) { m_we_need_next_packet_to_continue = true; return; } m_cb2_array_tag_index += 3; return; case 0x16: m_cb2_array_tag_index++; return; case 0x17: m_cb2_array_tag_index++; return; case 0x18: m_cb2_array_tag_index++; return; case 0x19: m_cb2_array_tag_index++; return; case 0x1b: m_cb2_array_tag_index++; return; default: p_error = true; return; } Label_01C3: m_cb2_array_tag_index += 2; }
public static bool Get_HID_Device(ushort p_VendorID, ushort p_PoductID, ushort p_index, ref IntPtr p_ReadHandle, ref IntPtr p_WriteHandle, ref string p_devicepath, bool p_pass_ptr_to_handle, ref Guid p_HidGuid, ref ushort p_num_devices_attached) { Utilities.InitializeParams(); LIN.initialize_LIN_frames(); IntPtr deviceInfoSet = IntPtr.Zero; IntPtr zero = IntPtr.Zero; GenericHID.HIDP_CAPS hIDP_CAPS = default(GenericHID.HIDP_CAPS); ushort num = 0; IntPtr intPtr = IntPtr.Zero; int num2 = 0; GenericHID.SECURITY_ATTRIBUTES sECURITY_ATTRIBUTES = default(GenericHID.SECURITY_ATTRIBUTES); IntPtr intPtr2 = new IntPtr(-1); sECURITY_ATTRIBUTES.lpSecurityDescriptor = 0; sECURITY_ATTRIBUTES.bInheritHandle = Convert.ToInt32(true); sECURITY_ATTRIBUTES.nLength = Marshal.SizeOf(sECURITY_ATTRIBUTES); Guid empty = Guid.Empty; GenericHID.SP_DEVICE_INTERFACE_DATA sP_DEVICE_INTERFACE_DATA; sP_DEVICE_INTERFACE_DATA.cbSize = 0; sP_DEVICE_INTERFACE_DATA.Flags = 0; sP_DEVICE_INTERFACE_DATA.InterfaceClassGuid = Guid.Empty; sP_DEVICE_INTERFACE_DATA.Reserved = 0; GenericHID.SP_DEVICE_INTERFACE_DETAIL_DATA sP_DEVICE_INTERFACE_DETAIL_DATA; sP_DEVICE_INTERFACE_DETAIL_DATA.cbSize = 0; sP_DEVICE_INTERFACE_DETAIL_DATA.DevicePath = ""; GenericHID.HIDD_ATTRIBUTES hIDD_ATTRIBUTES; hIDD_ATTRIBUTES.ProductID = 0; hIDD_ATTRIBUTES.Size = 0; hIDD_ATTRIBUTES.VendorID = 0; hIDD_ATTRIBUTES.VersionNumber = 0; bool result = false; sECURITY_ATTRIBUTES.lpSecurityDescriptor = 0; sECURITY_ATTRIBUTES.bInheritHandle = Convert.ToInt32(true); sECURITY_ATTRIBUTES.nLength = Marshal.SizeOf(sECURITY_ATTRIBUTES); /* * GenericHID.HidD_GetHidGuid(ref empty); * deviceInfoSet = GenericHID.SetupDiGetClassDevs(ref empty, null, 0, 18); * sP_DEVICE_INTERFACE_DATA.cbSize = Marshal.SizeOf(sP_DEVICE_INTERFACE_DATA); * for (int i = 0; i < 30; i++) * { * int num3 = GenericHID.SetupDiEnumDeviceInterfaces(deviceInfoSet, 0, ref empty, i, ref sP_DEVICE_INTERFACE_DATA); * if (num3 != 0) * { * GenericHID.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref sP_DEVICE_INTERFACE_DATA, IntPtr.Zero, 0, ref num2, IntPtr.Zero); * sP_DEVICE_INTERFACE_DETAIL_DATA.cbSize = Marshal.SizeOf(sP_DEVICE_INTERFACE_DETAIL_DATA); * IntPtr intPtr3 = Marshal.AllocHGlobal(num2); * Marshal.WriteInt32(intPtr3, 4 + Marshal.SystemDefaultCharSize); * GenericHID.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref sP_DEVICE_INTERFACE_DATA, intPtr3, num2, ref num2, IntPtr.Zero); * IntPtr intPtr4 = new IntPtr(intPtr3.ToInt32() + 4); * string text = Marshal.PtrToStringAuto(intPtr4); * intPtr = GenericHID.CreateFile(text, 3221225472u, 3u, ref sECURITY_ATTRIBUTES, 3, 0u, 0); * if (intPtr != intPtr2) * { * hIDD_ATTRIBUTES.Size = Marshal.SizeOf(hIDD_ATTRIBUTES); * num3 = GenericHID.HidD_GetAttributes(intPtr, ref hIDD_ATTRIBUTES); * if (num3 != 0) * { * if (hIDD_ATTRIBUTES.VendorID == p_VendorID && hIDD_ATTRIBUTES.ProductID == p_PoductID) * { * if (num == p_index) * { * result = true; * if (p_pass_ptr_to_handle) * { * p_WriteHandle = intPtr; * } * p_devicepath = text; * p_HidGuid = empty; * // Utilities.m_flags.HID_write_handle = intPtr; * GenericHID.HidD_GetPreparsedData(intPtr, ref zero); * GenericHID.HidP_GetCaps(zero, ref hIDP_CAPS); * Utilities.m_flags.irbl = (ushort)hIDP_CAPS.InputReportByteLength; * // Utilities.m_flags.HID_read_handle = GenericHID.CreateFile(text, 3221225472u, 3u, ref sECURITY_ATTRIBUTES, 3, 1073741824u, 0); * if (p_pass_ptr_to_handle) * { * // p_ReadHandle = Utilities.m_flags.HID_read_handle; * } * GenericHID.HidD_FreePreparsedData(ref zero); * break; * } * num += 1; * } * else * { * result = false; * GenericHID.CloseHandle(intPtr); * } * } * else * { * result = false; * GenericHID.CloseHandle(intPtr); * } * } * } * } * GenericHID.SetupDiDestroyDeviceInfoList(deviceInfoSet); * p_num_devices_attached = num; */ return(result); }
public static bool Add_LIN_Slave_Profile_To_PKS(byte p_array_byte_count, ref byte[] p_profile_array, ref string p_result_str, 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 (!Basic.Get_Status_Packet(ref array3)) { p_result_str = string.Format("Error reading status packet.", new object[0]); p_error_code = 2; return(false); } byte[] expr_A6_cp_0 = array3; int expr_A6_cp_1 = 23; expr_A6_cp_0[expr_A6_cp_1] |= 32; USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array3); flag = USBWrite.Send_Data_Packet_To_PICkitS(ref array); 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]; } bool flag2 = USBWrite.Send_Script_To_PICkitS(ref array2); if (flag & flag2) { 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); }
private static void finish_this_frame() { LIN.m_we_are_finishing_a_frame = true; LIN.m_working_frame.BuildState.we_are_building_a_frame = false; LIN.m_FrameStartTimer.Change(-1, -1); bool flag = false; if (LIN.this_is_a_valid_frame()) { if (LIN.m_next_frame_is_first_frame) { LIN.m_working_frame.FrameInfo.time = 0.0; LIN.m_next_frame_is_first_frame = false; flag = !USBRead.reset_timer_params(); } if (LIN.m_working_frame.FrameInfo.baud != 0) { LIN.m_working_frame.FrameInfo.baud = LIN.calculate_baud_rate(LIN.m_working_frame.FrameInfo.baud); } else { LIN.m_working_frame.FrameInfo.baud = LIN.m_last_master_baud_rate; } LIN.m_OnReceive_error = 0; uint num = 0u; if (Status.There_Is_A_Status_Error(ref num)) { LIN.m_OnReceive_error = 4; Device.Clear_Status_Errors(); } if (LIN.m_OnReceive_error == 0 && LIN.m_working_frame.BuildState.we_had_a_status_error) { LIN.m_OnReceive_error = 5; } else if (LIN.m_working_frame.BuildState.we_timed_out) { LIN.m_OnReceive_error = 1; } else if (flag) { LIN.m_OnReceive_error = 3; } else if (LIN.m_working_frame.BuildState.next_frame_header_received) { LIN.m_OnReceive_error = 6; } if ((LIN.this_frame_is_different_than_last() && LIN.m_opmode == LIN.OPMODE.LISTEN) || LIN.m_opmode == LIN.OPMODE.DISPLAY_ALL) { if (LIN.m_working_frame.BuildState.we_have_transmitted && LIN.m_working_frame.BuildState.transmit_data_byte_count_zero) { OnAnswer(LIN.m_working_frame.FrameInfo.FrameID, LIN.m_working_frame.FrameInfo.FrameData, LIN.m_working_frame.FrameInfo.bytecount, LIN.m_OnReceive_error, LIN.m_working_frame.FrameInfo.baud, LIN.m_working_frame.FrameInfo.time); } else if ((!LIN.m_working_frame.BuildState.we_have_transmitted || !LIN.m_working_frame.BuildState.transmit_data_byte_count_zero) && LIN.OnReceive != null) { if (LIN.m_OnReceive_error == 6) { LIN.m_OnReceive_error = 0; } OnReceive(LIN.m_working_frame.FrameInfo.FrameID, LIN.m_working_frame.FrameInfo.FrameData, LIN.m_working_frame.FrameInfo.bytecount, LIN.m_OnReceive_error, LIN.m_working_frame.FrameInfo.baud, LIN.m_working_frame.FrameInfo.time); } } LIN.copy_this_frame_into_array(); } LIN.reset_working_frame(); LIN.m_working_frame_is_done.Set(); LIN.m_we_are_finishing_a_frame = false; }
public static bool Configure_PICkitSerial_For_LIN(bool p_chip_select_hi, bool p_receive_enable, bool p_autobaud) { bool flag = false; if ((Utilities.m_flags.HID_DeviceReady != false) && Basic.Configure_PICkitSerial(10, true)) { string text = ""; string text2 = ""; byte[] array = new byte[65]; byte[] array2 = new byte[65]; if (Utilities.m_flags.HID_DeviceReady != false) //(Utilities.m_flags.HID_read_handle != IntPtr.Zero) { Array.Clear(array, 0, array.Length); Array.Clear(array2, 0, array2.Length); if (!Basic.Get_Status_Packet(ref array2)) { return(false); } if (p_chip_select_hi) { byte[] expr_8D_cp_0 = array2; int expr_8D_cp_1 = 23; expr_8D_cp_0[expr_8D_cp_1] |= 8; } else { byte[] expr_A6_cp_0 = array2; int expr_A6_cp_1 = 23; expr_A6_cp_0[expr_A6_cp_1] &= 247; } if (p_receive_enable) { byte[] expr_C4_cp_0 = array2; int expr_C4_cp_1 = 23; expr_C4_cp_0[expr_C4_cp_1] |= 64; } else { byte[] expr_DE_cp_0 = array2; int expr_DE_cp_1 = 23; expr_DE_cp_0[expr_DE_cp_1] &= 191; } if (p_autobaud) { byte[] expr_FC_cp_0 = array2; int expr_FC_cp_1 = 23; expr_FC_cp_0[expr_FC_cp_1] |= 128; } else { byte[] expr_119_cp_0 = array2; int expr_119_cp_1 = 23; expr_119_cp_0[expr_119_cp_1] &= 127; } USBWrite.configure_outbound_control_block_packet(ref array, ref text, ref array2); flag = USBWrite.write_and_verify_config_block(ref array, ref text2, true, ref text); if (flag) { LIN.Get_LIN_BAUD_Rate(); } } } return(flag); }