Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set to numeric format in atcmdUpdateMccMnc #161

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Set to numeric format in 3GPP atcmdUpdateMccMnc
chinglee-iot committed Dec 26, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit be5c61ce9983628d33b39b589a45905d61f3bf98
26 changes: 18 additions & 8 deletions source/cellular_3gpp_api.c
Original file line number Diff line number Diff line change
@@ -1416,16 +1416,25 @@ static CellularError_t atcmdUpdateMccMnc( CellularContext_t * pContext,
{
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularPktStatus_t pktStatus;
CellularAtReq_t atReqGetMccMnc = { 0 };
CellularAtReq_t atCopsRequest = { 0 };

atReqGetMccMnc.pAtCmd = "AT+COPS?";
atReqGetMccMnc.atCmdType = CELLULAR_AT_WITH_PREFIX;
atReqGetMccMnc.pAtRspPrefix = "+COPS";
atReqGetMccMnc.respCallback = _Cellular_RecvFuncUpdateMccMnc;
atReqGetMccMnc.pData = pOperatorInfo;
atReqGetMccMnc.dataLen = ( uint16_t ) sizeof( cellularOperatorInfo_t );
/* Set the response to numeric format. */
atCopsRequest.pAtCmd = "AT+COPS=3,2",
atCopsRequest.atCmdType = CELLULAR_AT_NO_RESULT,
pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atCopsRequest );

if( pktStatus == CELLULAR_PKT_STATUS_OK )
{
/* Acquire the MCC and MNC information. */
atCopsRequest.pAtCmd = "AT+COPS?";
atCopsRequest.atCmdType = CELLULAR_AT_WITH_PREFIX;
atCopsRequest.pAtRspPrefix = "+COPS";
atCopsRequest.respCallback = _Cellular_RecvFuncUpdateMccMnc;
atCopsRequest.pData = pOperatorInfo;
atCopsRequest.dataLen = ( uint16_t ) sizeof( cellularOperatorInfo_t );
pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atCopsRequest );
}

pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atReqGetMccMnc );
cellularStatus = _Cellular_TranslatePktStatus( pktStatus );

return cellularStatus;
@@ -1799,6 +1808,7 @@ CellularError_t Cellular_CommonGetRegisteredNetwork( CellularHandle_t cellularHa
}
else
{
memset( pOperatorInfo, 0, sizeof( cellularOperatorInfo_t ) );
cellularStatus = atcmdUpdateMccMnc( pContext, pOperatorInfo );
}

103 changes: 81 additions & 22 deletions test/unit-test/cellular_3gpp_api_utest.c
Original file line number Diff line number Diff line change
@@ -194,11 +194,23 @@ CellularPktStatus_t Mock_AtcmdRequestWithCallback( CellularContext_t * pContext,
CellularAtReq_t atReq,
int cmock_num_calls )
{
cellularOperatorInfo_t * pOperatorInfo = ( cellularOperatorInfo_t * ) atReq.pData;

cellularOperatorInfo_t * pOperatorInfo;
( void ) pContext;
( void ) cmock_num_calls;
pOperatorInfo->rat = CELLULAR_RAT_INVALID;

if( cmock_num_calls == 0 )
{
/* AT+COPS=3,2 call. */
}
else if( cmock_num_calls == 1 )
{
/* AT+COPS? call. */
pOperatorInfo = ( cellularOperatorInfo_t * ) atReq.pData;
pOperatorInfo->rat = CELLULAR_RAT_INVALID;
}
else
{
TEST_FAIL_MESSAGE( "Unexpected Mock_AtcmdRequestWithCallback call" );
}

return CELLULAR_PKT_STATUS_OK;
}
@@ -643,35 +655,46 @@ CellularPktStatus_t Mock_AtcmdRequestWithCallback__Cellular_RecvFuncUpdateMccMnc
CellularATCommandResponse_t atResp;
cellularOperatorInfo_t cellularOperatorInfo;

( void ) cmock_num_calls;
memset( &atResp, 0, sizeof( CellularATCommandResponse_t ) );
memset( &cellularOperatorInfo, 0, sizeof( cellularOperatorInfo_t ) );

if( cbCondition < 3 )
if( cmock_num_calls == 0 )
{
pktStatus = handleCommonCallback( pContext, atReq );
/* AT+COPS=3,2 call. */
}
else if( cbCondition == 3 )
else if( cmock_num_calls == 1 )
{
char pLine[] = CELLULAR_SAMPLE_PREFIX_STRING_INPUT;

_saveData( pLine, &atResp, strlen( pLine ) + 1 );

if( parseNetworkNameFailureCase == 2 )
{
cellularOperatorInfo.operatorNameFormat = OPERATOR_NAME_FORMAT_LONG;
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
}
else if( parseNetworkNameFailureCase == 3 )
/* AT+COPS? call. */
if( cbCondition < 3 )
{
cellularOperatorInfo.operatorNameFormat = OPERATOR_NAME_FORMAT_NUMERIC;
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
pktStatus = handleCommonCallback( pContext, atReq );
}
else
else if( cbCondition == 3 )
{
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
char pLine[] = CELLULAR_SAMPLE_PREFIX_STRING_INPUT;

_saveData( pLine, &atResp, strlen( pLine ) + 1 );

if( parseNetworkNameFailureCase == 2 )
{
cellularOperatorInfo.operatorNameFormat = OPERATOR_NAME_FORMAT_LONG;
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
}
else if( parseNetworkNameFailureCase == 3 )
{
cellularOperatorInfo.operatorNameFormat = OPERATOR_NAME_FORMAT_NUMERIC;
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
}
else
{
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
}
}
}
else
{
TEST_FAIL_MESSAGE( "Unexpected Mock_AtcmdRequestWithCallback call" );
}

return pktStatus;
}
@@ -2016,6 +2039,42 @@ void test_Cellular_CommonGetRegisteredNetwork_No_Memory( void )
TEST_ASSERT_EQUAL( CELLULAR_NO_MEMORY, cellularStatus );
}

/**
* @brief Test that set to numeric format failed.
*
* <b>Coverage</b>
* @code{c}
* static CellularError_t atcmdUpdateMccMnc( CellularContext_t * pContext,
* cellularOperatorInfo_t * pOperatorInfo )
* {
* ...
* atCopsRequest.pAtCmd = "AT+COPS=3,2",
* atCopsRequest.atCmdType = CELLULAR_AT_NO_RESULT,
* pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atCopsRequest );
*
* if( pktStatus == CELLULAR_PKT_STATUS_OK )
* {
* ...
* }
* }
* @endcode
* ( pktStatus == CELLULAR_PKT_STATUS_OK ) is false.
*/
void test_Cellular_CommonGetRegisteredNetwork_Set_Numeric_Format_Fail( void )
{
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularContext_t context;

memset( &context, 0, sizeof( CellularContext_t ) );
CellularHandle_t cellularHandle = &context;
CellularPlmnInfo_t networkInfo;

_Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS );
_Cellular_AtcmdRequestWithCallback_IgnoreAndReturn( CELLULAR_INTERNAL_FAILURE );
cellularStatus = Cellular_CommonGetRegisteredNetwork( cellularHandle, &networkInfo );
TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus );
}

/**
* @brief Test that invalid rat case Cellular_CommonGetRegisteredNetwork to return CELLULAR_UNKNOWN.
*/