Skip to content

Commit

Permalink
Update SARA-R4 socket receive response handling (#85)
Browse files Browse the repository at this point in the history
* Add socket receive response handling for '+USORD: 0,0,""'. In the
  response, 0 data length is returned by SARA-R4 modem.
* Remove redundant check in getDataFromResp
  • Loading branch information
chinglee-iot authored May 11, 2022
1 parent e03728a commit dda105f
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions modules/sara_r4/cellular_r4_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,30 +237,17 @@ static CellularATError_t getDataFromResp( const CellularATCommandResponse_t * pA
}

/* Data is stored in the next intermediate response. */
if( pAtResp->pItm->pNext != NULL )
{
pInputLine = pAtResp->pItm->pNext->pLine;
pInputLine = pAtResp->pItm->pNext->pLine;

if( ( pInputLine != NULL ) && ( dataLenToCopy > 0U ) )
{
/* Copy the data to the out buffer. */
( void ) memcpy( ( void * ) pDataRecv->pData, ( const void * ) pInputLine, dataLenToCopy );
}
else
{
LogError( ( "Receive Data: paramerter error, data pointer %p, data to copy %u",
pInputLine, dataLenToCopy ) );
atCoreStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
else if( *pDataRecv->pDataLen == 0U )
if( ( pInputLine != NULL ) && ( dataLenToCopy > 0U ) )
{
/* Receive command success but no data. */
LogDebug( ( "Receive Data: no data" ) );
/* Copy the data to the out buffer. */
( void ) memcpy( ( void * ) pDataRecv->pData, ( const void * ) pInputLine, dataLenToCopy );
}
else
{
LogError( ( "Receive Data: Intermediate response empty" ) );
LogError( ( "Receive Data: paramerter error, data pointer %p, data to copy %u",
pInputLine, dataLenToCopy ) );
atCoreStatus = CELLULAR_AT_BAD_PARAMETER;
}

Expand All @@ -282,8 +269,6 @@ static CellularPktStatus_t _Cellular_RecvFuncData( CellularContext_t * pContext,
const _socketDataRecv_t * pDataRecv = ( _socketDataRecv_t * ) pData;
int32_t tempValue = 0;

( void ) dataLen;

if( pContext == NULL )
{
LogError( ( "Receive Data: invalid context" ) );
Expand Down Expand Up @@ -314,7 +299,8 @@ static CellularPktStatus_t _Cellular_RecvFuncData( CellularContext_t * pContext,
{
if( pAtResp->pItm->pNext == NULL )
{
/* No data response. */
/* Modem return +USORD: 0,"". No data returned since there is no data
* length field in modem response. */
*pDataRecv->pDataLen = 0;
}
else
Expand All @@ -341,10 +327,11 @@ static CellularPktStatus_t _Cellular_RecvFuncData( CellularContext_t * pContext,
}
}

/* Process the data buffer. */
if( atCoreStatus == CELLULAR_AT_SUCCESS )
/* Process the data buffer. Modem may also return +USORD: 0,0,"" with 0 data length.
* Process the data response only when data length is greater than 0. */
if( ( atCoreStatus == CELLULAR_AT_SUCCESS ) && ( *pDataRecv->pDataLen > 0U ) )
{
atCoreStatus = getDataFromResp( pAtResp, pDataRecv, *pDataRecv->pDataLen );
atCoreStatus = getDataFromResp( pAtResp, pDataRecv, dataLen );
}
}
}
Expand Down

0 comments on commit dda105f

Please sign in to comment.