Beispiel #1
0
def send_steer(msg):  #new 03/01
    data_ = binascii.hexlify(msg.data)  #new 03/01
    #convert the hex to dec    #new 03/01
    auto_steer = int(data_[0:4], 16)  #new 03/01

    MSG_ = OSCMessage('/steer')
    #CounterClockwise from 0 to 343  #new 03/01
    if auto_steer < 344:  #new 03/01
        MSG_ += 1
        MSG_ += auto_steer  #new 03/01
    #Clockwise from 1 to 342   #new 03/01
    else:
        auto_steer = 4096 - auto_steer
        MSG_ += 0
        MSG_ += auto_steer
    print(MSG_)  #new 03/01
    binary = MSG_.getBinary()
    sock.sendto(binary, (UDP_IP, UDP_PORT))  #new 03/01
Beispiel #2
0
def fader_callback(path, tags, args, source):
    print("path", path)
    print("args", args)
    print("source", source)

    value = int(args[0] * 10)
    if value > 1:
        led[0].on()
    if value > 2:
        led[1].on()
    if value > 3:
        led[2].on()
    if value > 4:
        led[3].on()
    if value > 5:
        led[4].on()
    if value > 6:
        led[5].on()
    if value > 7:
        led[6].on()
    if value > 8:
        led[7].on()

    if value < 1:
        led[0].off()
    if value < 2:
        led[1].off()
    if value < 3:
        led[2].off()
    if value < 4:
        led[3].off()
    if value < 5:
        led[4].off()
    if value < 6:
        led[5].off()
    if value < 7:
        led[6].off()
    if value < 8:
        led[7].off()

    msg = OSCMessage("/1/rotary1")
    msg.append(args)
    client.send(msg)
Beispiel #3
0
def send(nodes, jeu):
    mean_p = 0.0
    mean_dp = 0.0
    for node in nodes:
        try:
            msg = OSCMessage("/%i" % node.ip)
            # presure and presure derivative (constants setted to assure equal mean)
            p = gate(1.5 * node.current)
            dp = gate(5 * (node.current - node.previous))
            if jeu == "2osc":
                xA0, xA1, xA2 = dp, p, 0
                xB0, xB1, xB2 = 0, 0, 0
                xC0, xC1, xC2 = 0, 0, 0
            elif jeu == "3chords":
                p /= 3.
                dp /= 3.
                xA0, xA1, xA2 = dp, p, dp + p
                xB0, xB1, xB2 = dp, p, dp + p
                xC0, xC1, xC2 = dp, p, dp + p
            if DEBUG:
                print("%i %f %f %f %f %f %f %f %f %f" %
                      (node.ip, xA0, xA1, xA2, xB0, xB1, xB2, xC0, xC1, xC2))
            msg.append(xA0)
            msg.append(xA1)
            msg.append(xA2)
            msg.append(xB0)
            msg.append(xB1)
            msg.append(xB2)
            msg.append(xC0)
            msg.append(xC1)
            msg.append(xC2)
            bundle = OSCBundle()
            bundle.append(msg)
            client.send(bundle)
        except Exception as e:
            print(node)
            print(e)
        if DEBUG:
            mean_p += p
            mean_dp += dp
    if DEBUG:
        print("mean_p %f mean_dp %f" % (mean_p, mean_dp))
def cleanTagAndSendText(text):
    ## removes punctuation
    text = re.sub(r'[.,;:!?*/+=\-&%^/\\_$~()<>{}\[\]]', ' ', text)
    ## removes some bad words
    text = re.sub(r'(f *u *c *k)', 'tuck', text)
    text = re.sub(r'(s *h *i *t)', 'isht', text)
    text = re.sub(r'(c *o *c *k)', 'dock', text)
    text = re.sub(r'(d *i *c *k)', 'wick', text)
    text = re.sub(r'(c *u *n *t)', 'grunt', text)
    text = re.sub(r'(p *u *s *s *y)', 'juicy', text)
    text = re.sub(r'(b *i *t *c *h)', 'itch', text)
    text = re.sub(r'(a *s *s)', 'grass', text)
    ## replaces double-spaces with single space
    text = re.sub(r'( +)', ' ', text)

    taggedText = pos_tag(text.split())
    for (word, tag) in taggedText:
        print "(%s:%s)" % (word, tag),
    print " "

    ## log
    logFile.write(strftime("%Y%m%d-%H%M%S", localtime()) + "***" + text + "\n")
    logFile.flush()

    ## forward to all subscribers
    msg = OSCMessage()
    msg.setAddress("/NotTooPublic/response")
    msg.append(" ".join([str(i[0]) for i in taggedText]))
    msg.append(" ".join([str(i[1]) for i in taggedText]))

    delQ = Queue()
    for (ip, port) in myOscSubscribers:
        try:
            myOscClient.connect((ip, port))
            myOscClient.sendto(msg, (ip, port))
            myOscClient.connect((ip, port))
        except OSCClientError:
            print "no connection to %s : %s, can't send message" % (ip, port)
            delQ.put((ip, port))

    while not delQ.empty():
        del myOscSubscribers[delQ.get()]
