J2534 connection mask and pattern help

Disassembly, Reassembly, Tools and devleopment. Going deep with Hardware and Software.
Post Reply
hjtrbo
Posts: 227
Joined: Tue Jul 06, 2021 6:57 pm
cars: VF2 R8 LSA
FG XR6T
HJ Ute w/RB25DET

J2534 connection mask and pattern help

Post by hjtrbo »

Just wondering if I could please have some help setting up a mask and pattern using BrianHumlicek J2534-Sharp API. I'm wanting can ID's 0x7ea and 0x5ea to pass. I've got a kind friendly helper bench testing for me. We're getting data on the bus on those can id's, it's just not coming into the receive buffer. If I set a hard coded filter for just 0x7ea the data comes in, this verifies the bus connection and J tool are ok. This is how I've got it set up:

Code: Select all

public static void Connect(byte[] mask, byte[] pattern)
{
    // ...
    
    MessageFilter messageFilter = new MessageFilter()
    {
        FilterType = Filter.PASS_FILTER,
        Mask    = new byte[] { 0x0, 0x0, 0x7, 0xFE},     
        Pattern = new byte[] { 0x0, 0x0, 0x7, 0xEA } 
    };

    Channel = APIFactory.GetAPI(DllFileName).GetDevice("").GetChannel(Protocol.CAN, Baud.CAN, ConnectFlag.NONE, false);
    Thread.Sleep(180);
    Channel.StartMsgFilter(messageFilter);
    Channel.DefaultTxTimeout = 350;
    Channel.DefaultRxTimeout = 500;

    // ...
}
ironduke
Posts: 695
Joined: Thu Feb 13, 2020 11:32 pm
cars: Mainly GM trucks, a Cruze and an Equinox for dailys..

Re: J2534 connection mask and pattern help

Post by ironduke »

I generally only do one at a time but you should be able to just have a second filter and set that one up.

Code: Select all

 MessageFilter messageFilter = new MessageFilter2()
    {
        FilterType = Filter.PASS_FILTER,
        Mask    = new byte[] { 0x0, 0x0, 0x7, 0xFE},     
        Pattern = new byte[] { 0x0, 0x0, 0x5, 0xEA } 
    };
    
    and then after the connection is made
    Channel.StartMsgFilter(messageFilter2);
User avatar
Tazzi
Posts: 3546
Joined: Thu May 17, 2012 8:53 pm
cars: VE SS Ute
Location: WA
Contact:

Re: J2534 connection mask and pattern help

Post by Tazzi »

You can set more then 1 filter (technically, there’s 32 for j2534), but if wanting to use just 1 filter.

To cover both 7EA and 5EA, you will need to set a mask of 5FF

Fastest way to work it out is 7EA XOR 5EA = 200
Then 7FF-200=5FF

That’ll pass both those values through and nothing else.
Your Local Aussie Reverse Engineer
Contact for Software/Hardware development and Reverse Engineering
Site:https://www.envyouscustoms.com
Mob:+61406 140 726
Image
hjtrbo
Posts: 227
Joined: Tue Jul 06, 2021 6:57 pm
cars: VF2 R8 LSA
FG XR6T
HJ Ute w/RB25DET

Re: J2534 connection mask and pattern help

Post by hjtrbo »

Thanks to both of you. I'll try them.
hjtrbo
Posts: 227
Joined: Tue Jul 06, 2021 6:57 pm
cars: VF2 R8 LSA
FG XR6T
HJ Ute w/RB25DET

Re: J2534 connection mask and pattern help

Post by hjtrbo »

Tazzi wrote: Sat Oct 12, 2024 1:40 am You can set more then 1 filter (technically, there’s 32 for j2534), but if wanting to use just 1 filter.

To cover both 7EA and 5EA, you will need to set a mask of 5FF

Fastest way to work it out is 7EA XOR 5EA = 200
Then 7FF-200=5FF

