From 477a8bf11f447ea690c87fe1c2a1627ee7e64e86 Mon Sep 17 00:00:00 2001
From: Martin Teichmann <martin.teichmann@xfel.eu>
Date: Mon, 18 Mar 2024 07:35:31 +0000
Subject: [PATCH] allow for writing of dedicated PDOs

on some terminals, the PDO can be configured. This
allows for that. It is not perfect yet as we do not properly
overwrite existing PDOs.
---
 ebpfcat/ebpfcat.py   | 13 +++++++++++++
 ebpfcat/terminals.py |  6 +++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/ebpfcat/ebpfcat.py b/ebpfcat/ebpfcat.py
index 6f8f20e..30291c4 100644
--- a/ebpfcat/ebpfcat.py
+++ b/ebpfcat/ebpfcat.py
@@ -255,6 +255,8 @@ class EBPFTerminal(Terminal):
     compatibility = None
     position_offset = {SyncManager.OUT: 0, SyncManager.IN: 0}
     use_fmmu = True
+    out_pdos = None
+    in_pdos = None
 
     async def apply_eeprom(self):
         await super().apply_eeprom()
@@ -263,6 +265,10 @@ class EBPFTerminal(Terminal):
             raise EtherCatError(
                 f"Incompatible Terminal: {self.vendorId}:{self.productCode}")
         await self.to_operational(MachineState.PRE_OPERATIONAL)
+        if self.out_pdos is not None:
+            await self.write_pdos(0x1c12, self.out_pdos)
+        if self.in_pdos is not None:
+            await self.write_pdos(0x1c13, self.in_pdos)
         self.pdos = {}
         outbits, inbits = await self.parse_pdos()
         self.pdo_out_sz = int((outbits + 7) // 8)
@@ -271,6 +277,13 @@ class EBPFTerminal(Terminal):
         assert not self.pdo_in_sz or self.pdo_in_off
         await self.write_pdo_sm()
 
+    async def write_pdos(self, index, values):
+        await self.sdo_write(pack('B', 0), index, 0)
+        for i, v in enumerate(values, 1):
+            await self.sdo_write(pack('<H', v), index, i)
+        await self.sdo_write(pack('<H', 0), index, i + 1)
+        await self.sdo_write(pack('B', len(values)), index, 0)
+
     def allocate(self, packet, readwrite):
         """allocate space in packet for the pdos of this terminal
 
diff --git a/ebpfcat/terminals.py b/ebpfcat/terminals.py
index 35a8046..a4db465 100644
--- a/ebpfcat/terminals.py
+++ b/ebpfcat/terminals.py
@@ -159,13 +159,17 @@ class EL6022(EBPFTerminal):
 
 class EL7041(EBPFTerminal):
     compatibility = {(2, 461451346), (2, 461455442), (2, 460795986)}
+    out_pdos = [0x1600, 0x1602, 0x1604]
+    in_pdos = [0x1A00, 0x1A03, 0x1A07]
     velocity = ProcessDesc(0x7010, 0x21, "h")
     enable = ProcessDesc(0x7010, 1)
+    reset = ProcessDesc(0x7010, 2)
     reduced_current = ProcessDesc(0x7010, 3)
     status = ProcessDesc(0x6010, 1, "H")
+    error = ProcessDesc(0x6010, 4)
     low_switch = ProcessDesc(0x6010, 0xc)
     high_switch = ProcessDesc(0x6010, 0xd)
-
+    stepcounter = ProcessDesc(0x6010, 0x14)
 
 
 class EL7332(EBPFTerminal):
-- 
GitLab