Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes ncp-client not waiting for modem ready on cold boot #2700

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1059,10 +1061,19 @@ bool QuectelNcpClient::isQuecBG95xDevice() {

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 @@ -1280,6 +1291,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