Skip to content

Commit 4bc022e

Browse files
authored
Support AT command with no success result code (#138)
* Add CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE and CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE at command type
1 parent f09e135 commit 4bc022e

File tree

5 files changed

+256
-18
lines changed

5 files changed

+256
-18
lines changed

docs/doxygen/include/size_table.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
</tr>
4040
<tr>
4141
<td>cellular_pktio.c</td>
42-
<td><center>2.1K</center></td>
42+
<td><center>2.2K</center></td>
4343
<td><center>1.9K</center></td>
4444
</tr>
4545
<tr>
4646
<td><b>Total estimates</b></td>
47-
<td><b><center>14.9K</center></b></td>
47+
<td><b><center>15.0K</center></b></td>
4848
<td><b><center>13.6K</center></b></td>
4949
</tr>
5050
</table>

lexicon.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ pclosedcallbackcontext
510510
pcomminterface
511511
pcomminterfacehandle
512512
pcommintf
513+
pcommintfrecvcustomstring
513514
pcontext
514515
pcomparestring
515516
pcurrentcmd
@@ -551,6 +552,7 @@ pinputptr
551552
pinputstr
552553
pitm
553554
pkio
555+
pkstatus
554556
pkt
555557
pktdataprefixcallback
556558
pktdataprefixcb
@@ -644,6 +646,8 @@ prl
644646
processmodemrdy
645647
processpowerdown
646648
prssivalue
649+
prvpacketcallbackerror
650+
prvpacketcallbacksuccess
647651
ps
648652
psaveptr
649653
psentdatalength

source/cellular_pktio.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,18 @@ static CellularPktStatus_t _processIntermediateResponse( char * pLine,
250250
pkStatus = CELLULAR_PKT_STATUS_PENDING_BUFFER;
251251
break;
252252

253+
case CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE:
254+
case CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE:
255+
/* Save the line in the response. */
256+
_saveATData( pLine, pResp );
257+
258+
/* Returns CELLULAR_PKT_STATUS_OK to indicate that the response of the
259+
* command is received. No success result code is expected. Set the response
260+
* status to true here. */
261+
pkStatus = CELLULAR_PKT_STATUS_OK;
262+
pResp->status = true;
263+
break;
264+
253265
default:
254266
/* Unexpected message received when sending the AT command. */
255267
LogInfo( ( "Undefind message received %s when sending AT command type %d.",
@@ -374,20 +386,20 @@ static CellularPktStatus_t _Cellular_ProcessLine( CellularContext_t * pContext,
374386
pResp->status = false;
375387
pkStatus = CELLULAR_PKT_STATUS_OK;
376388
}
377-
else
378-
{
379-
pkStatus = _processIntermediateResponse( pLine, pResp, atType );
380-
}
389+
}
390+
391+
if( result != true )
392+
{
393+
pkStatus = _processIntermediateResponse( pLine, pResp, atType );
381394
}
382395
}
383396

384397
if( ( result == true ) && ( pResp->status == false ) )
385398
{
386-
LogWarn( ( "Modem return ERROR: line %s, cmd : %s, respPrefix %s, status: %d",
387-
( pContext->pCurrentCmd != NULL ? pContext->pCurrentCmd : "NULL" ),
399+
LogWarn( ( "Modem return ERROR: line %s, cmd : %s, respPrefix %s",
388400
pLine,
389-
( pRespPrefix != NULL ? pRespPrefix : "NULL" ),
390-
pkStatus ) );
401+
( pContext->pCurrentCmd != NULL ? pContext->pCurrentCmd : "NULL" ),
402+
( pRespPrefix != NULL ? pRespPrefix : "NULL" ) ) );
391403
}
392404

393405
PlatformMutex_Unlock( &pContext->PktRespMutex );
@@ -470,7 +482,8 @@ static _atRespType_t _getMsgType( CellularContext_t * pContext,
470482
if( ( ( pContext->PktioAtCmdType != CELLULAR_AT_NO_COMMAND ) && ( pRespPrefix == NULL ) ) ||
471483
( pContext->PktioAtCmdType == CELLULAR_AT_MULTI_DATA_WO_PREFIX ) ||
472484
( pContext->PktioAtCmdType == CELLULAR_AT_WITH_PREFIX ) ||
473-
( pContext->PktioAtCmdType == CELLULAR_AT_MULTI_WITH_PREFIX ) )
485+
( pContext->PktioAtCmdType == CELLULAR_AT_MULTI_WITH_PREFIX ) ||
486+
( pContext->PktioAtCmdType == CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE ) )
474487
{
475488
atRespType = AT_SOLICITED;
476489
}

source/include/cellular_types.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,15 @@ typedef enum CellularPktStatus
358358
*/
359359
typedef enum CellularATCommandType
360360
{
361-
CELLULAR_AT_NO_RESULT, /**< no response expected, only OK, ERROR etc. */
362-
CELLULAR_AT_WO_PREFIX, /**< string response without a prefix. */
363-
CELLULAR_AT_WITH_PREFIX, /**< string response with a prefix. */
364-
CELLULAR_AT_MULTI_WITH_PREFIX, /**< multiple line response all start with a prefix. */
365-
CELLULAR_AT_MULTI_WO_PREFIX, /**< multiple line response with or without a prefix. */
366-
CELLULAR_AT_MULTI_DATA_WO_PREFIX, /**< multiple line data response with or without a prefix. */
367-
CELLULAR_AT_NO_COMMAND /**< no command is waiting response. */
361+
CELLULAR_AT_NO_RESULT, /**< no response expected, only OK, ERROR etc. */
362+
CELLULAR_AT_WO_PREFIX, /**< string response without a prefix. */
363+
CELLULAR_AT_WITH_PREFIX, /**< string response with a prefix. */
364+
CELLULAR_AT_MULTI_WITH_PREFIX, /**< multiple line response all start with a prefix. */
365+
CELLULAR_AT_MULTI_WO_PREFIX, /**< multiple line response with or without a prefix. */
366+
CELLULAR_AT_MULTI_DATA_WO_PREFIX, /**< multiple line data response with or without a prefix. */
367+
CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE, /**< string response without a prefix and no result code is expected. */
368+
CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE, /**< string response WITH a prefix and no result code is expected. */
369+
CELLULAR_AT_NO_COMMAND /**< no command is waiting response. */
368370
} CellularATCommandType_t;
369371

370372
/**

test/unit-test/cellular_pktio_utest.c

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,51 @@ static void prvInputBufferCommIntfRecvCallback( void )
974974
pCommIntfRecvCustomString = URC_DATA_CALLBACK_MATCH_STR_PART2;
975975
}
976976

977+
static CellularPktStatus_t prvPacketCallbackError( CellularContext_t * pContext,
978+
_atRespType_t atRespType,
979+
const void * pBuffer )
980+
{
981+
const CellularATCommandResponse_t * pAtResp = ( const CellularATCommandResponse_t * ) pBuffer;
982+
983+
( void ) pContext;
984+
985+
/* Verify the response type is AT_SOLICITED. */
986+
TEST_ASSERT_EQUAL( AT_SOLICITED, atRespType );
987+
988+
/* Verify that no item is added to the response. */
989+
TEST_ASSERT_NOT_EQUAL( NULL, pAtResp );
990+
TEST_ASSERT_EQUAL( NULL, pAtResp->pItm );
991+
992+
/* Verify that the response indicate error. */
993+
TEST_ASSERT_EQUAL( false, pAtResp->status );
994+
995+
return CELLULAR_PKT_STATUS_OK;
996+
}
997+
998+
static CellularPktStatus_t prvPacketCallbackSuccess( CellularContext_t * pContext,
999+
_atRespType_t atRespType,
1000+
const void * pBuffer )
1001+
{
1002+
const CellularATCommandResponse_t * pAtResp = ( const CellularATCommandResponse_t * ) pBuffer;
1003+
int cmpResult;
1004+
1005+
( void ) pContext;
1006+
1007+
/* Verify the response type is AT_SOLICITED. */
1008+
TEST_ASSERT_EQUAL( AT_SOLICITED, atRespType );
1009+
1010+
/* Verify the string is the same as expected. */
1011+
TEST_ASSERT_NOT_EQUAL( NULL, pAtResp );
1012+
TEST_ASSERT_NOT_EQUAL( NULL, pAtResp->pItm );
1013+
TEST_ASSERT_NOT_EQUAL( NULL, pAtResp->pItm->pLine );
1014+
cmpResult = strncmp( pAtResp->pItm->pLine, pCommIntfRecvCustomString, strlen( pAtResp->pItm->pLine ) );
1015+
TEST_ASSERT_EQUAL( 0, cmpResult );
1016+
1017+
/* Verify that the response indicate error. */
1018+
TEST_ASSERT_EQUAL( true, pAtResp->status );
1019+
1020+
return CELLULAR_PKT_STATUS_OK;
1021+
}
9771022

9781023
/* ========================================================================== */
9791024

@@ -2141,6 +2186,180 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_STRING_
21412186
TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus );
21422187
}
21432188

