Skip to content

Commit 9b939eb

Browse files
authored
Set to numeric format in atcmdUpdateMccMnc (#161)
* Set to numeric format in 3GPP atcmdUpdateMccMnc * Fix format and unit test * Update size_table
1 parent 4675955 commit 9b939eb

File tree

3 files changed

+103
-31
lines changed

3 files changed

+103
-31
lines changed

docs/doxygen/include/size_table.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</tr>
1010
<tr>
1111
<td>cellular_3gpp_api.c</td>
12-
<td><center>6.4K</center></td>
12+
<td><center>6.5K</center></td>
1313
<td><center>5.9K</center></td>
1414
</tr>
1515
<tr>
@@ -44,7 +44,7 @@
4444
</tr>
4545
<tr>
4646
<td><b>Total estimates</b></td>
47-
<td><b><center>15.0K</center></b></td>
47+
<td><b><center>15.1K</center></b></td>
4848
<td><b><center>13.6K</center></b></td>
4949
</tr>
5050
</table>

source/cellular_3gpp_api.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,16 +1416,25 @@ static CellularError_t atcmdUpdateMccMnc( CellularContext_t * pContext,
14161416
{
14171417
CellularError_t cellularStatus = CELLULAR_SUCCESS;
14181418
CellularPktStatus_t pktStatus;
1419-
CellularAtReq_t atReqGetMccMnc = { 0 };
1419+
CellularAtReq_t atCopsRequest = { 0 };
14201420

1421-
atReqGetMccMnc.pAtCmd = "AT+COPS?";
1422-
atReqGetMccMnc.atCmdType = CELLULAR_AT_WITH_PREFIX;
1423-
atReqGetMccMnc.pAtRspPrefix = "+COPS";
1424-
atReqGetMccMnc.respCallback = _Cellular_RecvFuncUpdateMccMnc;
1425-
atReqGetMccMnc.pData = pOperatorInfo;
1426-
atReqGetMccMnc.dataLen = ( uint16_t ) sizeof( cellularOperatorInfo_t );
1421+
/* Set the response to numeric format. */
1422+
atCopsRequest.pAtCmd = "AT+COPS=3,2",
1423+
atCopsRequest.atCmdType = CELLULAR_AT_NO_RESULT,
1424+
pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atCopsRequest );
1425+
1426+
if( pktStatus == CELLULAR_PKT_STATUS_OK )
1427+
{
1428+
/* Acquire the MCC and MNC information. */
1429+
atCopsRequest.pAtCmd = "AT+COPS?";
1430+
atCopsRequest.atCmdType = CELLULAR_AT_WITH_PREFIX;
1431+
atCopsRequest.pAtRspPrefix = "+COPS";
1432+
atCopsRequest.respCallback = _Cellular_RecvFuncUpdateMccMnc;
1433+
atCopsRequest.pData = pOperatorInfo;
1434+
atCopsRequest.dataLen = ( uint16_t ) sizeof( cellularOperatorInfo_t );
1435+
pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atCopsRequest );
1436+
}
14271437

1428-
pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atReqGetMccMnc );
14291438
cellularStatus = _Cellular_TranslatePktStatus( pktStatus );
14301439

14311440
return cellularStatus;
@@ -1799,6 +1808,7 @@ CellularError_t Cellular_CommonGetRegisteredNetwork( CellularHandle_t cellularHa
17991808
}
18001809
else
18011810
{
1811+
memset( pOperatorInfo, 0, sizeof( cellularOperatorInfo_t ) );
18021812
cellularStatus = atcmdUpdateMccMnc( pContext, pOperatorInfo );
18031813
}
18041814

test/unit-test/cellular_3gpp_api_utest.c

Lines changed: 83 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,24 @@ CellularPktStatus_t Mock_AtcmdRequestWithCallback( CellularContext_t * pContext,
194194
CellularAtReq_t atReq,
195195
int cmock_num_calls )
196196
{
197-
cellularOperatorInfo_t * pOperatorInfo = ( cellularOperatorInfo_t * ) atReq.pData;
197+
cellularOperatorInfo_t * pOperatorInfo;
198198

199199
( void ) pContext;
200-
( void ) cmock_num_calls;
201-
pOperatorInfo->rat = CELLULAR_RAT_INVALID;
200+
201+
if( cmock_num_calls == 0 )
202+
{
203+
/* AT+COPS=3,2 call. */
204+
}
205+
else if( cmock_num_calls == 1 )
206+
{
207+
/* AT+COPS? call. */
208+
pOperatorInfo = ( cellularOperatorInfo_t * ) atReq.pData;
209+
pOperatorInfo->rat = CELLULAR_RAT_INVALID;
210+
}
211+
else
212+
{
213+
TEST_FAIL_MESSAGE( "Unexpected Mock_AtcmdRequestWithCallback call" );
214+
}
202215

203216
return CELLULAR_PKT_STATUS_OK;
204217
}
@@ -643,35 +656,46 @@ CellularPktStatus_t Mock_AtcmdRequestWithCallback__Cellular_RecvFuncUpdateMccMnc
643656
CellularATCommandResponse_t atResp;
644657
cellularOperatorInfo_t cellularOperatorInfo;
645658

