Skip to content

Commit

Permalink
[quectel] fixes quectel-ncp-client not waiting for modem ready on col…
Browse files Browse the repository at this point in the history
…d boot
  • Loading branch information
technobly committed Sep 22, 2023
1 parent 74a41f7 commit eecda85
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 39 additions & 1 deletion hal/network/ncp_client/quectel/quectel_ncp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ const unsigned REGISTRATION_TWILIO_HOLDOFF_TIMEOUT = 5 * 60 * 1000;
const system_tick_t QUECTEL_COPS_TIMEOUT = 3 * 60 * 1000;
const system_tick_t QUECTEL_CFUN_TIMEOUT = 3 * 60 * 1000;

const auto QUECTEL_CFUN_MAX_ATTEMPTS = 10;

// Undefine hardware version
const auto HW_VERSION_UNDEFINED = 0xFF;

Expand Down Expand Up @@ -1041,10 +1043,19 @@ bool QuectelNcpClient::isQuecCat1Device() {

int QuectelNcpClient::initReady(ModemState state) {
// Set modem full functionality
int r = CHECK_PARSER(parser_.execCommand("AT+CFUN=1,0"));
int r = AtResponse::OK;
for (int x = 0; x < QUECTEL_CFUN_MAX_ATTEMPTS; x++) {
int r = setModuleFunctionality(CellularFunctionality::FULL, true /* check */);
if (r == AtResponse::OK) {
break;
}
HAL_Delay_Milliseconds(1000);
}
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);

if (state != ModemState::MuxerAtChannel) {
// Cold Boot only, Warm Boot will skip the following block...

// Enable flow control and change to runtime baudrate
#if PLATFORM_ID == PLATFORM_B5SOM
uint32_t hwVersion = HW_VERSION_UNDEFINED;
Expand Down Expand Up @@ -1262,6 +1273,33 @@ int QuectelNcpClient::checkSimCard() {
return SYSTEM_ERROR_UNKNOWN;
}

int QuectelNcpClient::getModuleFunctionality() {
auto resp = parser_.sendCommand(QUECTEL_CFUN_TIMEOUT, "AT+CFUN?");
int curVal = -1;
auto r = resp.scanf("+CFUN: %d", &curVal);
CHECK_PARSER_OK(resp.readResult());
CHECK_TRUE(r == 1, SYSTEM_ERROR_AT_RESPONSE_UNEXPECTED);
return curVal;
}

int QuectelNcpClient::setModuleFunctionality(CellularFunctionality cfun, bool check) {
if (check) {
if ((int)cfun == CHECK(getModuleFunctionality())) {
// Already in required state
return 0;
}
}

int r = SYSTEM_ERROR_UNKNOWN;

r = parser_.execCommand(QUECTEL_CFUN_TIMEOUT, "AT+CFUN=%d,0", (int)cfun);

CHECK_PARSER(r);

// AtResponse::Result!
return r;
}

int QuectelNcpClient::configureApn(const CellularNetworkConfig& conf) {
// IMPORTANT: Set modem full functionality!
// Otherwise we won't be able to query ICCID/IMSI
Expand Down
2 changes: 2 additions & 0 deletions hal/network/ncp_client/quectel/quectel_ncp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class QuectelNcpClient: public CellularNcpClient {
int checkNetConfForImsi();
int selectSimCard();
int checkSimCard();
int getModuleFunctionality();
int setModuleFunctionality(CellularFunctionality cfun, bool check);
int configureApn(const CellularNetworkConfig& conf);
int registerNet();
int changeBaudRate(unsigned int baud);
Expand Down

0 comments on commit eecda85

Please sign in to comment.