Get message " Failed to alloc rx size" when transfert data with WINC3400 over TCP

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I made an application allowing me to create a point access and once the connection was established, I set up a loop transfer of a sound signal made up of 100 samples at 8000 samples / second.
So I transfer 100 sample every 12.5ms.
During testing, for about 4 seconds, works perfectly. then i have the message below looping.
 
Have you ever had this type of message, if so how to resolve ?

(APP)(INFO)Failed to alloc rx size
(APP)(INFO)Failed to alloc rx size
(APP)(INFO)Failed to alloc rx size
(APP)(INFO)Failed to alloc rx size
socket_cb: recv error!

 

 

Thanks for your answers

 

Please, see belong the code testing. 

 

***********************************************************************

static void socket_cb(SOCKET sock, uint8_t u8Msg, void *pvMsg)
{
    
    printf("socket_cb ::::::: get (%d )!\r\n", u8Msg );
    switch (u8Msg) {
            
    /* Socket bind */
    case SOCKET_MSG_BIND:
    {
        tstrSocketBindMsg *pstrBind = (tstrSocketBindMsg *)pvMsg;
        if (pstrBind && pstrBind->status == 0) {
            //printf("socket_cb: bind success!\r\n");
            listen(tcp_server_socket, 0);
        } else {
            printf("socket_cb: bind error!\r\n");
            close(tcp_server_socket);
            tcp_server_socket = -1;
        }
    }
    break;

    /* Socket listen */
    case SOCKET_MSG_LISTEN:
    {
        tstrSocketListenMsg *pstrListen = (tstrSocketListenMsg *)pvMsg;
        if (pstrListen && pstrListen->status == 0) {
            //printf("socket_cb: listen success!\r\n");
            accept(tcp_server_socket, NULL, NULL);
        } else {
            printf("socket_cb: listen error!\r\n");
            close(tcp_server_socket);
            tcp_server_socket = -1;
        }
    }
    break;

    /* Connect accept */
    case SOCKET_MSG_ACCEPT:
    {
        tstrSocketAcceptMsg *pstrAccept = (tstrSocketAcceptMsg *)pvMsg;
        if (pstrAccept) {
        //    printf("socket_cb: accept success!\r\n");
            accept(tcp_server_socket, NULL, NULL);
            tcp_client_socket = pstrAccept->sock;
            tcp_connected = TCPIP_CONNECTED; 
            recv(tcp_client_socket, gau8SocketTestBuffer, sizeof(gau8SocketTestBuffer), 0);
        } else {
        //    printf("socket_cb: accept error!\r\n");
            close(tcp_server_socket);
            tcp_connected = TCPIP_DISCONNECTED; 
            tcp_server_socket = -1;
        }
    }
    break;

    /* Message send */
    case SOCKET_MSG_SEND:
    {

        tstrSocketRecvMsg *pstrRecv = (tstrSocketRecvMsg *)pvMsg;
        if (pstrRecv && pstrRecv->s16BufferSize > 0) {
            recv(tcp_client_socket, gau8SocketTestBuffer, sizeof(gau8SocketTestBuffer), 0);
        }
        
        //        printf("socket_cb: send success!\r\n");
        //        printf("TCP Server Test Complete!\r\n");
        //        printf("close socket\n");
                
    //    close(tcp_client_socket);
    //    close(tcp_server_socket);
    }
    break;

    /* Message receive */
    case SOCKET_MSG_RECV:
    {
        tstrSocketRecvMsg *pstrRecv = (tstrSocketRecvMsg *)pvMsg;
        if (pstrRecv && pstrRecv->s16BufferSize > 0) {
        //    printf("socket_cb: recv success!\r\n");
            tcp_connected = TCPIP_CONNECTED; 
            //send(tcp_client_socket, &msg_wifi_product, sizeof(t_msg_wifi_product), 0);
        } else {
            printf("socket_cb: recv error!\r\n");
            close(tcp_server_socket);
            tcp_connected = TCPIP_DISCONNECTED; 
            tcp_server_socket = -1;
        }
    }

    break;

    default:
        break;
    }
}

 

