-
Notifications
You must be signed in to change notification settings - Fork 513
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
[Diagnostics] Signal strength/quality #1423
Changes from all commits
56b2db0
8908876
6aee4d8
b70f91a
d14c19c
6a1ab90
cba95fd
9848ca3
1938c26
aea33bc
07f6b17
280d674
7d43a26
270fa29
7fbf1a8
6a691f4
a7bb79a
467f4a5
a103e88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,10 @@ | |
#include "spark_macros.h" | ||
#include "security.h" | ||
#include "evnt_handler.h" | ||
|
||
#include "timer_hal.h" | ||
#include <sys/param.h> | ||
#include "system_error.h" | ||
#include <limits.h> | ||
|
||
/* Smart Config Prefix */ | ||
static char aucCC3000_prefix[] = {'T', 'T', 'T'}; | ||
|
@@ -166,26 +169,53 @@ wlan_result_t wlan_disconnect_now() | |
|
||
int wlan_connected_rssi() | ||
{ | ||
tNetappIpconfigRetArgs config; | ||
netapp_ipconfig((void*)&config); | ||
|
||
int _returnValue = 0; | ||
int l; | ||
for (l=0; l<16; l++) | ||
{ | ||
char wlan_scan_results_table[50]; | ||
if(wlan_ioctl_get_scan_results(0, (unsigned char*)wlan_scan_results_table) != 0) | ||
return(1); | ||
if (wlan_scan_results_table[0] == 0) | ||
break; | ||
if (!strcmp(wlan_scan_results_table+12, config.uaSSID)) { | ||
_returnValue = ((wlan_scan_results_table[8] >> 1) - 127); | ||
|
||
system_tick_t _functionStart = HAL_Timer_Get_Milli_Seconds(); | ||
while ((HAL_Timer_Get_Milli_Seconds() - _functionStart) < 1000) { | ||
tNetappIpconfigRetArgs config; | ||
netapp_ipconfig((void*)&config); | ||
int l; | ||
for (l=0; l<16; l++) | ||
{ | ||
char wlan_scan_results_table[50]; | ||
if(wlan_ioctl_get_scan_results(0, (unsigned char*)wlan_scan_results_table) != 0) { | ||
_returnValue = 1; | ||
break; | ||
} | ||
if (wlan_scan_results_table[0] == 0) | ||
break; | ||
if (!strcmp(wlan_scan_results_table+12, config.uaSSID)) { | ||
_returnValue = ((wlan_scan_results_table[8] >> 1) - 127); | ||
break; | ||
} | ||
} | ||
if (_returnValue != 0) { | ||
break; | ||
} | ||
} | ||
return _returnValue; | ||
} | ||
|
||
int wlan_connected_info(void* reserved, wlan_connected_info_t* inf, void* reserved1) | ||
{ | ||
system_error_t ret = SYSTEM_ERROR_NONE; | ||
|
||
int32_t rssi = wlan_connected_rssi(); | ||
if (rssi >= 0) { | ||
// Error | ||
return SYSTEM_ERROR_UNKNOWN; | ||
} | ||
|
||
inf->rssi = rssi * 100; | ||
inf->snr = INT_MIN; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add flags to explicitly indicate which fields are supported? |
||
inf->noise = INT_MIN; | ||
|
||
inf->strength = MIN(MAX(2 * (rssi + 100), 0L), 100L) * 65535 / 100; | ||
inf->quality = INT_MIN; | ||
return ret; | ||
} | ||
|
||
netapp_pingreport_args_t ping_report; | ||
uint8_t ping_report_num; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
#include "modem/mdm_hal.h" | ||
#include "cellular_hal.h" | ||
#include "cellular_internal.h" | ||
#include "system_error.h" | ||
#include <limits> | ||
#include <cmath> | ||
#include "net_hal.h" | ||
|
||
#define CHECK_SUCCESS(x) { if (!(x)) return -1; } | ||
|
||
|
@@ -176,13 +180,93 @@ void cellular_cancel(bool cancel, bool calledFromISR, void*) | |
} | ||
} | ||
|
||
cellular_result_t cellular_signal(CellularSignalHal &signal, void* reserved) | ||
cellular_result_t cellular_signal(CellularSignalHal* signal, cellular_signal_t* signalext) | ||
{ | ||
// % * 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}; | ||
|
||
cellular_result_t res = SYSTEM_ERROR_NONE; | ||
if (signal == nullptr && signalext == nullptr) { | ||
return SYSTEM_ERROR_INVALID_ARGUMENT; | ||
} | ||
NetStatus status; | ||
CHECK_SUCCESS(electronMDM.getSignalStrength(status)); | ||
signal.rssi = status.rssi; | ||
signal.qual = status.qual; | ||
return 0; | ||
if (signal != nullptr) { | ||
signal->rssi = status.rssi; | ||
signal->qual = status.qual; | ||
} | ||
|
||
if (signalext != nullptr) { | ||
switch (status.act) { | ||
case ACT_GSM: | ||
signalext->rat = NET_ACCESS_TECHNOLOGY_GSM; | ||
break; | ||
case ACT_EDGE: | ||
signalext->rat = NET_ACCESS_TECHNOLOGY_EDGE; | ||
break; | ||
case ACT_UTRAN: | ||
signalext->rat = NET_ACCESS_TECHNOLOGY_UTRAN; | ||
break; | ||
default: | ||
signalext->rat = NET_ACCESS_TECHNOLOGY_NONE; | ||
break; | ||
} | ||
switch (status.act) { | ||
case ACT_GSM: | ||
case ACT_EDGE: | ||
// Convert to dBm [-111, -48], see 3GPP TS 45.008 8.1.4 | ||
// Reported multiplied by 100 | ||
signalext->rssi = ((status.rxlev != 99) ? status.rxlev - 111 : -111) * 100; | ||
|
||
// NOTE: From u-blox AT Command Reference manual: | ||
// SARA-U260-00S / SARA-U270-00S / SARA-U270-00X / SARA-U280-00S / LISA-U200-00S / | ||
// LISA-U200-01S / LISA-U200-02S / LISA-U200-52S / LISA-U200-62S / LISA-U230 / LISA-U260 / | ||
// LISA-U270 / LISA-U1 | ||
// The <qual> parameter is not updated in GPRS and EGPRS packet transfer mode | ||
if (status.act == ACT_GSM) { | ||
// Convert to BER (% * 100), see 3GPP TS 45.008 8.2.4 | ||
signalext->ber = (status.rxqual != 99) ? berMapping[status.rxqual] : std::numeric_limits<int32_t>::min(); | ||
} else /* status.act == ACT_EDGE */ { | ||
// Convert to MEAN_BEP level first | ||
// See u-blox AT Reference Manual: | ||
// In 2G RAT EGPRS packet transfer mode indicates the Mean Bit Error Probability (BEP) of a radio | ||
// block. 3GPP TS 45.008 [148] specifies the range 0-31 for the Mean BEP which is mapped to | ||
// the range 0-7 of <qual> | ||
int bepLevel = (status.rxqual != 99) ? (7 - status.rxqual) * 31 / 7 : std::numeric_limits<int32_t>::min(); | ||
// Convert to log10(MEAN_BEP) multiplied by 100, see 3GPP TS 45.008 10.2.3.3 | ||
// Uses QPSK table | ||
signalext->bep = bepLevel >= 0 ? (-(bepLevel - 31) * 10 - 3.7) : bepLevel; | ||
} | ||
|
||
// RSSI in % [0, 100] based on [-111, -48] range mapped to [0, 65535] integer range | ||
signalext->strength = (status.rxlev != 99) ? status.rxlev * 65535 / 63 : std::numeric_limits<int32_t>::min(); | ||
// Quality based on RXQUAL in % [0, 100] mapped to [0, 65535] integer range | ||
signalext->quality = (status.rxqual != 99) ? (7 - status.rxqual) * 65535 / 7 : std::numeric_limits<int32_t>::min(); | ||
break; | ||
case ACT_UTRAN: | ||
// Convert to dBm [-121, -25], see 3GPP TS 25.133 9.1.1.3 | ||
// Reported multiplied by 100 | ||
signalext->rscp = ((status.rscp != 255) ? status.rscp - 116 : -121) * 100; | ||
// Convert to Ec/Io (dB) [-24.5, 0], see 3GPP TS 25.133 9.1.2.3 | ||
// Report multiplied by 100 | ||
signalext->ecno = (status.ecno != 255) ? status.ecno * 50 - 2450 : -2450; | ||
|
||
// RSCP in % [0, 100] based on [-121, -25] range mapped to [0, 65535] integer range | ||
signalext->strength = (status.rscp != 255) ? (status.rscp + 5) * 65535 / 96 : std::numeric_limits<int32_t>::min(); | ||
// Quality based on Ec/Io in % [0, 100] mapped to [0,65535] integer range | ||
signalext->quality = (status.ecno != 255) ? status.ecno * 65535 / 49 : std::numeric_limits<int32_t>::min(); | ||
break; | ||
default: | ||
res = SYSTEM_ERROR_UNKNOWN; | ||
signalext->rssi = std::numeric_limits<int32_t>::min(); | ||
signalext->qual = std::numeric_limits<int32_t>::min(); | ||
signalext->strength = 0; | ||
signalext->quality = 0; | ||
break; | ||
} | ||
} | ||
return res; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps factor out fetching the data from the modem from computing the percentages so that the computation can be more easily tested. |
||
} | ||
|
||
cellular_result_t cellular_command(_CALLBACKPTR_MDM cb, void* param, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should have flags to indicate which fields are supported.