2014-11-06 53 views

回答

0

你可以去源代碼(NetSim_Install_Directory - > src - > simulation - > Zigbee)並檢查文件sensor.c,它正是你所要求的。代碼複製如下 -

_declspec(dllexport)int fn_NetSim_Zigbee_SensorEvent(int nSensorLoop,NETSIM_ID nGlobalPANCoordinatorId,AGENT** pstruAgent,SENSORS* pstru_Sensor,METRICS** pstruMetrics,NetSim_EVENTDETAILS* pstruEventDetails,IEEE802_15_4_PRIMITIVES *pstruIEEE802_15_4_Primitives) 
{ 

....... 
..... 
pstruTemppos->dXPos = NETWORK->ppstruDeviceList[nSensorLoop-1]->pstruDevicePosition->X; 
     pstruTemppos->dYPos = NETWORK->ppstruDeviceList[nSensorLoop-1]->pstruDevicePosition->Y; 
     dDistance = fn_Sensor_CalculateDistance(pstruTemppos,pstruPos); 
.... 
.... 
} 

/** This function is used to find the distance between the Agent and the Sensor. */ 
double fn_Sensor_CalculateDistance(POS_2D* pstruPos1, POS_2D* pstruPos2) 
{ 
    double dDistance; 
    if(pstruPos1 == NULL || pstruPos2 == NULL) 
     return 0; 

    dDistance = (pstruPos1->dXPos - pstruPos2->dXPos)*(pstruPos1->dXPos - pstruPos2->dXPos); 
    dDistance += (pstruPos1->dYPos - pstruPos2->dYPos)*(pstruPos1->dYPos - pstruPos2->dYPos); 
    dDistance = sqrt(dDistance); 
    return dDistance; 
} 

本節將給你任何傳感器和任何代理之間的距離。然後您可以將其打印到文件中。

+0

謝謝你的回答。 也可以請讓我知道如何繪製無線傳感器網絡模型中每個傳感器的能量與時間關係圖 – 2014-11-07 05:20:19

+0

通過在NetSim中編寫自定義代碼,可以在WSN中獲取能量與時間的關係。 在文件ChangeRadioState.c的功能fn_NetSim_Zigbee_ChangeRadioState 你可以寫像 fprintf中的線(FP, 「%LF \噸%LF \ n」 個,pstruEventDetails-> dEventTime,pstruDevicePower [nDeviceId-1] - > dRemainingPower) ; 重建並鏈接更新後的DLL到NetSim。這將在文件中打印由nDeviceID定義的傳感器的剩餘電量。然後使用這些值,您可以在合適的電子表格程序中繪製圖表。 – 2014-11-08 04:14:51