Skip to content

Commit 0a0157d

Browse files
authored
Merge pull request #2 from christiansandberg/master
2 parents afd9f5c + e3829fc commit 0a0157d

File tree

5 files changed

+54
-26
lines changed

5 files changed

+54
-26
lines changed

canopen/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def connect(self, *args, **kwargs) -> "Network":
109109
Backend specific channel for the CAN interface.
110110
:param str bustype:
111111
Name of the interface. See
112-
`python-can manual <https://python-can.readthedocs.io/en/latest/configuration.html#interface-names>`__
112+
`python-can manual <https://python-can.readthedocs.io/en/stable/configuration.html#interface-names>`__
113113
for full list of supported interfaces.
114114
:param int bitrate:
115115
Bitrate in bit/s.

canopen/objectdictionary/eds.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def import_eds(source, node_id):
5252
else:
5353
for rate in [10, 20, 50, 125, 250, 500, 800, 1000]:
5454
baudPossible = int(
55-
eds.get("DeviceInfo", "Baudrate_%i" % rate, fallback='0'), 0)
55+
eds.get("DeviceInfo", "BaudRate_%i" % rate, fallback='0'), 0)
5656
if baudPossible != 0:
5757
od.device_information.allowed_baudrates.add(rate*1000)
5858

@@ -85,7 +85,7 @@ def import_eds(source, node_id):
8585
pass
8686

8787
if eds.has_section("DeviceComissioning"):
88-
od.bitrate = int(eds.get("DeviceComissioning", "Baudrate")) * 1000
88+
od.bitrate = int(eds.get("DeviceComissioning", "BaudRate")) * 1000
8989
od.node_id = int(eds.get("DeviceComissioning", "NodeID"), 0)
9090

9191
for section in eds.sections():
@@ -370,10 +370,10 @@ def export_record(var, eds):
370370
"EdsVersion": 4.2,
371371
}
372372

373-
file_info.setdefault("ModificationDate", defmtime.strftime("%m-%d-%Y"))
374-
file_info.setdefault("ModificationTime", defmtime.strftime("%I:%m%p"))
375-
for k, v in origFileInfo.items():
376-
file_info.setdefault(k, v)
373+
file_info.setdefault("ModificationDate", defmtime.strftime("%m-%d-%Y"))
374+
file_info.setdefault("ModificationTime", defmtime.strftime("%I:%m%p"))
375+
for k, v in origFileInfo.items():
376+
file_info.setdefault(k, v)
377377

378378
eds.add_section("FileInfo")
379379
for k, v in file_info.items():
@@ -408,13 +408,13 @@ def export_record(var, eds):
408408
for rate in od.device_information.allowed_baudrates.union(
409409
{10e3, 20e3, 50e3, 125e3, 250e3, 500e3, 800e3, 1000e3}):
410410
eds.set(
411-
"DeviceInfo", "Baudrate_%i" % (rate/1000),
411+
"DeviceInfo", "BaudRate_%i" % (rate/1000),
412412
int(rate in od.device_information.allowed_baudrates))
413413

414414
if device_commisioning and (od.bitrate or od.node_id):
415415
eds.add_section("DeviceComissioning")
416416
if od.bitrate:
417-
eds.set("DeviceComissioning", "Baudrate", int(od.bitrate / 1000))
417+
eds.set("DeviceComissioning", "BaudRate", int(od.bitrate / 1000))
418418
if od.node_id:
419419
eds.set("DeviceComissioning", "NodeID", int(od.node_id))
420420

