在node.h里面找到了static Node* get_node_by_address(nsaddr_t);
MobileNode* pN=(MobileNode*)node->get_node_by_address(hdrcmn->prev_hop_);
cout<<"prev_hop address is "<<hdrcmn->prev_hop_<<",";
if(pN)
cout<<"and get node point"<<endl;
else
cout<<"but get node point failed."<<endl;
pN->update_position();
double dist=node->distance(pN);
cout<<"Distance between me and my previous hop is "<<dist<<endl;
在 ns2中取得 node position 與 speed 的方法,
可使用 getLoc()函數、getVelo(),speed()函數
函式的定義是在:/common/mobilenode.h
所以使用時記得 include這個標頭檔。
(1)取得節點座標
使用MobileNode 類別內的 getLoc() 函數:
double x = 0.0, y = 0.0, z = 0.0; //傳入三變數
Node *thisnode; // 宣告指標
thisnode = Node::get_node_by_address(index);
((MobileNode *)thisnode)->getLoc(&x, &y, &z);
(2)取得節點速度
使用MobileNode 類別內的 getVelo() 函數,用法同上:
double x = 0.0, y = 0.0, z = 0.0; //傳入三變數
Node *thisnode; // 宣告指標
thisnode = Node::get_node_by_address(index);
((MobileNode *)thisnode)->getVelo(&x, &y, &z);
或者使用 speed()函數
Node *thisnode; // 宣告指標
double [...]
cout<<"prev_hop address is "<<hdrcmn->prev_hop_<<",";
if(pN)
cout<<"and get node point"<<endl;
else
cout<<"but get node point failed."<<endl;
pN->update_position();
double dist=node->distance(pN);
cout<<"Distance between me and my previous hop is "<<dist<<endl;
在 ns2中取得 node position 與 speed 的方法,
可使用 getLoc()函數、getVelo(),speed()函數
函式的定義是在:/common/mobilenode.h
所以使用時記得 include這個標頭檔。
(1)取得節點座標
使用MobileNode 類別內的 getLoc() 函數:
double x = 0.0, y = 0.0, z = 0.0; //傳入三變數
Node *thisnode; // 宣告指標
thisnode = Node::get_node_by_address(index);
((MobileNode *)thisnode)->getLoc(&x, &y, &z);
(2)取得節點速度
使用MobileNode 類別內的 getVelo() 函數,用法同上:
double x = 0.0, y = 0.0, z = 0.0; //傳入三變數
Node *thisnode; // 宣告指標
thisnode = Node::get_node_by_address(index);
((MobileNode *)thisnode)->getVelo(&x, &y, &z);
或者使用 speed()函數
Node *thisnode; // 宣告指標
double [...]