Skip to content

Commit

Permalink
backport CellularSignal::isValid()
Browse files Browse the repository at this point in the history
  • Loading branch information
avtolstoy committed Jun 22, 2021
1 parent 90ae7d7 commit 25666be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions wiring/inc/spark_wiring_cellular_printable.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class CellularSignal : public particle::Signal, public Printable {

virtual size_t printTo(Print& p) const;

virtual bool isValid() const;
virtual operator bool() const;

private:
cellular_signal_t sig_ = {0};
};
Expand Down
20 changes: 20 additions & 0 deletions wiring/src/spark_wiring_cellular_printable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ size_t CellularSignal::printTo(Print& p) const
}
#pragma GCC diagnostic pop

bool CellularSignal::isValid() const
{
return (sig_.rat != NET_ACCESS_TECHNOLOGY_NONE &&
sig_.rssi != std::numeric_limits<int32_t>::min() &&
#if (PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION)
// U-blox GSM radios may not always support quality as it depends on the packet switching mode
// at the time of network connection, which is not possible to query. For now, we will return "true"
// for GSM Electrons and will not check if quality is actually supported / valid.
// Hence, `isValid()` can return "true" for invalid signal value. To add a note in docs.
(sig_.rat == NET_ACCESS_TECHNOLOGY_GSM || sig_.qual != std::numeric_limits<int32_t>::min()));
#else
sig_.qual != std::numeric_limits<int32_t>::min());
#endif
}

CellularSignal::operator bool() const
{
return isValid();
}

size_t CellularData::printTo(Print& p) const
{
size_t n = 0;
Expand Down

0 comments on commit 25666be

Please sign in to comment.