コード例 #1
0
 else:
     records = [msg]
 
 for idx in range(len(records)-1,-1,-1):
     last_rec = records[idx]
     tm = sensor_packet.read_packet_timestamp(last_rec)
     if tm:
         break;                    
 
 if tm:
     if abs(time.time() - tm) > MAX_TIMESTAMP_ERROR:
         offset = tm - time.time()
         for midx in range(len(records)):
             tm2 = sensor_packet.read_packet_timestamp(records[midx])
             if tm2:
                 records[midx] = sensor_packet.set_packet_timestamp(records[midx],tm2 - offset);                            
                 
         client.desynched = True
     else:
         if client.desynched:
             print "Client at %s synchronized"%uid
         client.desynched = False
 
 for m in records:
     if sensor_packet.read_packet_type(m) == sensor_packet.MT_DEVICE_IDENTIFIER:
         r = sensor_packet.read_packet(m)
         uid = r[3]
         
 print "%d records from %s"%(len(records),uid)
 
 for m in records:
コード例 #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);