in source/cellular/qgsm/cellular_setup_qgsm.c [80:234]
bool setupCellular( void )
{
bool cellularRet = true;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularSimCardStatus_t simStatus = { 0 };
CellularServiceStatus_t serviceStatus = { 0 };
CellularCommInterface_t * pCommIntf = &CellularCommInterface;
uint8_t tries = 0;
CellularPdnConfig_t pdnConfig = { CELLULAR_PDN_CONTEXT_IPV4, CELLULAR_PDN_AUTH_NONE, CELLULAR_APN, "", "" };
char localIP[ CELLULAR_IP_ADDRESS_MAX_SIZE ] = { '\0' };
uint32_t timeoutCountLimit = ( CELLULAR_PDN_CONNECT_TIMEOUT / CELLULAR_PDN_CONNECT_WAIT_INTERVAL_MS ) + 1U;
uint32_t timeoutCount = 0;
/* Initialize Cellular Comm Interface. */
cellularStatus = Cellular_Init( &CellularHandle, pCommIntf );
if( cellularStatus != CELLULAR_SUCCESS )
{
configPRINTF( ( ">>> Cellular_Init failure %d <<<\r\n", cellularStatus ) );
}
else
{
/* wait until SIM is ready */
for( tries = 0; tries < CELLULAR_MAX_SIM_RETRY; tries++ )
{
cellularStatus = Cellular_GetSimCardStatus( CellularHandle, &simStatus );
if( ( cellularStatus == CELLULAR_SUCCESS ) &&
( ( simStatus.simCardState == CELLULAR_SIM_CARD_INSERTED ) &&
( simStatus.simCardLockState == CELLULAR_SIM_CARD_READY ) ) )
{
configPRINTF( ( ">>> Cellular SIM okay <<<\r\n" ) );
break;
}
else
{
configPRINTF( ( ">>> Cellular SIM card state %d, Lock State %d <<<\r\n",
simStatus.simCardState,
simStatus.simCardLockState ) );
}
vTaskDelay( pdMS_TO_TICKS( CELLULAR_SIM_CARD_WAIT_INTERVAL_MS ) );
}
if( cellularStatus != CELLULAR_SUCCESS )
{
configPRINTF( ( ">>> Cellular SIM failure <<<\r\n" ) );
}
}
/* Setup the PDN config. */
if( cellularStatus == CELLULAR_SUCCESS )
{
cellularStatus = Cellular_SetPdnConfig( CellularHandle, CellularSocketPdnContextId, &pdnConfig );
if( cellularStatus != CELLULAR_SUCCESS )
{
configPRINTF( ( ">>> Cellular_SetPdnConfig failure %d <<<\r\n", cellularStatus ) );
}
}
/* Rescan network. */
if( cellularStatus == CELLULAR_SUCCESS )
{
cellularStatus = Cellular_RfOff( CellularHandle );
if( cellularStatus != CELLULAR_SUCCESS )
{
configPRINTF( ( ">>> Cellular_RfOff failure %d <<<\r\n", cellularStatus ) );
}
}
if( cellularStatus == CELLULAR_SUCCESS )
{
cellularStatus = Cellular_RfOn( CellularHandle );
if( cellularStatus != CELLULAR_SUCCESS )
{
configPRINTF( ( ">>> Cellular_RfOn failure %d <<<\r\n", cellularStatus ) );
}
}
/* Get service status. */
if( cellularStatus == CELLULAR_SUCCESS )
{
while( timeoutCount < timeoutCountLimit )
{
cellularStatus = Cellular_GetServiceStatus( CellularHandle, &serviceStatus );
if( ( cellularStatus == CELLULAR_SUCCESS ) &&
( ( serviceStatus.psRegistrationStatus == REGISTRATION_STATUS_REGISTERED_HOME ) ||
( serviceStatus.psRegistrationStatus == REGISTRATION_STATUS_ROAMING_REGISTERED ) ) )
{
configPRINTF( ( ">>> Cellular module registered <<<\r\n" ) );
break;
}
else
{
configPRINTF( ( ">>> Cellular GetServiceStatus failed %d, ps registration status %d <<<\r\n",
cellularStatus, serviceStatus.psRegistrationStatus ) );
}
timeoutCount++;
if( timeoutCount >= timeoutCountLimit )
{
configPRINTF( ( ">>> Cellular module can't be registered <<<\r\n" ) );
}
vTaskDelay( pdMS_TO_TICKS( CELLULAR_PDN_CONNECT_WAIT_INTERVAL_MS ) );
}
}
if( cellularStatus == CELLULAR_SUCCESS )
{
cellularStatus = Cellular_StartTCPIP( CellularHandle );
if( cellularStatus != CELLULAR_SUCCESS )
{
configPRINTF( ( ">>> Cellular_StartTCPIP failure %d <<<\r\n", cellularStatus ) );
}
}
if( cellularStatus == CELLULAR_SUCCESS )
{
cellularStatus = Cellular_ActivatePdn( CellularHandle, CellularSocketPdnContextId );
if( cellularStatus != CELLULAR_SUCCESS )
{
configPRINTF( ( ">>> Cellular_ActivatePdn failure %d <<<\r\n", cellularStatus ) );
}
}
if( cellularStatus == CELLULAR_SUCCESS )
{
cellularStatus = Cellular_GetIPAddress( CellularHandle, CellularSocketPdnContextId, localIP, sizeof( localIP ) );
if( cellularStatus != CELLULAR_SUCCESS )
{
configPRINTF( ( ">>> Cellular_GetIPAddress failure %d <<<\r\n", cellularStatus ) );
}
}
if (cellularStatus == CELLULAR_SUCCESS)
{
configPRINTF( ( ">>> Cellular module registered, IP address %s <<<\r\n", localIP ) );
cellularRet = true;
}
else
{
cellularRet = false;
}
return cellularRet;
}