From e2d3a43c6614fdbcbbafdd33e806570bd28fa689 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Tue, 23 May 2023 14:50:33 +0800 Subject: [PATCH 1/6] Staging code --- source/cellular_pktio.c | 44 ++++++++++++++++++++++ source/include/cellular_types.h | 16 ++++---- test/unit-test/cellular_pktio_utest.c | 54 +++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 7 deletions(-) diff --git a/source/cellular_pktio.c b/source/cellular_pktio.c index 6f6f9796..c092a8b3 100644 --- a/source/cellular_pktio.c +++ b/source/cellular_pktio.c @@ -205,6 +205,26 @@ static CellularPktStatus_t _processIntermediateResponse( char * pLine, break; + case CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE: + + if( pResp->pItm == NULL ) + { + _saveATData( pLine, pResp ); + + /* This command only expect one response and no result code. */ + pResp->status = true; + pkStatus = CELLULAR_PKT_STATUS_OK; + } + else + { + /* We already have an intermediate response. */ + pkStatus = CELLULAR_PKT_STATUS_INVALID_DATA; + LogError( ( "CELLULAR_AT_WO_PREFIX process intermediate response ERROR: %s, status: %d, previous line %s", + pLine, pkStatus, pResp->pItm->pLine ) ); + } + + break; + case CELLULAR_AT_WITH_PREFIX: if( pResp->pItm == NULL ) @@ -224,6 +244,30 @@ static CellularPktStatus_t _processIntermediateResponse( char * pLine, break; + case CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE: + + if( pResp->pItm == NULL ) + { + /* The removed code which demonstrate the existence of the prefix has been done in + * function _getMsgType(), so the failure condition here won't be touched. + */ + _saveATData( pLine, pResp ); + + /* This command only expect one response and no result code. */ + pResp->status = true; + pkStatus = CELLULAR_PKT_STATUS_OK; + + } + else + { + /* We already have an intermediate response. */ + pkStatus = CELLULAR_PKT_STATUS_INVALID_DATA; + LogError( ( "CELLULAR_AT_WITH_PREFIX process intermediate response ERROR: %s, status: %d, previous line %s", + pLine, pkStatus, pResp->pItm->pLine ) ); + } + + break; + case CELLULAR_AT_MULTI_WITH_PREFIX: /* The removed code which demonstrate the existence of the prefix has been done in diff --git a/source/include/cellular_types.h b/source/include/cellular_types.h index b8b3b9f8..f2cb3f7f 100644 --- a/source/include/cellular_types.h +++ b/source/include/cellular_types.h @@ -358,13 +358,15 @@ typedef enum CellularPktStatus */ typedef enum CellularATCommandType { - CELLULAR_AT_NO_RESULT, /**< no response expected, only OK, ERROR etc. */ - CELLULAR_AT_WO_PREFIX, /**< string response without a prefix. */ - CELLULAR_AT_WITH_PREFIX, /**< string response with a prefix. */ - CELLULAR_AT_MULTI_WITH_PREFIX, /**< multiple line response all start with a prefix. */ - CELLULAR_AT_MULTI_WO_PREFIX, /**< multiple line response with or without a prefix. */ - CELLULAR_AT_MULTI_DATA_WO_PREFIX, /**< multiple line data response with or without a prefix. */ - CELLULAR_AT_NO_COMMAND /**< no command is waiting response. */ + CELLULAR_AT_NO_RESULT, /**< no response expected, only OK, ERROR etc. */ + CELLULAR_AT_WO_PREFIX, /**< string response without a prefix. */ + CELLULAR_AT_WITH_PREFIX, /**< string response with a prefix. */ + CELLULAR_AT_MULTI_WITH_PREFIX, /**< multiple line response all start with a prefix. */ + CELLULAR_AT_MULTI_WO_PREFIX, /**< multiple line response with or without a prefix. */ + CELLULAR_AT_MULTI_DATA_WO_PREFIX, /**< multiple line data response with or without a prefix. */ + CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE, /**< string response without a prefix and no result code is expected. */ + CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE, /**< string response WITH a prefix and no result code is expected. */ + CELLULAR_AT_NO_COMMAND /**< no command is waiting response. */ } CellularATCommandType_t; /** diff --git a/test/unit-test/cellular_pktio_utest.c b/test/unit-test/cellular_pktio_utest.c index 16c77b88..cb55852c 100644 --- a/test/unit-test/cellular_pktio_utest.c +++ b/test/unit-test/cellular_pktio_utest.c @@ -1755,6 +1755,60 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_STRING_ TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); } +static CellularPktStatus_t prvHandlePacketCallback( CellularContext_t * pContext, + _atRespType_t atRespType, + const void * pBuffer ) +{ + const CellularATCommandResponse_t * pAtResp = ( const CellularATCommandResponse_t * ) pBuffer; + int cmpResult; + + ( void ) pContext; + + /* Verify the response type is AT_SOLICITED. */ + TEST_ASSERT_EQUAL( AT_SOLICITED, atRespType ); + + /* Verify the string is the same as expected. */ + TEST_ASSERT_NOT_EQUAL( NULL, pAtResp ); + TEST_ASSERT_NOT_EQUAL( NULL, pAtResp->pItm ); + TEST_ASSERT_NOT_EQUAL( NULL, pAtResp->pItm->pLine ); + cmpResult = strncmp( pAtResp->pItm->pLine, pCommIntfRecvCustomString, strlen( pAtResp->pItm->pLine ) ); + TEST_ASSERT_EQUAL( 0, cmpResult ); + + return CELLULAR_PKT_STATUS_OK; +} + +void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE_success( void ) +{ + CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + CellularCommInterface_t * pCommIntf = &CellularCommInterface; + + threadReturn = true; + memset( &context, 0, sizeof( CellularContext_t ) ); + + /* copy the token table. */ + ( void ) memcpy( &context.tokenTable, &tokenTable, sizeof( CellularTokenTable_t ) ); + + /* Assign the comm interface to pContext. */ + context.pCommIntf = pCommIntf; + context.pPktioShutdownCB = _shutdownCallback; + + /* Test the rx_data event with CELLULAR_AT_WO_PREFIX resp. */ + pktioEvtMask = PKTIO_EVT_MASK_RX_DATA; + recvCount = 1; + atCmdType = CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE; + testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING; + pCommIntfRecvCustomString = "12345\r\n"; /* Dummy string to be verified in the callback. */ + + /* Check that CELLULAR_PKT_STATUS_OK is returned. */ + pktStatus = _Cellular_PktioInit( &context, prvHandlePacketCallback ); + + /* Veification. */ + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); + + /* The result is verified in prvHandlePacketCallback. */ +} + /** * @brief Test thread receiving rx data event with success token for _Cellular_PktioInit to return CELLULAR_PKT_STATUS_OK. */ From c5b78bfaed2ae83e81fc436158ccc8d280a76e8e Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Tue, 23 May 2023 16:07:27 +0800 Subject: [PATCH 2/6] Add no result code command * Add CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE and CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE at command type --- source/cellular_pktio.c | 60 +++++++----------------- test/unit-test/cellular_pktio_utest.c | 66 +++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 44 deletions(-) diff --git a/source/cellular_pktio.c b/source/cellular_pktio.c index 84c4418c..ec498321 100644 --- a/source/cellular_pktio.c +++ b/source/cellular_pktio.c @@ -213,26 +213,6 @@ static CellularPktStatus_t _processIntermediateResponse( char * pLine, break; - case CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE: - - if( pResp->pItm == NULL ) - { - _saveATData( pLine, pResp ); - - /* This command only expect one response and no result code. */ - pResp->status = true; - pkStatus = CELLULAR_PKT_STATUS_OK; - } - else - { - /* We already have an intermediate response. */ - pkStatus = CELLULAR_PKT_STATUS_INVALID_DATA; - LogError( ( "CELLULAR_AT_WO_PREFIX process intermediate response ERROR: %s, status: %d, previous line %s", - pLine, pkStatus, pResp->pItm->pLine ) ); - } - - break; - case CELLULAR_AT_WITH_PREFIX: if( pResp->pItm == NULL ) @@ -252,30 +232,6 @@ static CellularPktStatus_t _processIntermediateResponse( char * pLine, break; - case CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE: - - if( pResp->pItm == NULL ) - { - /* The removed code which demonstrate the existence of the prefix has been done in - * function _getMsgType(), so the failure condition here won't be touched. - */ - _saveATData( pLine, pResp ); - - /* This command only expect one response and no result code. */ - pResp->status = true; - pkStatus = CELLULAR_PKT_STATUS_OK; - - } - else - { - /* We already have an intermediate response. */ - pkStatus = CELLULAR_PKT_STATUS_INVALID_DATA; - LogError( ( "CELLULAR_AT_WITH_PREFIX process intermediate response ERROR: %s, status: %d, previous line %s", - pLine, pkStatus, pResp->pItm->pLine ) ); - } - - break; - case CELLULAR_AT_MULTI_WITH_PREFIX: /* The removed code which demonstrate the existence of the prefix has been done in @@ -294,6 +250,15 @@ static CellularPktStatus_t _processIntermediateResponse( char * pLine, pkStatus = CELLULAR_PKT_STATUS_PENDING_BUFFER; break; + case CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE: + case CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE: + _saveATData( pLine, pResp ); + + /* Returns CELLULAR_PKT_STATUS_OK to indicate that the response of the + * command is received. */ + pkStatus = CELLULAR_PKT_STATUS_OK; + break; + default: /* Unexpected message received when sending the AT command. */ LogInfo( ( "Undefind message received %s when sending AT command type %d.", @@ -421,6 +386,13 @@ static CellularPktStatus_t _Cellular_ProcessLine( CellularContext_t * pContext, else { pkStatus = _processIntermediateResponse( pLine, pResp, atType ); + + /* This is the case that no final result code is expected. The AT + * command only expect one resonse from modem. */ + if( pkStatus == CELLULAR_PKT_STATUS_OK ) + { + pResp->status = true; + } } } } diff --git a/test/unit-test/cellular_pktio_utest.c b/test/unit-test/cellular_pktio_utest.c index 47266312..6e762ccc 100644 --- a/test/unit-test/cellular_pktio_utest.c +++ b/test/unit-test/cellular_pktio_utest.c @@ -2163,6 +2163,23 @@ static CellularPktStatus_t prvHandlePacketCallback( CellularContext_t * pContext return CELLULAR_PKT_STATUS_OK; } +/** + * @brief _processIntermediateResponse - Successfully handle at command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE. + * + * Successfully handle at command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE. Verify + * the respones string in the callback function. + * + * Coverage + * @code{c} + * case CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE: + * ... + * _saveATData( pLine, pResp ); + * + * pkStatus = CELLULAR_PKT_STATUS_OK; + * break; + * @endcode + * The CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE case. + */ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE_success( void ) { CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK; @@ -2195,6 +2212,55 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESU /* The result is verified in prvHandlePacketCallback. */ } +/** + * @brief _processIntermediateResponse - Successfully handle at command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE. + * + * Successfully handle at command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE. Verify + * the respones string in the callback function. + * + * Coverage + * @code{c} + * case CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE: + * _saveATData( pLine, pResp ); + * + * pkStatus = CELLULAR_PKT_STATUS_OK; + * break; + * @endcode + * The CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE case. + */ +void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE_success( void ) +{ + CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + CellularCommInterface_t * pCommIntf = &CellularCommInterface; + + threadReturn = true; + memset( &context, 0, sizeof( CellularContext_t ) ); + + /* copy the token table. */ + ( void ) memcpy( &context.tokenTable, &tokenTable, sizeof( CellularTokenTable_t ) ); + + /* Assign the comm interface to pContext. */ + context.pCommIntf = pCommIntf; + context.pPktioShutdownCB = _shutdownCallback; + + /* Test the rx_data event with CELLULAR_AT_WO_PREFIX resp. */ + pktioEvtMask = PKTIO_EVT_MASK_RX_DATA; + recvCount = 1; + atCmdType = CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE; + testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING; + context.pRespPrefix = "+CMD_PREFIX"; + pCommIntfRecvCustomString = "+CMD_PREFIX:12345\r\n"; /* Dummy string to be verified in the callback. */ + + /* Check that CELLULAR_PKT_STATUS_OK is returned. */ + pktStatus = _Cellular_PktioInit( &context, prvHandlePacketCallback ); + + /* Veification. */ + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); + + /* The result is verified in prvHandlePacketCallback. */ +} + /** * @brief Test thread receiving rx data event with success token for _Cellular_PktioInit to return CELLULAR_PKT_STATUS_OK. */ From c6e797b3de1cdd16adec8d21e4dbad0d8544b2bc Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Tue, 23 May 2023 17:07:44 +0800 Subject: [PATCH 3/6] Add modem return error test cases --- source/cellular_pktio.c | 3 +- test/unit-test/cellular_pktio_utest.c | 154 +++++++++++++++++++++----- 2 files changed, 128 insertions(+), 29 deletions(-) diff --git a/source/cellular_pktio.c b/source/cellular_pktio.c index ec498321..0a1f82c6 100644 --- a/source/cellular_pktio.c +++ b/source/cellular_pktio.c @@ -486,7 +486,8 @@ static _atRespType_t _getMsgType( CellularContext_t * pContext, if( ( ( pContext->PktioAtCmdType != CELLULAR_AT_NO_COMMAND ) && ( pRespPrefix == NULL ) ) || ( pContext->PktioAtCmdType == CELLULAR_AT_MULTI_DATA_WO_PREFIX ) || ( pContext->PktioAtCmdType == CELLULAR_AT_WITH_PREFIX ) || - ( pContext->PktioAtCmdType == CELLULAR_AT_MULTI_WITH_PREFIX ) ) + ( pContext->PktioAtCmdType == CELLULAR_AT_MULTI_WITH_PREFIX ) || + ( pContext->PktioAtCmdType == CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE ) ) { atRespType = AT_SOLICITED; } diff --git a/test/unit-test/cellular_pktio_utest.c b/test/unit-test/cellular_pktio_utest.c index 6e762ccc..461e5014 100644 --- a/test/unit-test/cellular_pktio_utest.c +++ b/test/unit-test/cellular_pktio_utest.c @@ -974,6 +974,50 @@ static void prvInputBufferCommIntfRecvCallback( void ) pCommIntfRecvCustomString = URC_DATA_CALLBACK_MATCH_STR_PART2; } +static CellularPktStatus_t prvPacketCallbackError( CellularContext_t * pContext, + _atRespType_t atRespType, + const void * pBuffer ) +{ + const CellularATCommandResponse_t * pAtResp = ( const CellularATCommandResponse_t * ) pBuffer; + ( void ) pContext; + + /* Verify the response type is AT_SOLICITED. */ + TEST_ASSERT_EQUAL( AT_SOLICITED, atRespType ); + + /* Verify that no item is added to the response. */ + TEST_ASSERT_NOT_EQUAL( NULL, pAtResp ); + TEST_ASSERT_EQUAL( NULL, pAtResp->pItm ); + + /* Verify that the response indicate error. */ + TEST_ASSERT_EQUAL( false, pAtResp->status ); + + return CELLULAR_PKT_STATUS_OK; +} + +static CellularPktStatus_t prvPacketCallbackSuccess( CellularContext_t * pContext, + _atRespType_t atRespType, + const void * pBuffer ) +{ + const CellularATCommandResponse_t * pAtResp = ( const CellularATCommandResponse_t * ) pBuffer; + int cmpResult; + + ( void ) pContext; + + /* Verify the response type is AT_SOLICITED. */ + TEST_ASSERT_EQUAL( AT_SOLICITED, atRespType ); + + /* Verify the string is the same as expected. */ + TEST_ASSERT_NOT_EQUAL( NULL, pAtResp ); + TEST_ASSERT_NOT_EQUAL( NULL, pAtResp->pItm ); + TEST_ASSERT_NOT_EQUAL( NULL, pAtResp->pItm->pLine ); + cmpResult = strncmp( pAtResp->pItm->pLine, pCommIntfRecvCustomString, strlen( pAtResp->pItm->pLine ) ); + TEST_ASSERT_EQUAL( 0, cmpResult ); + + /* Verify that the response indicate error. */ + TEST_ASSERT_EQUAL( true, pAtResp->status ); + + return CELLULAR_PKT_STATUS_OK; +} /* ========================================================================== */ @@ -2141,30 +2185,8 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_STRING_ TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); } -static CellularPktStatus_t prvHandlePacketCallback( CellularContext_t * pContext, - _atRespType_t atRespType, - const void * pBuffer ) -{ - const CellularATCommandResponse_t * pAtResp = ( const CellularATCommandResponse_t * ) pBuffer; - int cmpResult; - - ( void ) pContext; - - /* Verify the response type is AT_SOLICITED. */ - TEST_ASSERT_EQUAL( AT_SOLICITED, atRespType ); - - /* Verify the string is the same as expected. */ - TEST_ASSERT_NOT_EQUAL( NULL, pAtResp ); - TEST_ASSERT_NOT_EQUAL( NULL, pAtResp->pItm ); - TEST_ASSERT_NOT_EQUAL( NULL, pAtResp->pItm->pLine ); - cmpResult = strncmp( pAtResp->pItm->pLine, pCommIntfRecvCustomString, strlen( pAtResp->pItm->pLine ) ); - TEST_ASSERT_EQUAL( 0, cmpResult ); - - return CELLULAR_PKT_STATUS_OK; -} - /** - * @brief _processIntermediateResponse - Successfully handle at command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE. + * @brief _processIntermediateResponse - Successfully handle AT command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE. * * Successfully handle at command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE. Verify * the respones string in the callback function. @@ -2204,16 +2226,54 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESU pCommIntfRecvCustomString = "12345\r\n"; /* Dummy string to be verified in the callback. */ /* Check that CELLULAR_PKT_STATUS_OK is returned. */ - pktStatus = _Cellular_PktioInit( &context, prvHandlePacketCallback ); + pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackSuccess ); + + /* Veification. */ + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); + + /* The result is verified in prvPacketCallbackSuccess. */ +} + +/** + * @brief _processIntermediateResponse - Modem returns error when sending AT command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE. + * + * Modem returns error when sending AT command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE. + */ +void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE_error( void ) +{ + CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + CellularCommInterface_t * pCommIntf = &CellularCommInterface; + + threadReturn = true; + memset( &context, 0, sizeof( CellularContext_t ) ); + + /* copy the token table. */ + ( void ) memcpy( &context.tokenTable, &tokenTable, sizeof( CellularTokenTable_t ) ); + + /* Assign the comm interface to pContext. */ + context.pCommIntf = pCommIntf; + context.pPktioShutdownCB = _shutdownCallback; + + /* Test the rx_data event with CELLULAR_AT_WO_PREFIX resp. */ + pktioEvtMask = PKTIO_EVT_MASK_RX_DATA; + recvCount = 1; + atCmdType = CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE; + testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING; + pCommIntfRecvCustomString = "ERROR\r\n"; /* Return one of the error token. */ + + /* Check that CELLULAR_PKT_STATUS_OK is returned. */ + pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackError ); /* Veification. */ TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); - /* The result is verified in prvHandlePacketCallback. */ + /* The result is verified in prvPacketCallbackError. */ } + /** - * @brief _processIntermediateResponse - Successfully handle at command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE. + * @brief _processIntermediateResponse - Successfully handle AT command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE. * * Successfully handle at command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE. Verify * the respones string in the callback function. @@ -2253,12 +2313,50 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WITH_PREFIX_NO_RE pCommIntfRecvCustomString = "+CMD_PREFIX:12345\r\n"; /* Dummy string to be verified in the callback. */ /* Check that CELLULAR_PKT_STATUS_OK is returned. */ - pktStatus = _Cellular_PktioInit( &context, prvHandlePacketCallback ); + pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackSuccess ); + + /* Veification. */ + TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); + + /* The result is verified in prvPacketCallbackSuccess. */ +} + +/** + * @brief _processIntermediateResponse - Modem returns error when sending AT command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE. + * + * Modem returns error when sending AT command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE. + */ +void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE_error( void ) +{ + CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK; + CellularContext_t context; + CellularCommInterface_t * pCommIntf = &CellularCommInterface; + + threadReturn = true; + memset( &context, 0, sizeof( CellularContext_t ) ); + + /* copy the token table. */ + ( void ) memcpy( &context.tokenTable, &tokenTable, sizeof( CellularTokenTable_t ) ); + + /* Assign the comm interface to pContext. */ + context.pCommIntf = pCommIntf; + context.pPktioShutdownCB = _shutdownCallback; + + /* Test the rx_data event with CELLULAR_AT_WO_PREFIX resp. */ + pktioEvtMask = PKTIO_EVT_MASK_RX_DATA; + recvCount = 1; + atCmdType = CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE; + testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING; + context.pRespPrefix = "+CMD_PREFIX"; + pCommIntfRecvCustomString = "ERROR\r\n"; /* Return one of the error token. */ + + /* Check that CELLULAR_PKT_STATUS_OK is returned. */ + pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackError ); /* Veification. */ TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); - /* The result is verified in prvHandlePacketCallback. */ + /* The result is verified in prvPacketCallbackError. */ } /** From 7f7dd3f8b21c6b7f4f04eb415126bf9eafa216c2 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Tue, 23 May 2023 17:11:50 +0800 Subject: [PATCH 4/6] Fix lexicon --- lexicon.txt | 2 ++ source/cellular_pktio.c | 2 +- test/unit-test/cellular_pktio_utest.c | 14 +++++++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lexicon.txt b/lexicon.txt index ef820fd8..f059befb 100644 --- a/lexicon.txt +++ b/lexicon.txt @@ -504,6 +504,7 @@ pclosedcallbackcontext pcomminterface pcomminterfacehandle pcommintf +pcommintfrecvcustomstring pcontext pcomparestring pcurrentcmd @@ -545,6 +546,7 @@ pinputptr pinputstr pitm pkio +pkstatus pkt pktdataprefixcallback pktdataprefixcb diff --git a/source/cellular_pktio.c b/source/cellular_pktio.c index 0a1f82c6..1e2b5f03 100644 --- a/source/cellular_pktio.c +++ b/source/cellular_pktio.c @@ -388,7 +388,7 @@ static CellularPktStatus_t _Cellular_ProcessLine( CellularContext_t * pContext, pkStatus = _processIntermediateResponse( pLine, pResp, atType ); /* This is the case that no final result code is expected. The AT - * command only expect one resonse from modem. */ + * command only expect one response from modem. */ if( pkStatus == CELLULAR_PKT_STATUS_OK ) { pResp->status = true; diff --git a/test/unit-test/cellular_pktio_utest.c b/test/unit-test/cellular_pktio_utest.c index 461e5014..f232e8bf 100644 --- a/test/unit-test/cellular_pktio_utest.c +++ b/test/unit-test/cellular_pktio_utest.c @@ -2189,7 +2189,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_STRING_ * @brief _processIntermediateResponse - Successfully handle AT command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE. * * Successfully handle at command type CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE. Verify - * the respones string in the callback function. + * the response string in the callback function. * * Coverage * @code{c} @@ -2197,7 +2197,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_STRING_ * ... * _saveATData( pLine, pResp ); * - * pkStatus = CELLULAR_PKT_STATUS_OK; + * pktStatus = CELLULAR_PKT_STATUS_OK; * break; * @endcode * The CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE case. @@ -2228,7 +2228,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESU /* Check that CELLULAR_PKT_STATUS_OK is returned. */ pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackSuccess ); - /* Veification. */ + /* Verification. */ TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); /* The result is verified in prvPacketCallbackSuccess. */ @@ -2265,7 +2265,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESU /* Check that CELLULAR_PKT_STATUS_OK is returned. */ pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackError ); - /* Veification. */ + /* Verification. */ TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); /* The result is verified in prvPacketCallbackError. */ @@ -2276,7 +2276,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESU * @brief _processIntermediateResponse - Successfully handle AT command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE. * * Successfully handle at command type CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE. Verify - * the respones string in the callback function. + * the response string in the callback function. * * Coverage * @code{c} @@ -2315,7 +2315,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WITH_PREFIX_NO_RE /* Check that CELLULAR_PKT_STATUS_OK is returned. */ pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackSuccess ); - /* Veification. */ + /* Verification. */ TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); /* The result is verified in prvPacketCallbackSuccess. */ @@ -2353,7 +2353,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WITH_PREFIX_NO_RE /* Check that CELLULAR_PKT_STATUS_OK is returned. */ pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackError ); - /* Veification. */ + /* Verification. */ TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus ); /* The result is verified in prvPacketCallbackError. */ From 6c8619638b0f3f5a0ca8ca52d172f919a8426f72 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Tue, 23 May 2023 17:31:37 +0800 Subject: [PATCH 5/6] Fix CI size complexity and format --- docs/doxygen/include/size_table.md | 4 ++-- source/cellular_pktio.c | 26 +++++++++++--------------- test/unit-test/cellular_pktio_utest.c | 9 +++++---- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/docs/doxygen/include/size_table.md b/docs/doxygen/include/size_table.md index b27e6752..7f20224a 100644 --- a/docs/doxygen/include/size_table.md +++ b/docs/doxygen/include/size_table.md @@ -39,12 +39,12 @@ cellular_pktio.c -
2.1K
+
2.2K
1.9K
Total estimates -
14.9K
+
15.0K
13.6K
diff --git a/source/cellular_pktio.c b/source/cellular_pktio.c index 1e2b5f03..81f32534 100644 --- a/source/cellular_pktio.c +++ b/source/cellular_pktio.c @@ -252,11 +252,14 @@ static CellularPktStatus_t _processIntermediateResponse( char * pLine, case CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE: case CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE: + /* Save the line in the response. */ _saveATData( pLine, pResp ); /* Returns CELLULAR_PKT_STATUS_OK to indicate that the response of the - * command is received. */ + * command is received. No success result code is expected. Set the response + * status to true here. */ pkStatus = CELLULAR_PKT_STATUS_OK; + pResp->status = true; break; default: @@ -383,27 +386,20 @@ static CellularPktStatus_t _Cellular_ProcessLine( CellularContext_t * pContext, pResp->status = false; pkStatus = CELLULAR_PKT_STATUS_OK; } - else - { - pkStatus = _processIntermediateResponse( pLine, pResp, atType ); + } - /* This is the case that no final result code is expected. The AT - * command only expect one response from modem. */ - if( pkStatus == CELLULAR_PKT_STATUS_OK ) - { - pResp->status = true; - } - } + if( result != true ) + { + pkStatus = _processIntermediateResponse( pLine, pResp, atType ); } } if( ( result == true ) && ( pResp->status == false ) ) { - LogWarn( ( "Modem return ERROR: line %s, cmd : %s, respPrefix %s, status: %d", - ( pContext->pCurrentCmd != NULL ? pContext->pCurrentCmd : "NULL" ), + LogWarn( ( "Modem return ERROR: line %s, cmd : %s, respPrefix %s", pLine, - ( pRespPrefix != NULL ? pRespPrefix : "NULL" ), - pkStatus ) ); + ( pContext->pCurrentCmd != NULL ? pContext->pCurrentCmd : "NULL" ), + ( pRespPrefix != NULL ? pRespPrefix : "NULL" ) ) ); } PlatformMutex_Unlock( &pContext->PktRespMutex ); diff --git a/test/unit-test/cellular_pktio_utest.c b/test/unit-test/cellular_pktio_utest.c index f232e8bf..46097639 100644 --- a/test/unit-test/cellular_pktio_utest.c +++ b/test/unit-test/cellular_pktio_utest.c @@ -979,6 +979,7 @@ static CellularPktStatus_t prvPacketCallbackError( CellularContext_t * pContext, const void * pBuffer ) { const CellularATCommandResponse_t * pAtResp = ( const CellularATCommandResponse_t * ) pBuffer; + ( void ) pContext; /* Verify the response type is AT_SOLICITED. */ @@ -2223,7 +2224,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESU recvCount = 1; atCmdType = CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE; testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING; - pCommIntfRecvCustomString = "12345\r\n"; /* Dummy string to be verified in the callback. */ + pCommIntfRecvCustomString = "12345\r\n"; /* Dummy string to be verified in the callback. */ /* Check that CELLULAR_PKT_STATUS_OK is returned. */ pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackSuccess ); @@ -2260,7 +2261,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_NO_RESU recvCount = 1; atCmdType = CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE; testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING; - pCommIntfRecvCustomString = "ERROR\r\n"; /* Return one of the error token. */ + pCommIntfRecvCustomString = "ERROR\r\n"; /* Return one of the error token. */ /* Check that CELLULAR_PKT_STATUS_OK is returned. */ pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackError ); @@ -2310,7 +2311,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WITH_PREFIX_NO_RE atCmdType = CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE; testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING; context.pRespPrefix = "+CMD_PREFIX"; - pCommIntfRecvCustomString = "+CMD_PREFIX:12345\r\n"; /* Dummy string to be verified in the callback. */ + pCommIntfRecvCustomString = "+CMD_PREFIX:12345\r\n"; /* Dummy string to be verified in the callback. */ /* Check that CELLULAR_PKT_STATUS_OK is returned. */ pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackSuccess ); @@ -2348,7 +2349,7 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WITH_PREFIX_NO_RE atCmdType = CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE; testCommIfRecvType = COMM_IF_RECV_CUSTOM_STRING; context.pRespPrefix = "+CMD_PREFIX"; - pCommIntfRecvCustomString = "ERROR\r\n"; /* Return one of the error token. */ + pCommIntfRecvCustomString = "ERROR\r\n"; /* Return one of the error token. */ /* Check that CELLULAR_PKT_STATUS_OK is returned. */ pktStatus = _Cellular_PktioInit( &context, prvPacketCallbackError ); From 485ca5ace81756d21a1f4b0712ab9c46ccfc75b6 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Tue, 23 May 2023 17:34:38 +0800 Subject: [PATCH 6/6] Fix CI again --- lexicon.txt | 2 ++ source/include/cellular_types.h | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lexicon.txt b/lexicon.txt index f059befb..8b3d0869 100644 --- a/lexicon.txt +++ b/lexicon.txt @@ -640,6 +640,8 @@ prl processmodemrdy processpowerdown prssivalue +prvpacketcallbackerror +prvpacketcallbacksuccess ps psaveptr psentdatalength diff --git a/source/include/cellular_types.h b/source/include/cellular_types.h index f2cb3f7f..53eeba61 100644 --- a/source/include/cellular_types.h +++ b/source/include/cellular_types.h @@ -358,15 +358,15 @@ typedef enum CellularPktStatus */ typedef enum CellularATCommandType { - CELLULAR_AT_NO_RESULT, /**< no response expected, only OK, ERROR etc. */ - CELLULAR_AT_WO_PREFIX, /**< string response without a prefix. */ - CELLULAR_AT_WITH_PREFIX, /**< string response with a prefix. */ - CELLULAR_AT_MULTI_WITH_PREFIX, /**< multiple line response all start with a prefix. */ - CELLULAR_AT_MULTI_WO_PREFIX, /**< multiple line response with or without a prefix. */ - CELLULAR_AT_MULTI_DATA_WO_PREFIX, /**< multiple line data response with or without a prefix. */ - CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE, /**< string response without a prefix and no result code is expected. */ - CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE, /**< string response WITH a prefix and no result code is expected. */ - CELLULAR_AT_NO_COMMAND /**< no command is waiting response. */ + CELLULAR_AT_NO_RESULT, /**< no response expected, only OK, ERROR etc. */ + CELLULAR_AT_WO_PREFIX, /**< string response without a prefix. */ + CELLULAR_AT_WITH_PREFIX, /**< string response with a prefix. */ + CELLULAR_AT_MULTI_WITH_PREFIX, /**< multiple line response all start with a prefix. */ + CELLULAR_AT_MULTI_WO_PREFIX, /**< multiple line response with or without a prefix. */ + CELLULAR_AT_MULTI_DATA_WO_PREFIX, /**< multiple line data response with or without a prefix. */ + CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE, /**< string response without a prefix and no result code is expected. */ + CELLULAR_AT_WITH_PREFIX_NO_RESULT_CODE, /**< string response WITH a prefix and no result code is expected. */ + CELLULAR_AT_NO_COMMAND /**< no command is waiting response. */ } CellularATCommandType_t; /**