Пример #1
0
    def update(self, dispatch_fn):
        '''Update the tuio provider (pop event from the queue)'''

        # deque osc queue
        osc.readQueue(self.oscid)

        # read the Queue with event
        try:
            while True:
                value = self.tuio_event_q.pop()
                self._update(dispatch_fn, value)
        except IndexError:
            return
Пример #2
0
    def update(self, dispatch_fn):
        '''Update the tuio provider (pop event from the queue)'''

        # deque osc queue
        osc.readQueue(self.oscid)

        # read the Queue with event
        while True:
            try:
                value = self.tuio_event_q.pop()
            except IndexError:
                # queue is empty, we're done for now
                return
            self._update(dispatch_fn, value)
Пример #3
0
    def update(self, dispatch_fn):
        '''Update the tuio provider (pop events from the queue)'''

        # deque osc queue
        osc.readQueue(self.oscid)

        # read the Queue with event
        while True:
            try:
                value = self.tuio_event_q.pop()
            except IndexError:
                # queue is empty, we're done for now
                return
            self._update(dispatch_fn, value)
Пример #4
0
    def update(self):#, dispatch_fn):
        '''Update the tuio provider (pop events from the queue)'''

        # deque osc queue
        osc.readQueue(self.oscid)
        
        positions = []
        ids = []
        idx = 0

        # read the Queue with event
        while True:
            try:
                value = self.tuio_event_q.pop()
                
                #if value:
                #    
            except IndexError:
                # queue is empty, we're done for now
                #print ''
                break
            #print 'aaaaaaaaa_', value
            messageType = value[1][0]
            if messageType == 'set':
                
                # [!!!]
                # Learn to tell the difference between reactivision and Tuio, so you don't
                # have to use this yucky hard coding.
                
                # The Movid messages are formatted thus:
                #player_id = value[1][1]
                #player_position = [ value[1][2], value[1][3] ]
                
                # The Reactivision messages are formatted thus: 
                player_id = value[1][2]
                player_position = [ value[1][3], value[1][4] ]
                
                
                positions.append( player_position )
                ids.append( player_id )
                idx = idx + 1
        
        self.idAndPositionCallback(ids, positions)
Пример #5
0
    def __init__(self):
        osc.init()
        oscid = osc.listen(ipAddr="0.0.0.0", port=3000)
        # Receive start/stop message
        osc.bind(oscid, self.startquit, "/start")
        self.can_start = False
        # Cycle info?
        osc.bind(oscid, self.send_hello, "/hello")
        # Send status of simulation
        osc.bind(oscid, self.simulation_status_send, "/simu-status_ask")
        # Receive simulation speed
        osc.bind(oscid, self.simuspeed, "/simu-speed")

        # Init actual model
        self.sim = Simulation()
        self.sim_speed = 1
        self.cycle = 0
        self.max_cycles = self.sim.model.parameters.get("max_cycles")
        print("Max cycles: {}".format(self.max_cycles))

        # Make statistics instance
        # Only for testing writing to CSV
        self.statistics = Statistics()

        # Send server is running
        self.simulation_status_send()

        # Code always running / waiting for instructions
        while True:
            # Try so that a server stopped message can be send
            try:
                if self.cycle % 1000 == 0 or self.cycle == 0:
                    print("Current cycle: {}".format(self.cycle))
                osc.readQueue(oscid)
                # Only run simulation when started and max cycles not reached
                # print("Start: {}, Max Cycles: {}".format(self.can_start, self.max_cycles))
                if self.can_start == True and self.cycle < self.max_cycles:
                    # Reset model
                    if self.cycle == 0:
                        print("\nNew simulation detected!!!\n")
                        print("\nReset model")
                        self.sim.model.reset()
                        self.statistics.driver_update(self.sim.model.drivers)
                        # print("\nCSV filename function")
                        self.statistics.create_csv(self.sim.model.parameters.param)

                    # Make statistics instance
                    # print "LIST PRINTED in LOOP\n"

                    # Agent stuff
                    self.sim.run()

                    # Send agent positions
                    self.positions()

                    # Statistics stuff
                    self.do_statistics()

                    # Hello world test
                    self.cycle += 1
                    self.send_hello()

                sleep(self.sim_speed)

            # Send message server stopped
            except:
                traceback.print_exc()  # Please tell me what is wrong then...
                self.send_server_stop()
                exit()
Пример #6
0
for entry in to.split(':'):
    if entry.startswith('throttle_output='):
        throttle_output = False if entry[16:] == '0' else True
    if entry.startswith('use_thread='):
        use_thread = False if entry[11:] == '0' else True
    if entry.startswith('send_port='):
        send_port = int(entry.split('=')[-1])
    if entry.startswith('receive_port='):
        receive_port = int(entry.split('=')[-1])


osc.init()
oscid = osc.listen(ipAddr='127.0.0.1', port=receive_port)
osc.bind(oscid, receive_message, b'/interpret')
osc.bind(oscid, receive_message, b'/ping')
osc.bind(oscid, receive_message, b'/sigint')
osc.bind(oscid, receive_message, b'/throttling')
osc.bind(oscid, receive_message, b'/userinput')
osc.bind(oscid, receive_message, b'/execfile')

sys.stdout = OscOut(b'/stdout', send_port)
sys.stderr = OscOut(b'/stderr', send_port)

real_print('got this far4')

while True:
    osc.readQueue(oscid)
    time.sleep(.1)


 def read_osc_queue(self, *args):
     osc.readQueue(self.oscid)
Пример #8
0
def main(host='0.0.0.0', port=8000, address='/update'):
    oscid = listen(host, port)
    bind(oscid, dump_data, address)
    while True:
        readQueue(oscid)
Пример #9
0
print('got this far')

to = os.environ.get('PYTHON_SERVICE_ARGUMENT', '')
for entry in to.split(':'):
    if entry.startswith('throttle_output='):
        throttle_output = False if entry[16:] == '0' else True
    if entry.startswith('use_thread='):
        use_thread = False if entry[11:] == '0' else True
    if entry.startswith('send_port='):
        send_port = int(entry.split('=')[-1])
    if entry.startswith('receive_port='):
        receive_port = int(entry.split('=')[-1])

osc.init()
oscid = osc.listen(ipAddr='127.0.0.1', port=receive_port)
osc.bind(oscid, receive_message, b'/interpret')
osc.bind(oscid, receive_message, b'/ping')
osc.bind(oscid, receive_message, b'/sigint')
osc.bind(oscid, receive_message, b'/throttling')
osc.bind(oscid, receive_message, b'/userinput')
osc.bind(oscid, receive_message, b'/execfile')

sys.stdout = OscOut(b'/stdout', send_port)
sys.stderr = OscOut(b'/stderr', send_port)

real_print('got this far4')

while True:
    osc.readQueue(oscid)
    time.sleep(.1)