Skip to content

Commit f71d527

Browse files
Add virtual interface to VALID_INTERFACES.
Add __eq__ and __repr__ to can.Message.
1 parent 441ddba commit f71d527

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

can/interfaces/interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from can.broadcastmanager import CyclicSendTaskABC, MultiRateCyclicSendTaskABC
44

55
VALID_INTERFACES = set(['kvaser', 'serial', 'pcan', 'socketcan_native',
6-
'socketcan_ctypes', 'socketcan', 'usb2can', 'ixxat'])
6+
'socketcan_ctypes', 'socketcan', 'usb2can', 'ixxat',
7+
'virtual'])
78

89

910
class Bus(object):

can/message.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,23 @@ def __str__(self):
7777
pass
7878

7979
return " ".join(field_strings).strip()
80+
81+
def __repr__(self):
82+
data = ["{:#02x}".format(byte) for byte in self.data]
83+
args = ["timestamp={}".format(self.timestamp),
84+
"is_remote_frame={}".format(self.is_remote_frame),
85+
"extended_id={}".format(self.id_type),
86+
"is_error_frame={}".format(self.is_error_frame),
87+
"arbitration_id={:#x}".format(self.arbitration_id),
88+
"dlc={}".format(self.dlc),
89+
"data=[{}]".format(", ".join(data))]
90+
return "can.Message({})".format(", ".join(args))
91+
92+
def __eq__(self, other):
93+
return (self.arbitration_id == other.arbitration_id and
94+
#self.timestamp == other.timestamp and
95+
self.id_type == other.id_type and
96+
self.dlc == other.dlc and
97+
self.data == other.data and
98+
self.is_remote_frame == other.is_remote_frame and
99+
self.is_error_frame == other.is_error_frame)

0 commit comments

Comments
 (0)