2189+
/**
2190+
* @brief _processIntermediateResponse - Successfully handle AT command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE.
2191+
*
2192+
* Successfully handle at command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE. Verify
2193+
* the response string in the callback function.
2194+
*
2195+
* <b>Coverage</b>
2196+
* @code{c}
2197+
* case CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE:
2198+
* ...
2199+
* _saveATData( pLine, pResp );
2200+
*
2201+
* pktStatus = CELLULAR_PKT_STATUS_OK;
2202+
* break;
2203+
* @endcode
2204+
* The CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE case.
2205+
*/
2206+
void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE_success( void )
2207+
{
2208+
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
2209+
CellularContext_t context;
2210+
CellularCommInterface_t * pCommIntf = &CellularCommInterface;
2211+
2212+
threadReturn = true;
2213+
memset( &context, 0, sizeof( CellularContext_t ) );
2214+
2215+
/* copy the token table. */
2216+
( void ) memcpy( &context.tokenTable, &tokenTable, sizeof( CellularTokenTable_t ) );
2217+
2218+
/* Assign the comm interface to pContext. */
2219+
context.pCommIntf = pCommIntf;
2220+
context.pPktioShutdownCB = _shutdownCallback;
2221+
2222+
/* Test the rx_data event with CELLULAR_AT_WO_PREFIX resp. */
2223+
pktioEvtMask = PKTIO_EVT_MASK_RX_DATA;
2224+
recvCount = 1;
2225+
atCmdType = CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE;
2226+
testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING;
2227+
pCommIntfRecvCustomString = "12345\r\n"; /* Dummy string to be verified in the callback. */
2228+
2229+
/* Check that CELLULAR_PKT_STATUS_OK is returned. */
2230+
pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackSuccess );
2231+
2232+
/* Verification. */
2233+
TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus );
2234+
2235+
/* The result is verified in prvPacketCallbackSuccess. */
2236+
}
2237+
2238+
/**
2239+
* @brief _processIntermediateResponse - Modem returns error when sending AT command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE.
2240+
*
2241+
* Modem returns error when sending AT command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE.
2242+
*/
2243+
void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE_error( void )
2244+
{
2245+
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
2246+
CellularContext_t context;
2247+
CellularCommInterface_t * pCommIntf = &CellularCommInterface;
2248+
2249+
threadReturn = true;
2250+
memset( &context, 0, sizeof( CellularContext_t ) );
2251+
2252+
/* copy the token table. */
2253+
( void ) memcpy( &context.tokenTable, &tokenTable, sizeof( CellularTokenTable_t ) );
2254+
2255+
/* Assign the comm interface to pContext. */
2256+
context.pCommIntf = pCommIntf;
2257+
context.pPktioShutdownCB = _shutdownCallback;
2258+
2259+
/* Test the rx_data event with CELLULAR_AT_WO_PREFIX resp. */
2260+
pktioEvtMask = PKTIO_EVT_MASK_RX_DATA;
2261+
recvCount = 1;
2262+
atCmdType = CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE;
2263+
testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING;
2264+
pCommIntfRecvCustomString = "ERROR\r\n"; /* Return one of the error token. */
2265+
2266+
/* Check that CELLULAR_PKT_STATUS_OK is returned. */
2267+
pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackError );
2268+
2269+
/* Verification. */
2270+
TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus );
2271+
2272+
/* The result is verified in prvPacketCallbackError. */
2273+
}
2274+
2275+
2276+
/**
2277+
* @brief _processIntermediateResponse - Successfully handle AT command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE.
2278+
*
2279+
* Successfully handle at command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE. Verify
2280+
* the response string in the callback function.
2281+
*
2282+
* <b>Coverage</b>
2283+
* @code{c}
2284+
* case CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE:
2285+
* _saveATData( pLine, pResp );
2286+
*
2287+
* pkStatus = CELLULAR_PKT_STATUS_OK;
2288+
* break;
2289+
* @endcode
2290+
* The CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE case.
2291+
*/
2292+
void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE_success( void )
2293+
{
2294+
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
2295+
CellularContext_t context;
2296+
CellularCommInterface_t * pCommIntf = &CellularCommInterface;
2297+
2298+
threadReturn = true;
2299+
memset( &context, 0, sizeof( CellularContext_t ) );
2300+
2301+
/* copy the token table. */
2302+
( void ) memcpy( &context.tokenTable, &tokenTable, sizeof( CellularTokenTable_t ) );
2303+
2304+
/* Assign the comm interface to pContext. */
2305+
context.pCommIntf = pCommIntf;
2306+
context.pPktioShutdownCB = _shutdownCallback;
2307+
2308+
/* Test the rx_data event with CELLULAR_AT_WO_PREFIX resp. */
2309+
pktioEvtMask = PKTIO_EVT_MASK_RX_DATA;
2310+
recvCount = 1;
2311+
atCmdType = CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE;
2312+
testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING;
2313+
context.pRespPrefix = "+CMD_PREFIX";
2314+
pCommIntfRecvCustomString = "+CMD_PREFIX:12345\r\n"; /* Dummy string to be verified in the callback. */
2315+
2316+
/* Check that CELLULAR_PKT_STATUS_OK is returned. */
2317+
pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackSuccess );
2318+
2319+
/* Verification. */
2320+
TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus );
2321+
2322+
/* The result is verified in prvPacketCallbackSuccess. */
2323+
}
2324+
2325+
/**
2326+
* @brief _processIntermediateResponse - Modem returns error when sending AT command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE.
2327+
*
2328+
* Modem returns error when sending AT command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE.
2329+
*/
2330+
void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE_error( void )
2331+
{
2332+
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
2333+
CellularContext_t context;
2334+
CellularCommInterface_t * pCommIntf = &CellularCommInterface;
2335+
2336+
threadReturn = true;
2337+
memset( &context, 0, sizeof( CellularContext_t ) );
2338+
2339+
/* copy the token table. */
2340+
( void ) memcpy( &context.tokenTable, &tokenTable, sizeof( CellularTokenTable_t ) );
2341+
2342+
/* Assign the comm interface to pContext. */
2343+
context.pCommIntf = pCommIntf;
2344+
context.pPktioShutdownCB = _shutdownCallback;
2345+
2346+
/* Test the rx_data event with CELLULAR_AT_WO_PREFIX resp. */
2347+
pktioEvtMask = PKTIO_EVT_MASK_RX_DATA;
2348+
recvCount = 1;
2349+
atCmdType = CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE;
2350+
testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING;
2351+
context.pRespPrefix = "+CMD_PREFIX";
2352+
pCommIntfRecvCustomString = "ERROR\r\n"; /* Return one of the error token. */
2353+
2354+
/* Check that CELLULAR_PKT_STATUS_OK is returned. */
2355+
pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackError );
2356+
2357+
/* Verification. */
2358+
TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus );
2359+
2360+
/* The result is verified in prvPacketCallbackError. */
2361+
}
2362+
21442363
/**
21452364
* @brief Test thread receiving rx data event with success token for _Cellular_PktioInit to return CELLULAR_PKT_STATUS_OK.
21462365
*/

0 commit comments

Comments
 (0)