Applicable VersionsNetSim StandardNetSim Pro

Applicable Releases
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 */ //&&

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';


            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.
else if (pstruPacket->nControlDataType == packet_COAP_REQUEST)
                APP_INFO* pstruappinfo;
                pstruappinfo = appInfo[pstruPacket->pstruAppData->nApplicationId - 1];
                pstruPacket->pstruAppData->dEndTime = pstruEventDetails->dEventTime;
                //On receiving COAP Packet
                fprintf(stderr,"COAP_RESPONSE Payload:%c\n", pstruPacket->szPayload->packet[0]);

                appmetrics_dest_add(pstruappinfo, pstruPacket, pstruEventDetails->nDeviceId);
                fn_NetSim_Application_COAP_AppIn(pstruappinfo, pstruPacket);
                //Delete the packet

Related Articles: