Exemple #1
0
 public PassThruMsg(ProtocolID myProtocolId, TxFlag myTxFlag, byte[] myByteArray)
     : this()
 {
     ProtocolID = myProtocolId;
     TxFlags = myTxFlag;
     SetBytes(myByteArray);
 }
Exemple #2
0
 public ObdComm(IJ2534 j2534Interface)
 {
     m_j2534Interface = j2534Interface;
     m_isConnected = false;
     m_protocol = ProtocolID.ISO15765;
     m_status = J2534Err.STATUS_NOERROR;
 }
Exemple #3
0
 public ObdComm(IJ2534Extended j2534Interface)
 {
     m_j2534Interface = j2534Interface;
     m_isConnected    = false;
     m_protocol       = ProtocolID.ISO15765;
     m_status         = J2534Err.STATUS_NOERROR;
 }
Exemple #4
0
 public OBDConnection(IJ2534Extended j2534Interface)
 {
     this.J2534Interface = j2534Interface;
     _isConnected        = false;
     ProtocolId          = ProtocolID.ISO15765;
     J2534Status         = J2534Err.STATUS_NOERROR;
 }
Exemple #5
0
        public void ConnectISO15765()
        {
            Connect();

            byte[] value;
            J2534Status = J2534Interface.PassThruConnect(DeviceId, ProtocolID.ISO15765, ConnectFlag.NONE, BaudRate.ISO15765, ref ChannelId);
            if (J2534Err.STATUS_NOERROR != J2534Status)
            {
                throw new J2534Exception(J2534Status);
            }

            //List<SConfig> configBits = new List<SConfig>();
            //SConfig conf = new SConfig();
            //conf.Parameter = ConfigParameter.LOOPBACK;
            //conf.Value = 0;
            //SConfig conf1 = new SConfig();
            //conf1.Parameter = ConfigParameter.DATA_RATE;
            //conf1.Value = 0;

            //configBits.Add(conf);
            //configBits.Add(conf1);
            //m_status = m_j2534Interface.GetConfig(m_channelId, ref configBits);


            int filterId = 0;

            byte i;

            for (i = 0; i < 1; i++)
            {
                PassThruMsg maskMsg        = new PassThruMsg(ProtocolID.ISO15765, TxFlag.ISO15765_FRAME_PAD, new byte[] { 0xff, 0xff, 0xff, 0xff });
                PassThruMsg patternMsg     = new PassThruMsg(ProtocolID.ISO15765, TxFlag.ISO15765_FRAME_PAD, new byte[] { 0x00, 0x00, 0x07, (byte)(0xE8 + i) });
                PassThruMsg flowControlMsg = new PassThruMsg(ProtocolID.ISO15765, TxFlag.ISO15765_FRAME_PAD, new byte[] { 0x00, 0x00, 0x07, (byte)(0xE0 + i) });

                J2534Status = J2534Interface.PassThruStartMsgFilter(
                    ChannelId,
                    FilterType.FLOW_CONTROL_FILTER,
                    maskMsg.ToIntPtr(),
                    patternMsg.ToIntPtr(),
                    flowControlMsg.ToIntPtr(),
                    ref filterId);

                if (J2534Err.STATUS_NOERROR != J2534Status)
                {
                    J2534Interface.PassThruDisconnect(ChannelId);
                    throw new J2534Exception(J2534Status);
                }
            }

            //Check we can read some PIDs back
            ReadObdPid(OBDcmd.Mode.REQUEST_CURRENT_DATA, out value);
            if (value.Length <= 0)
            {
                //m_status = j2534Interface.PassThruDisconnect(channelId);
                //throw new OBDException(OBDcmd.Response.NEGATIVE_RESPONSE);
            }

            ProtocolId = ProtocolID.ISO15765;
        }
Exemple #6
0
 public J2534Err PassThruConnect(int deviceId, ProtocolID protocolId, ConnectFlag flags, BaudRate baudRate, ref int channelId)
 {
     if (!IsLoaded)
     {
         return(J2534Err.ERR_DLL_NOT_LOADED);
     }
     return((J2534Err)_wrapper.Connect(deviceId, (int)protocolId, (int)flags, (int)baudRate, ref channelId));
 }
