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:
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);
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
Tazzi wrote: Fri Oct 11, 2024 3:40 pm
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.
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
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
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.
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?
}
// ...
}