support multiple addresses per distributor
Stefan Schuermans

Stefan Schuermans commited on 2017-06-04 20:17:29
Showing 3 changed files, with 41 additions and 28 deletions.

... ...
@@ -68,25 +68,6 @@ class Display(object):
68 68
         for distri in self._distris.values():
69 69
           distri.send(self._socket)
70 70
 
71
-    def _proc_config_file(self, config_file):
72
-        """process config file
73
-           config_file: name of config file to read
74
-           returns True on success, False on error"""
75
-        self._msg.msg(Msg.INFO, "using config file \"%s\"" % config_file)
76
-        # process all lines in config file
77
-        okay = True
78
-        try:
79
-            with open(config_file, "r") as cfile:
80
-                lineno = 1
81
-                for line in cfile:
82
-                   if not self._proc_config_line(line, lineno):
83
-                       okay = False
84
-                   lineno += 1
85
-        except (IOError, OSError) as e:
86
-            self._msg.msg(Msg.ERR, str(e))
87
-            okay = False
88
-        return okay
89
-
90 71
     def _proc_config_distri(self, setting, value, lineno):
91 72
         """process distributor line from config file"""
92 73
         # distributor number
... ...
@@ -115,6 +96,28 @@ class Display(object):
115 96
         self._distris[distri_no] = Distributor(distri_no, outputs, pixels)
116 97
         return True
117 98
 
99
+    def _proc_config_file(self, config_file):
100
+        """process config file
101
+           config_file: name of config file to read
102
+           returns True on success, False on error"""
103
+        self._msg.msg(Msg.INFO, "using config file \"%s\"" % config_file)
104
+        # process all lines in config file
105
+        okay = True
106
+        try:
107
+            with open(config_file, "r") as cfile:
108
+                lineno = 1
109
+                for line in cfile:
110
+                   if not self._proc_config_line(line, lineno):
111
+                       okay = False
112
+                   lineno += 1
113
+        except (IOError, OSError) as e:
114
+            self._msg.msg(Msg.ERR, str(e))
115
+            okay = False
116
+        # set default address of all distributors without address
117
+        for distri in self._distris.values():
118
+            distri.def_addr()
119
+        return okay
120
+
118 121
     def _proc_config_distri_addr(self, setting, value, lineno):
119 122
         """process distributor address line from config file"""
120 123
         # distributor number
... ...
@@ -138,8 +141,8 @@ class Display(object):
138 141
                                     " in line %u of config file" %
139 142
                                     (distri_no, lineno))
140 143
              return False
141
-        # set address
142
-        self._distris[distri_no].set_addr(addr)
144
+        # add address to distributor
145
+        self._distris[distri_no].add_addr(addr)
143 146
         return True
144 147
 
145 148
     def _proc_config_line(self, line, lineno):
... ...
@@ -33,8 +33,8 @@ class Distributor(object):
33 33
         self._distri_no = distri_no
34 34
         self._outputs = outputs
35 35
         self._pixels = pixels
36
-        # default address
37
-        self._addr = ("10.70.80.%u" % distri_no, 2323)
36
+        # no address(es) yet
37
+        self._addrs = []
38 38
         # default color mapping
39 39
         self._mappings = []
40 40
         for c in range(Mapping.CHANNELS):
... ...
@@ -59,9 +59,17 @@ class Distributor(object):
59 59
         """get number of pixels per output"""
60 60
         return self._pixels
61 61
 
62
-    def set_addr(self, addr):
63
-        """set distributor address"""
64
-        self._addr = addr
62
+    def add_addr(self, addr):
63
+        """add distributor address"""
64
+        self._addrs.append(addr)
65
+
66
+    def def_addr(self):
67
+        """set distributor address to default if no address configured"""
68
+        if len(self._addrs) == 0:
69
+            high = (self._distri_no >> 8) & 0x0F
70
+            low = self._distri_no & 0xFF
71
+            addr = ("10.70.%u.%u" % (80 + high, low), 2323)
72
+            self._addrs.append(addr)
65 73
 
66 74
     def data_clear(self):
67 75
         """clear image data, i.e. set entire image to black"""
... ...
@@ -98,8 +106,10 @@ class Distributor(object):
98 106
 
99 107
     def send(self, socket):
100 108
         """send image data to actual distributor module using UDP"""
109
+        # send to each address
110
+        for addr in self._addrs:
101 111
             try:
102
-            socket.sendto(self._buffer, self._addr)
112
+                socket.sendto(self._buffer, addr)
103 113
             except:
104 114
                 pass
105 115
 
... ...
@@ -1,7 +1,7 @@
1 1
 from setuptools import setup
2 2
 
3 3
 setup(name='pyetherpix',
4
-      version='0.1',
4
+      version='0.2',
5 5
       description='python implementation of EtherPix output library',
6 6
       url='https://git.blinkenarea.org?p=pyetherpix',
7 7
       author='Stefan Schuermans',
8 8