Skip to content

python type of message data sent to subscribers is different for TP versus non-TP messages #67

@grant-allan-ctct

Description

@grant-allan-ctct

When subscribers are notified of a regular 8-byte frame of data, the message type is a bytearray of binary data. You can see why this is so in the sourcecode of j1939_21.py by looking here and here and here.

Here is an example of the output of print(message) in this case:
{'priority': 6, 'pgn': 60928, 'source': 128, 'dest': 255, 'timestamp': 9.7563833, 'data': bytearray(b'\xfc\xbdp\x11\x00\x91\x00\x80')}

But when the subscriber gets notified of incoming TP, the type of data is a list of bytes, and you can see why by looking here and here.

Example:
{'priority': 6, 'pgn': 65242, 'source': 128, 'dest': 199, 'timestamp': 27.9721957, 'data': [14, 67, 84, 67, 84, 95, 80, 67, 66, 83, 78, 52, 42, 48, 56, 56, 51, 56, 52, 51, 51, 50, 56, 42, 67, 84, 67, 84, 95, 68, 83, 78, 42, 69, 82, 82, 42, 67, 84, 67, 84, 95, 70, 87, 80, 82, 69, 70, 73, 88, 42, 71, 83, 53, 49, 88, 42, 65, 80, 42, 49, 46, 55, 50, 42, 79, 83, 42, 48, 46, 52, 52, 42, 67, 84, 67, 84, 95, 80, 82, 79, 68, 42, 71, 83, 53, 49, 48, 42, 67, 84, 67, 84, 95, 83, 69, 78, 83, 79, 82, 83, 42, 48, 49, 42, 67, 84, 67, 84, 95, 79, 80, 84, 83, 42, 48, 42, 80, 82, 79, 84, 95, 86, 69, 82, 42, 49, 46, 49, 46, 48, 42]}

Unless we consider that this horse has bolted already, I think that it would be good to standardize so that subscribers always receive message data using a consistent data type.

A potential workaround would appear to be that we override ElectronicControlUnit._notify_subscribers in a subclass, and give the incoming data argument a massage before forwarding it to subscribers.

Does anyone have any thoughts on whether it would be preferable to standardize upon using a bytearray versus using a list of bytes?

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