Tool/software:
Dear Team,
I want to implement client server integration on AM2634 eval board,
currently i'm using mcu_plus_sdk_am263x_09_02_00_56 and enet_cpsw_rawhttpserver as base source code for client implementation,
/-------------------------------------- Base source code --------------------------------/
while (false == App_isNetworkUp(netif_default))
{
//DebugP_log("Waiting for network UP ...\r\n");
sys_check_timeouts();
const uint32_t recvdEventsMask = App_receiveEvents(&hEvent);
if (recvdEventsMask != AppEventId_NONE)
{
App_handleEvent(recvdEventsMask);
}
}
DebugP_log("Network is UP ...\r\n");
ClockP_sleep(1);
// AppTcp_startServer();
// tcpecho_raw_init();
// httpd_init(); // base http app not used, because its client integration
app_altcp(); // my client base function this function is define at the last
while (1)
{
sys_check_timeouts();
ClockP_usleep(1000);
const uint32_t recvdEventsMask = App_receiveEvents(&hEvent);
if (recvdEventsMask != AppEventId_NONE)
{
App_handleEvent(recvdEventsMask);
}
}
App_shutdownNetworkStack();
EnetApp_driverDeInit();
EventP_destruct(&hEvent);
return 0;
}
/------------------ Rest of source code is same as in existing example--------------/
void app_altcp()
{
uint8_t status;
ip_addr_t myIPaddr;
IP_ADDR4(&myIPaddr, 192, 168, 1, 200);
ip_addr_t DestIPaddr;
IP_ADDR4(&DestIPaddr, 192, 168, 1, 2);
pcb_altcp = altcp_new(altcpblock);
altcp_bind(pcb_altcp, &myIPaddr, 2024); // bind with ip and port
status = altcp_connect(pcb_altcp, &DestIPaddr, app_port, connected);
if(status == 0)
{
DebugP_log("connect =%d \r\n", status);
}
else
{
altcp_close(pcb_altcp);
}
}
void connected(void *arg, struct altcp_pcb *conn, err_t err)
{
uint8_t dataptr[14] = "Hello Ethernet";
uint8_t apiflags;
DebugP_log("Connected data ...\r\n");
altcp_write(pcb_altcp, dataptr, 14, TCP_WRITE_FLAG_COPY);
altcp_recv(pcb_altcp, recved);
}
void recved(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err)
{
static int k;
if ((err != ERR_OK) || (p != NULL) )
{
/* error or closed by other side? */
if (p != NULL)
{
k++;
/* Inform TCP that we have taken the data. */
altcp_recved(conn, p->tot_len);
strncpy(buffer, (char*) p->payload, p->len);
DebugP_log("buffer = %s %d\r\n", buffer, k);
pbuf_free(p);
}
else
{
pbuf_free(p);
}
}
}
In above code I'm able to connect with server and sending data to server but problem is in receiving
in receiving Data is copy from p->payload to buffer after that its coming in this function mutiple times and pbuf_free try to free the allocated memory but its crash the code.
kindly check what wrong in this, I thing some issue in
const uint32_t recvdEventsMask = App_receiveEvents(&hEvent);
if (recvdEventsMask != AppEventId_NONE)
{
App_handleEvent(recvdEventsMask);
please guide me how to solve this problem