Exemple #7
0
 /**
  * Installs a new Protocol on the Node
  *
  * @param name
  *            Name of the protocol to install
  * @param protocol
  *            ProtocolID installed
  */
 public /*synchronized*/ static void installProtocol(String name, ProtocolID protocol)
 {
     if (!NodeAddress.installedProtocols.ContainsKey(name))
     {
         NodeAddress.installedProtocols.Add(name, protocol);
     }
     // If the protocol is already installed, we do nothing.
 }
Exemple #8
0
        public static J2534Err PassThruConnect(int deviceId, ProtocolID protocolId, ConnectFlag flags, BaudRate baudRate, ref int channelId)
        {
            Log.WriteTimestamp("", "PTConnect({0}, {1}, {2}, {3}, {4})", deviceId, protocolId, flags, baudRate, channelId);

            var result = Loader.Lib.PassThruConnect(deviceId, protocolId, flags, baudRate, ref channelId);

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

            return(result);
        }
Exemple #9
0
        private void WriteID(ProtocolID id)
        {
            if (m_Data == null)
            {
                m_Data = new byte[BUFFER_SIZE];
            }

            byte[] data = BitConverter.GetBytes((ushort)id);
            data.CopyTo(m_Data, ID_OFFSET);
        }
Exemple #10
0
        public static J2534Err PassThruConnect(int deviceId, ProtocolID protocolId, ConnectFlag flags, BaudRate baudRate, ref int channelId)
        {
            Log.WriteTimestamp("", "PTConnect({0}, {1}, {2}, {3}, {4})", deviceId, protocolId, flags, baudRate, channelId);

            var result = Loader.Lib.PassThruConnect(deviceId, protocolId, flags, baudRate, ref channelId);

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

            return result;
        }
Exemple #11
0
        public override int GetHashCode()
        {
            var hashCode = -1534566933;

            hashCode = hashCode * -1521134295 + ID.GetHashCode();
            hashCode = hashCode * -1521134295 + ProtocolID.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <byte[]> .Default.GetHashCode(PrivateKey);

            hashCode = hashCode * -1521134295 + Timeout.GetHashCode();
            return(hashCode);
        }
Exemple #12
0
 /// <summary>
 /// connect to selected protocol
 /// Must provide protocol, speed, connection flags, recommended optional is pins
 /// </summary>
 private Response <J2534Err> ConnectToProtocol(ProtocolID ReqProtocol, BaudRate Speed, ConnectFlag ConnectFlags)
 {
     OBDError = J2534Port.Functions.PassThruConnect(DeviceID, ReqProtocol, ConnectFlags, Speed, ref ChannelID);
     if (OBDError != J2534Err.STATUS_NOERROR)
     {
         return(Response.Create(ResponseStatus.Error, OBDError));
     }
     Protocol       = ReqProtocol;
     IsProtocolOpen = true;
     return(Response.Create(ResponseStatus.Success, OBDError));
 }
Exemple #13
0
 IParser _GetParser(ProtocolID id)
 {
     if (_mapper.ContainsKey(id))
     {
         return(_mapper[id]);
     }
     else
     {
         return(null);
     }
 }
Exemple #14
0
        public Packet(ProtocolID id)
        {
            m_Data = new byte[BUFFER_SIZE];
            ID     = id;
            WriteID(id);
            m_wPacketSize  = 0;
            m_wReadOffSet  = 0;
            m_wWriteOffSet = 0;

            m_wPacketLen = (ushort)m_Data.Length;
            WritePacketSize(0);
        }
Exemple #15
0
        public Packet(ProtocolID id)
        {
            m_Data = new byte[BUFFER_SIZE];
            ID = id;
            WriteID(id);
            m_wPacketSize = 0;
            m_wReadOffSet = 0;
            m_wWriteOffSet = 0;

            m_wPacketLen = (ushort)m_Data.Length;
            WritePacketSize(0);
        }
