Ejemplo n.º 1
0
        public static int PassThruIoctl(int channelId, Ioctl ioctlID, IntPtr input, IntPtr output)
        {
            Log.WriteTimestamp("", "PTIoctl({0}, {1}, 0x{2}, 0x{3})", channelId, ioctlID, input.ToString("X8"),
                output.ToString("X8"));

            if (input == IntPtr.Zero)
            {
                Log.WriteLine("  Input is null");
            }
            else
            {
                Log.Write("  Input: ");
                switch (ioctlID)
                {
                    case Ioctl.SET_CONFIG:
                        var configList = input.AsStruct<SConfigList>();
                        if (configList.Count > 0) Log.WriteLine("");
                        foreach (var config in configList.GetList())
                        {
                            Log.WriteLine("  {0} = {1}", config.Parameter, config.Value);
                        }
                        break;
                    case Ioctl.FAST_INIT:
                        Log.WriteLine(input.AsStruct<PassThruMsg>().ToString("\t"));
                        break;
                    case Ioctl.FIVE_BAUD_INIT:
                    case Ioctl.ADD_TO_FUNCT_MSG_LOOKUP_TABLE:
                    case Ioctl.DELETE_FROM_FUNCT_MSG_LOOKUP_TABLE:
                        Log.WriteLine(Environment.NewLine + "    " + input.AsStruct<SByteArray>().ToString());
                        break;
                    default:
                        Log.WriteLine("");
                        break;
                }
            }

            var result = Loader.Lib.PassThruIoctl(channelId, (int)ioctlID, input, output);

            if (result == J2534Err.STATUS_NOERROR)
            {
                if (output == IntPtr.Zero)
                {
                    Log.WriteLine("  Output is null");
                }
                else
                {
                    Log.Write("  Output:");
                    switch (ioctlID)
                    {
                        case Ioctl.GET_CONFIG:
                            var configList = input.AsStruct<SConfigList>();
                            foreach (var config in configList.GetList())
                            {
                                Log.WriteLine("    {0} = {1}", config.Parameter, config.Value);
                            }
                            break;
                        case Ioctl.READ_VBATT:
                        case Ioctl.READ_PROG_VOLTAGE:
                            Log.WriteLine(" {0:#.000} Volts", output.AsStruct<uint>() / 1000.0);
                            break;
                        case Ioctl.FAST_INIT:
                            Log.WriteLine(output.AsStruct<PassThruMsg>().ToString("\t"));
                            break;
                        case Ioctl.FIVE_BAUD_INIT:
                            Log.WriteLine(Environment.NewLine + "    " + input.AsStruct<SByteArray>().ToString());
                            break;
                        default:
                            Log.WriteLine("");
                            break;
                    }
                }
            }

            Log.WriteTimestamp("  ", "{0}: {1}", (int)result, result);

            return (int)result;
        }
Ejemplo n.º 2
0
        public static int PassThruIoctl(int channelId, Ioctl ioctlID, IntPtr input, IntPtr output)
        {
            Log.WriteTimestamp("", "PTIoctl({0}, {1}, 0x{2}, 0x{3})", channelId, ioctlID, input.ToString("X8"),
                               output.ToString("X8"));

            if (input == IntPtr.Zero)
            {
                Log.WriteLine("  Input is null");
            }
            else
            {
                Log.Write("  Input: ");
                switch (ioctlID)
                {
                case Ioctl.SET_CONFIG:
                    var configList = input.AsStruct <SConfigList>();
                    if (configList.Count > 0)
                    {
                        Log.WriteLine("");
                    }
                    foreach (var config in configList.GetList())
                    {
                        Log.WriteLine("  {0} = {1}", config.Parameter, config.Value);
                    }
                    break;

                case Ioctl.FAST_INIT:
                    Log.WriteLine(input.AsStruct <PassThruMsg>().ToString("\t"));
                    break;

                case Ioctl.FIVE_BAUD_INIT:
                case Ioctl.ADD_TO_FUNCT_MSG_LOOKUP_TABLE:
                case Ioctl.DELETE_FROM_FUNCT_MSG_LOOKUP_TABLE:
                    Log.WriteLine(Environment.NewLine + "    " + input.AsStruct <SByteArray>().ToString());
                    break;

                default:
                    Log.WriteLine("");
                    break;
                }
            }

            var result = Loader.Lib.PassThruIoctl(channelId, (int)ioctlID, input, output);

            if (result == J2534Err.STATUS_NOERROR)
            {
                if (output == IntPtr.Zero)
                {
                    Log.WriteLine("  Output is null");
                }
                else
                {
                    Log.Write("  Output:");
                    switch (ioctlID)
                    {
                    case Ioctl.GET_CONFIG:
                        var configList = input.AsStruct <SConfigList>();
                        foreach (var config in configList.GetList())
                        {
                            Log.WriteLine("    {0} = {1}", config.Parameter, config.Value);
                        }
                        break;

                    case Ioctl.READ_VBATT:
                    case Ioctl.READ_PROG_VOLTAGE:
                        Log.WriteLine(" {0:#.000} Volts", output.AsStruct <uint>() / 1000.0);
                        break;

                    case Ioctl.FAST_INIT:
                        Log.WriteLine(output.AsStruct <PassThruMsg>().ToString("\t"));
                        break;

                    case Ioctl.FIVE_BAUD_INIT:
                        Log.WriteLine(Environment.NewLine + "    " + input.AsStruct <SByteArray>().ToString());
                        break;

                    default:
                        Log.WriteLine("");
                        break;
                    }
                }
            }

            Log.WriteTimestamp("  ", "{0}: {1}", (int)result, result);

            return((int)result);
        }