Cellular Interface: AT+COPS=3,2 timeout on HL7802

I am having problem with Cellular_ModuleEnableUrc function in cellular_hl7802.c.
Command AT+COPS has 120 second timeout (according to AirPrime HL78xx AT Commands Interface Guide) but the driver uses _Cellular_AtcmdRequestWithCallback function with 5-second default timeout. I measured that response to this command takes around 9 seconds on my HL7802 development board with 1NCE sim card.
I think that changing the call to

( void ) _Cellular_TimeoutAtcmdRequestWithCallback( pContext, atReqGetNoResult, UINT32_C(120000) ); 

would fix the problem.

This, however, brings me to a second problem:
When a command times out, the response from HL7802 can still arrive later. Also, when a command times out, other command will be sent after the timeout by the driver. But when the response to the original command then arrives, the driver will take it as a response to the second command. Because a lot of the responses are just plain “OK”, they can get mixed up and it basically creates a lag or off-by-one kind of error until it fails on some command that expects a different response. The problem is with the AT command system itself but that is something we cannot change. The only fix I could come up with is flushing the input buffer before sending command. It helps but I think it would be prone to race conditions on a full-duplex UART line. In the end, I only encountered this problem when the timeout for AT+COPS was the original 5 seconds and I changed it to 120 seconds so I no longer have issues with wrongfully assigned responses but still, this is something that bothers me. I wanted to point this – what I consider a weak point – out.

Hi Kaktus,

If the AT command timeout event received, the command status will be set to CELLULAR_NO_AT_COMMAND.
The following response “OK” will be regarded as “AT_UNDEFINED” and the input buffer will be flushed.

If new AT command is issued before the response of previous command is received, there will be race condition as you mentioned.
A safe suggestion is to reboot the modem if the modem can’t response within the timeout time according to the spec.
We will also think about other solution to mitigate the race condition.

The problem you encountered is the timeout value should be set according to the spec.
We will create a PR to update the library with the timeout value from the spec.

Thank you for your information. Your suggestion and concern are valuable to us.

Hi Kaktus,

HL7802 AT command timeout is updated in this commit.

Thank you very much!