Exemple #16
0
    NetworkEventArgs _ParseData(byte[] data)
    {
        ProtocolID id     = _GetProtocolID(data);
        IParser    parser = _GetParser(id);

        if (parser == null)
        {
            return(null);
        }

        byte[] content = new byte[data.Length - sizeof(int)];
        Buffer.BlockCopy(data, sizeof(int), content, 0, content.Length);
        NetworkEventArgs args = parser.Deserialize(content);

        return(args);
    }
Exemple #17
0
 public byte[] Build()
 {
     return(ProtocolID
            .Concat(Length)
            .Concat(CreditCharge)
            .Concat(NTStatus)
            .Concat(Command)
            .Concat(Credits)
            .Concat(Flags)
            .Concat(NextCommand)
            .Concat(MessageID)
            .Concat(ProcessID)
            .Concat(TreeID)
            .Concat(SessionID)
            .Concat(Signature)
            .ToArray());
 }
Exemple #18
0
        public Packet(byte[] data, int length)
        {
            ID = (ProtocolID)BitConverter.ToUInt16(data, ID_OFFSET);

            m_wPacketSize  = BitConverter.ToUInt16(data, PACKET_SIZE_OFFSET);
            m_wReadOffSet  = 0;
            m_wWriteOffSet = 0;

            if (data.Length < (int)(HEADER_SIZE + m_wPacketSize)) //이상하게 패킷이 오면 응급처리를 한다.
            {
                m_wPacketSize = (ushort)(length - 4);
            }

            m_Data = new byte[length];

            Array.Copy(data, 0, m_Data, 0, length);
            m_wPacketLen = (ushort)length;
        }
Exemple #19
0
 public bool DetectProtocol()
 {
     // possible return values:
     //  ProtocolID.ISO15765; // CAN
     //  ProtocolID.ISO9141;  // ISO-K
     //  ProtocolID.J1850PWM;  // J1850PWM
     //  ProtocolID.J1850VPW;  // J1850VPW
     m_deviceId = 0;
     m_status   = m_j2534Interface.PassThruOpen(IntPtr.Zero, ref m_deviceId);
     if (m_status != J2534Err.STATUS_NOERROR)
     {
         return(false);
     }
     if (ConnectIso15765())
     {
         m_protocol    = ProtocolID.ISO15765;
         m_isConnected = true;
     }
     return(true);
 }
Exemple #20
0
        /**
         * Parses a string representation of a NodeAddress back to its object form
         *
         * @param str
         *            The string to parse
         * @return A new NodeAddress created from a String form
         * @//throws ArgumentException
         *             Thrown if the string is not for a recognised protocol.
         */


        public static NodeAddress parse(String str)
        //throws ArgumentException
        {
            int        index    = str.IndexOf("\\");
            ProtocolID protocol = (ProtocolID)NodeAddress.installedProtocols[str.Substring(0, index)];

            //if (protocol != null)
            //{
            //    return protocol.parse(str.Substring(index + 4));
            //}

            return(protocol.parse(str));

            //String[] strings = str.Split(@"\\\\");

            //if (strings[0].Equals("tcpip", StringComparison.OrdinalIgnoreCase))
            //{
            //    String[] addressStrings = strings[1].Split(":");
            //    return new TCPIPNodeAddress(addressStrings[0], Int32.Parse(addressStrings[1]));
            //}

            throw new ArgumentException("Unknown protocol used for parsing NodeAddress");
        }
Exemple #21
0
    ProtocolID _GetProtocolID(byte[] data)
    {
        ProtocolID id = ProtocolID.ProtocolID_Invalid;

        if (data.Length < sizeof(int))
        {
            return(id);
        }

        byte[] idBytes = new byte[sizeof(int)];
        Buffer.BlockCopy(data, 0, idBytes, 0, idBytes.Length);
        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(idBytes);
        }
        int nID = BitConverter.ToInt32(idBytes, 0);

        if (nID > (int)ProtocolID.ProtocolID_Begin && nID < (int)ProtocolID.ProtocolID_End)
        {
            id = (ProtocolID)nID;
        }
        return(id);
    }
Exemple #22
0
 protected Protocol(ProtocolID protocolID)
 {
     this.protocolID = protocolID;
     enabled         = true;
 }
