rtime = sensor_packet.read_packet_timestamp(data)
                if rtime != None:
                    if time.time() - rtime <= MAX_TIMESTAMP_ERROR:
                        if source_addr not in ts_updated:
                            print "Device at "+source_addr+" synced."
                            ts_updated.add(source_addr)
                            if source_addr in ts_sent_update:
                                ts_sent_update.pop(source_addr)
                    else:
                        if source_addr in ts_updated:
                            print "Device at "+source_addr+" desynced."
                            ts_updated.remove(source_addr)

                if xbee_relay_IF.connected():
                    xbee_relay_IF.publish(source_addr,data)
                        
                if ( source_addr not in ts_updated and source_addr not in ts_sent_update  ):
                    ts_send(source_addr)
            else:
                print "Don't know what to do with frame type=",frame['id']
            
        for source,stime in ts_sent_update.items():
	    #print source,stime
            if time.time() - stime > MAX_TIMESTAMP_ERROR:
                ts_send(source)
            
            
        if time.time() - last_broadcast_sink > BROADCAST_SINK:
            ts_send("000000000000FFFF")
            last_broadcast_sink = time.time()
Ejemplo n.º 2
0
    else:
        reconnect()
        
    return retval
       

reconnect(True);       
while True:
    # process connection to relay server
    if xbee_relay_IF.connected():
        msgs = xbee_relay_IF.tick()
    else:
        xbee_relay_IF.reconnect();
        if xbee_relay_IF.connected():
            xbee_relay_IF.register_as_relay();
        
    # process connection w/ remotes
    msgs = tick()
    for addr,chunk in msgs:
        #print "<",addr,utils.hexify(chunk)
        chunk = sensor_packet.set_packet_timestamp(chunk,time.time())
        
        if xbee_relay_IF.connected():
            xbee_relay_IF.publish(addr,chunk)
                        

    time.sleep(0.01);