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

set_standard_filter doesn't seem to work #39

Open
bjh-teleo opened this issue Jul 12, 2023 · 5 comments
Open

set_standard_filter doesn't seem to work #39

bjh-teleo opened this issue Jul 12, 2023 · 5 comments

Comments

@bjh-teleo
Copy link

bjh-teleo commented Jul 12, 2023

Trying to filter for arb ID 0x700 and still receiving all messages when I call can1.receive0(msg) later on

Have tried this

let arb_id = StandardId::new(0x700 as u16).unwrap().into();
let slot = StandardFilterSlot::_0;
let filter = StandardFilter {
    filter: FilterType::DedicatedSingle(arb_id),
    action: Action::StoreInFifo0,
};
can1.set_standard_filter(slot, filter);

and this

let filter = StandardFilter {
    filter: FilterType::BitMask {
         filter: 0x700,
         mask: 0x7ff,
    },
    action: Action::StoreInFifo0,
};

still receive all can messages

An example would be helpful. I came across this https://github.com/stm32-rs/stm32h7xx-hal/blob/master/examples/can-echo.rs example, but it only shows use of accept_all_into_fifo0()

can.set_standard_filter(
        StandardFilterSlot::_0,
        StandardFilter::accept_all_into_fifo0(),
    );
@bjh-teleo bjh-teleo changed the title can't get set_standard_filter to work set_standard_filter doesn't seem to work Jul 12, 2023
@bjh-teleo
Copy link
Author

Came across this #35, could be related.

@David-OConnor
Copy link

Have you tried setting a reject all filter in a higher-numbered slot than your accept filter? That seems to be what I had to do from experimenting.

@bjh-teleo
Copy link
Author

bjh-teleo commented Jul 15, 2023 via email

@bjh-teleo
Copy link
Author

@David-OConnor been a few months and I'm finally getting back to this. Can you share an example for how to set a "reject all" filter?

@David-OConnor
Copy link

pub fn setup_protocol_filters(can: Can_) -> Can_ {
    let mut can = can.into_config_mode();

    // Node: H7 has up to 64 filters available. This is set up for G4's limitations.
    // This `GetNodeInfo` also matches dynamic ID allocation.

    let s = ServiceData {
        dest_node_id: 0, // 7 bits
        req_or_resp: RequestResponse::Request,
    };

    set_dronecan_filter(
        &mut can,
        ExtendedFilterSlot::_0,
        FrameType::Service(s),
        MsgType::GetNodeInfo.id(),
    );
    set_dronecan_filter(
        &mut can,
        ExtendedFilterSlot::_1,
        FrameType::Message,
        MsgType::IdAllocation.id(),
    );
    set_dronecan_filter(
        &mut can,
        ExtendedFilterSlot::_2,
        FrameType::Service(s),
        MsgType::GetSet.id(),
    );
    set_dronecan_filter(&mut can, ExtendedFilterSlot::_3, FrameType::Service(s), MsgType::Restart.id());

    // Place this reject filter in the filal slot, rejecting all messages not explicitly accepted
    // by our dronecan ID filters.
    let reject_filter = ExtendedFilter::reject_all();
    can.set_extended_filter(ExtendedFilterSlot::_7, reject_filter);

    can.into_normal()
}

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

2 participants