Skip to content

Abort SDO server upload when the object has zero length #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion canopen/sdo/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ def init_upload(self, request):

data = self._node.get_data(index, subindex, check_readable=True)
size = len(data)
if size <= 4:
if size == 0:
logger.info("No content to upload for 0x%04X:%02X", index, subindex)
self.abort(0x0800_0024)
return
elif size <= 4:
logger.info("Expedited upload for 0x%04X:%02X", index, subindex)
res_command |= EXPEDITED
res_command |= (4 - size) << 2
Expand Down
7 changes: 7 additions & 0 deletions test/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def test_expedited_upload_default_value_real(self):
sampling_rate = self.remote_node.sdo["Sensor Sampling Rate (Hz)"].raw
self.assertAlmostEqual(sampling_rate, 5.2, places=2)

def test_upload_zero_length(self):
self.local_node.sdo["Manufacturer device name"].raw = b""
with self.assertRaises(canopen.SdoAbortedError) as error:
self.remote_node.sdo["Manufacturer device name"].data
# Should be No data available
self.assertEqual(error.exception.code, 0x0800_0024)

def test_segmented_upload(self):
self.local_node.sdo["Manufacturer device name"].raw = "Some cool device"
device_name = self.remote_node.sdo["Manufacturer device name"].data
Expand Down
Loading