Skip to content

Commit

Permalink
[b5som] ncp: strip padding F from ICCID, use queryAndParseAtCops() in…
Browse files Browse the repository at this point in the history
… getSignalQuality()
  • Loading branch information
avtolstoy committed Mar 27, 2020
1 parent a03c56a commit 4aa1746
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions hal/src/b5som/network/quectel_ncp_client.cpp
Expand Up @@ -109,6 +109,8 @@ const auto HW_VERSION_UNDEFINED = 0xFF;
// V003 - 0x00 (disable hwfc)
// V004 - 0x01 (enable hwfc)
const auto HAL_VERSION_B5SOM_V003 = 0x00;

const auto ICCID_MAX_LENGTH = 20;

This comment has been minimized.

Copy link
@keeramis

keeramis Mar 27, 2020

Contributor

Is it ok to stick to 20 here? I am not aware that it will be longer than 20, but we are currently scanning for 31 chars in ICCID, and wonder why we picked 31.

CHECK_TRUE(r == 1, SYSTEM_ERROR_UNKNOWN);

This comment has been minimized.

Copy link
@keeramis

keeramis Mar 27, 2020

Contributor

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Mar 27, 2020

Author Member

It is. ICCIDs are 19 or 20 digits. The 31 comes from the buffer size (which is 32) minus 1 byte for null-terminating character. We only need to take a look at ICCIDs of length 20 (which is the max) to check for the padding character.

} // namespace

QuectelNcpClient::QuectelNcpClient() {}
Expand Down Expand Up @@ -404,7 +406,13 @@ int QuectelNcpClient::getIccid(char* buf, size_t size) {
CHECK_TRUE(r == 1, SYSTEM_ERROR_UNKNOWN);
r = CHECK_PARSER(resp.readResult());
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);
size_t n = std::min(strlen(iccid), size);
auto iccidLen = strlen(iccid);
// Strip padding F, as for certain SIMs Quectel's AT+CCID does not strip it on its own
if (iccidLen == ICCID_MAX_LENGTH && (iccid[iccidLen - 1] == 'F' || iccid[iccidLen - 1] == 'f')) {
iccid[iccidLen - 1] = '\0';
--iccidLen;
}
size_t n = std::min(iccidLen, size);
memcpy(buf, iccid, n);
if (size > 0) {
if (n == size) {
Expand Down Expand Up @@ -486,7 +494,20 @@ int QuectelNcpClient::getCellularGlobalIdentity(CellularGlobalIdentity* cgi) {
CHECK(checkParser());
CHECK(queryAndParseAtCops(nullptr));

*cgi = cgi_;
switch (cgi->version)
{
case CGI_VERSION_1:
default:
{
// Confirm user is expecting the correct amount of data
CHECK_TRUE((cgi->size >= sizeof(cgi_)), SYSTEM_ERROR_INVALID_ARGUMENT);

*cgi = cgi_;
cgi->size = sizeof(cgi_);
cgi->version = CGI_VERSION_1;
break;
}
}

return SYSTEM_ERROR_NONE;
}
Expand All @@ -496,36 +517,7 @@ int QuectelNcpClient::getSignalQuality(CellularSignalQuality* qual) {
CHECK_TRUE(connState_ != NcpConnectionState::DISCONNECTED, SYSTEM_ERROR_INVALID_STATE);
CHECK_TRUE(qual, SYSTEM_ERROR_INVALID_ARGUMENT);
CHECK(checkParser());

{
int act;
int v;
auto resp = parser_.sendCommand("AT+COPS?");
int r = CHECK_PARSER(resp.scanf("+COPS: %d,%*d,\"%*[^\"]\",%d", &v, &act));
CHECK_TRUE(r == 2, SYSTEM_ERROR_UNKNOWN);
r = CHECK_PARSER(resp.readResult());
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);

switch (static_cast<CellularAccessTechnology>(act)) {
case CellularAccessTechnology::NONE:
case CellularAccessTechnology::GSM:
case CellularAccessTechnology::GSM_COMPACT:
case CellularAccessTechnology::UTRAN:
case CellularAccessTechnology::GSM_EDGE:
case CellularAccessTechnology::UTRAN_HSDPA:
case CellularAccessTechnology::UTRAN_HSUPA:
case CellularAccessTechnology::UTRAN_HSDPA_HSUPA:
case CellularAccessTechnology::LTE:
case CellularAccessTechnology::EC_GSM_IOT:
case CellularAccessTechnology::E_UTRAN: {
break;
}
default: {
return SYSTEM_ERROR_BAD_DATA;
}
}
qual->accessTechnology(static_cast<CellularAccessTechnology>(act));
}
CHECK(queryAndParseAtCops(qual));

// Using AT+QCSQ first
struct RatMap {
Expand Down

0 comments on commit 4aa1746

Please sign in to comment.