Exemple #23
0
 public PassThruMsg(ProtocolID myProtocolId, TxFlag myTxFlag, byte[] myByteArray)
 {
     ProtocolID = myProtocolId;
     TxFlags    = myTxFlag;
     Data       = myByteArray;
 }
 public Protocol(ProtocolID protocolID)
 {
     this.protocolID = protocolID;
     enabled         = true;
 }
Exemple #25
0
 public void SetID(ProtocolID id)
 {
     ID = id;
     WriteID(id);
 }
Exemple #26
0
        private void WriteID(ProtocolID id)
        {
            if (m_Data == null)
                m_Data = new byte[BUFFER_SIZE];

            byte[] data = BitConverter.GetBytes((ushort)id);
            data.CopyTo(m_Data, ID_OFFSET);
        }
Exemple #27
0
 public J2534Err Connect(int deviceId, ProtocolID protocolId, ConnectFlag flags, int baudRate, ref int channelId)
 {
     return (J2534Err)m_wrapper.Connect(deviceId, (int)protocolId, (int)flags, baudRate, ref channelId);
 }
Exemple #28
0
 public PassThruMsg(ProtocolID myProtocolId, TxFlag myTxFlag, byte[] myByteArray) : this()
 {
     ProtocolID = myProtocolId;
     TxFlags    = myTxFlag;
     SetBytes(myByteArray);
 }
Exemple #29
0
        private bool ReadObdPid(byte mode, byte pid, ProtocolID protocolId, ref List<byte> value)
        {
            List<PassThruMsg> rxMsgs = new List<PassThruMsg>();
            PassThruMsg txMsg = new PassThruMsg();
            int timeout;

            txMsg.ProtocolID = protocolId;
	        switch (protocolId)
	        {
		        case ProtocolID.ISO15765:
                    txMsg.TxFlags = TxFlag.ISO15765_FRAME_PAD;
                    if (mode == 0x03 || mode == 0x04)
                    {
                        txMsg.Data = new byte[] { 0x00, 0x00, 0x07, 0xdf, mode};
                    }
                    else
                    {
                        txMsg.Data = new byte[] { 0x00, 0x00, 0x07, 0xdf, mode, pid };
                    }
                    timeout = 50;
			        break;
		        case ProtocolID.J1850PWM:
                case ProtocolID.J1850VPW:
		        case ProtocolID.ISO9141:
                case ProtocolID.ISO14230:
                    byte protocolByte = (byte)((protocolId == ProtocolID.J1850PWM) ? 0x61 : 0x68);
                    txMsg.TxFlags = TxFlag.NONE;
                    txMsg.Data = new byte[]{protocolByte, 0x6A, 0xF1, mode, pid};
			        timeout = 100;
			        break;
		        default:
			        return false;
	        }

	        m_j2534Interface.ClearRxBuffer(m_channelId);

	        int numMsgs = 1;
            m_status = m_j2534Interface.WriteMsgs(m_channelId, ref txMsg, ref numMsgs, timeout);
            if (J2534Err.STATUS_NOERROR != m_status)
            {
                return false;
            }

            numMsgs = 1;
            while (J2534Err.STATUS_NOERROR == m_status)
	        {
                m_status = m_j2534Interface.ReadMsgs(m_channelId, ref rxMsgs, ref numMsgs, timeout * 4);
	        }

            if (J2534Err.ERR_BUFFER_EMPTY == m_status || J2534Err.ERR_TIMEOUT == m_status)
            {
                if (rxMsgs.Count > 1)
                {
                    // Select the last value
                    value = rxMsgs[rxMsgs.Count - 1].Data.ToList();
                    value.RemoveRange(0, txMsg.Data.Length);
                    return true;
                }
                return false;
            }
            return false;
        }
Exemple #30
0
 public bool DetectProtocol()
 {
     // possible return values:
     //  ProtocolID.ISO15765; // CAN
     //  ProtocolID.ISO9141;  // ISO-K
     //  ProtocolID.J1850PWM;  // J1850PWM
     //  ProtocolID.J1850VPW;  // J1850VPW
     m_deviceId = 0;
     m_status = m_j2534Interface.Open(ref m_deviceId);
     if (m_status != J2534Err.STATUS_NOERROR)
         return false;
     if (ConnectIso15765())
     {
         m_protocol = ProtocolID.ISO15765;
         m_isConnected = true;
     }
     return true;
 }
