CellularError_t Cellular_ModuleEnableUE()

in sim70x0/cellular_sim70x0.c [285:419]


CellularError_t Cellular_ModuleEnableUE( CellularContext_t * pContext )
{
    CellularError_t cellularStatus = CELLULAR_SUCCESS;
    CellularAtReq_t atReqGetNoResult =
    {
        NULL,
        CELLULAR_AT_NO_RESULT,
        NULL,
        NULL,
        NULL,
        0
    };
    CellularAtReq_t atReqGetWithResult =
    {
        NULL,
        CELLULAR_AT_MULTI_WO_PREFIX,
        NULL,
        NULL,
        NULL,
        0
    };

    if( pContext == NULL )
    {
        return CELLULAR_INVALID_HANDLE;
    }

    /* Disable echo. */
    atReqGetWithResult.pAtCmd = "ATE0";
    cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetWithResult );

    if( cellularStatus != CELLULAR_SUCCESS )
    {
        return cellularStatus;
    }

    /* Disable DTR function. */
    atReqGetNoResult.pAtCmd = "AT&D0";
    cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetNoResult );

    if( cellularStatus != CELLULAR_SUCCESS )
    {
        return cellularStatus;
    }

    /* Enable RTS/CTS hardware flow control. */
    atReqGetNoResult.pAtCmd = "AT+IFC=2,2";
    cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetNoResult );

    if( cellularStatus != CELLULAR_SUCCESS )
    {
        return cellularStatus;
    }

    /* Configure Band configuration to all Cat-M1 bands. */
    atReqGetNoResult.pAtCmd = "AT+CBANDCFG=\"CAT-M\",1,3,8,18,19,26"; /*for Japan     */
    cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetNoResult );

    if( cellularStatus != CELLULAR_SUCCESS )
    {
        return cellularStatus;
    }

    /* Configure Band configuration to all NB-IOT bands. */
    atReqGetNoResult.pAtCmd = "AT+CBANDCFG=\"NB-IOT\",1,3,8,18,19,26"; /*for Japan    */
    cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetNoResult );

    if( cellularStatus != CELLULAR_SUCCESS )
    {
        return cellularStatus;
    }

    /* Configure RAT(s) to be Searched to Automatic. */
    atReqGetNoResult.pAtCmd = "AT+CNMP=2";
    cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetNoResult );

    if( cellularStatus != CELLULAR_SUCCESS )
    {
        return cellularStatus;
    }

    /* Configure Network Category to be Searched under LTE  */
    atReqGetNoResult.pAtCmd = "AT+CNMP=38"; /*Only LTE, no GSM support  */
    cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetNoResult );

    if( cellularStatus != CELLULAR_SUCCESS )
    {
        return cellularStatus;
    }

    /* Configure RAT Searching Sequence to default radio access technology. */
    switch( CELLULAR_CONFIG_DEFAULT_RAT )
    {
        case CELLULAR_RAT_CATM1:
            atReqGetNoResult.pAtCmd = "AT+CMNB=1";
            break;

        case CELLULAR_RAT_NBIOT:
            atReqGetNoResult.pAtCmd = "AT+CMNB=2";
            break;

        case CELLULAR_RAT_GSM:
            atReqGetNoResult.pAtCmd = "AT+CNMP=13";
            break;

        default:
            /* Configure RAT Searching Sequence to automatic. */
            atReqGetNoResult.pAtCmd = "AT+CMNB=3";
            break;
    }

    cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetNoResult );

    if( cellularStatus != CELLULAR_SUCCESS )
    {
        return cellularStatus;
    }

    atReqGetNoResult.pAtCmd = "AT+CFUN=1";
    cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetNoResult );

    atReqGetWithResult.pAtCmd = "AT+CACID=?";
    atReqGetWithResult.pAtRspPrefix = "+CACID";
    atReqGetWithResult.atCmdType = CELLULAR_AT_WITH_PREFIX;
    atReqGetWithResult.respCallback = set_CID_range_cb;
    cellularStatus = _Cellular_AtcmdRequestWithCallback( pContext, atReqGetWithResult );

    atReqGetWithResult.pAtCmd = "AT+CNACT=?";
    atReqGetWithResult.pAtRspPrefix = "+CNACT";
    atReqGetWithResult.atCmdType = CELLULAR_AT_WITH_PREFIX;
    atReqGetWithResult.respCallback = set_PDP_range_cb;
    cellularStatus = _Cellular_AtcmdRequestWithCallback( pContext, atReqGetWithResult );

    return cellularStatus;
}