예제 #1
0
def init_xbee(s,x):
    global ser, xbee
    ser = s;
    xbee = x;
    something_changed = False
    
    if XBEE_TYPE == ROUTER:
        if verify_at("SM","\x00"): something_changed = True
    elif XBEE_TYPE == END_DEVICE:
        if verify_at("SM","\x04"): something_changed = True
    
    
    for cval in AT_COMMANDS:
        try:
            cmd,val = cval.split(',')
            
            if ( len(val) > 2 and val.startswith('0x') ):
                sstr = utils.unhexify(val[2:])
            elif (len(val) > 2 and val.startswith('0d')):
                sstr = utils.undecify(int(val[2:]))
            else:
                sstr = val
        except Exception,e:
            print "Error parsing AT Command",cmd," value ",sstr," : ",e
        
        if cmd == 'NK' or cmd == 'KY':
            xbee.send('at',command=cmd,parameter=sstr)
        else:
            if verify_at(cmd,sstr):
                something_changed = True
def send_to_xbee(dest, data):
    global children_cache
    
    if not SEND_ONLY_TO_CACHE or dest in children_cache or dest == '000000000000FFFF':
        xbee.send('tx_long_addr',dest_addr=utils.unhexify(dest),data=data)
        return True
    else:
        return False