Applicable Versions | NetSim Standard | NetSim Pro |
Applicable Releases | v12 | v13 |
Perform the code changes explained below to add a single character to the COAP response payload and print it at the receiver side(Changes highlighted in red):
1. In the function fn_NetSim_Add_DummyPayload() in the Application.c file of Application project, modify the if condition as shown below:
if(!packet->szPayload &&
packet->pstruAppData &&
packet->pstruAppData->dPacketSize &&
packet->pstruAppData->nAppType != TRAFFIC_EMULATION) /* Don't set payload in emulation */ //&&
//wireshark_flag)
packet->pstruAppData &&
packet->pstruAppData->dPacketSize &&
packet->pstruAppData->nAppType != TRAFFIC_EMULATION) /* Don't set payload in emulation */ //&&
//wireshark_flag)
2. In copy_payload function under Application.c i.e adding character X for every response packet.
void copy_payload(UINT8 real[],NetSim_PACKET* packet,unsigned int* payload,APP_INFO* info)
{
u_short i;
uint32_t key = 16;
if (payload)
{
if (packet->nControlDataType == packet_COAP_REQUEST)
real[0] = 'X';
else
{
for (i = 0; i < *payload; i++)
{
-----------------
{
u_short i;
uint32_t key = 16;
if (payload)
{
if (packet->nControlDataType == packet_COAP_REQUEST)
real[0] = 'X';
else
{
for (i = 0; i < *payload; i++)
{
-----------------
-------------
}
}
}
3. To read and print it on the receiver side, go to Application IN Event of Appplcaion run function under Application.c file of the application project.
}
}
}
3. To read and print it on the receiver side, go to Application IN Event of Appplcaion run function under Application.c file of the application project.
else if (pstruPacket->nControlDataType == packet_COAP_REQUEST)
{
APP_INFO* pstruappinfo;
fnValidatePacket(pstruPacket);
pstruappinfo = appInfo[pstruPacket->pstruAppData->nApplicationId - 1];
pstruPacket->pstruAppData->dEndTime = pstruEventDetails->dEventTime;
//On receiving COAP Packet
if(strcmp(pstruPacket->szPacketType,"COAP_RESPONSE"))
fprintf(stderr,"COAP_RESPONSE Payload:%c\n", pstruPacket->szPayload->packet[0]);
{
APP_INFO* pstruappinfo;
fnValidatePacket(pstruPacket);
pstruappinfo = appInfo[pstruPacket->pstruAppData->nApplicationId - 1];
pstruPacket->pstruAppData->dEndTime = pstruEventDetails->dEventTime;
//On receiving COAP Packet
if(strcmp(pstruPacket->szPacketType,"COAP_RESPONSE"))
fprintf(stderr,"COAP_RESPONSE Payload:%c\n", pstruPacket->szPayload->packet[0]);
appmetrics_dest_add(pstruappinfo, pstruPacket, pstruEventDetails->nDeviceId);
fn_NetSim_Application_Plot(pstruPacket);
fn_NetSim_Application_COAP_AppIn(pstruappinfo, pstruPacket);
//Delete the packet
fn_NetSim_Packet_FreePacket(pstruPacket);
}
Related Articles:
how-do-i-change-the-payload-of-a-packet-in-netsim-
wireless-body-area-network-wban-application-reading-sensor-measurements-from-a-csv-xl-file