From 2360f31814b5bdc05d822bfffdb42211ae5479f4 Mon Sep 17 00:00:00 2001
From: Martin Teichmann <martin.teichmann@xfel.eu>
Date: Thu, 7 Sep 2023 11:49:58 +0200
Subject: [PATCH] ethercat object doesn't need to know its terminals

especially if we want to assign terminals dynamically, we cannot assing
terminals to loops at creation time.
---
 ebpfcat/ebpfcat.py  | 6 +++---
 ebpfcat/ethercat.py | 2 ++
 ebpfcat/scripts.py  | 6 ++----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/ebpfcat/ebpfcat.py b/ebpfcat/ebpfcat.py
index f5d1ac3..92d246f 100644
--- a/ebpfcat/ebpfcat.py
+++ b/ebpfcat/ebpfcat.py
@@ -342,15 +342,15 @@ class EtherCatBase:
                        for (i, t) in enumerate(self.terminals)])
 
 
-class SimpleEtherCat(EtherCatBase, EtherCat):
+class SimpleEtherCat(EtherCat):
     pass
 
 
 class FastEtherCat(SimpleEtherCat):
     MAX_PROGS = 64
 
-    def __init__(self, network, terminals):
-        super().__init__(network, terminals)
+    def __init__(self, network):
+        super().__init__(network)
         self.programs = create_map(MapType.PROG_ARRAY, 4, 4, self.MAX_PROGS)
         self.sync_groups = {}
 
diff --git a/ebpfcat/ethercat.py b/ebpfcat/ethercat.py
index b875f74..1903252 100644
--- a/ebpfcat/ethercat.py
+++ b/ebpfcat/ethercat.py
@@ -413,6 +413,8 @@ class EtherCat(Protocol):
 
 class Terminal:
     """Represent one terminal ("slave") in the loop"""
+    def __init__(self, ethercat):
+        self.ec = ethercat
 
     async def initialize(self, relative, absolute):
         """Initialize the terminal
diff --git a/ebpfcat/scripts.py b/ebpfcat/scripts.py
index 0605b45..035a999 100644
--- a/ebpfcat/scripts.py
+++ b/ebpfcat/scripts.py
@@ -52,8 +52,7 @@ async def info():
                                for i, t in zip(terminals, terms)))
     else:
         free = await ec.find_free_address()
-        term = Terminal()
-        term.ec = ec
+        term = Terminal(ec)
         await term.initialize(-args.terminal, free)
         terms = [term]
 
@@ -128,8 +127,7 @@ async def eeprom():
         await ec.roundtrip(ECCmd.FPRW, 7, 0x10, "H", 0)
         terminals = [args.terminal]
 
-    t = Terminal()
-    t.ec = ec
+    t = Terminal(ec)
     await t.initialize(-args.terminal, 7)
 
     if args.read or args.check is not None:
-- 
GitLab