canopen/sdo/client.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,8 @@ def __init__(self, sdo_client, index, subindex=0, size=None, request_crc_support
10581058
self._seqno = 0
10591059
self._crc = sdo_client.crc_cls()
10601060
self._last_bytes_sent = 0
1061+
self._current_block = []
1062+
self._retransmitting = False
10611063
command = REQUEST_BLOCK_DOWNLOAD | INITIATE_BLOCK_TRANSFER
10621064
if request_crc_support:
10631065
command |= CRC_SUPPORTED
@@ -1138,7 +1140,10 @@ def send(self, b, end=False):
11381140
request[1:len(b) + 1] = b
11391141
self.sdo_client.send_request(request)
11401142
self.pos += len(b)
1141-
if self.crc_supported:
1143+
# Add the sent data to the current block buffer
1144+
self._current_block.append(b)
1145+
# Don't calculate crc if retransmitting
1146+
if self.crc_supported and not self._retransmitting:
11421147
# Calculate CRC
11431148
self._crc.process(b)
11441149
if self._seqno >= self._blksize:
@@ -1161,14 +1166,37 @@ def _block_ack(self):
11611166
raise SdoCommunicationError("Server did not respond with a "
11621167
"block download response")
11631168
if ackseq != self._blksize:
1164-
self.sdo_client.abort(0x05040003)
1165-
raise SdoCommunicationError(
1166-
("%d of %d sequences were received. "
1167-
"Retransmission is not supported yet.") % (ackseq, self._blksize))
1169+
# Sequence error, try to retransmit
1170+
self._retransmit(ackseq, blksize)
1171+
# We should be back in sync
1172+
return
1173+
# Clear the current block buffer
1174+
self._current_block = []
11681175
logger.debug("All %d sequences were received successfully", ackseq)
11691176
logger.debug("Server requested a block size of %d", blksize)
11701177
self._blksize = blksize
11711178
self._seqno = 0
1179+
1180+
def _retransmit(self, ackseq, blksize):
1181+
"""Retransmit the failed block"""
1182+
logger.info(("%d of %d sequences were received. "
1183+
"Will start retransmission") % (ackseq, self._blksize))
1184+
# Sub blocks betwen ackseq and end of corrupted block need to be resent
1185+
# Get the part of the block to resend
1186+
block = self._current_block[ackseq:]
1187+
# Go back to correct position in stream
1188+
self.pos = self.pos - (len(block) * 7)
1189+
# Reset the _current_block before starting the retransmission
1190+
self._current_block = []
1191+
# Reset _seqno and update blksize
1192+
self._seqno = 0
1193+
self._blksize = blksize
1194+
# We are retransmitting
1195+
self._retransmitting = True
1196+
# Resend the block
1197+
for b in block:
1198+
self.write(b)
1199+
self._retransmitting = False
11721200

11731201
def close(self):
11741202
"""Closes the stream."""

examples/eds/e35.eds

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ ModifiedBy=Manufacturer
1313

1414
[DeviceInfo]
1515
VendorName=Manufacturer
16-
VendorNumber=001
16+
VendorNumber=101
1717
ProductName=example
1818
ProductNumber=25
1919
RevisionNumber=295
2020
OrderCode=25
21-
Baudrate_10=1
22-
Baudrate_20=1
23-
Baudrate_50=1
24-
Baudrate_125=1
25-
Baudrate_250=1
26-
Baudrate_500=1
27-
Baudrate_800=0
28-
Baudrate_1000=1
21+
BaudRate_10=1
22+
BaudRate_20=1
23+
BaudRate_50=1
24+
BaudRate_125=1
25+
BaudRate_250=1
26+
BaudRate_500=1
27+
BaudRate_800=0
28+
BaudRate_1000=1
2929
SimpleBootUpMaster=0
3030
SimpleBootUpSlave=1
3131
Granularity=8
@@ -243,7 +243,7 @@ HighLimit=0x7F
243243
ParameterValue=0x20
244244

245245
[2000sub2]
246-
ParameterName=Baudrate
246+
ParameterName=BaudRate
247247
ObjectType=0x7
248248
DataType=0x0005
249249
AccessType=rw
@@ -324,7 +324,7 @@ LowLimit=0x1
324324
HighLimit=0x7F
325325

326326
[2001sub2]
327-
ParameterName=Baudrate
327+
ParameterName=BaudRate
328328
ObjectType=0x7
329329
DataType=0x0005
330330
AccessType=rw

test/sample.eds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ LSS_Supported=0
3232
[DeviceComissioning]
3333
NodeID=2
3434
NodeName=Some name
35-
Baudrate=500
35+
BaudRate=500
3636
NetNumber=0
3737
LSS_SerialNumber=0
3838

0 commit comments

Comments
 (0)