void load_data(void)
{
    int i ; 
    uint16_t freq = 1000;
    uint16_t samplerate = 8000;
    float measure[nsample],t; 
    
    for(i=0; i<nsample; i++) 
    {
            t = (float) i / samplerate;
            measure[i] = 1.4142*sin(freq*t*2*M_PI)*65535/5;
            samplebuffer[i] = (int16_t )measure[i];
    }
    
      PtrTcp = (uint8_t *)samplebuffer; 
}

/**
 * \brief Main application function.
 *
 * \return program return value.
 */
int main(void)
{
    tstrWifiInitParam param;
    tstrM2MAPConfig strM2MAPConfig;
    struct sockaddr_in addr;
    int8_t ret;
    

    /* Initialize the board. */
    sysclk_init();
    board_init();

    /* Initialize the UART console. */
    configure_console();
    printf(STRING_HEADER);

    /* Initialize the BSP. */
    nm_bsp_init();

    /* Initialize socket address structure. */
    addr.sin_family = AF_INET;
    addr.sin_port = _htons(MAIN_WIFI_M2M_SERVER_PORT);
    addr.sin_addr.s_addr = 0;
    
    /* Initialize Wi-Fi parameters structure. */
    memset((uint8_t *)&param, 0, sizeof(tstrWifiInitParam));

    /* Initialize Wi-Fi driver with data and status callbacks. */
    param.pfAppWifiCb = wifi_cb;
    ret = m2m_wifi_init(&param);
    if (M2M_SUCCESS != ret) {
        printf("main: m2m_wifi_init call error!(%d)\r\n", ret);
        while (1) {
        }
    }
  
       /* Initialize socket module */
    socketInit();
    registerSocketCallback(socket_cb, NULL);

   
    /* Initialize AP mode parameters structure with SSID, channel and OPEN security type. */
    memset(&strM2MAPConfig, 0x00, sizeof(tstrM2MAPConfig));
    strcpy((char *)&strM2MAPConfig.au8SSID, MAIN_WLAN_SSID);
    strM2MAPConfig.u8ListenChannel = MAIN_WLAN_CHANNEL;
    strM2MAPConfig.u8SecType = MAIN_WLAN_AUTH;

    strM2MAPConfig.au8DHCPServerIP[0] = 190;
    strM2MAPConfig.au8DHCPServerIP[1] = 170;
    strM2MAPConfig.au8DHCPServerIP[2] = 0;
    strM2MAPConfig.au8DHCPServerIP[3] = 1;

#if USE_WEP
    strcpy((char *)&strM2MAPConfig.au8WepKey, MAIN_WLAN_WEP_KEY);
    strM2MAPConfig.u8KeySz = strlen(MAIN_WLAN_WEP_KEY);
    strM2MAPConfig.u8KeyIndx = MAIN_WLAN_WEP_KEY_INDEX;
#endif

    /* Bring up AP mode with parameters structure. */
    ret = m2m_wifi_enable_ap(&strM2MAPConfig);
    if (M2M_SUCCESS != ret) {
        printf("main: m2m_wifi_enable_ap call error!\r\n");
        while (1) {
        }
    }

    printf("AP mode started. You can connect to %s.\r\n", (char *)MAIN_WLAN_SSID);
  
    while (1) {
        /* Handle pending events from network controller. */
        
         m2m_wifi_handle_events(NULL); 
         
         
         if(tcp_connected == TCPIP_CONNECTED )
         {
            LED_Toggle(LED0);
            
            load_data(); 
            
            //printf("  TCP connected   %d ! \r\n" , sizeof(samplebuffer));
            //send(tcp_client_socket, &msg_wifi_product, sizeof(t_msg_wifi_product), 0);
            send(tcp_client_socket, PtrTcp,sizeof(samplebuffer), 0);
            delay_ms(12);
            delay_us(500);
            //delay_ms(5000);
               
        }

        if (wifi_connected == M2M_WIFI_CONNECTED) {
            
            
            if (tcp_server_socket < 0) {
                /* Open TCP server socket */
                if ((tcp_server_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
                    printf("main: failed to create TCP server socket error!\r\n");
                    continue;
                }
                
                /* Bind service*/
                bind(tcp_server_socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in));
            }    
        }
    //    }
    }

    return 0;
}