Beispiel #5
0
    def img_osc_callback(path, tags, args, source):
        """Sends the result of the prediction to the server.

    Args:
      path:
      tags:
      args:
      source:

    """
        file = args[0]
        print(file)
        t = read_tensor_from_image_file(file,
                                        input_height=input_height,
                                        input_width=input_width,
                                        input_mean=input_mean,
                                        input_std=input_std)

        input_name = "import/" + input_layer
        output_name = "import/" + output_layer
        input_operation = graph.get_operation_by_name(input_name)
        output_operation = graph.get_operation_by_name(output_name)

        #Starts a tensorflow session to realize the prediction
        with tf.Session(graph=graph) as sess:
            start = time.time()
            results = sess.run(output_operation.outputs[0],
                               {input_operation.outputs[0]: t})
            end = time.time()
            results = np.squeeze(results)
            #Top 5 of the prediction (according to the score)
            top_k = results.argsort()[-5:][::-1]
            labels = load_labels(label_file)
            template = "{} (score={:0.5f})"
            #Sends the label (and its score) of the prediction that has the best score to the server.
            print(template.format(labels[top_k[0]], results[top_k[0]]))
            mess = labels[top_k[0]]

            if results[top_k[0]] < 0.9:
                mess = "Not sure"

            client.send(OSCMessage(mess))
Beispiel #6
0
def bridge():
    while True:
        msg = socket.recv()
        print "raw msg:\n", msg

        items = msg.split("\n")
        msg_type = items.pop(0)
        items = dict([i.split(':') for i in items[:-1]])

        if msg_type == 'Pupil':
            if 'norm_pos' in items:
                pupil_x2, pupil_y2 = map(float,
                                         items['norm_pos'][1:-1].split(','))

            client.send(
                OSCMessage("/pupil/norm_pos1", ('test', items['norm_pos'])))

        else:
            # process event msgs from plugins here
            pass
Beispiel #7
0
def SendLJ(oscaddress, oscargs=''):

    oscmsg = OSCMessage()
    oscmsg.setAddress(oscaddress)
    oscmsg.append(oscargs)

    osclientlj = OSCClient()
    osclientlj.connect((redisIP, 8002))
    #print("lj23layers for", name, "sending OSC message :", oscmsg, "to", redisIP, ":8002")

    if gstt.debug > 0:
        print("lj23layers for", name, "sending OSC message :", oscmsg, "to",
              redisIP, ":8002")

    try:
        osclientlj.sendto(oscmsg, (redisIP, 8002))
        oscmsg.clearData()

    except:
        print('Connection to LJ refused : died ?')
        pass
def sendMessage():
    #value = 0.1
    #values = arduino.readline()
    try:
        value = arduino.readline()
        print value
        #print struct.unpack("<L", value)[0]
        #print isinstance(value, chr)
        #intvalue = ord(value)
        msg = OSCMessage()
        msg.setAddress('/oscTest')
        msg.append(float(value))
    except:
        print "lo saltiamo"
        pass
    #print value
    try:
        client.send(msg)
    except:
        print "Waiting for SuperCollider to become available..."
        pass
    timedSendMessage()  # recursive call, keeps the timer going
def cleanTagAndSendText(text):
    ## removes punctuation
    text = re.sub(r'[.,;:!?*/+=\-&%^/\\_$~()<>{}\[\]]', ' ', text)
    ## replaces double-spaces with single space
    text = re.sub(r'( +)', ' ', text)
    ## log
    now = datetime.now(utc)
    logFile.write(now.isoformat() + "  ***  " + text + "\n")
    logFile.flush()

    ## forward to all subscribers
    msg = OSCMessage()
    msg.setAddress("/airmsg/response")
    msg.append(text.encode('utf-8'))

    try:
        myOscClient.connect((DISPLAY_ADDR, DISPLAY_PORT))
        myOscClient.sendto(msg, (DISPLAY_ADDR, DISPLAY_PORT))
        myOscClient.connect((DISPLAY_ADDR, DISPLAY_PORT))
    except OSCClientError:
        print("no connection to %s : %s, can't send message" %
              (DISPLAY_ADDR, DISPLAY_PORT))
