2020-09-19 12:28:56 +00:00
|
|
|
#!/usr/bin/python3
|
2019-01-16 00:50:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- mode: Python -*-
|
2018-12-13 11:05:32 +00:00
|
|
|
'''
|
2020-09-19 12:28:56 +00:00
|
|
|
LJ Laser Server v0.8.2
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-20 19:46:53 +00:00
|
|
|
Inspiration for a future WebUI icon menu :
|
2019-08-06 01:08:54 +00:00
|
|
|
https://codepen.io/AlbertFeynman/pen/mjXeMV
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
Laser server + webUI servers (ws + OSC)
|
|
|
|
|
|
|
|
- get point list to draw : /pl/lasernumber
|
|
|
|
- for report /lstt/lasernumber /lack/lasernumber /cap/lasernumber
|
2020-09-19 12:28:56 +00:00
|
|
|
- a nice ws debug tool : websocat
|
2019-08-06 01:08:54 +00:00
|
|
|
- a "plugin" is a generator that send points to LJ. Plugins if they have an open OSC port can be checked and restart if in the same computer.
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2019-03-10 22:06:04 +00:00
|
|
|
|
|
|
|
All used ports:
|
|
|
|
|
|
|
|
8002 OSC incoming
|
2020-09-19 12:28:56 +00:00
|
|
|
9001 Websocket communication with WebGUI
|
2019-08-06 01:08:54 +00:00
|
|
|
Plugins OSC Ports (see LJ.conf)
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
'''
|
2020-09-19 12:28:56 +00:00
|
|
|
#import pdb
|
2019-02-26 10:10:57 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
from libs3 import log
|
|
|
|
print("")
|
|
|
|
print("")
|
|
|
|
log.infog("LJ Laser Server")
|
|
|
|
log.infog("v0.8.2")
|
|
|
|
print("")
|
|
|
|
print("-h will display help")
|
|
|
|
print("")
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2019-08-06 01:08:54 +00:00
|
|
|
import redis
|
2020-09-19 12:28:56 +00:00
|
|
|
import os
|
|
|
|
ljpath = r'%s' % os.getcwd().replace('\\','/')
|
|
|
|
import sys
|
|
|
|
|
|
|
|
#sys.path.append('libs3/')
|
|
|
|
from libs3 import gstt, settings
|
2020-10-10 17:29:07 +00:00
|
|
|
gstt.ljpath = ljpath
|
2020-09-19 12:28:56 +00:00
|
|
|
|
|
|
|
log.info("Reading " + gstt.ConfigName + " setup file...")
|
2018-12-13 11:05:32 +00:00
|
|
|
settings.Read()
|
|
|
|
|
2019-08-06 01:08:54 +00:00
|
|
|
# Arguments may alter .conf file so import settings first then cli
|
2020-09-19 12:28:56 +00:00
|
|
|
from libs3 import cli
|
2018-12-14 11:34:41 +00:00
|
|
|
settings.Write()
|
2019-08-06 01:08:54 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
from multiprocessing import Process, set_start_method
|
2018-12-13 11:05:32 +00:00
|
|
|
import random, ast
|
2020-09-19 12:28:56 +00:00
|
|
|
from libs3 import plugins
|
2020-10-10 17:29:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
#from libs3 import lasytracer as tracer
|
2020-09-19 12:28:56 +00:00
|
|
|
from libs3 import tracer3 as tracer
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-10-10 17:29:07 +00:00
|
|
|
from libs3 import homographyp, commands, font1
|
|
|
|
#import subprocess
|
2019-03-10 22:06:04 +00:00
|
|
|
import os
|
2019-08-06 01:08:54 +00:00
|
|
|
#import midi
|
2020-09-19 12:28:56 +00:00
|
|
|
from libs3 import OSC3
|
2018-12-13 11:05:32 +00:00
|
|
|
from websocket_server import WebsocketServer
|
|
|
|
#import socket
|
2020-09-19 12:28:56 +00:00
|
|
|
import types, _thread, time
|
|
|
|
|
2019-08-06 01:08:54 +00:00
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
r = redis.StrictRedis(host=gstt.LjayServerIP , port=6379, db=0)
|
2020-09-19 12:28:56 +00:00
|
|
|
# r = redis.StrictRedis(host=gstt.LjayServerIP , port=6379, db=0, password='-+F816Y+-')
|
2018-12-15 19:03:32 +00:00
|
|
|
args =[0,0]
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2018-12-18 01:45:23 +00:00
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
def dac_process(number, pl):
|
2020-09-19 12:28:56 +00:00
|
|
|
|
|
|
|
import sys
|
|
|
|
from libs3 import gstt
|
|
|
|
|
|
|
|
print("Starting dac process", number)
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
while True:
|
|
|
|
try:
|
2018-12-21 16:23:43 +00:00
|
|
|
d = tracer.DAC(number,pl)
|
2018-12-13 11:05:32 +00:00
|
|
|
d.play_stream()
|
2020-09-19 12:28:56 +00:00
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
except Exception as e:
|
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
import sys
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
if gstt.debug > 0:
|
|
|
|
log.err('\n---------------------')
|
|
|
|
log.err('Exception: %s' % e)
|
|
|
|
log.err('- - - - - - - - - - -')
|
2018-12-13 11:05:32 +00:00
|
|
|
traceback.print_tb(sys.exc_info()[2])
|
2020-09-19 12:28:56 +00:00
|
|
|
print("\n")
|
2018-12-13 11:05:32 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
2020-09-19 12:28:56 +00:00
|
|
|
# Servers init variables
|
2018-12-13 11:05:32 +00:00
|
|
|
#
|
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
print("Start Scene number :",gstt.SceneNumber)
|
|
|
|
|
|
|
|
print("WebUI connect to :", gstt.wwwIP)
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
serverIP = gstt.LjayServerIP
|
2020-09-19 12:28:56 +00:00
|
|
|
print("Redis IP :", serverIP)
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
oscserverIP = gstt.oscIPin
|
2020-09-19 12:28:56 +00:00
|
|
|
print("OSCserver IP :", oscserverIP)
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
nozoscIP = gstt.nozoscip
|
2020-09-19 12:28:56 +00:00
|
|
|
print("Nozosc IP :", nozoscIP)
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
debug = gstt.debug
|
2020-09-19 12:28:56 +00:00
|
|
|
print("Debug :", debug)
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Websocket listening port
|
|
|
|
wsPORT = 9001
|
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
# oscserver
|
2019-01-16 00:50:24 +00:00
|
|
|
# OSC Server : accept OSC message on port 8002
|
2018-12-15 19:03:32 +00:00
|
|
|
#oscIPin = "192.168.1.10"s
|
2019-03-29 14:13:25 +00:00
|
|
|
oscserverIPin = serverIP
|
2019-03-20 16:33:09 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
print("oscserverIPin", oscserverIPin)
|
2019-03-29 14:13:25 +00:00
|
|
|
oscserverPORTin = 8002
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
# OSC Client : to send OSC message to an IP port 8001
|
2019-03-29 14:13:25 +00:00
|
|
|
oscserverIPout = oscserverIP
|
|
|
|
oscserverPORTout = 8001
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
# Nozoid OSC Client : to send OSC message to Nozoid inport 8003
|
2018-12-13 11:05:32 +00:00
|
|
|
NozoscIPout = nozoscIP
|
2019-03-10 22:06:04 +00:00
|
|
|
NozoscPORTout = plugins.Port("nozoid")
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2018-12-15 19:03:32 +00:00
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
# Planetarium OSC Client : to send OSC message to planetarium inport 8005
|
2019-02-26 10:10:57 +00:00
|
|
|
planetIPout = nozoscIP
|
2019-03-10 22:06:04 +00:00
|
|
|
planetPORTout = plugins.Port("planet")
|
2019-02-26 10:10:57 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
|
|
|
|
import socket
|
2019-02-26 10:10:57 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
#retry = 1
|
|
|
|
#delay = 1
|
2019-03-29 14:13:25 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# OSC
|
|
|
|
#
|
|
|
|
|
|
|
|
oscserver = OSC3.OSCServer( (oscserverIPin, oscserverPORTin) )
|
2018-12-13 11:05:32 +00:00
|
|
|
oscserver.timeout = 0
|
|
|
|
OSCRunning = True
|
|
|
|
|
|
|
|
|
|
|
|
def handle_timeout(self):
|
|
|
|
self.timed_out = True
|
|
|
|
|
|
|
|
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
|
|
|
|
|
2019-03-10 22:06:04 +00:00
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
# OSC default path handler : send incoming OSC message to UI via websocket 9001
|
2018-12-13 11:05:32 +00:00
|
|
|
def handler(path, tags, args, source):
|
|
|
|
|
|
|
|
oscpath = path.split("/")
|
2019-08-06 01:08:54 +00:00
|
|
|
if gstt.debug > 0:
|
2020-09-19 12:28:56 +00:00
|
|
|
print("")
|
|
|
|
print("OSC handler in main said : path", path," oscpath ", oscpath," args", args)
|
2019-08-06 01:08:54 +00:00
|
|
|
|
|
|
|
if oscpath[1] != "pong":
|
|
|
|
sendWSall(path + " " + str(args[0]))
|
2018-12-21 16:23:43 +00:00
|
|
|
commands.handler(oscpath,args)
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
# RAW OSC Frame available ?
|
|
|
|
def osc_frame():
|
2018-12-18 01:45:23 +00:00
|
|
|
#print 'oscframe'
|
2018-12-13 11:05:32 +00:00
|
|
|
# clear timed_out flag
|
|
|
|
oscserver.timed_out = False
|
|
|
|
# handle all pending requests then return
|
|
|
|
while not oscserver.timed_out:
|
|
|
|
oscserver.handle_request()
|
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
def PingAll():
|
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
if gstt.debug > 0:
|
|
|
|
print("Pinging all plugins...")
|
|
|
|
|
|
|
|
for plugin in list(gstt.plugins.keys()):
|
|
|
|
if gstt.debug > 0:
|
|
|
|
print("pinging", plugin)
|
2019-08-06 01:08:54 +00:00
|
|
|
#sendWSall("/"+ plugin + "/start 0")
|
|
|
|
plugins.Ping(plugin)
|
2019-03-29 14:13:25 +00:00
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
|
2019-01-16 00:50:24 +00:00
|
|
|
# OSC server Thread : handler, dacs reports and simulator points sender to UI.
|
2018-12-13 11:05:32 +00:00
|
|
|
def osc_thread():
|
|
|
|
|
2019-08-06 01:08:54 +00:00
|
|
|
#while True:
|
2018-12-13 11:05:32 +00:00
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
|
2018-12-31 02:41:02 +00:00
|
|
|
time.sleep(0.1)
|
2018-12-13 11:05:32 +00:00
|
|
|
osc_frame()
|
2018-12-15 19:03:32 +00:00
|
|
|
for laserid in range(0,gstt.LaserNumber): # Laser not used -> led is not lit
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
lstate = {'0': 'IDLE', '1': 'PREPARE', '2': "PLAYING", '64': "NOCONNECTION ?" }
|
|
|
|
lstt = r.get('/lstt/'+ str(laserid)).decode('ascii')
|
|
|
|
#print ("laserid", laserid,"lstt",lstt, type(lstt))
|
|
|
|
if gstt.debug >1:
|
|
|
|
print("DAC", laserid, "is in (lstt) :", lstt , lstate[str(lstt)])
|
|
|
|
if lstt == "0": # Dac IDLE state(0) -> led is blue (3)
|
2018-12-13 11:05:32 +00:00
|
|
|
sendWSall("/lstt/" + str(laserid) + " 3")
|
2020-09-19 12:28:56 +00:00
|
|
|
|
|
|
|
if lstt == "1": # Dac PREPARE state (1) -> led is cyan (2)
|
2018-12-13 11:05:32 +00:00
|
|
|
sendWSall("/lstt/" + str(laserid) + " 2")
|
2020-09-19 12:28:56 +00:00
|
|
|
|
|
|
|
if lstt == "2": # Dac PLAYING (2) -> led is green (1)
|
2018-12-13 11:05:32 +00:00
|
|
|
sendWSall("/lstt/" + str(laserid) + " 1")
|
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
|
|
|
|
ackstate = {'61': 'ACK', '46': 'FULL', '49': "INVALID", '21': 'STOP', '64': "NOCONNECTION ?", '35': "NOCONNECTION ?" , '97': 'ACK', '70': 'FULL', '73': "INVALID", '33': 'STOP', '100': "NOCONNECTION", '48': "NOCONNECTION", 'a': 'ACK', 'F': 'FULL', 'I': "INVALID", '!': 'STOP', 'd': "NOCONNECTION", '0': "NOCONNECTION"}
|
|
|
|
lack= r.get('/lack/'+str(laserid)).decode('ascii')
|
|
|
|
|
2019-02-26 10:10:57 +00:00
|
|
|
if gstt.debug >1:
|
2020-09-19 12:28:56 +00:00
|
|
|
print("DAC", laserid, "answered (lack):", lack, chr(int(lack)), ackstate[str(lack)])
|
|
|
|
|
|
|
|
if chr(int(lack)) == 'a': # Dac sent ACK ("a") -> led is green (1)
|
2018-12-13 11:05:32 +00:00
|
|
|
sendWSall("/lack/" + str(laserid) +" 1")
|
2020-09-19 12:28:56 +00:00
|
|
|
|
|
|
|
if chr(int(lack)) == 'F': # Dac sent FULL ("F") -> led is orange (5)
|
2018-12-13 11:05:32 +00:00
|
|
|
sendWSall("/lack/" + str(laserid) +" 5")
|
2020-09-19 12:28:56 +00:00
|
|
|
|
|
|
|
if chr(int(lack)) == 'I': # Dac sent INVALID ("I") -> led is yellow (4)
|
2018-12-13 11:05:32 +00:00
|
|
|
sendWSall("/lack/" + str(laserid)+" 4")
|
|
|
|
#print lack
|
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
if lack == "64" or lack =="35": # no connection to dac -> leds are red (6)
|
|
|
|
sendWSall("/lack/" + str(laserid) + " 6")
|
|
|
|
sendWSall("/lstt/" + str(laserid) + " 6")
|
2018-12-13 11:05:32 +00:00
|
|
|
#sendWSall("/lstt/" + str(laserid) + " 0")
|
2020-09-19 12:28:56 +00:00
|
|
|
sendWSall("/points/" + str(laserid) + " 6")
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
# last number of points sent to etherdream buffer
|
2020-09-19 12:28:56 +00:00
|
|
|
sendWSall("/points/" + str(laserid) + " " + str(r.get('/cap/'+str(laserid)).decode('ascii')))
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-30 21:40:39 +00:00
|
|
|
#print("Sending simu frame from",'/pl/'+str(gstt.SceneNumber)+'/'+str(gstt.Laser))
|
|
|
|
#print(r.get('/pl/'+str(gstt.SceneNumber)+'/'+str(gstt.Laser)))
|
2020-10-10 17:29:07 +00:00
|
|
|
sendWSall("/simul" +" "+ str(r.get('/po/'+str(gstt.SceneNumber)+'/'+str(gstt.Laser)).decode('ascii')))
|
|
|
|
if random.randint(0,100)>95:
|
|
|
|
plugins.sendbroadcast()
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
import sys, traceback
|
2020-10-10 17:29:07 +00:00
|
|
|
print('\n--------------------------')
|
|
|
|
print('OSC Thread Exception: %s' % e)
|
|
|
|
print('- - - - - - - - - - - - - - ')
|
2018-12-13 11:05:32 +00:00
|
|
|
traceback.print_tb(sys.exc_info()[2])
|
2020-09-19 12:28:56 +00:00
|
|
|
print("\n")
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Websocket part
|
|
|
|
#
|
|
|
|
|
|
|
|
# Called for every WS client connecting (after handshake)
|
2019-03-10 22:06:04 +00:00
|
|
|
def new_client(client, wserver):
|
2018-12-15 19:03:32 +00:00
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
print("New WS client connected and was given id %d" % client['id'])
|
2020-09-19 12:28:56 +00:00
|
|
|
sendWSall("/status Hello " + str(client['id']))
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2018-12-14 11:34:41 +00:00
|
|
|
for laserid in range(0,gstt.LaserNumber):
|
2019-08-06 01:08:54 +00:00
|
|
|
|
2018-12-14 11:34:41 +00:00
|
|
|
sendWSall("/ip/" + str(laserid) + " " + str(gstt.lasersIPS[laserid]))
|
|
|
|
sendWSall("/kpps/" + str(laserid)+ " " + str(gstt.kpps[laserid]))
|
2020-09-19 12:28:56 +00:00
|
|
|
#sendWSall("/laser"+str(laserid)+"/start 1")
|
|
|
|
sendWSall("/laser "+str(laserid))
|
|
|
|
#print("/laser "+str(laserid))
|
|
|
|
sendWSall("/lack/" + str(laserid) + " 6")
|
|
|
|
#print("/lack/" + str(laserid) + " 6")
|
|
|
|
sendWSall("/lstt/" + str(laserid) + " 6")
|
|
|
|
#print("/lstt/" + str(laserid) + " 6")
|
|
|
|
sendWSall("/points/" + str(laserid) + " 0")
|
|
|
|
#print("/points/" + str(laserid) + " 0")
|
2018-12-14 11:34:41 +00:00
|
|
|
|
|
|
|
if gstt.swapX[laserid] == 1:
|
2018-12-15 19:03:32 +00:00
|
|
|
sendWSall("/swap/X/" + str(laserid)+ " 1")
|
2018-12-14 11:34:41 +00:00
|
|
|
else:
|
2018-12-15 19:03:32 +00:00
|
|
|
sendWSall("/swap/X/" + str(laserid)+ " 0")
|
2018-12-14 11:34:41 +00:00
|
|
|
|
|
|
|
if gstt.swapY[laserid] == 1:
|
2018-12-15 19:03:32 +00:00
|
|
|
sendWSall("/swap/Y/" + str(laserid)+ " 1")
|
2018-12-14 11:34:41 +00:00
|
|
|
else:
|
2018-12-15 19:03:32 +00:00
|
|
|
sendWSall("/swap/Y/" + str(laserid)+ " 0")
|
2018-12-14 11:34:41 +00:00
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
# Called for every WS client disconnecting
|
2019-03-10 22:06:04 +00:00
|
|
|
def client_left(client, wserver):
|
2018-12-13 11:05:32 +00:00
|
|
|
print("WS Client(%d) disconnected" % client['id'])
|
|
|
|
|
|
|
|
|
2019-03-10 22:06:04 +00:00
|
|
|
# Called for each WS received message.
|
|
|
|
def message_received(client, wserver, message):
|
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
#if len(message) > 200:
|
|
|
|
# message = message[:200]+'..'
|
2018-12-15 19:03:32 +00:00
|
|
|
|
2019-02-26 10:10:57 +00:00
|
|
|
#if gstt.debug >0:
|
|
|
|
# print ("")
|
|
|
|
# print("WS Client(%d) said: %s" % (client['id'], message))
|
2018-12-15 19:03:32 +00:00
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
oscpath = message.split(" ")
|
2020-09-19 12:28:56 +00:00
|
|
|
#print "WS Client", client['id'], "said :", message, "splitted in an oscpath :", oscpath
|
2019-03-29 14:13:25 +00:00
|
|
|
if gstt.debug > 0:
|
2020-09-19 12:28:56 +00:00
|
|
|
print("WS Client", client['id'], "said :", message, "splitted in an oscpath :", oscpath)
|
2019-08-06 01:08:54 +00:00
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
PingAll()
|
|
|
|
message4plugin = False
|
2019-03-17 03:19:57 +00:00
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
# WS received Message is for a plugin ?
|
2019-03-17 03:19:57 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
for plugin in list(gstt.plugins.keys()):
|
2019-03-29 14:13:25 +00:00
|
|
|
|
|
|
|
if oscpath[0].find(plugin) != -1:
|
|
|
|
|
|
|
|
message4plugin = True
|
2020-09-19 12:28:56 +00:00
|
|
|
#print(oscpath)
|
|
|
|
if plugins.Send(plugin, oscpath):
|
|
|
|
print("plugins sent incoming WS correctly to", plugin)
|
2019-08-06 01:08:54 +00:00
|
|
|
else:
|
2020-09-19 12:28:56 +00:00
|
|
|
print("plugins detected", plugin, "offline.")
|
2019-02-26 10:10:57 +00:00
|
|
|
|
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
# WS received message is an LJ command
|
2019-03-17 03:19:57 +00:00
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
if message4plugin == False:
|
2019-03-17 03:19:57 +00:00
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
if len(oscpath) == 1:
|
|
|
|
args[0] = "noargs"
|
|
|
|
#print "noargs command"
|
2019-03-17 03:19:57 +00:00
|
|
|
|
2019-03-29 14:13:25 +00:00
|
|
|
elif len(oscpath) > 1:
|
|
|
|
args[0] = str(oscpath[1])
|
|
|
|
#print "arg",oscpath[1]
|
|
|
|
|
|
|
|
commands.handler(oscpath[0].split("/"),args)
|
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
# if needed a loop back : WS Client -> server -> WS Client
|
|
|
|
#sendWSall("ws"+message)
|
|
|
|
|
|
|
|
|
|
|
|
def handle_timeout(self):
|
|
|
|
self.timed_out = True
|
|
|
|
|
|
|
|
|
|
|
|
def sendWSall(message):
|
2018-12-27 11:40:30 +00:00
|
|
|
#if gstt.debug >0:
|
|
|
|
#print("WS sending %s" % (message))
|
2019-03-10 22:06:04 +00:00
|
|
|
wserver.send_message_to_all(message)
|
2019-08-06 01:08:54 +00:00
|
|
|
|
|
|
|
'''
|
|
|
|
print ""
|
|
|
|
print "Midi Configuration"
|
|
|
|
midi.InConfig()
|
|
|
|
midi.OutConfig()
|
|
|
|
'''
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-10-05 20:22:42 +00:00
|
|
|
def fff(name):
|
|
|
|
print()
|
|
|
|
print('HELLO', name ) #indent
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Create a startup point list for each laser : 0,1,2,...
|
|
|
|
#
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
print("")
|
|
|
|
log.info("Creating startup point lists...")
|
|
|
|
|
|
|
|
|
|
|
|
if r.set("/clientkey","/pl/"+str(gstt.SceneNumber)+"/")==True:
|
|
|
|
print("sent clientkey : /pl/"+str(gstt.SceneNumber)+"/")
|
|
|
|
|
|
|
|
#pdb.set_trace()
|
|
|
|
for sceneid in range(0,gstt.MaxScenes+1):
|
|
|
|
print("Scene "+ str(sceneid))
|
|
|
|
#digit_points = font1.DigitsDots(sceneid,65280)
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-10-05 20:22:42 +00:00
|
|
|
# Order all lasers to show its number at startup -> tell all 4 laser process to USER PLs
|
2018-12-19 11:39:54 +00:00
|
|
|
for laserid in range(0,gstt.LaserNumber):
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
digit_points = font1.DigitsDots(laserid,65280)
|
|
|
|
if r.set('/pl/'+str(sceneid)+'/'+str(laserid), str(digit_points)) == True:
|
|
|
|
pass
|
|
|
|
#print( ast.literal_eval(r.get('/pl/'+str(sceneid)+'/'+str(laserid)).decode('ascii')))
|
|
|
|
#print("/pl/"+str(sceneid)+"/"+str(laserid)+" "+str(ast.literal_eval(r.get('/pl/'+str(sceneid)+'/'+str(laserid)).decode('ascii'))))
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2018-12-19 11:39:54 +00:00
|
|
|
r.set('/order/'+str(laserid), 0)
|
2018-12-14 11:34:41 +00:00
|
|
|
|
2020-10-05 20:22:42 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
#
|
|
|
|
# Starts one DAC process per requested Laser
|
|
|
|
#
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
if __name__ == '__main__':
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
# Bug in 3.8.4 MacOS default multiprocessing start method is spawn. Spawn doesn't work properly
|
|
|
|
set_start_method('fork')
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-27 23:04:05 +00:00
|
|
|
print("gstt.LaserNumber", gstt.LaserNumber)
|
2020-09-19 12:28:56 +00:00
|
|
|
if gstt.LaserNumber == -1:
|
|
|
|
log.infog("Autodetected DACs mode")
|
|
|
|
commands.DAChecks()
|
|
|
|
print("dacs", gstt.dacs)
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
else:
|
|
|
|
log.infog("Resquested DACs mode")
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
lasernumber = gstt.LaserNumber -1
|
|
|
|
print("LaserNumber = ", gstt.LaserNumber)
|
2019-03-10 22:06:04 +00:00
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
log.info("Starting "+str(gstt.LaserNumber) + " DACs process...")
|
2018-12-14 11:34:41 +00:00
|
|
|
|
2020-10-05 20:22:42 +00:00
|
|
|
# Launch one process (a tracer3 instance) by etherdream
|
2020-09-19 12:28:56 +00:00
|
|
|
dac_worker0= Process(target=dac_process, args=(0,0,))
|
|
|
|
dac_worker0.start()
|
2020-09-29 22:15:40 +00:00
|
|
|
commands.worker0 = dac_worker0
|
2020-09-19 12:28:56 +00:00
|
|
|
print("Tracer 0 : name", dac_worker0.name , "pid", dac_worker0.pid )
|
2018-12-18 01:45:23 +00:00
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
if lasernumber >0:
|
2020-09-19 12:28:56 +00:00
|
|
|
dac_worker1= Process(target=dac_process, args=(1,0,))
|
2020-09-29 22:15:40 +00:00
|
|
|
commands.worker1 = dac_worker1
|
2020-09-19 12:28:56 +00:00
|
|
|
print("Tracer 1 : name", dac_worker1.name , "pid", dac_worker1.pid )
|
|
|
|
dac_worker1.start()
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
if lasernumber >1:
|
2020-09-19 12:28:56 +00:00
|
|
|
dac_worker2= Process(target=dac_process, args=(2,0,))
|
|
|
|
dac_worker2.start()
|
2020-09-29 22:15:40 +00:00
|
|
|
commands.worker2 = dac_worker2
|
2020-09-19 12:28:56 +00:00
|
|
|
print("Tracer 2 : name", dac_worker2.name , "pid", dac_worker2.pid )
|
|
|
|
|
2018-12-13 11:05:32 +00:00
|
|
|
if lasernumber >2:
|
2020-09-19 12:28:56 +00:00
|
|
|
dac_worker3= Process(target=dac_process, args=(3,0,))
|
|
|
|
print("Tracer 3 : name", dac_worker3.name , "pid", dac_worker3.pid )
|
2020-09-29 22:15:40 +00:00
|
|
|
commands.worker3 = dac_worker3
|
2020-09-19 12:28:56 +00:00
|
|
|
dac_worker3.start()
|
|
|
|
print("")
|
|
|
|
|
|
|
|
#
|
2020-10-05 20:22:42 +00:00
|
|
|
# start WS and OSC servers
|
2020-09-19 12:28:56 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
# Websocket startup
|
|
|
|
wserver = WebsocketServer(wsPORT,host=serverIP)
|
|
|
|
plugins.Init(wserver)
|
|
|
|
|
|
|
|
log.info("Starting servers...")
|
|
|
|
# Launch OSC thread listening to oscserver
|
|
|
|
print("Launching OSC server...")
|
|
|
|
print("at", oscserverIPin, "port",str(oscserverPORTin))
|
|
|
|
oscserver.addMsgHandler( "/noteon", commands.NoteOn)
|
|
|
|
oscserver.addMsgHandler( "/scim", commands.Scim)
|
|
|
|
oscserver.addMsgHandler( "/line1", commands.Line1)
|
|
|
|
oscserver.addMsgHandler( "/forwardui", commands.ForwardUI)
|
|
|
|
# Default OSC handler for all OSC incoming message
|
|
|
|
oscserver.addMsgHandler("default", handler)
|
|
|
|
_thread.start_new_thread(osc_thread, ())
|
|
|
|
|
|
|
|
print("Launching webUI Websocket server...")
|
|
|
|
print("at", serverIP, "port",wsPORT)
|
|
|
|
wserver.set_fn_new_client(new_client)
|
|
|
|
wserver.set_fn_client_left(client_left)
|
|
|
|
wserver.set_fn_message_received(message_received)
|
|
|
|
print("")
|
|
|
|
log.info("Resetting all Homographies...")
|
|
|
|
for laserid in range(0,gstt.LaserNumber):
|
|
|
|
homographyp.newEDH(laserid)
|
|
|
|
|
|
|
|
# plugins autostart
|
|
|
|
print("")
|
|
|
|
log.info("Plugins startup...")
|
|
|
|
|
|
|
|
if gstt.autostart != "":
|
|
|
|
|
|
|
|
for pluginname in gstt.autostart.split(","):
|
|
|
|
print("Autostarting", pluginname, "...")
|
|
|
|
plugins.Start(pluginname)
|
|
|
|
|
|
|
|
print("")
|
|
|
|
log.infog("LJ server running...")
|
|
|
|
|
2020-10-05 20:22:42 +00:00
|
|
|
# websocket loop
|
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
wserver.run_forever()
|
|
|
|
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
log.err("Exception")
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
# Gently stop on CTRL C
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
2020-09-29 22:15:40 +00:00
|
|
|
commands.LJautokill()
|
2020-10-05 20:22:42 +00:00
|
|
|
|
2020-09-19 12:28:56 +00:00
|
|
|
'''
|
|
|
|
Some code previously used, for reference :
|
|
|
|
|
|
|
|
random_points = [(300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 0), (500.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280), (500.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 400.0+random.randint(-100, 100), 65280), (300.0+random.randint(-100, 100), 200.0+random.randint(-100, 100), 65280)]
|
|
|
|
'''
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|