Networking NetSim—传感器节点和各种代理之间的距离?

Networking NetSim—传感器节点和各种代理之间的距离?,networking,simulation,Networking,Simulation,在NetSim中,需要在何处以及添加什么代码来打印传感器感测到的各种传感器和代理之间的距离。您可以转到源代码NetSim\u Install\u Directory->src->simulation->Zigbee,并检查文件sensor.c,该文件完全符合您的要求。代码复制如下: _declspec(dllexport)int fn_NetSim_Zigbee_SensorEvent(int nSensorLoop,NETSIM_ID nGlobalPANCoordinatorId,AGENT

在NetSim中,需要在何处以及添加什么代码来打印传感器感测到的各种传感器和代理之间的距离。

您可以转到源代码NetSim\u Install\u 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;
}

本节将为您提供任何传感器和任何代理之间的距离。然后您可以将其打印到文件中。

谢谢您的回答。另外,您能告诉我如何在无线传感器网络模型中绘制每个传感器的能量与时间图吗?通过在NetSim中编写自定义代码,可以在无线传感器网络中获得能量与时间。在函数fn_NetSim_Zigbee_changereradiostate of file changereradiostate.c中,您可以编写一行,如fprintffp,%lf\t%lf\n,pstrueventdetDetails->dEventTime,pstruDevicePower[nDeviceId-1]->dRemainingPower;重新生成并将更新的DLL链接到NetSim。这将在文件中打印nDeviceID定义的传感器剩余功率后的时间。然后使用这些值,您可以在适当的电子表格程序中绘制图形。