Skip to content

Commit aa292a6

Browse files
committed
Migrate SDO client to another thread which allow reuse of existing code in async use
* Remove duplicated async code in SdoClient * Implemented to thread in aupload() and adownload() * Removed async callbacks * Temporary fix issue with truncated SDO uploads * Temporary fix iterator on SdoArray
1 parent fe08d89 commit aa292a6

File tree

5 files changed

+20
-1313
lines changed

5 files changed

+20
-1313
lines changed

canopen/node/remote.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,24 @@ def associate_network(self, network: Network):
5757
self.tpdo.network = network
5858
self.rpdo.network = network
5959
self.nmt.network = network
60+
for sdo in self.sdo_channels:
61+
network.subscribe(sdo.tx_cobid, sdo.on_response)
6062
if network.is_async():
61-
for sdo in self.sdo_channels:
62-
network.subscribe(sdo.tx_cobid, sdo.aon_response)
6363
network.subscribe(0x700 + self.id, self.nmt.aon_heartbeat)
6464
network.subscribe(0x80 + self.id, self.emcy.aon_emcy)
6565
else:
66-
for sdo in self.sdo_channels:
67-
network.subscribe(sdo.tx_cobid, sdo.on_response)
6866
network.subscribe(0x700 + self.id, self.nmt.on_heartbeat)
6967
network.subscribe(0x80 + self.id, self.emcy.on_emcy)
7068
network.subscribe(0, self.nmt.on_command)
7169

7270
def remove_network(self):
7371
network = self.network
72+
for sdo in self.sdo_channels:
73+
network.unsubscribe(sdo.tx_cobid, sdo.on_response)
7474
if network.is_async():
75-
for sdo in self.sdo_channels:
76-
network.unsubscribe(sdo.tx_cobid, sdo.aon_response)
7775
network.unsubscribe(0x700 + self.id, self.nmt.aon_heartbeat)
7876
network.unsubscribe(0x80 + self.id, self.emcy.aon_emcy)
7977
else:
80-
for sdo in self.sdo_channels:
81-
network.unsubscribe(sdo.tx_cobid, sdo.on_response)
8278
network.unsubscribe(0x700 + self.id, self.nmt.on_heartbeat)
8379
network.unsubscribe(0x80 + self.id, self.emcy.on_emcy)
8480
network.unsubscribe(0, self.nmt.on_command)
@@ -105,10 +101,7 @@ def add_sdo(self, rx_cobid, tx_cobid):
105101
client = SdoClient(rx_cobid, tx_cobid, self.object_dictionary)
106102
self.sdo_channels.append(client)
107103
if self.network is not None:
108-
if self.network.is_async():
109-
self.network.subscribe(client.tx_cobid, client.aon_response)
110-
else:
111-
self.network.subscribe(client.tx_cobid, client.on_response)
104+
self.network.subscribe(client.tx_cobid, client.on_response)
112105
return client
113106

114107
def store(self, subindex=1):

canopen/objectdictionary/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ def __len__(self) -> int:
356356
if self.data_type in self.STRUCT_TYPES:
357357
return self.STRUCT_TYPES[self.data_type].size * 8
358358
else:
359-
return 8
359+
# FIXME: Temporary fix for trucated 24-bit integers
360+
return 64
360361

361362
@property
362363
def writable(self) -> bool:

canopen/sdo/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ def __getitem__(self, subindex: Union[int, str]) -> "SdoVariable":
150150
return SdoVariable(self.sdo_node, self.od[subindex])
151151

152152
def __iter__(self) -> Iterable[int]:
153-
return iter(self.od)
153+
return iter(range(1, len(self) + 1))
154154

155155
async def aiter(self):
156-
for i in iter(self.od):
156+
for i in range(1, await self.alen() + 1):
157157
yield i
158158

159159
def __aiter__(self):

0 commit comments

Comments
 (0)