Skip to content

Commit

Permalink
[b5som] fixes EG91NA getting stuck in COPS? ERROR init loop
Browse files Browse the repository at this point in the history
  • Loading branch information
technobly committed May 18, 2022
1 parent 421844d commit 1ef3805
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions hal/network/ncp_client/quectel/quectel_ncp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ const int DATA_MODE_BREAK_ATTEMPTS = 5;
const int PPP_ECHO_REQUEST_ATTEMPTS = 3;
const int CGDCONT_ATTEMPTS = 5;

const int COPS_MAX_RETRY_CNT = 3;

} // anonymous

QuectelNcpClient::QuectelNcpClient() {
Expand Down Expand Up @@ -1287,12 +1289,26 @@ int QuectelNcpClient::registerNet() {

connectionState(NcpConnectionState::CONNECTING);

auto resp = parser_.sendCommand("AT+COPS?");
// EG91NA can get stuck in an COPS? ERROR init loop, retry 2 times.
int copsCount = 0;
int copsState = 2;
r = CHECK_PARSER(resp.scanf("+COPS: %d", &copsState));
CHECK_TRUE(r == 1, SYSTEM_ERROR_AT_RESPONSE_UNEXPECTED);
r = CHECK_PARSER(resp.readResult());
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_AT_NOT_OK);
char copsResponse[64] = {};
do {
auto resp = parser_.sendCommand("AT+COPS?");
if (resp.hasNextLine()) {
CHECK_PARSER(resp.readLine(copsResponse, sizeof(copsResponse)));
CHECK_PARSER(::sscanf(copsResponse, "+COPS: %d", &copsState));
}
r = CHECK_PARSER(resp.readResult());
if (r == AtResponse::OK) {
break;
} else if (copsCount >= COPS_MAX_RETRY_CNT) {
// if max retries are exhausted
return SYSTEM_ERROR_AT_RESPONSE_UNEXPECTED;
}
++copsCount;
HAL_Delay_Milliseconds(2000 * copsCount);
} while (copsCount < COPS_MAX_RETRY_CNT);

if (copsState != 0 && copsState != 1) {
// Only run AT+COPS=0 if currently de-registered, to avoid PLMN reselection
Expand Down

0 comments on commit 1ef3805

Please sign in to comment.