Beispiel #10
0
	def sendMsgBlocking(self,msg,*args):
		packetNumber = self.getPacketNumber()
		print "Sending %r (#%i)..." % (msg,packetNumber)
		omcall = Call()
		omcall.result = None
		omcall.done = False
		self.calls[packetNumber] = omcall
		message = OSCMessage()
		message.setAddress(msg)
		message.append(packetNumber)
		for arg in args:
			message.append(arg)
		self.transport.write(message.getBinary())
		now = time.time()
		while not omcall.done:
			time.sleep(INGEN_CALL_POLLTIME)			
			distance = time.time() - now
			if distance > INGEN_CALL_TIMEOUT:
				print "timeout"
				break			
		del self.calls[packetNumber]
		return omcall.result
Beispiel #11
0
PORT = 50000

client = OSCClient()
client.connect(("127.0.0.1", 22243))

s = socket(AF_INET, SOCK_DGRAM)
s.bind(('', PORT))

while 1:
    data, wherefrom = s.recvfrom(1500, 0)
    #print data
    strsplit = data.split(',')
    kind = strsplit[0]
    val = strsplit[1]
    print kind, val

    if kind == 'TEMP':
        client.send(OSCMessage("/shast/beebox/tmp", val))
    elif kind == 'HUM':
        client.send(OSCMessage("/shast/beebox/hum", val))
    elif kind == 'LIGHT':
        client.send(OSCMessage("/shast/beebox/lht", val))
    elif kind == 'MOIST':
        client.send(OSCMessage("/shast/beebox/moi", val))

#time.sleep(2)

#sys.stderr.write(repr(wherefrom) + '\n')
#sys.stdout.write('->' + data)
if __name__ == "__main__":
    server = OSCServer(("127.0.0.1", 7777))
    server.addMsgHandler("/sl", sl_callback)
    server.addMsgHandler("/sl_len", sl_length)
    server.addMsgHandler("/state", sl_state)
    server.addMsgHandler("/sl_pos", sl_pos)
    server.handle_error = types.MethodType(handle_error, server)

    client = OSCClient()
    client.connect(("localhost", 9951))  #soooperlooper default port

    client2 = OSCClient()
    client2.connect(("localhost", 8000))

    client.send(OSCMessage("/ping", ["localhost:7777", '/sl']))

    Soup = SL_global()

    L0 = Loop()  #this should probably be done more dynamically but....
    L1 = Loop()
    L2 = Loop()
    L3 = Loop()
    L4 = Loop()
    L5 = Loop()
    L6 = Loop()
    L7 = Loop()

    looplist = [L0, L1, L2, L3, L4, L5, L6, L7]

    print looplist
Beispiel #13
0
def sendosc(oscaddress,oscargs):
#def sendosc(oscargs):
    
    # also works : osclient.send(OSCMessage("/led", oscargs))

    oscpath = oscaddress.split("/")
    pathlength = len(oscpath)

    oscmsg = OSCMessage()

    #print "here in sendosc in nozosc"
    #print oscaddress
    #print oscargs
    #raw_input("Press Enter to continue3...")


    if oscpath[2] == "name":
	print "we are asked to send a name"
	oscmsg.setAddress(oscaddress)
	oscmsg.append(oscargs)

    if oscpath[2] == "status":
	print "we are asked to send a status"
	oscmsg.setAddress(oscaddress)
	oscmsg.append(oscargs)

    if oscpath[2] == "knob":
	print "we are asked to send knob %d's value" % int(oscargs[0:3])
	oscmsg.setAddress(''.join((oscaddress,"/",str(int(oscargs[0:3])))))
	oscmsg.append(int(oscargs[3:100]))
	
    if oscpath[2] == "osc":
	#print "we are asked to send continusouly an osc value"
	#print oscargs
	oscmsg.setAddress(''.join((oscaddress,"/",str(int(oscargs[0:3])))))
	#print "oscmsg:", oscmsg
	oscmsg.append(int(oscargs[3:100]))

    if oscpath[2] == "lfo":
	#print "we are asked to send continusouly a lfo value"
	oscmsg.setAddress(''.join((oscaddress,"/",str(int(oscargs[0:2])))))
	oscmsg.append(int(oscargs[2:100]))

    if oscpath[2] == "vco":
	#print "we are asked to send continusouly a vco value"
	oscmsg.setAddress(''.join((oscaddress,"/",str(int(oscargs[0:2])))))
	oscmsg.append(int(oscargs[2:100]))

    if oscpath[2] == "mix":
	#print "we are asked to send continusouly a mix value"
	oscmsg.setAddress(''.join((oscaddress,"/",str(int(oscargs[0:2])))))
	oscmsg.append(int(oscargs[2:100]))

    if oscpath[2] == "X":
	print "we are asked to send continusouly a X value"
	oscmsg.setAddress(oscaddress)
	oscmsg.append(oscargs)

    if oscpath[2] == "Y":
	print "we are asked to send continusouly a Y value"
	print "oscaddress:",oscaddress
	print "oscargs",oscargs
	oscmsg.setAddress(oscaddress)
	oscmsg.append(oscargs)

    if oscpath[2] == "offset":
	print "we are asked to offset a curve"
	oscmsg.setAddress(oscaddress)
	oscmsg.append(oscargs)

    if oscpath[2] == "color":
	print "we are asked to change lazer color"
	oscmsg.setAddress(oscaddress)
	if len(oscargs) > 0:
		oscmsg.append(oscargs)

    try:
        #print oscmsg
	osclient.sendto(oscmsg, (oscIPout, oscPORTout))
	oscmsg.clearData()
    except:
	print ('Connection refused at ',oscIPout)
        pass
