Skip to content

Commit 5715eca

Browse files
DavyGillebertH-Grobben
authored andcommitted
Fixed some review comments and extended tests to cover more use cases
1 parent 88bf866 commit 5715eca

5 files changed

Lines changed: 337 additions & 82 deletions

File tree

canopen/sdo/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Command, index, subindex
66
SDO_STRUCT = struct.Struct("<BHB")
7-
SDO_BLOCKINIT_STRUCT = "<BHBI" # Command + seqno, index, subindex, size
7+
SDO_BLOCKINIT_STRUCT = struct.Struct("<BHBI") # Command + seqno, index, subindex, size
88
SDO_BLOCKACK_STRUCT = struct.Struct("<BBB") # c + ackseq + new blocksize
99
SDO_BLOCKEND_STRUCT = struct.Struct("<BH") # c + CRC
1010
SDO_ABORT_STRUCT = struct.Struct("<BHBI") # c +i + si + Abort code

canopen/sdo/exceptions.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,21 @@ def __str__(self):
6060
text = text + ", " + self.CODES[self.code]
6161
return text
6262

63-
def __eq__(self, other):
63+
def __eq__(self, other:Union['SdoAbortedError', int, str]):
6464
"""Compare two exception objects based on SDO abort code."""
65+
if isinstance(other, int):
66+
other = SdoAbortedError(other)
67+
elif isinstance(other, str):
68+
other = SdoAbortedError(other)
69+
elif not isinstance(other, SdoAbortedError):
70+
raise TypeError(f"Cannot compare SdoAbortedError with {type(other)}")
6571
return self.code == other.code
6672

67-
def from_string(self, text):
73+
def from_string(self, text: str) -> int:
6874
code = list(SdoAbortedError.CODES.keys())[
6975
list(SdoAbortedError.CODES.values()).index(text)
7076
]
71-
return code
77+
return SdoAbortedError(code)
7278

7379

7480
class SdoCommunicationError(SdoError):

0 commit comments

Comments
 (0)