Skip to content

Commit 329d45a

Browse files
authored
Handle undefined message when sending AT command (#110)
* Update pktio to handle undefined message when sending AT command * Undefined message handler is moved to pkthandler * Use PktRespMutex in pktio thread to keep data consistency * Add test cases to cover the undefined message handle flow * Update ATE0 handling in SARA R4 and HL7802. ATE0 may still echo back ATE0. Change the AT command type to CELLULAR_AT_WO_PREFIX
1 parent c0cb120 commit 329d45a

13 files changed

Lines changed: 792 additions & 82 deletions

docs/doxygen/include/size_table.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@
2424
</tr>
2525
<tr>
2626
<td>cellular_common_api.c</td>
27+
<td><center>0.7K</center></td>
2728
<td><center>0.6K</center></td>
28-
<td><center>0.5K</center></td>
2929
</tr>
3030
<tr>
3131
<td>cellular_common.c</td>
32-
<td><center>1.6K</center></td>
32+
<td><center>1.7K</center></td>
3333
<td><center>1.5K</center></td>
3434
</tr>
3535
<tr>
3636
<td>cellular_pkthandler.c</td>
37-
<td><center>1.5K</center></td>
38-
<td><center>1.4K</center></td>
37+
<td><center>1.7K</center></td>
38+
<td><center>1.6K</center></td>
3939
</tr>
4040
<tr>
4141
<td>cellular_pktio.c</td>
42+
<td><center>2.0K</center></td>
4243
<td><center>1.8K</center></td>
43-
<td><center>1.6K</center></td>
4444
</tr>
4545
<tr>
4646
<td><b>Total estimates</b></td>
47-
<td><b><center>14.2K</center></b></td>
48-
<td><b><center>12.9K</center></b></td>
47+
<td><b><center>14.8K</center></b></td>
48+
<td><b><center>13.4K</center></b></td>
4949
</tr>
5050
</table>

lexicon.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ pktioreadthread
547547
pktiosendatcmd
548548
pktiosenddata
549549
pktioshutdown
550+
pktrequestmutex
551+
pktrespmutex
550552
pktrespqueue
551553
pktrxcallback
552554
pktstatus
@@ -799,6 +801,7 @@ technoloyg
799801
tempvalue
800802
testindex
801803
testresultnumber
804+
threadreturn
802805
threadroutine
803806
ticktype
804807
timeoutatcmddatarecvrequestwithcallback

modules/hl7802/cellular_hl7802.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ CellularError_t Cellular_ModuleEnableUE( CellularContext_t * pContext )
335335
{
336336
CellularError_t cellularStatus = CELLULAR_SUCCESS;
337337
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
338+
CellularAtReq_t atReqGetWoPrefix =
339+
{
340+
NULL,
341+
CELLULAR_AT_WO_PREFIX,
342+
NULL,
343+
NULL,
344+
NULL,
345+
0
346+
};
338347
CellularAtReq_t atReqGetNoResult =
339348
{
340349
NULL,
@@ -351,8 +360,8 @@ CellularError_t Cellular_ModuleEnableUE( CellularContext_t * pContext )
351360
if( pContext != NULL )
352361
{
353362
/* Disable echo. */
354-
atReqGetNoResult.pAtCmd = "ATE0";
355-
cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetNoResult,
363+
atReqGetWoPrefix.pAtCmd = "ATE0";
364+
cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetWoPrefix,
356365
CELLULAR_HL7802_AT_TIMEOUT_2_SECONDS_MS );
357366

358367
if( cellularStatus == CELLULAR_SUCCESS )
@@ -464,8 +473,8 @@ CellularError_t Cellular_ModuleEnableUE( CellularContext_t * pContext )
464473
if( cellularStatus == CELLULAR_SUCCESS )
465474
{
466475
Platform_Delay( CELLULAR_HL7802_RESET_DELAY_MS );
467-
atReqGetNoResult.pAtCmd = "ATE0";
468-
cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetNoResult,
476+
atReqGetWoPrefix.pAtCmd = "ATE0";
477+
cellularStatus = sendAtCommandWithRetryTimeout( pContext, &atReqGetWoPrefix,
469478
CELLULAR_HL7802_AT_TIMEOUT_2_SECONDS_MS );
470479
}
471480
}

modules/sara_r4/cellular_r4.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,15 @@ CellularError_t rebootCellularModem( CellularContext_t * pContext,
262262
CellularError_t cellularStatus = CELLULAR_SUCCESS;
263263
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
264264
uint32_t count = 0;
265-
265+
CellularAtReq_t atReqGetWoPrefix =
266+
{
267+
NULL,
268+
CELLULAR_AT_WO_PREFIX,
269+
NULL,
270+
NULL,
271+
NULL,
272+
0
273+
};
266274
CellularAtReq_t atReqGetNoResult =
267275
{
268276
"AT+CFUN=15",
@@ -283,9 +291,9 @@ CellularError_t rebootCellularModem( CellularContext_t * pContext,
283291
{
284292
LogInfo( ( "rebootCellularModem: Use ATE0 command to test modem status." ) );
285293

286-
atReqGetNoResult.pAtCmd = "ATE0";
294+
atReqGetWoPrefix.pAtCmd = "ATE0";
287295

288-
pktStatus = _Cellular_TimeoutAtcmdRequestWithCallback( pContext, atReqGetNoResult, ENBABLE_MODULE_UE_REBOOT_POLL_TIME );
296+
pktStatus = _Cellular_TimeoutAtcmdRequestWithCallback( pContext, atReqGetWoPrefix, ENBABLE_MODULE_UE_REBOOT_POLL_TIME );
289297
cellularStatus = _Cellular_TranslatePktStatus( pktStatus );
290298

291299
if( cellularStatus == CELLULAR_SUCCESS )

source/cellular_common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ CellularError_t _Cellular_RegisterUndefinedRespCallback( CellularContext_t * pCo
11151115
else
11161116
{
11171117
/* undefinedRespCallback can be set to NULL to unregister the callback. */
1118+
PlatformMutex_Lock( &pContext->PktRespMutex );
11181119
pContext->undefinedRespCallback = undefinedRespCallback;
11191120

11201121
if( pContext->undefinedRespCallback != NULL )
@@ -1125,6 +1126,8 @@ CellularError_t _Cellular_RegisterUndefinedRespCallback( CellularContext_t * pCo
11251126
{
11261127
pContext->pUndefinedRespCBContext = NULL;
11271128
}
1129+
1130+
PlatformMutex_Unlock( &pContext->PktRespMutex );
11281131
}
11291132

11301133
return cellularStatus;

source/cellular_common_api.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ CellularError_t Cellular_CommonRegisterUrcNetworkRegistrationEventCallback( Cell
206206
}
207207
else
208208
{
209+
PlatformMutex_Lock( &pContext->PktRespMutex );
209210
pContext->cbEvents.networkRegistrationCallback = networkRegistrationCallback;
210211
pContext->cbEvents.pNetworkRegistrationCallbackContext = pCallbackContext;
212+
PlatformMutex_Unlock( &pContext->PktRespMutex );
211213
}
212214

213215
return cellularStatus;
@@ -231,8 +233,10 @@ CellularError_t Cellular_CommonRegisterUrcPdnEventCallback( CellularHandle_t cel
231233
}
232234
else
233235
{
236+
PlatformMutex_Lock( &pContext->PktRespMutex );
234237
pContext->cbEvents.pdnEventCallback = pdnEventCallback;
235238
pContext->cbEvents.pPdnEventCallbackContext = pCallbackContext;
239+
PlatformMutex_Unlock( &pContext->PktRespMutex );
236240
}
237241

238242
return cellularStatus;
@@ -256,8 +260,10 @@ CellularError_t Cellular_CommonRegisterUrcSignalStrengthChangedCallback( Cellula
256260
}
257261
else
258262
{
263+
PlatformMutex_Lock( &pContext->PktRespMutex );
259264
pContext->cbEvents.signalStrengthChangedCallback = signalStrengthChangedCallback;
260265
pContext->cbEvents.pSignalStrengthChangedCallbackContext = pCallbackContext;
266+
PlatformMutex_Unlock( &pContext->PktRespMutex );
261267
}
262268

263269
return cellularStatus;
@@ -281,8 +287,10 @@ CellularError_t Cellular_CommonRegisterUrcGenericCallback( CellularHandle_t cell
281287
}
282288
else
283289
{
290+
PlatformMutex_Lock( &pContext->PktRespMutex );
284291
pContext->cbEvents.genericCallback = genericCallback;
285292
pContext->cbEvents.pGenericCallbackContext = pCallbackContext;
293+
PlatformMutex_Unlock( &pContext->PktRespMutex );
286294
}
287295

288296
return cellularStatus;
@@ -306,8 +314,10 @@ CellularError_t Cellular_CommonRegisterModemEventCallback( CellularHandle_t cell
306314
}
307315
else
308316
{
317+
PlatformMutex_Lock( &pContext->PktRespMutex );
309318
pContext->cbEvents.modemEventCallback = modemEventCallback;
310319
pContext->cbEvents.pModemEventCallbackContext = pCallbackContext;
320+
PlatformMutex_Unlock( &pContext->PktRespMutex );
311321
}
312322

313323
return cellularStatus;

0 commit comments

Comments
 (0)