Beispiel #14
0
def quick_message(host, port, path, *args):
    msg = OSCMessage(path)
    [msg.append(d) for d in args]
    client = OSCClient()
	client.sendto(msg, (host, port), timeout=0)
Beispiel #15
0
#!/usr/bin/env python

# http://shinybit.github.io/sending-osc-messages-from-pythonista/

# https://gist.github.com/shinybit/3d7e0fc7e62887ab48e931af1d4c0986

# Get pyOSC here: https://trac.v2.nl/wiki/pyOSC
# The GitHub-hosted version of pyOSC is for Python 3 which isn't supported by Pythonista at the moment
from OSC import OSCClient, OSCMessage

client = OSCClient()
client.connect(("192.168.43.120", 8000))

msg = OSCMessage("/msg/notes")
msg.append([50, 60])
client.send(msg)

msg.clearData()
msg.append(["C3", 127])
client.send(msg)

client.send(OSCMessage("/quit"))
Beispiel #16
0
#   ........


while True:
    # --- Bitalino ---
    millis = time.clock()
    millis = format(millis, '.3f')
    millis = str(millis)

    dataAcquired = device.read(nSample)

    SeqN = dataAcquired[0, 4:8]
    SeqN = str(SeqN)
    physio_data = SeqN.split()

    ecgBitalino = physio_data[2]
    participant1.processECG(ecgBitalino)

    ecgBitalino = physio_data[3]
    participant2.processECG(ecgBitalino)
    # ------


    if time.time() - time_send >= 0.5:
        #print("SEND MESSAGE")
        if (participant1.hr.size > 1 and participant2.hr.size > 1):
            print("SEND MESSAGE")
            msg = OSCMessage("/hr/" + str(int(participant1.hr[len(participant1.hr) - 1])) + "/" + str(int(participant2.hr[len(participant2.hr) - 1])))
            processing.send(msg)

        time_send = time.time()
def sendData(type, message):
    client.send(OSCMessage(type, message))
    verbosePrint(Vec)
Beispiel #18
0
import signal
import flicklib
from time import sleep
from curses import wrapper
from os import system
from OSC import OSCClient, OSCMessage

client = OSCClient()
client.connect(("192.168.0.15", 4559))

client.send(OSCMessage("HI"))
client.send(OSCMessage("POOP"))
client.send(OSCMessage("THISISSHIT"))
client.send(OSCMessage("NEWTOTHIS"))
    Tuple = Camera.read()
    if Tuple[0]:

        Img = Tuple[1]
        GImg = cv2.cvtColor(Img, cv2.COLOR_BGR2GRAY)

        if len(Last) == 0:
            Last = GImg
            continue

        if (Height == 0 or Width == 0):
            Height, Width = GImg.shape
            Prev = getFixedPoints(Height, Width)
            client.send(
                OSCMessage(
                    "/config",
                    ((Height, Width), Span, MinThreshold, MaxThreshold)))
            verbosePrint(Height, Width)

        Vec = []
        Next = cv2.calcOpticalFlowPyrLK(Last, GImg, Prev, None, **LkParam)[0]
        for I in range(len(Next)):
            Pt1 = (Prev[I, 0, 0], Prev[I, 0, 1])
            Pt2 = (Next[I, 0, 0], Next[I, 0, 1])

            Dist = distance(Pt1, Pt2)
            if (Dist > MinThreshold and Dist < MaxThreshold):
                Vec.append((Pt1, Dist, getAngle(Pt1, Pt2)))

            if ColorState:
                cv2.circle(Img, Pt1, int(Dist), color=getDistColor(Dist))
