From 4bc022eb73aaf6429d8a60175ee422d2b48e12cd Mon Sep 17 00:00:00 2001
From: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Date: Tue, 13 Jun 2023 11:27:35 +0800
Subject: [PATCH] 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
---
docs/doxygen/include/size_table.md | 4 +-
lexicon.txt | 4 +
source/cellular_pktio.c | 31 ++--
source/include/cellular_types.h | 16 +-
test/unit-test/cellular_pktio_utest.c | 219 ++++++++++++++++++++++++++
5 files changed, 256 insertions(+), 18 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/lexicon.txt b/lexicon.txt
index 70087620..dfe99513 100644
--- a/lexicon.txt
+++ b/lexicon.txt
@@ -510,6 +510,7 @@ pclosedcallbackcontext
pcomminterface
pcomminterfacehandle
pcommintf
+pcommintfrecvcustomstring
pcontext
pcomparestring
pcurrentcmd
@@ -551,6 +552,7 @@ pinputptr
pinputstr
pitm
pkio
+pkstatus
pkt
pktdataprefixcallback
pktdataprefixcb
@@ -644,6 +646,8 @@ prl
processmodemrdy
processpowerdown
prssivalue
+prvpacketcallbackerror
+prvpacketcallbacksuccess
ps
psaveptr
psentdatalength
diff --git a/source/cellular_pktio.c b/source/cellular_pktio.c
index 117c39ec..81f32534 100644
--- a/source/cellular_pktio.c
+++ b/source/cellular_pktio.c
@@ -250,6 +250,18 @@ 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:
+ /* Save the line in the response. */
+ _saveATData( pLine, pResp );
+
+ /* Returns CELLULAR_PKT_STATUS_OK to indicate that the response of the
+ * 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:
/* Unexpected message received when sending the AT command. */
LogInfo( ( "Undefind message received %s when sending AT command type %d.",
@@ -374,20 +386,20 @@ static CellularPktStatus_t _Cellular_ProcessLine( CellularContext_t * pContext,
pResp->status = false;
pkStatus = CELLULAR_PKT_STATUS_OK;
}
- else
- {
- pkStatus = _processIntermediateResponse( pLine, pResp, atType );
- }
+ }
+
+ 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 );
@@ -470,7 +482,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/source/include/cellular_types.h b/source/include/cellular_types.h
index b8b3b9f8..53eeba61 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 8e798080..46097639 100644
--- a/test/unit-test/cellular_pktio_utest.c
+++ b/test/unit-test/cellular_pktio_utest.c
@@ -974,6 +974,51 @@ 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,6 +2186,180 @@ void test__Cellular_PktioInit_Thread_Rx_Data_Event_CELLULAR_AT_WO_PREFIX_STRING_
TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus );
}
+/**
+ * @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 response string in the callback function.
+ *
+ * Coverage
+ * @code{c}
+ * case CELLULAR_AT_WO_PREFIX_NO_RESULT_CODE:
+ * ...
+ * _saveATData( pLine, pResp );
+ *
+ * pktStatus = 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;
+ 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, prvPacketCallbackSuccess );
+
+ /* Verification. */
+ 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 );
+
+ /* Verification. */
+ TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus );
+
+ /* The result is verified in prvPacketCallbackError. */
+}
+
+
+/**
+ * @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 response 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, prvPacketCallbackSuccess );
+
+ /* Verification. */
+ 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 );
+
+ /* Verification. */
+ TEST_ASSERT_EQUAL( CELLULAR_PKT_STATUS_OK, pktStatus );
+
+ /* The result is verified in prvPacketCallbackError. */
+}
+
/**
* @brief Test thread receiving rx data event with success token for _Cellular_PktioInit to return CELLULAR_PKT_STATUS_OK.
*/