That’ll pass both those values through and nothing else.
That worked, thank you. Mode22 and ModeAA are both working!

@ironduke, I have not tested adding a 2nd / 3rd... filter yet. Having separate filters would dumb it down to my level nicely :)

For the pattern parameter, is there anything to set that to now that the mask is nice and tight? We left it at 0x7ea and just changed the mask to 0x5ff. Its working for this test however, I have doubts if I move to a different module (with the appropriate mask changed) that it won't work.

E.g. RcvIds
ECM: 0x7e8, 0x5e8
TCM: 0x7ea, 0x5ea
BCM, FPCM and so on.

These are the message filter class properties:

Code: Select all

        public Filter FilterType;  // Filter.PASS_FILTER
        public byte[] Mask;        // new byte[] { 0x0, 0x0, 0x5, 0xFF}
        public byte[] Pattern;     // ??? <- help please
        public byte[] FlowControl; // n/a
        public TxFlag TxFlags;     // n/a
        public int    FilterId;    // 0
User avatar
Tazzi
Posts: 3546
Joined: Thu May 17, 2012 8:53 pm
cars: VE SS Ute
Location: WA
Contact:

Re: J2534 connection mask and pattern help

Post by Tazzi »

Patten = ID you are wanting to see
Mask = Which "bits" of that ID must Match
Flow = The ID used for the flow control messages (ie.. 7E0 for ECM, 7E2 for TCM ect).

To use the flow control properly, you will need to set the filter type to flow. Flow control requests are used when dealing with multi line responses (Like requesting VIN).

Typically, doing separate filters so you can individually set those items per module is ideal.
Its not common to be communicating to more then 1 module at a time so just bare that in mind.

If doing individual filters, always set the mask to 0x7FF. This means every last bit must match so it will always only return that exact ID.
Your Local Aussie Reverse Engineer
Contact for Software/Hardware development and Reverse Engineering
Site:https://www.envyouscustoms.com
Mob:+61406 140 726
Image
hjtrbo
Posts: 227
Joined: Tue Jul 06, 2021 6:57 pm
cars: VF2 R8 LSA
FG XR6T
HJ Ute w/RB25DET

Re: J2534 connection mask and pattern help

Post by hjtrbo »

Sick, thanks Tazz. :punk:

This is how I'm going to roll with it. User can add as many filters as they like. I'll try where each filter gets sent to the j tool individually. Only a basic pass filter is supported however provision is there for later expansion.

Code: Select all

public static void Connect()
{
    // ...
 
    // Attempts connection to the selected J device
    Channel = APIFactory.GetAPI(DllFileName).GetDevice("").GetChannel(Protocol.CAN, Baud.CAN, ConnectFlag.NONE, false);
    Thread.Sleep(180);
    Channel.DefaultTxTimeout = 350;
    Channel.DefaultRxTimeout = 500;

    // Each datagridview row gets its own filter class. Each instance will get sent to the j tool
    foreach (cMessageFilter.cParameter param in cMessageFilter.Parameters)
    {
        byte[] maskArr = BitConverter.GetBytes(Convert.ToUInt32(param.Mask))   .Reverse().ToArray();
        byte[] pattArr = BitConverter.GetBytes(Convert.ToUInt32(param.Pattern)).Reverse().ToArray();
        byte[] flowArr = BitConverter.GetBytes(Convert.ToUInt32(param.Flow))   .Reverse().ToArray();

        MessageFilter messageFilter = new MessageFilter();
        {
            messageFilter.Mask        = maskArr;
            messageFilter.Pattern     = pattArr;
            messageFilter.TxFlags     = param.TxFlags;
            messageFilter.FlowControl = flowArr;
            messageFilter.FilterType  = param.Filter;
        };

        // Call to start the configured message filter. Save the filter id to stop it when disconnecting
        param.FilterId = Channel.StartMsgFilter(messageFilter);

        Thread.Sleep(20); // Is this needed?
    }

    // ...
}

Image
Post Reply