Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAN Filter #6

Open
karlkobel opened this issue May 26, 2022 · 0 comments
Open

CAN Filter #6

karlkobel opened this issue May 26, 2022 · 0 comments

Comments

@karlkobel
Copy link

I apologize for using this communication path, but I don't feel comfortable doing a pull request.
I am using libj1939 a in an application and I am using filters. I ran into a problem and found a solution. It may be appropriate to include this solution in the library. The method in question is j1939_filter in linux_socketcan.c.

int j1939_filter(struct j1939_pgn_filter *filter, uint32_t num_filters)
{
struct can_filter rfilter[num_filters];
uint32_t id;

for (size_t i = 0; i < num_filters; i++) {
	id = j1939_pgn2id(filter[i].pgn, filter[i].priority, filter[i].addr);

    // all of the network messages have the CAN_EFF_FLAG bit cleared, so I don't
    // understand why this is set here. The mask is zero, so this bit wouldn't
    // be considered in the filter anyway
	rfilter[i].can_id = id | CAN_EFF_FLAG;
    
    // the filter mask didn't line up with the ID so I used the pgn2id macro to align it
    // I didn't know what to do with the polarity bit, so I left it at 0
    // I did not need to filter on the polarity
	// original code - rfilter[i].can_mask = filter[i].pgn_mask;
    rfilter[i].can_mask = j1939_pgn2id(filter[i].pgn_mask, 0, filter[i].addr_mask);

    // test code to verify the id and mask
	//printf("ID: %08x, Mask: %08x\n", rfilter[i].can_id, rfilter[i].can_mask);
}
setsockopt(cansock, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));

return 0;

}

Thanks for your consideration.

Karl Kobel

BTW - we have a slight connection - I work for Wabtec (albeit in the bus division). I know we have done work for Alstom.

[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant