fireandforget version

This commit is contained in:
Sam 2020-10-10 19:29:07 +02:00
parent 4faf53168d
commit 93cbcfefd5
24 changed files with 565 additions and 1840 deletions

84
clitools/exports/toUDP.py Normal file
View file

@ -0,0 +1,84 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
toUDP
v0.1.0
A basic exporter
LICENCE : CC
by cocoa
'''
from __future__ import print_function
import sys
import os
import argparse
import time
import socket
import ast
argsparser = argparse.ArgumentParser(description="toUDP v0.1b help mode")
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
argsparser.add_argument("-i","--ip",help="IP to bind to (0.0.0.0 by default)",default="0.0.0.0",type=str)
argsparser.add_argument("-p","--port",help="UDP port to bind to (9000 by default)",default="9003",type=str)
args = argsparser.parse_args()
verbose = args.verbose
ip = args.ip
port = int(args.port)
verbose = args.verbose
name = "exports::toUDP"
def debug(*args, **kwargs):
if( verbose == False ):
return
print(*args, file=sys.stderr, **kwargs)
def ClientStart(ip, port):
global sockclient
sockclient = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
def ClientSend(msgFromClient):
bytesToSend = str.encode(str(msgFromClient))
serverAddressPort = (ip, port)
bufferSize = 1024
# Send to server using created UDP socket
sockclient.sendto(bytesToSend, serverAddressPort)
'''
# If reply :
msgFromServer = sockclient.recvfrom(bufferSize)
msg = "Message from Server {}".format(msgFromServer[0])
print(msg)
'''
try:
ClientStart(ip, port)
while True:
line = sys.stdin.readline()
if line == "":
time.sleep(0.01)
line = line.rstrip('\n')
#pointsList = ast.literal_eval(line)
debug(name,": "+line)
ClientSend(line)
except EOFError:
debug("break")# no more information

View file

@ -163,6 +163,7 @@ try:
# Do the filter
result = kaleidoscope( pointsList )
print( result, flush=True )
looptime = time.time() - start
# debug(name+" looptime:"+str(looptime))
if( looptime < optimal_looptime ):

View file

@ -0,0 +1,126 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
Forward /pl pointlist to cli
input OSC in END points format : (x,y,color)
output CLI in CLI points format : [x,y,color]
/pl "[(150.0, 230.0, 255), (170.0, 170.0, 255), (230.0, 170.0, 255), (210.0, 230.0, 255), (150.0, 230.0, 255)]"
v0.1.0
LICENCE : CC
by Cocoa, Sam Neurohack
'''
from __future__ import print_function
from OSC3 import OSCServer, OSCClient, OSCMessage
import sys
from time import sleep
import argparse
import ast
argsparser = argparse.ArgumentParser(description="fromOSC generator")
argsparser.add_argument("-i","--ip",help="IP to bind to (0.0.0.0 by default)",default="0.0.0.0",type=str)
argsparser.add_argument("-p","--port",help="OSC port to bind to (9002 by default)",default=9002,type=str)
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
args = argsparser.parse_args()
verbose = args.verbose
ip = args.ip
port = int(args.port)
def debug(*args, **kwargs):
if( verbose == False ):
return
print(*args, file=sys.stderr, **kwargs)
oscserver = OSCServer( (ip, port) )
oscserver.timeout = 0
run = True
# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def handle_timeout(self):
self.timed_out = True
# funny python's way to add a method to an instance of a class
import types
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
# RAW OSC Frame available ?
def OSC_frame():
# clear timed_out flag
oscserver.timed_out = False
# handle all pending requests then return
while not oscserver.timed_out:
oscserver.handle_request()
# default handler
def OSChandler(oscpath, tags, args, source):
oscaddress = ''.join(oscpath.split("/"))
debug("fromOSC Default OSC Handler got oscpath", oscpath, "from" + str(source[0]), ":", args)
#print("OSC address", path)
#print("find.. /bhoreal ?", path.find('/bhoreal'))
if oscpath == "/pl" and len(args)==1:
debug("correct OSC type :'/pl")
if validate(args[0]) == True:
debug("new pl : ", args[0])
line = args[0].replace("(",'[')
line = line.replace(")",']')
line = "[{}]".format(line)
print(line, flush=True);
else:
debug("Bad pointlist -> msg trapped.")
else:
debug("BAD OSC Message : " + oscpath +" " +args[0])
oscserver.addMsgHandler( "default", OSChandler )
def validate(pointlist):
state = True
if len(pointlist)<9:
debug("Not enough characters :", pointlist)
state = False
if pointlist.find("(") == -1:
debug("Bad format : use () not [] for points", pointlist)
state = False
try:
pl = bytes(pointlist, 'ascii')
check = ast.literal_eval(pl.decode('ascii'))
except:
debug("BAD POINTLIST :", pointlist)
state = False
return state
# simulate a "game engine"
while run:
# do the game stuff:
sleep(0.01)
# call user script
OSC_frame()
oscserver.close()

View file

@ -0,0 +1,84 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
fromUDP
Udp server to cli
v0.1b
'''
from __future__ import print_function
import traceback, time
import argparse
import socket
import _thread
import sys
name="generator::fromUDP"
def debug(*args, **kwargs):
if( verbose == False ):
return
print(*args, file=sys.stderr, **kwargs)
argsparser = argparse.ArgumentParser(description="fromUDP v0.1b help mode")
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output")
argsparser.add_argument("-i","--ip",help="IP to bind to (0.0.0.0 by default)",default="0.0.0.0",type=str)
argsparser.add_argument("-p","--port",help="UDP port to bind to (9000 by default)",default=9000,type=str)
args = argsparser.parse_args()
verbose = args.verbose
ip = args.ip
port = int(args.port)
verbose = args.verbose
def udp_thread():
while True:
payload, client_address = sock.recvfrom(1024)
udpath = payload.decode('utf_8')
debug(udpath[0:])
print(udpath[0:], flush=True);
'''
# Reply to client
bytesToSend = str.encode("ACK :"+str(payload))
serverAddressPort = (client_address, port)
bufferSize = 1024
#sock.sendto(bytesToSend, serverAddressPort)
sock.sendto(bytesToSend, client_address)
'''
def StartUDP(serverIP, UDPORT):
global sock
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server = ( serverIP,UDPORT)
sock.bind(server)
_thread.start_new_thread(udp_thread, ())
StartUDP(ip, port)
# Do something else
try:
while True:
time.sleep(0.005)
except Exception:
traceback.print_exc()