Skip to content

How to get an IsoTP frame when using a NotifierBasedCanStack? #149

@starketomyf

Description

@starketomyf

I've been using python-can and python-can-isotp's CanStack in my application to receive IsoTP frames. I used the recv() function like so:

from isotp import CanStack
...
self.__bus = Bus(interface=socketcan, channel=can0, bitrate=baud)

rxid = config.get_pgn_rx()
txid = config.get_pgn_tx()
addr = AddressingMode.Normal_29bits

self.__addr = Address(addr, rxid=rxid, txid=txid)

params = {
    "blocking_send": True,
    "tx_padding": 0xFF,
    "tx_data_min_length": 8,
    "stmin": 20,
}

self.__stack = CanStack(
    self.__bus,
    address=self.__addr,
    error_handler=self.__error_handler,
    params=params,
)
...
message = self.__stack.recv()

I would like to use NotifierBasedCanStack instead. My goal is to have a function as a listener, that receives IsoTP frames. Currently I just have a simple function that prints the incoming messages:

from isotp import CanMessage, NotifierBasedCanStack
...
receiver = self.__notify_can_message
notifier = Notifier(self.__bus, [receiver])
self.__notifier_stack = NotifierBasedCanStack(
    self.__bus,
    notifier,
    address=self.__addr,
    error_handler=self.__error_handler,
    params=params,
)
...
def __notify_can_message(self, message: CanMessage) -> None:
    self.__debug("[RX-CAN] Message notification " + message.data.hex().upper())

When notified, this function receives a CanMessage object. Calling recv() on the stack returns an IsoTP frame, which I would like to have for my NotifierBasedCanStack as well.
What is the recommended way to get the actual IsoTP frame when using NotifierBasedCanStack?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions