Browse Source

changes: ?

micha 3 years ago
parent
commit
95e6265ff0
4 changed files with 135 additions and 23 deletions
  1. 2 2
      ArtNetProcessor.py
  2. 22 21
      send.py
  3. 106 0
      send2.py
  4. 5 0
      start_IN.sh

+ 2 - 2
ArtNetProcessor.py

@@ -102,7 +102,7 @@ class Window():
         self.cmd = []
         if options.sendto:
             self.mode="ltp"
-            #self.mode="stop"
+            self.mode="stop"
         else:
             self.mode="dmx"
         self.sel_host=Pager()
@@ -112,7 +112,7 @@ class Window():
         self.sel_mode=Pager()
         self.sel_mode.wrap=1
         if options.sendto:
-            self.sel_mode.data = ["ltp","dmx","mtx","main"] # mtx = matrix
+            self.sel_mode.data = ["stop","ltp","dmx","mtx","main"] # mtx = matrix
         else:
             self.sel_mode.data = ["dmx","main"] # mtx = matrix
         self.sel_mode.maxindex = len( self.sel_mode.data )-1

+ 22 - 21
send.py

@@ -69,37 +69,38 @@ class ArtNetNode():
             self.s.sendto(c, (self.sendto, port)) # default 6454
         else:
             self.s.sendto(c, (self.sendto, self.portto)) # default 6454
+        print(self.v)
+        time.sleep(0.0001)
         return c
     def _test_frame(self):
-        if self.test_stamp+0.1 > time.time():
-            return 0
-        self.test_stamp = time.time()
-        dmx = [0]*512
-        dmx[243-1] = self.v
-        self.dmx = dmx
-        self.next()
-        self.send(dmx)
-        #print( [x] )
-        if self.v >= 255:
-            self.d=0
-        elif self.v <=0:
-            self.d=1
-
-        if self.d:
-            self.v+=1
-        else:
-            self.v-=1
+        if self.test_stamp+(.01) < time.time():
+            self.test_stamp = time.time()
+            dmx = [0]*512
+            dmx[201-1] = self.v
+            self.dmx = dmx
+            if self.v >= 255:
+                self.d=0
+            elif self.v <=0:
+                self.d=1
 
+            if self.d:
+                self.v+=1
+            else:
+                self.v-=1
+            #print( self.v)
         #time.sleep(1/30.)
     def next(self):
-        if self.stamp + (1/60) <= time.time():
+        if self.stamp + (1/30.) < time.time():
             self.send()
 
 def artnet_test():
     #artnet = ArtNetNode(to="127.0.0.1",port=6555,univ=12)
-    artnet = ArtNetNode(to="127.0.0.1",port=6555,univ=0)
+    #artnet = ArtNetNode(to="127.0.0.1",port=6555,univ=0)
+    artnet = ArtNetNode(to="10.10.10.255",univ=0)
+    #artnet = ArtNetNode(to="10.10.10.255",univ=1)
     while 1:
         artnet._test_frame()
-        time.sleep(0.001)
+        artnet.next()
+        time.sleep(0.01)
 
 artnet_test()

+ 106 - 0
send2.py

@@ -0,0 +1,106 @@
+
+import time
+import socket
+import struct
+import random
+
+class ArtNetNode():
+    """simple Object to generate ArtNet Network packages 
+       works in Python2 and Python3  2021-12-05
+
+    """
+    def __init__(self, to="10.10.10.255",univ=7,port=6454):
+        try: 
+            univ = int(univ)
+        except:
+            print("errror univ",univ ,"is not int ... set to 7")
+            univ = 7
+        self.univ=univ
+        self.sendto = to
+        self.portto = port
+        print(__name__,"bind",to,port,univ)
+        self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+        self.s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+        self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+        self.stamp = time.time()
+        self.test_stamp = time.time()
+        self.dmx=[33]*512
+        self.v=0
+        self.d=1
+
+    def head(self):
+        self._header = []
+        self._header.append(b"Art-Net\x00")            # Name, 7byte + 0x00
+        self._header.append(struct.pack('<H', 0x5000)) # OpCode ArtDMX -> 0x5000, Low Byte first
+        self._header.append(struct.pack('>H', 14))     # Protocol Version 14, High Byte first
+        self._header.append(b"\x00")                   # Order -> nope -> 0x00
+        self._header.append(struct.pack('B',1))        # Eternity Port
+
+        # Address
+        #if 0 <= universe <= 15 and 0 <= net <= 127 and 0 <= subnet <= 15
+        net, subnet, universe = (0,0,self.univ) #address
+        self._header.append(struct.pack('<H', net << 8 | subnet << 4 | universe))
+
+        self._header = b"".join(self._header)
+
+    def send(self,dmx=None,port=''):
+        if dmx is None:
+            dmx = self.dmx
+        else:
+            self.dmx = dmx
+        self.head()
+        c=[self._header]
+
+        c.append( struct.pack('>H', len(dmx) ) )
+        #print([c])
+
+        dmx_count = 0
+        for v in dmx:
+            if type(v) is not int:
+                v=0
+            elif v > 255: # max dmx value 255
+                v = 255
+            elif v < 0: # min dmx value 0
+                v = 0
+            dmx_count += 1
+            c.append(struct.pack("B",v))
+        c = b"".join(c)
+        if port:
+            self.s.sendto(c, (self.sendto, port)) # default 6454
+        else:
+            self.s.sendto(c, (self.sendto, self.portto)) # default 6454
+        print(self.v)
+        time.sleep(0.0001)
+        return c
+    def _test_frame(self):
+        if self.test_stamp+(.0010351) < time.time():
+            self.test_stamp = time.time()
+            dmx = [0]*512
+            dmx[205-1] = self.v
+            self.dmx = dmx
+            if self.v >= 255:
+                self.d=0
+            elif self.v <=0:
+                self.d=1
+
+            if self.d:
+                self.v+=3
+            else:
+                self.v-=3
+            #print( self.v)
+        #time.sleep(1/30.)
+    def next(self):
+        if self.stamp + (1/30.) < time.time():
+            self.send()
+
+def artnet_test():
+    #artnet = ArtNetNode(to="127.0.0.1",port=6555,univ=12)
+    #artnet = ArtNetNode(to="127.0.0.1",port=6555,univ=0)
+    artnet = ArtNetNode(to="10.10.10.255",univ=0)
+    #artnet = ArtNetNode(to="10.10.10.255",univ=1)
+    while 1:
+        artnet._test_frame()
+        artnet.next()
+        time.sleep(0.01)
+
+artnet_test()

+ 5 - 0
start_IN.sh

@@ -0,0 +1,5 @@
+#sudo /home/pi/ASP/netns.sh 04
+#sudo sh /home/user/ASP/netns.sh 04 
+netns=$(ip netns identify $$)
+#ip netns exec blue204 "su - user bash; cd ASP; 
+python3 ArtNetProcessor.py -s 10.10.10.255 -r 2.0.0.14 --inmap 1 netns=$netns