MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / GetNeighbors

Method GetNeighbors

cpp/src/Node.cpp:858–899  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Gets the neighbors of a node -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

856// Gets the neighbors of a node
857//-----------------------------------------------------------------------------
858uint32 Node::GetNeighbors
859(
860 uint8** o_neighbors
861)
862{
863 // determine how many neighbors there are
864 int i;
865 uint32 numNeighbors = 0;
866 if( m_queryStage < QueryStage_Session )
867 {
868 *o_neighbors = NULL;
869 return 0;
870 }
871 for( i = 0; i < 29; i++ )
872 {
873 for( unsigned char mask = 0x80; mask != 0; mask >>= 1 )
874 if( ( m_neighbors[i] & mask ) != 0 )
875 numNeighbors++;
876 }
877
878 // handle the possibility that no neighbors are reported
879 if( !numNeighbors )
880 {
881 *o_neighbors = NULL;
882 return 0;
883 }
884
885 // create and populate an array with neighbor node ids
886 uint8* neighbors = new uint8[numNeighbors];
887 uint32 index = 0;
888 for( int by=0; by<29; by++ )
889 {
890 for( int bi=0; bi<8; bi++ )
891 {
892 if( (m_neighbors[by] & ( 0x01<<bi ) ) )
893 neighbors[index++] = ( ( by<<3 ) + bi + 1 );
894 }
895 }
896
897 *o_neighbors = neighbors;
898 return numNeighbors;
899}
900
901//-----------------------------------------------------------------------------
902// <Node::ReadXML>

Callers 1

GetNodeNeighborsMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected