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

[Cellular/Wiring] Remove rssi and qual from Cellular.RSSI() #2212

Merged
merged 6 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion hal/inc/cellular_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void cellular_cancel(bool cancel, bool calledFromISR, void* reserved);
/**
* Retrieve cellular signal strength info
*/
cellular_result_t cellular_signal(CellularSignalHal* signal, cellular_signal_t* reserved);
cellular_result_t cellular_signal(void* deprecated, cellular_signal_t* reserved);

/**
* Send an AT command and wait for response, optionally specify a callback function to parse the results
Expand Down
6 changes: 0 additions & 6 deletions hal/inc/cellular_hal_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ struct CellularDevice
typedef struct CellularDevice CellularDevice;
#endif

typedef struct
{
int rssi;
int qual;
} CellularSignalHal;

typedef struct
{
uint16_t size;
Expand Down
2 changes: 1 addition & 1 deletion hal/inc/hal_dynalib_cellular.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ DYNALIB_FN(13, hal_cellular, cellular_cancel, void(bool, bool, void*))
DYNALIB_FN(14, hal_cellular, HAL_NET_SetNetWatchDog, uint32_t(uint32_t))
DYNALIB_FN(15, hal_cellular, inet_gethostbyname, int(const char*, uint16_t, HAL_IPAddress*, network_interface_t, void*))
DYNALIB_FN(16, hal_cellular, inet_ping, int(const HAL_IPAddress*, network_interface_t, uint8_t, void*))
DYNALIB_FN(17, hal_cellular, cellular_signal, cellular_result_t(CellularSignalHal*, cellular_signal_t*))
DYNALIB_FN(17, hal_cellular, cellular_signal, cellular_result_t(void*, cellular_signal_t*))
DYNALIB_FN(18, hal_cellular, cellular_command, cellular_result_t(_CALLBACKPTR_MDM, void*, system_tick_t, const char*, ...))
DYNALIB_FN(19, hal_cellular, cellular_data_usage_set, cellular_result_t(CellularDataHal*,void*))
DYNALIB_FN(20, hal_cellular, cellular_data_usage_get, cellular_result_t(CellularDataHal*,void*))
Expand Down
57 changes: 6 additions & 51 deletions hal/network/ncp/cellular/cellular_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ bool cellular_sim_ready(void* reserved) {
void cellular_cancel(bool cancel, bool calledFromISR, void* reserved) {
}

int cellular_signal(CellularSignalHal* signal, cellular_signal_t* signalExt) {
int cellular_signal(void* deprecated, cellular_signal_t* signalExt) {
if (deprecated != nullptr && signalExt == nullptr) {
return SYSTEM_ERROR_INVALID_ARGUMENT;
}

const auto mgr = cellularNetworkManager();
CHECK_TRUE(mgr, SYSTEM_ERROR_UNKNOWN);
const auto client = mgr->ncpClient();
Expand All @@ -303,56 +307,7 @@ int cellular_signal(CellularSignalHal* signal, cellular_signal_t* signalExt) {
CHECK(client->getSignalQuality(&s));
const auto strn = s.strength();
const auto qual = s.quality();
if (signal) {
// Compatibility with Gen 2
if (strn != 99 && strn != 255) {
int compatStrn = strn;
switch (s.strengthUnits()) {
case CellularStrengthUnits::RXLEV: {
// Leave as-is
break;
}
case CellularStrengthUnits::RSCP: {
// Simply re-map from [0-96] to [0-63]
compatStrn = (compatStrn * 63) / 96;
break;
}
case CellularStrengthUnits::RSRP: {
// Simply remap from [0-97] to [0-63]
compatStrn = (compatStrn * 63) / 97;
break;
}
}
// -113 to -50dBm
signal->rssi = -113 + compatStrn;
}
// see 3GPP TS 45.008 [20] subclause 8.2.4
static const char compatQualMap[] = { 49, 43, 37, 25, 19, 13, 7, 0 };
if (qual != 99 && qual != 255) {
int compatQual = qual;
switch (s.qualityUnits()) {
case CellularQualityUnits::RXQUAL:
case CellularQualityUnits::MEAN_BEP: {
// Leave as-is
break;
}
case CellularQualityUnits::ECN0: {
// Re-map from [0-49] to [0-7]. Table in UBX-13002752 - R62 (7.2.4)
compatQual = 7 - ((std::max(std::min(compatQual, 44), 2) - 2) / 6);
break;
}
case CellularQualityUnits::RSRQ: {
// Re-map from [0-34] to [0-7]. Table in UBX-13002752 - R62 (7.2.4)
compatQual = (compatQual < 10) ? (compatQual / 5) : ((std::min(compatQual, 30) - 10) / 4) + 2;
break;
}
}
// Just in case validate that we are not going to go out of bounds
if (compatQual >= 0 && compatQual <= 7) {
signal->qual = compatQualMap[compatQual];
}
}
}

if (signalExt) {
signalExt->rat = fromCellularAccessTechnology(s.accessTechnology());
// Signal strength
Expand Down
5 changes: 1 addition & 4 deletions hal/shared/cellular_enums_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@ typedef struct {
Reg psd; //!< PSD Registration status (Packet Switched Data)
Reg eps; //!< EPS registration status (Evolved Packet System)
AcT act; //!< Access Technology
int rssi; //!< Received Signal Strength Indication (in dBm, range -113..-53)
int qual; //!< In UMTS RAT indicates the Energy per Chip/Noise ratio in dB levels
//!< of the current cell (see <ecn0_ lev> in +CGED command description),
//!< see 3GPP TS 45.008 [20] subclause 8.2.4

union {
int rxlev; //!< GSM RAT: RXLEV ([0, 63], 99), see 3GPP TS 45.008 subclause 8.1.4
int rscp; //!< UMTS RAT: RSCP ([-5, 91], 255), see 3GPP TS 25.133 subclause 9.1.1.3
Expand Down
6 changes: 3 additions & 3 deletions hal/src/electron/cellular_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,16 @@ void cellular_cancel(bool cancel, bool calledFromISR, void*)
}
}

cellular_result_t cellular_signal(CellularSignalHal* signal, cellular_signal_t* signalext)
cellular_result_t cellular_signal(void* deprecated, cellular_signal_t* signalext)
{
if (signal == nullptr && signalext == nullptr) {
if (deprecated != nullptr && signalext == nullptr) {
return SYSTEM_ERROR_INVALID_ARGUMENT;
}

NetStatus status;
bool r = electronMDM.getSignalStrength(status);

return particle::detail::cellular_signal_impl(signal, signalext, r, status);
return particle::detail::cellular_signal_impl(signalext, r, status);
}

cellular_result_t cellular_command(_CALLBACKPTR_MDM cb, void* param,
Expand Down
7 changes: 1 addition & 6 deletions hal/src/electron/cellular_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace particle { namespace detail {

cellular_result_t cellular_signal_impl(CellularSignalHal* signal, cellular_signal_t* signalext, bool strengthResult, const NetStatus& status) {
cellular_result_t cellular_signal_impl(cellular_signal_t* signalext, bool strengthResult, const NetStatus& status) {
// % * 100, see 3GPP TS 45.008 8.2.4
// 0.14%, 0.28%, 0.57%, 1.13%, 2.26%, 4.53%, 9.05%, 18.10%
static const uint16_t berMapping[] = {14, 28, 57, 113, 226, 453, 905, 1810};
Expand All @@ -23,11 +23,6 @@ cellular_result_t cellular_signal_impl(CellularSignalHal* signal, cellular_signa
return SYSTEM_ERROR_UNKNOWN;
}

if (signal != nullptr) {
signal->rssi = status.rssi;
signal->qual = status.qual;
}

if (signalext != nullptr) {
switch (status.act) {
case ACT_GSM:
Expand Down
2 changes: 1 addition & 1 deletion hal/src/electron/cellular_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cellular_result_t cellular_data_usage_get_impl(CellularDataHal &data, const MDM_
/* detail functions defined for unit tests */
namespace particle { namespace detail {

cellular_result_t cellular_signal_impl(CellularSignalHal* signal, cellular_signal_t* signalext, bool strengthResult, const NetStatus& status);
cellular_result_t cellular_signal_impl(cellular_signal_t* signalext, bool strengthResult, const NetStatus& status);

}} // namespace particle detail

Expand Down
27 changes: 0 additions & 27 deletions hal/src/electron/modem/mdm_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2160,15 +2160,6 @@ int MDMParser::_cbUCGED(int type, const char* buf, int len, NetStatus* status)
status->rsrp = 255;
}

// Compatibility values for old API
if (status->rsrp != 255) {
// Simply remap from [0-97] to [0-63]
int compatStrn = (status->rsrp * 63) / 97;
// -113 to -50dBm
status->rssi = -113 + compatStrn;
} else {
status->rssi = 0;
}
}
// RSRQ maps from dBm [-20,-3] to [0,34]
// We are defining hard boundaries for RSRP to be between [],
Expand All @@ -2185,17 +2176,6 @@ int MDMParser::_cbUCGED(int type, const char* buf, int len, NetStatus* status)
status->rsrq = 255;
}

// Compatibility values for old API
if (status->rsrq != 255) {
// Re-map from [0-34] to [0-7]. Table in UBX-13002752 - R62 (7.2.4)
int compatQual = (status->rsrq < 10) ? (status->rsrq / 5) : ((std::min(status->rsrq, 30) - 10) / 4) + 2;
// Just in case validate that we are not going to go out of bounds
if (compatQual >= 0 && compatQual <= 7) {
status->qual = compatQualMap[compatQual];
}
} else {
status->qual = 0;
}
}
}
return WAIT;
Expand All @@ -2207,9 +2187,6 @@ int MDMParser::_cbCSQ(int type, const char* buf, int len, NetStatus* status)
int a,b;
// +CSQ: <rssi>,<qual>
if (sscanf(buf, "\r\n+CSQ: %d,%d",&a,&b) == 2) {
if (a != 99) status->rssi = -113 + 2*a; // 0: -113 1: -111 ... 30: -53 dBm with 2 dBm steps
if ((b != 99) && (b < (int)sizeof(compatQualMap))) status->qual = compatQualMap[b]; //

switch (status->act) {
case ACT_GSM:
case ACT_EDGE:
Expand Down Expand Up @@ -3571,10 +3548,6 @@ void MDMParser::dumpNetStatus(NetStatus *status)
const char* txtAct[] = { "Unknown", "GSM", "Edge", "3G", "CDMA" };
if (status->act < sizeof(txtAct)/sizeof(*txtAct) && (status->act != ACT_UNKNOWN))
MDM_PRINTF(" Access Technology: %s\r\n", txtAct[status->act]);
if (status->rssi)
MDM_PRINTF(" Signal Strength: %d dBm\r\n", status->rssi);
if (status->qual)
MDM_PRINTF(" Signal Quality: %d\r\n", status->qual);
if (status->cgi.mobile_country_code != 0)
MDM_PRINTF(" Mobile Country Code: %d\r\n", status->cgi.mobile_country_code);
if (status->cgi.mobile_network_code != 0)
Expand Down
Loading