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
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</tr>
<tr>
<td>cellular_3gpp_api.c</td>
<td><center>6.4K</center></td>
<td><center>6.5K</center></td>
<td><center>5.9K</center></td>
</tr>
<tr>
Expand Down Expand Up @@ -44,7 +44,7 @@
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>15.0K</center></b></td>
<td><b><center>15.1K</center></b></td>
<td><b><center>13.6K</center></b></td>
</tr>
</table>
26 changes: 18 additions & 8 deletions source/cellular_3gpp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1799,6 +1808,7 @@ CellularError_t Cellular_CommonGetRegisteredNetwork( CellularHandle_t cellularHa
}
else
{
memset( pOperatorInfo, 0, sizeof( cellularOperatorInfo_t ) );
cellularStatus = atcmdUpdateMccMnc( pContext, pOperatorInfo );
}

Expand Down
104 changes: 83 additions & 21 deletions test/unit-test/cellular_3gpp_api_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,24 @@ 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;
}
Expand Down Expand Up @@ -643,35 +656,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;
}
Expand Down Expand Up @@ -2016,6 +2040,44 @@ 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_PKT_STATUS_FAILURE );
_Cellular_TranslatePktStatus_ExpectAndReturn( CELLULAR_PKT_STATUS_FAILURE, 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.
*/
Expand Down