public override string interpret(FullBinaryReader reader)
        {
            StringBuilder logentry = new StringBuilder();

            J2534_0404func f = (J2534_0404func)reader.ReadByte();

            checkEnum(typeof(J2534_0404func), f);

            logentry.Append(f + "(");

            //Loop over params
            bool firstparam = true;

            wiredatatype datatype = (wiredatatype)reader.ReadByte();

            while (datatype != wiredatatype.END)
            {
                if (!firstparam)
                {
                    logentry.Append(", ");
                }
                parseDataField(reader, logentry, datatype);
                firstparam = false;
                datatype   = (wiredatatype)reader.ReadByte();
            }

            logentry.Append(") -> ");
            J2534_errorCodes retcode = (J2534_errorCodes)reader.ReadInt32();

            checkEnum(typeof(J2534_errorCodes), retcode);
            logentry.Append(retcode);

            return(logentry.ToString());
        }
コード例 #2
0
        private void recvThreadFunc()
        {
            bool is_mid_msg = false;

            try
            {
                UInt16 wireProtoVersion = streamreader.ReadUInt16();
                if (wireProtoVersion != 0x0000)
                {
                    state = CONNSTATE.Unsupported;
                    form.updateConnectionListEntry(this);
                    return;
                }
                UInt16 J2534ProtoVersion = streamreader.ReadUInt16();
                switch (J2534ProtoVersion)
                {
                case 0x0404:
                    interpreter = new J2534ProtocolInterpreter_0404();
                    break;

                default:
                    state = CONNSTATE.Unsupported;
                    form.updateConnectionListEntry(this);
                    return;
                }

                state = CONNSTATE.Connected;
                form.updateConnectionListEntry(this);

                //Setup complete, Loop forever processing messages.
                while (state == CONNSTATE.Connected)
                {
                    msgtype mtype = (msgtype)streamreader.ReadByte();
                    checkEnum(typeof(msgtype), mtype);
                    is_mid_msg = true;

                    switch (mtype)
                    {
                    case msgtype.reportParam:
                        StringBuilder logentry = new StringBuilder();
                        param         p        = (param)streamreader.ReadByte();
                        checkEnum(typeof(param), p);

                        switch (p)
                        {
                        case param.client:
                            Client = streamreader.ReadString();
                            form.updateConnectionListEntry(this);
                            logentry.Append("Client: " + Client);
                            //logWriter.WriteLine("Client: " + Client);
                            break;

                        case param.driver:
                            Driver = streamreader.ReadString();
                            logentry.Append("Driver: " + Driver);
                            //logWriter.WriteLine("Driver: " + Driver);
                            int driverstatus = streamreader.ReadInt32();
                            if (driverstatus != 0)
                            {
                                close();
                                state = CONNSTATE.Error;
                                if (driverstatus > 0)
                                {
                                    state = CONNSTATE.BadDriver;
                                }
                                else if (driverstatus == -1)
                                {
                                    state = CONNSTATE.MissingDriver;
                                }
                            }
                            form.updateConnectionListEntry(this);
                            break;
                        }

                        saveLogEntry(logentry.ToString());
                        break;

                    case msgtype.J2534Msg:
                        saveLogEntry(interpreter.interpret(streamreader));
                        EventCount++;
                        form.updateConnectionListEntry(this);
                        break;
                    }
                    is_mid_msg = false;
                }
            }
            catch (System.ObjectDisposedException)
            {
                Console.WriteLine("Connectionclosed, unable to do stuff.");
                state = CONNSTATE.Disconnected;
                form.updateConnectionListEntry(this);
            }
            catch (System.Net.Sockets.SocketException e)
            {
                catchSocketException(e);
            }
            catch (System.IO.IOException e)
            {
                if (e.InnerException is System.Net.Sockets.SocketException)
                {
                    catchSocketException((System.Net.Sockets.SocketException)e.InnerException);
                }
                else if (!is_mid_msg)
                {
                    state = CONNSTATE.Disconnected;
                    form.updateConnectionListEntry(this);
                    socket.Close();
                }
                else
                {
                    die();
                }
            }
            catch (InvalidEnumException e)
            {
                Console.WriteLine(e.ToString());
                die();
            }
        }