Skip to content

Commit ee16bd4

Browse files
committed
Merge 'master' into feature-asyncio
2 parents b420035 + 8d9aa6c commit ee16bd4

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

canopen/objectdictionary/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ def __getitem__(
133133
self, index: Union[int, str]
134134
) -> Union[ODArray, ODRecord, ODVariable]:
135135
"""Get object from object dictionary by name or index."""
136-
# FIXME: See upstream #588
137136
item = self.names.get(index)
138137
if item is None:
139138
item = self.indices.get(index)
@@ -423,6 +422,12 @@ def add_bit_definition(self, name: str, bits: List[int]) -> None:
423422
"""
424423
self.bit_definitions[name] = bits
425424

425+
@property
426+
def fixed_size(self) -> bool:
427+
"""Indicate whether the amount of needed data is known in advance."""
428+
# Only for types which we parse using a structure.
429+
return self.data_type in self.STRUCT_TYPES
430+
426431
def decode_raw(self, data: bytes) -> Union[int, float, str, bytes, bytearray]:
427432
if self.data_type == VISIBLE_STRING:
428433
# Strip any trailing NUL characters from C-based systems

canopen/sdo/client.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ def truncate_data(self, index: int, subindex: int, data: bytes, size: int) -> by
142142
var = self.od.get_variable(index, subindex)
143143
if var is not None:
144144
# Found a matching variable in OD
145-
# If this is a data type (string, domain etc) the size is
146-
# unknown anyway so keep the data as is
147-
if var.data_type not in objectdictionary.DATA_TYPES:
145+
if var.fixed_size:
148146
# Get the size in bytes for this variable
149147
var_size = len(var) // 8
150148
if size is None or var_size < size:
@@ -727,7 +725,6 @@ def __init__(self, sdo_client, index, subindex=0, size=None, request_crc_support
727725
logger.debug("Server requested a block size of %d", self._blksize)
728726
self.crc_supported = bool(res_command & CRC_SUPPORTED)
729727
# Run this last, used later to determine if initialization was successful
730-
# FIXME: Upstream #590
731728
self._initialized = True
732729

733730
def write(self, b):
@@ -844,8 +841,7 @@ def close(self):
844841
if self.closed:
845842
return
846843
super(BlockDownloadStream, self).close()
847-
# FIXME: Upstream #590
848-
if not hasattr(self, "_initialized"):
844+
if not getattr(self, "_initialized", False):
849845
# Don't do finalization if initialization was not successful
850846
return
851847
if not self._done:

canopen/sdo/server.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ def init_upload(self, request):
6969

7070
data = self._node.get_data(index, subindex, check_readable=True)
7171
size = len(data)
72-
if size <= 4:
72+
if size == 0:
73+
logger.info("No content to upload for 0x%04X:%02X", index, subindex)
74+
self.abort(0x0800_0024)
75+
return
76+
elif size <= 4:
7377
logger.info("Expedited upload for 0x%04X:%02X", index, subindex)
7478
res_command |= EXPEDITED
7579
res_command |= (4 - size) << 2
@@ -124,7 +128,6 @@ def request_aborted(self, data):
124128
def block_download(self, data):
125129
# We currently don't support BLOCK DOWNLOAD
126130
# Unpack the index and subindex in order to send appropriate abort
127-
# FIXME: See upstream #590
128131
command, index, subindex = SDO_STRUCT.unpack_from(data)
129132
self._index = index
130133
self._subindex = subindex

test/test_local.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ async def test_expedited_upload_default_value_real(self):
8383
sampling_rate = self.remote_node.sdo["Sensor Sampling Rate (Hz)"].raw
8484
self.assertAlmostEqual(sampling_rate, 5.2, places=2)
8585

86+
async def test_upload_zero_length(self):
87+
if self.use_async:
88+
await self.local_node.sdo["Manufacturer device name"].aset_raw(b"")
89+
with self.assertRaises(canopen.SdoAbortedError) as error:
90+
await self.remote_node.sdo["Manufacturer device name"].aget_data()
91+
else:
92+
self.local_node.sdo["Manufacturer device name"].raw = b""
93+
with self.assertRaises(canopen.SdoAbortedError) as error:
94+
self.remote_node.sdo["Manufacturer device name"].data
95+
# Should be No data available
96+
self.assertEqual(error.exception.code, 0x0800_0024)
97+
8698
async def test_segmented_upload(self):
8799
if self.use_async:
88100
await self.local_node.sdo["Manufacturer device name"].aset_raw("Some cool device")

test/test_od.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ def test_get_item_dot(self):
249249
self.assertEqual(test_od["Test Array.Test Variable"], member1)
250250
self.assertEqual(test_od["Test Array.Test Variable 2"], member2)
251251

252-
# FIXME: See upstream #588
253252
def test_get_item_index(self):
254253
test_od = od.ObjectDictionary()
255254
array = od.ODArray("Test Array", 0x1000)

test/test_sdo.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,6 @@ async def test_unknown_od_112(self):
991991

992992
async def test_unknown_datatype32(self):
993993
"""Test an unknown datatype, but known OD, of 32 bits (4 bytes)."""
994-
self.skipTest("Datatype conditionals are not fixed yet, see #436")
995994
# Add fake entry 0x2100 to OD, using fake datatype 0xFF
996995
if 0x2100 not in self.node.object_dictionary:
997996
fake_var = ODVariable("Fake", 0x2100)
@@ -1009,7 +1008,6 @@ async def test_unknown_datatype32(self):
10091008

10101009
async def test_unknown_datatype112(self):
10111010
"""Test an unknown datatype, but known OD, of 112 bits (14 bytes)."""
1012-
self.skipTest("Datatype conditionals are not fixed yet, see #436")
10131011
# Add fake entry 0x2100 to OD, using fake datatype 0xFF
10141012
if 0x2100 not in self.node.object_dictionary:
10151013
fake_var = ODVariable("Fake", 0x2100)

0 commit comments

Comments
 (0)