/**	Compares two 64-bit XBeeAddress **/
bool LithneClass::equals( XBeeAddress64 _addr1, XBeeAddress64 _addr2 )
{
	bool _equal	=	true;

	if( _addr1.getMsb() != _addr2.getMsb() )
	{
		_equal	=	false;
	}
	else if( _addr1.getLsb() != _addr2.getLsb() )
	{
		_equal	=	false;
	}

	return _equal;
}
Ejemplo n.º 2
0
void XBeePlus::meetCoordinator()
{
        //XBeeAddress64 tmp = 
	_xbee.getResponse().getZBRxResponse(rx);//.getRemoteAddress64();
        XBeeAddress64 tmp = rx.getRemoteAddress64();
	addr64.setMsb(tmp.getMsb());
        addr64.setLsb(tmp.getLsb());
}
/** Look up the position of the node in the array, based on the 64-bit address **/
uint16_t LithneClass::getNodeArrayPosition( XBeeAddress64 _addr64 )
{
	for( uint8_t i=0; i<numNodes; i++)
	{
		if( getNode( i )->getAddress64().getMsb() == _addr64.getMsb() &&
			getNode( i )->getAddress64().getLsb() == _addr64.getLsb() )
		{
			return i;
		}
	}
	return UNKNOWN_NODE_ID;
}
/**	Returns the own 64-bit Serial Address of the XBee connected	**/
XBeeAddress64 LithneClass::getMyAddress64( bool forceCheck )
{
	/*	If the address is unknown, or if we force a recheck.	*/
	if( myAddress64.getLsb() ==	UNKNOWN_64B || forceCheck )
	{
		uint32_t msb	=	sendATCommand( atSH, 1000 );	//We want to wait for an answer
		uint32_t lsb	=	sendATCommand( atSL, 1000 );	//We want to wait for an answer
		myAddress64		=	XBeeAddress64( msb, lsb );
		// Serial.print("myadd is now: ");
		// Serial.println(myAddress64.getLsb());
	}
	
	return myAddress64;
}
/*	Send a DB request to a specific node. This is the new function all the
	other request forward their code to. **/
void LithneClass::sendDBRequest( XBeeAddress64 _addr64, uint16_t _addr16 )
{	
	
	/* Serial.print("Opening DB req. on node ");
	Serial.print(getNodeBy64( _addr64 )->getID());
	Serial.print(" from 16 bit add ");
	Serial.print( _addr16 );
	Serial.print(" and 64 bit add ");
	Serial.print( _addr64.getMsb() , HEX );
	Serial.print( ", ");
	Serial.println( _addr64.getLsb() , HEX );*/
	
	RemoteAtCommandRequest db;
	/* If we know the 16 bit address, we transmit to that */
	if( _addr16 != UNKNOWN_16B )
	{
		db = RemoteAtCommandRequest( _addr16, atDB );
		// If the 64 bit add is not a broadcast, we set that add as well.
		if ( _addr64.getMsb() != 0x0 || 
			 _addr64.getLsb() != 0xFFFF )
		{
				db.setRemoteAddress64( _addr64 );
		}
		
		/*	Open the request on the node we	transmit the DB request to	*/
		if (nodeKnown16( _addr16 ) )
		{
			getNodeBy16( _addr16 )->openDBRequest();
		}
	}
	
	/* If we don't know the 16 bit address, we use the 64 bit, at least if we know it */
	else // if ( _addr64 != NULL ) // unfortunately, we can't put NULL as a 64 bit address
	{
		db = RemoteAtCommandRequest( _addr64, atDB );
		
		/*	If we broadcast the DB request, open the node request on all nodes	*/
		if ( _addr64.getMsb() == 0x0 && 
			 _addr64.getLsb() == 0xFFFF )
		{
			for(uint16_t i=0; i< numNodes; i++)
			{
				nodes[i]->openDBRequest();
			}
		}
		/*	Otherwise, we open the request on the node we	transmit the DB request to	*/
		else 
		{
			Node * receiverNode = getNodeBy64( _addr64 );
			if (receiverNode != NULL)
			{
				receiverNode->openDBRequest();
				/* Serial.print("Found node by 64bit add to send DB request to; node ID: ");
				Serial.println( receiverNode->getID() ); */
			}
		}
		/*Serial.print("Opened DB req. on node ");
		Serial.print(getNodeBy64( _addr64 )->getID());
		Serial.print(" from 64 bit add ");
		Serial.println( _addr64.getLsb() ); */
	}
    /*	Transmit the request	*/
	/*Serial.print("Transmitting DB Request:");
	for (int i = 0; i < db.getFrameDataLength (); i++)
	{
		Serial.print(db.getFrameData(i),HEX);
		Serial.print(" ");
	}
	Serial.println();*/
    xbee.send( db );
}