Applicable VersionsNetSim StandardNetSim Pro


Applicable Releasesv13v14


fprintf() statement can be used to print to NetSim console using the default file descriptor stderr

fprintf(stderr, "The value of the variable X is %d\n", X);

You may insert such a line at a suitable place. Note that NetSim is a discrete event simulator and hence you may see this line printed multiple times, each time that particular event (where the fprintf is written) is called.


Example 1: Printing remaining power of sensors in WSN


Note: The power source needs to be set to Battery to see the effect of this code change to see the impact.\


Inside fn_NetSim_Zigbee_ChangeRadioState() function present in ChangeRadioState.c file add following codes(highlighted in red):


bool fn_NetSim_Zigbee_ChangeRadioState(NETSIM_ID nDeviceId, PHY_TX_STATUS nOldState, PHY_TX_STATUS nNewState)
{
ptrIEEE802_15_4_PHY_VAR phy = WSN_PHY(nDeviceId);
ptrBATTERY battery = phy->battery;
bool isChange = true;
if (battery)
{
isChange = battery_set_mode(battery, nNewState, pstruEventDetails->dEventTime);

fprintf(stderr, "\nNode Name\tRemaining_Power \t Time\n");
fprintf(stderr, "\n%s\t%lf mW\t%lf ms\n\n",
NETWORK->ppstruDeviceList[nDeviceId - 1]->szDeviceName,
battery_get_remaining_energy(battery),
pstruEventDetails->dEventTime);
_getch();

}


  • Rebuild the Zigbee project, libZigbee.dll inside the binary folder of the current workspace will get modified.
  • Create a scenario in WSN and simulate.
  • During the simulation, user can see the remaining power of each node along printed to the simulation console along with the timestamp.


Example 2: Print node positions in MANET


Open Mobility Project, and in Mobility.c and go to fn_NetSim_Mobility_Run() function. Inside the default, case add the following codes


For NetSim  v13, v14:


case MOVE_GROUP:

    fn_NetSim_MoveGroup();

    break;

case NODE_JOIN:

    fn_NetSim_Mobility_NodeJoined();

    break;

case NODE_LEAVE:

    fn_NetSim_Mobility_NodeLeaved();

    break;

default:

{

    unsigned int nLoop;

    double X = NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId - 1]->pstruDeviceMobility->pstruCurrentPosition->X;

    double Y = NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId - 1]->pstruDeviceMobility->pstruCurrentPosition->Y;

    double vel = NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId - 1]->pstruDeviceMobility->dAvgSpeed;

    fprintf(stderr, "\n The position of %s at time %.2lfms is X=%.2lf and Y = %.2lf \n", DEVICE_NAME(pstruEventDetails->nDeviceId),

        pstruEventDetails->dEventTime,

        DEVICE_POSITION(pstruEventDetails->nDeviceId)->X,

        DEVICE_POSITION(pstruEventDetails->nDeviceId)->Y);

    _getch();


  • Rebuild Mobility project,libMobility.dll inside the binary folder of the current workspace will get modified.
  • Create a scenario in MANET and configure the mobility model of the nodes.
  • During the simulation, the user can notice that the positions of the nodes are displayed in the console w.r.t. the simulation time.