Beispiel #20
0
 def playback(self,arrCmd):
     oscm = OSCMessage("/live/stop") if arrCmd[0].lower() == 'stop' else OSCMessage("/live/play")
     return oscm
def quit_callback(path, tags, args, source):
    global run
    run = False


server.addMsgHandler("/servo", servo_callback)
server.addMsgHandler("/quit", quit_callback)


def each_frame():
    server.timed_out = False
    while not server.timed_out:
        server.handle_request()


try:
    while run:
        time.sleep(0.3)
        each_frame()
        try:
            client.send(OSCMessage("/angle", [args.identifier, int(angle), 0]))
        except:
            pass
    print "quiting..."
except KeyboardInterrupt:
    print "quiting..."

server.close()
p.stop()
GPIO.cleanup()
Beispiel #22
0
 def simple_cmd(self,osc_addr,arrCmd):
     oscm = OSCMessage(osc_addr)
     for i in range(len(arrCmd)):
         if arrCmd[i] not in self.parent.filler_words:
             oscm.append(self.int_or_string(arrCmd[i]))
     return oscm
Beispiel #23
0
 def _sendMsg(client, address, items):
     m = OSCMessage()
     m.setAddress(address)
     m.append(items)
     client.send(m)
Beispiel #24
0
 def tempo(self,arrCmd):
     oscm = OSCMessage("/live/tempo")
     oscm.append(float(arrCmd[0]),'f')
     self.parent.tempo = float(arrCmd[0])
     return oscm
Beispiel #25
0
 def grid_key(self, x, y, s):
     msg = OSCMessage("%s/grid/key" % self.prefix)
     msg.append(x)
     msg.append(y)
     msg.append(s)
 	self.client.sendto(msg, (self.app_host, self.app_port), timeout=0)
Beispiel #26
0
 def unmute(self,arrCmd):
     oscm = OSCMessage("/live/track/mute" )
     oscm.append(self.int_or_string(arrCmd[0]))
     oscm.append(0,'i')
     return oscm        
Beispiel #27
0
def XXXNozMsg(channel,value):
    
    print channel
    print value
    
    
#
# OSC messages handlers
#
   
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)


osclient = OSCClient()
osclientme = OSCClient()
oscmsg = OSCMessage()

#oscaddress="/on"

# sendosc(oscaddress, [arg1, arg2,...])

def sendosc(oscaddress,oscargs):
#def sendosc(oscargs):
    
    # also works : osclient.send(OSCMessage("/led", oscargs))

    oscpath = oscaddress.split("/")
    pathlength = len(oscpath)

    oscmsg = OSCMessage()
Beispiel #28
0
 def vol(self,arrCmd):
     oscm = OSCMessage("/live/track/volume" )
     oscm.append(self.int_or_string(arrCmd[0]))
     oscm.append(int(arrCmd[1]) / 100.0,'f')
     return oscm
Beispiel #29
0
        # Creamos el objeto "Cliente"
        client = OSCClient()

        # Realizamos la conexion
        client.connect(client_IP)

        connected = True
    except:
        print("Esperando cliente OS ")

print("Sending OSC messages to: " + str(client_IP))
try:
    while 1:  # endless loop
        try:
            msg = OSCMessage(
            )  #  we reuse the same variable msg used above overwriting it
            msg.setAddress("/ping")
            print "/ping"
            client.send(
                msg)  # now we dont need to tell the client the address anymore
        except:
            print("Sin conexion OSC")
            time.sleep(timerPing)
        time.sleep(timerPing)

except KeyboardInterrupt:
    print "Closing OSCClient"
    client.close()
    print "Done"
Beispiel #30
0
 def xfade(self,arrCmd):
     oscm = OSCMessage("/live/track/crossfader" )
     oscm.append(self.int_or_string(arrCmd[0]))
     oscm.append(int(arrCmd[1]) / 100.0,'f')
     return oscm