646-
( void ) cmock_num_calls;
647659
memset( &atResp, 0, sizeof( CellularATCommandResponse_t ) );
648660
memset( &cellularOperatorInfo, 0, sizeof( cellularOperatorInfo_t ) );
649661

650-
if( cbCondition < 3 )
662+
if( cmock_num_calls == 0 )
651663
{
652-
pktStatus = handleCommonCallback( pContext, atReq );
664+
/* AT+COPS=3,2 call. */
653665
}
654-
else if( cbCondition == 3 )
666+
else if( cmock_num_calls == 1 )
655667
{
656-
char pLine[] = CELLULAR_SAMPLE_PREFIX_STRING_INPUT;
657-
658-
_saveData( pLine, &atResp, strlen( pLine ) + 1 );
659-
660-
if( parseNetworkNameFailureCase == 2 )
661-
{
662-
cellularOperatorInfo.operatorNameFormat = OPERATOR_NAME_FORMAT_LONG;
663-
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
664-
}
665-
else if( parseNetworkNameFailureCase == 3 )
668+
/* AT+COPS? call. */
669+
if( cbCondition < 3 )
666670
{
667-
cellularOperatorInfo.operatorNameFormat = OPERATOR_NAME_FORMAT_NUMERIC;
668-
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
671+
pktStatus = handleCommonCallback( pContext, atReq );
669672
}
670-
else
673+
else if( cbCondition == 3 )
671674
{
672-
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
675+
char pLine[] = CELLULAR_SAMPLE_PREFIX_STRING_INPUT;
676+
677+
_saveData( pLine, &atResp, strlen( pLine ) + 1 );
678+
679+
if( parseNetworkNameFailureCase == 2 )
680+
{
681+
cellularOperatorInfo.operatorNameFormat = OPERATOR_NAME_FORMAT_LONG;
682+
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
683+
}
684+
else if( parseNetworkNameFailureCase == 3 )
685+
{
686+
cellularOperatorInfo.operatorNameFormat = OPERATOR_NAME_FORMAT_NUMERIC;
687+
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
688+
}
689+
else
690+
{
691+
pktStatus = atReq.respCallback( pContext, &atResp, &cellularOperatorInfo, sizeof( cellularOperatorInfo_t ) );
692+
}
673693
}
674694
}
695+
else
696+
{
697+
TEST_FAIL_MESSAGE( "Unexpected Mock_AtcmdRequestWithCallback call" );
698+
}
675699

676700
return pktStatus;
677701
}
@@ -2016,6 +2040,44 @@ void test_Cellular_CommonGetRegisteredNetwork_No_Memory( void )
20162040
TEST_ASSERT_EQUAL( CELLULAR_NO_MEMORY, cellularStatus );
20172041
}
20182042

2043+
/**
2044+
* @brief Test that set to numeric format failed.
2045+
*
2046+
* <b>Coverage</b>
2047+
* @code{c}
2048+
* static CellularError_t atcmdUpdateMccMnc( CellularContext_t * pContext,
2049+
* cellularOperatorInfo_t * pOperatorInfo )
2050+
* {
2051+
* ...
2052+
* atCopsRequest.pAtCmd = "AT+COPS=3,2",
2053+
* atCopsRequest.atCmdType = CELLULAR_AT_NO_RESULT,
2054+
* pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atCopsRequest );
2055+
*
2056+
* if( pktStatus == CELLULAR_PKT_STATUS_OK )
2057+
* {
2058+
* ...
2059+
* }
2060+
* }
2061+
* @endcode
2062+
* ( pktStatus == CELLULAR_PKT_STATUS_OK ) is false.
2063+
*/
2064+
void test_Cellular_CommonGetRegisteredNetwork_Set_Numeric_Format_Fail( void )
2065+
{
2066+
CellularError_t cellularStatus = CELLULAR_SUCCESS;
2067+
CellularContext_t context;
2068+
2069+
memset( &context, 0, sizeof( CellularContext_t ) );
2070+
CellularHandle_t cellularHandle = &context;
2071+
CellularPlmnInfo_t networkInfo;
2072+
2073+
_Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS );
2074+
_Cellular_AtcmdRequestWithCallback_IgnoreAndReturn( CELLULAR_PKT_STATUS_FAILURE );
2075+
_Cellular_TranslatePktStatus_ExpectAndReturn( CELLULAR_PKT_STATUS_FAILURE, CELLULAR_INTERNAL_FAILURE );
2076+
2077+
cellularStatus = Cellular_CommonGetRegisteredNetwork( cellularHandle, &networkInfo );
2078+
TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus );
2079+
}
2080+
20192081
/**
20202082
* @brief Test that invalid rat case Cellular_CommonGetRegisteredNetwork to return CELLULAR_UNKNOWN.
20212083
*/

0 commit comments

Comments
 (0)