static void _Cellular_ProcessSocketState()

in sim70x0/cellular_sim70x0_urc_handler.c [782:875]


static void _Cellular_ProcessSocketState( CellularContext_t * pContext,
                                          char * pInputLine )
{
    /*Handling: +CASTATE: <cid>,<state> */
    char * pUrcStr = NULL;
    char * pToken = NULL;
    int32_t socketId, socketState;

    CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
    CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
    CellularSocketContext_t * pSocketData = NULL;

    if( ( pContext == NULL ) || ( pInputLine == NULL ) )
    {
        pktStatus = CELLULAR_PKT_STATUS_BAD_PARAM;
        goto err;
    }

    pUrcStr = pInputLine;
    atCoreStatus = Cellular_ATRemoveLeadingWhiteSpaces( &pUrcStr );

    if( atCoreStatus != CELLULAR_AT_SUCCESS )
    {
        goto err;
    }

    atCoreStatus = Cellular_ATGetNextTok( &pUrcStr, &pToken );

    if( atCoreStatus != CELLULAR_AT_SUCCESS )
    {
        goto err;
    }

    atCoreStatus = Cellular_ATStrtoi( pToken, 10, &socketId );

    if( atCoreStatus != CELLULAR_AT_SUCCESS )
    {
        goto err;
    }

    if( !IsValidCID( ( uint8_t ) socketId ) )
    {
        LogError( ( "Error in processing Socket Index. Token %s", pToken ) );
        atCoreStatus = CELLULAR_AT_ERROR;
        goto err;
    }

    pSocketData = _Cellular_GetSocketData( pContext, socketId );

    if( pSocketData == NULL )
    {
        LogError( ( "Error can't get Socket data. socketId=%d", socketId ) );
        atCoreStatus = CELLULAR_AT_ERROR;
        goto err;
    }

    atCoreStatus = Cellular_ATGetNextTok( &pUrcStr, &pToken );

    if( atCoreStatus != CELLULAR_AT_SUCCESS )
    {
        goto err;
    }

    atCoreStatus = Cellular_ATStrtoi( pToken, 10, &socketState );

    if( atCoreStatus != CELLULAR_AT_SUCCESS )
    {
        goto err;
    }

    /*
     *  0 Closed by remote server or internal error
     *  1 Connected to remote server
     *  2 Listening (server mode)
     */
    pSocketData->socketState = socketState == 0 ? SOCKETSTATE_DISCONNECTED : SOCKETSTATE_CONNECTED;
    LogDebug( ( "Socket %d. change state: %d", socketId, socketState ) );

    /* Indicate the upper layer about the socket close. */
    if( pSocketData->closedCallback != NULL )
    {
        pSocketData->closedCallback( pSocketData, pSocketData->pClosedCallbackContext );
    }
    else
    {
        LogInfo( ( "_parseSocketUrc: Socket close callback not set!!" ) );
    }

    return;

err:
    _Cellular_TranslateAtCoreStatus( atCoreStatus );
    LogDebug( ( "SocketStateInd process failure" ) );
}