-
Notifications
You must be signed in to change notification settings - Fork 619
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
Meaning of can.BusABC.state #736
Comments
Unfortunately it is a mix of both. I’m guessing the idea was that when reading it you would get the first and when writing to it you change the second. You could look at another implementation, like pcan for inspiration. |
I was writing a post to the message board, but found this issue and decided to post it here instead: Could we consider renaming the BusState enum options according to the CAN specification (ERROR_ACTIVE, ERROR_PASSIVE, BUS_DOWN)? Also, as I primarily use socketcan, there is a fourth state ("STOPPED"), which means the interface (not just the "bus") is down and will not automatically recover (as in Bus-Off) until brought back up. I'm not sure how applicable this is to the other interfaces, but maybe add this fourth state? Knowing the difference between Bus-Off and down/stopped in an application can be important. For those who are interested, the SocketCAN state can be found using "ip -d link show ", then finding the string on this line: "can state restart-ms ". Additionally, defaulting BusABC's state property to be ACTIVE seems to be bad practice. It seems the better practice would be to either make the state property throw a NotImplementedError() by default or default to a new UNKNOWN enum value. If there is no way to detect the state for an interface and it actually needs the state property to return ACTIVE (and not UNKNOWN) or an exception, then only that interface's Bus class would override the state property. This may solve the "mix of both" issue by simply defining more states, or making them different class properties (hardware state vs. software state). I would prefer a single property (state) with more enum options. I can work on a PR if pursuing this is worthwhile. |
For reference, from iproute2:
|
Do we plan to agree on a naming for the |
Agree, needs a champion! My 2c is that |
Why there is no a state to stand for RUNNING / NORMAL / BUS_ON ? |
The |
@hardbyte @felixdivo Now that 4.0 has been released and this was not incorporated :(, what's the plan? Maybe 4.1? I updated PR #847 with upstream so the change can be easily merged. |
@bggardner thanks for reviving this. I'm not involved anymore, so @hardbyte maybe you have an opinion? |
I suggest adding these properties to from enum import Enum, auto
class ErrorState(Enum):
ERROR_ACTIVE = auto()
ERROR_WARNING = auto()
ERROR_PASSIVE = auto()
BUS_OFF = auto()
STOPPED = auto()
SLEEPING = auto()
class BusABC(metaclass=ABCMeta):
@property
def error_state(self) -> ErrorState:
raise NotImplementedError()
@property
def tx_error_count(self) -> int:
raise NotImplementedError()
@property
def rx_error_count(self) -> int:
raise NotImplementedError() The |
Point of order: The definition of In any case, it is important to indicate these three "node states" to the application. The state of the can interface should also be indicated to the application, which would most likely be one of "up" or "down". However, if the interface is "up", the node will be in one of those three states; and if the interface is "down", the node will be in none of those states. I believe the iproute2 developers came to the same conclusion, which is why they have combined the "node states" with the "interface states" into the six "can states" above. I propose(d) we do the same. So, props to @zariiii9003 for recommending error counts as well, but I think we can keep the |
"Error state" is quite common in CAN interface docs. There's even an "error state indicator" bit. |
Hello,
please help me understand the meaning of
class BusState(Enum):
. I would like to show status of the interface (Kvaser Leaf and Vector VN1610 are on my desk) as specified by CAN specification (error active, error passive and bus-off state).But the @Property
def state(self):
of the classesclass KvaserBus(BusABC):
andclass VectorBus(BusABC):
are not implemented.I would like to implement them but I am not sure what it shall returns
The documentation says that it returns "current state of the hardware". Does it mean state of driver connection with HW interface or state of CAN bus controller (active->passive->busoff)?
The text was updated successfully, but these errors were encountered: