Skip to content

Commit c37420d

Browse files
felixdivohardbyte
authored andcommitted
Change can.Message (#413)
Lots of general tweaks and fixes to the Messages class. * use is_extended_id instead of id_type for message objects * better documentation for Message * run test on CI for logformats_test.py * added channel to docs * add example messages with channel attribute set * change logformat tests * nicer __repr__ * add __slots__, * deprecate id_type * make timestamp comparison a bit more forgiving * use extended_id in constructor * fix TestBlfFileFormat test * implemented Message._check * properly implement warning & update deprecation notes * remove undocumented setting of flags in kvaser backend * add __copy__ and __deepcopy__ * add Message.equals(), and correctly check for equality in failing tests * Remove message hash implementation * small tweak to codecov
1 parent 1110ac3 commit c37420d

27 files changed

Lines changed: 424 additions & 161 deletions

.codecov.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ coverage:
88
round: down
99
range: 50...100
1010
status:
11-
# pull-requests only
11+
project:
12+
default:
13+
# coverage may fall by <1.0% and still be considered "passing"
14+
threshold: 1.0%
1215
patch:
1316
default:
1417
# coverage may fall by <1.0% and still be considered "passing"

can/CAN.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
log = logging.getLogger('can')
2424

25-
# See #267
25+
# See #267.
2626
# Version 2.0 - 2.1: Log a Debug message
2727
# Version 2.2: Log a Warning
2828
# Version 2.3: Log an Error
2929
# Version 2.4: Remove the module
30-
log.warning('Loading python-can via the old "CAN" API is deprecated since v2.0 an will get removed in v2.4. '
30+
log.error('Loading python-can via the old "CAN" API is deprecated since v2.0 an will get removed in v2.4. '
3131
'Please use `import can` instead.')

can/broadcastmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,5 @@ def send_periodic(bus, message, period, *args, **kwargs):
154154
:return: A started task instance
155155
"""
156156
log.warning("The function `can.send_periodic` is deprecated and will " +
157-
"be removed in version 2.3. Please use `can.Bus.send_periodic` instead.")
157+
"be removed in version 3.0. Please use `can.Bus.send_periodic` instead.")
158158
return bus.send_periodic(message, period, *args, **kwargs)

can/interfaces/ixxat/canlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def send(self, msg, timeout=None):
485485
message = structures.CANMSG()
486486
message.uMsgInfo.Bits.type = constants.CAN_MSGTYPE_DATA
487487
message.uMsgInfo.Bits.rtr = 1 if msg.is_remote_frame else 0
488-
message.uMsgInfo.Bits.ext = 1 if msg.id_type else 0
488+
message.uMsgInfo.Bits.ext = 1 if msg.is_extended_id else 0
489489
message.uMsgInfo.Bits.srr = 1 if self._receive_own_messages else 0
490490
message.dwMsgId = msg.arbitration_id
491491
if msg.dlc:
@@ -545,7 +545,7 @@ def __init__(self, scheduler, msg, period, duration, resolution):
545545
self._msg.wCycleTime = int(round(period * resolution))
546546
self._msg.dwMsgId = msg.arbitration_id
547547
self._msg.uMsgInfo.Bits.type = constants.CAN_MSGTYPE_DATA
548-
self._msg.uMsgInfo.Bits.ext = 1 if msg.id_type else 0
548+
self._msg.uMsgInfo.Bits.ext = 1 if msg.is_extended_id else 0
549549
self._msg.uMsgInfo.Bits.rtr = 1 if msg.is_remote_frame else 0
550550
self._msg.uMsgInfo.Bits.dlc = msg.dlc
551551
for i, b in enumerate(msg.data):

can/interfaces/kvaser/canlib.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,6 @@ def _recv_internal(self, timeout=None):
516516
error_state_indicator=error_state_indicator,
517517
channel=self.channel,
518518
timestamp=msg_timestamp + self._timestamp_offset)
519-
rx_msg.flags = flags
520-
rx_msg.raw_timestamp = msg_timestamp
521519
#log.debug('Got message: %s' % rx_msg)
522520
return rx_msg, self._is_filtered
523521
else:
@@ -526,7 +524,7 @@ def _recv_internal(self, timeout=None):
526524

527525
def send(self, msg, timeout=None):
528526
#log.debug("Writing a message: {}".format(msg))
529-
flags = canstat.canMSG_EXT if msg.id_type else canstat.canMSG_STD
527+
flags = canstat.canMSG_EXT if msg.is_extended_id else canstat.canMSG_STD
530528
if msg.is_remote_frame:
531529
flags |= canstat.canMSG_RTR
532530
if msg.is_error_frame:

can/interfaces/nican.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def send(self, msg, timeout=None):
263263
It does not wait for message to be ACKed currently.
264264
"""
265265
arb_id = msg.arbitration_id
266-
if msg.id_type:
266+
if msg.is_extended_id:
267267
arb_id |= NC_FL_CAN_ARBID_XTD
268268
raw_msg = TxMessageStruct(arb_id,
269269
bool(msg.is_remote_frame),

can/interfaces/pcan/pcan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def _recv_internal(self, timeout):
226226
return rx_msg, False
227227

228228
def send(self, msg, timeout=None):
229-
if msg.id_type:
229+
if msg.is_extended_id:
230230
msgType = PCAN_MESSAGE_EXTENDED
231231
else:
232232
msgType = PCAN_MESSAGE_STANDARD

can/interfaces/usb2can/usb2canInterface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def message_convert_tx(msg):
5151
if msg.is_remote_frame:
5252
messagetx.flags |= IS_REMOTE_FRAME
5353

54-
if msg.id_type:
54+
if msg.is_extended_id:
5555
messagetx.flags |= IS_ID_TYPE
5656

5757
return messagetx

can/interfaces/vector/canlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def _recv_internal(self, timeout):
319319
def send(self, msg, timeout=None):
320320
msg_id = msg.arbitration_id
321321

322-
if msg.id_type:
322+
if msg.is_extended_id:
323323
msg_id |= vxlapi.XL_CAN_EXT_MSG_ID
324324

325325
flags = 0

can/io/blf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def on_message_received(self, msg):
293293
channel += 1
294294

295295
arb_id = msg.arbitration_id
296-
if msg.id_type:
296+
if msg.is_extended_id:
297297
arb_id |= CAN_MSG_EXT
298298
flags = REMOTE_FLAG if msg.is_remote_frame else 0
299299
data = bytes(msg.data)

0 commit comments

Comments
 (0)