Exemple #31
0
 public void SetID(ProtocolID id)
 {
     ID = id;
     WriteID(id);
 }
Exemple #32
0
 public PassThruMsg(ProtocolID myProtocolId, TxFlag myTxFlag, byte[] myByteArray)
 {
     ProtocolID = myProtocolId;
     TxFlags = myTxFlag;
     Data = myByteArray;
 }
Exemple #33
0
 public bool Set_15765_para()
 {
     m_protocol    = ProtocolID.ISO15765;
     m_isConnected = true;
     return(true);
 }
Exemple #34
0
        private bool ReadObdPid(byte mode, byte pid, ProtocolID protocolId, ref List <byte> value)
        {
            PassThruMsg txMsg = new PassThruMsg();
            int         timeout;

            txMsg.ProtocolID = protocolId;
            switch (protocolId)
            {
            case ProtocolID.ISO15765:
                txMsg.TxFlags = TxFlag.ISO15765_FRAME_PAD;
                if (mode == 0x03 || mode == 0x04)
                {
                    txMsg.SetBytes(new byte[] { 0x00, 0x00, 0x07, 0xdf, mode });
                }
                else
                {
                    txMsg.SetBytes(new byte[] { 0x00, 0x00, 0x07, 0xdf, mode, pid });
                }
                timeout = 50;
                break;

            case ProtocolID.J1850PWM:
            case ProtocolID.J1850VPW:
            case ProtocolID.ISO9141:
            case ProtocolID.ISO14230:
                byte protocolByte = (byte)((protocolId == ProtocolID.J1850PWM) ? 0x61 : 0x68);
                txMsg.TxFlags = TxFlag.NONE;
                txMsg.SetBytes(new byte[] { protocolByte, 0x6A, 0xF1, mode, pid });
                timeout = 100;
                break;

            default:
                return(false);
            }

            m_j2534Interface.ClearRxBuffer(m_channelId);

            int numMsgs = 1;

            m_status = m_j2534Interface.PassThruWriteMsgs(m_channelId, txMsg.ToIntPtr(), ref numMsgs, timeout);
            if (J2534Err.STATUS_NOERROR != m_status)
            {
                return(false);
            }

            IntPtr rxMsgs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PassThruMsg)) * numMsgs);

            numMsgs = 1;
            while (J2534Err.STATUS_NOERROR == m_status)
            {
                m_status = m_j2534Interface.PassThruReadMsgs(m_channelId, rxMsgs, ref numMsgs, timeout * 4);
            }

            if (J2534Err.ERR_BUFFER_EMPTY == m_status || J2534Err.ERR_TIMEOUT == m_status)
            {
                if (numMsgs > 0)
                {
                    // Select the last value
                    PassThruMsg msg = rxMsgs.AsMsgList(numMsgs).Last();
                    value = msg.GetBytes().ToList();
                    value.RemoveRange(0, txMsg.GetBytes().Length);
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Exemple #35
0
        private bool ReadObdPid(byte mode, byte pid, ProtocolID protocolId, ref List <byte> value)
        {
            List <PassThruMsg> rxMsgs = new List <PassThruMsg>();
            PassThruMsg        txMsg  = new PassThruMsg();
            int timeout;

            txMsg.ProtocolID = protocolId;
            switch (protocolId)
            {
            case ProtocolID.ISO15765:
                txMsg.TxFlags = TxFlag.ISO15765_FRAME_PAD;
                if (mode == 0x03 || mode == 0x04)
                {
                    txMsg.Data = new byte[] { 0x00, 0x00, 0x07, 0xdf, mode };
                }
                else
                {
                    txMsg.Data = new byte[] { 0x00, 0x00, 0x07, 0xdf, mode, pid };
                }
                timeout = 50;
                break;

            case ProtocolID.J1850PWM:
            case ProtocolID.J1850VPW:
            case ProtocolID.ISO9141:
            case ProtocolID.ISO14230:
                byte protocolByte = (byte)((protocolId == ProtocolID.J1850PWM) ? 0x61 : 0x68);
                txMsg.TxFlags = TxFlag.NONE;
                txMsg.Data    = new byte[] { protocolByte, 0x6A, 0xF1, mode, pid };
                timeout       = 100;
                break;

            default:
                return(false);
            }

            m_j2534Interface.ClearRxBuffer(m_channelId);

            int numMsgs = 1;

            m_status = m_j2534Interface.WriteMsgs(m_channelId, ref txMsg, ref numMsgs, timeout);
            if (J2534Err.STATUS_NOERROR != m_status)
            {
                return(false);
            }

            numMsgs = 1;
            while (J2534Err.STATUS_NOERROR == m_status)
            {
                m_status = m_j2534Interface.ReadMsgs(m_channelId, ref rxMsgs, ref numMsgs, timeout * 4);
            }

            if (J2534Err.ERR_BUFFER_EMPTY == m_status || J2534Err.ERR_TIMEOUT == m_status)
            {
                if (rxMsgs.Count > 1)
                {
                    // Select the last value
                    value = rxMsgs[rxMsgs.Count - 1].Data.ToList();
                    value.RemoveRange(0, txMsg.Data.Length);
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Exemple #36
0
 public J2534Err Connect(int deviceId, ProtocolID protocolId, ConnectFlag flags, int baudRate, ref int channelId)
 {
     return((J2534Err)m_wrapper.Connect(deviceId, (int)protocolId, (int)flags, baudRate, ref channelId));
 }
Exemple #37
0
        private bool ReadObdPid(byte mode, byte pid, ProtocolID protocolId, ref List<byte> value)
        {
            PassThruMsg txMsg = new PassThruMsg();
            int timeout;

            txMsg.ProtocolID = protocolId;
            switch (protocolId)
            {
                case ProtocolID.ISO15765:
                    txMsg.TxFlags = TxFlag.ISO15765_FRAME_PAD;
                    if (mode == 0x03 || mode == 0x04)
                    {
                        txMsg.SetBytes(new byte[] { 0x00, 0x00, 0x07, 0xdf, mode});
                    }
                    else
                    {
                        txMsg.SetBytes(new byte[] { 0x00, 0x00, 0x07, 0xdf, mode, pid });
                    }
                    timeout = 50;
                    break;
                case ProtocolID.J1850PWM:
                case ProtocolID.J1850VPW:
                case ProtocolID.ISO9141:
                case ProtocolID.ISO14230:
                    byte protocolByte = (byte)((protocolId == ProtocolID.J1850PWM) ? 0x61 : 0x68);
                    txMsg.TxFlags = TxFlag.NONE;
                    txMsg.SetBytes(new byte[]{protocolByte, 0x6A, 0xF1, mode, pid});
                    timeout = 100;
                    break;
                default:
                    return false;
            }

            m_j2534Interface.ClearRxBuffer(m_channelId);

            int numMsgs = 1;
            m_status = m_j2534Interface.PassThruWriteMsgs(m_channelId, txMsg.ToIntPtr(), ref numMsgs, timeout);
            if (J2534Err.STATUS_NOERROR != m_status)
            {
                return false;
            }

            IntPtr rxMsgs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PassThruMsg)) * numMsgs);
            numMsgs = 1;
            while (J2534Err.STATUS_NOERROR == m_status)
            {
                m_status = m_j2534Interface.PassThruReadMsgs(m_channelId, rxMsgs, ref numMsgs, timeout * 4);
            }

            if (J2534Err.ERR_BUFFER_EMPTY == m_status || J2534Err.ERR_TIMEOUT == m_status)
            {
                if (numMsgs > 0)
                {
                    // Select the last value
                    PassThruMsg msg = rxMsgs.AsMsgList(numMsgs).Last();
                    value = msg.GetBytes().ToList();
                    value.RemoveRange(0, txMsg.GetBytes().Length);
                    return true;
                }
                return false;
            }
            return false;
        }