Skip to content

Commit 9bdeb68

Browse files
author
Ari Parkkila
committed
Cellular: Updated debug prints, and network registration return value
Updated cellular debug trace prints: - Removed unnecessary prints. - Tracing more in DEBUG level. - Read/write bytes not printed on big packets. - Signal quality (RSSI) traced to log network problems. - Dismissed AT data is traced. - Modem type and firmware version are traced. Network registration returns NotRegistered instead of StatusNotAvailable, because that's not in 3GPP TS 27.007.
1 parent 8a2044b commit 9bdeb68

File tree

13 files changed

+216
-157
lines changed

13 files changed

+216
-157
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_registration_params)
185185
reg_params._periodic_tau = 3;
186186

187187
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_registration_params(CellularNetwork::C_EREG, reg_params));
188-
EXPECT_TRUE(reg_params._status == CellularNetwork::StatusNotAvailable);
188+
EXPECT_TRUE(reg_params._status == CellularNetwork::NotRegistered);
189189
EXPECT_TRUE(reg_params._act == CellularNetwork::RAT_UNKNOWN);
190190
EXPECT_TRUE(reg_params._cell_id == -1 && reg_params._active_time == -1 && reg_params._periodic_tau == -1);
191191

192192
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_registration_params(CellularNetwork::C_GREG, reg_params));
193-
EXPECT_TRUE(reg_params._status == CellularNetwork::StatusNotAvailable);
193+
EXPECT_TRUE(reg_params._status == CellularNetwork::NotRegistered);
194194
EXPECT_TRUE(reg_params._act == CellularNetwork::RAT_UNKNOWN);
195195
EXPECT_TRUE(reg_params._cell_id == -1);
196196

@@ -201,12 +201,12 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_registration_params)
201201
reg_params._periodic_tau = 3;
202202

203203
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == nw.get_registration_params(CellularNetwork::C_EREG, reg_params));
204-
EXPECT_TRUE(reg_params._status == CellularNetwork::StatusNotAvailable);
204+
EXPECT_TRUE(reg_params._status == CellularNetwork::NotRegistered);
205205
EXPECT_TRUE(reg_params._act == CellularNetwork::RAT_UNKNOWN);
206206
EXPECT_TRUE(reg_params._cell_id == -1 && reg_params._active_time == -1 && reg_params._periodic_tau == -1);
207207
// Check get_registration_params without specifying the registration type
208208
EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_registration_params(reg_params_check));
209-
EXPECT_TRUE(reg_params_check._status == CellularNetwork::StatusNotAvailable);
209+
EXPECT_TRUE(reg_params_check._status == CellularNetwork::NotRegistered);
210210
EXPECT_TRUE(reg_params_check._act == CellularNetwork::RAT_UNKNOWN);
211211
EXPECT_TRUE(reg_params_check._cell_id == -1 && reg_params_check._active_time == -1 && reg_params_check._periodic_tau == -1);
212212
}
@@ -497,7 +497,7 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_signal_quality)
497497
ATHandler_stub::int_value = 1;
498498
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
499499
EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_signal_quality(rs, ber));
500-
EXPECT_TRUE(rs == 1 && ber == 1);
500+
EXPECT_TRUE(rs == -111 && ber == 1);
501501
}
502502

503503
TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_3gpp_error)

features/cellular/framework/API/CellularNetwork.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ class CellularNetwork {
7979
AttachedEmergencyOnly,
8080
RegisteredCSFBNotPreferredHome,
8181
RegisteredCSFBNotPreferredRoaming,
82-
AlreadyRegistered = 11 // our our definition when modem says that we are not registered but we have active PDP Context
82+
AlreadyRegistered = 11, // our definition when modem says that we are not registered but we have active PDP Context
83+
RegistrationStatusMax
8384
};
8485

8586
/* Network registration type */
@@ -107,7 +108,8 @@ class CellularNetwork {
107108
RAT_E_UTRAN,
108109
RAT_CATM1,
109110
RAT_NB1,
110-
RAT_UNKNOWN
111+
RAT_UNKNOWN,
112+
RAT_MAX = 11 // to reserve string array
111113
};
112114

113115
// 3GPP TS 27.007 - 7.3 PLMN selection +COPS
@@ -342,7 +344,7 @@ class CellularNetwork {
342344
*/
343345
virtual bool is_active_context() = 0;
344346

345-
/** Gets current network registration parameters:
347+
/** Gets the latest received registration parameters from the network:
346348
* type, status, access technology, cell_id, lac, active_time, periodic_tau.
347349
*
348350
* @param reg_params see registration_params_t
@@ -351,7 +353,7 @@ class CellularNetwork {
351353
*/
352354
virtual nsapi_error_t get_registration_params(registration_params_t &reg_params) = 0;
353355

354-
/** Gets the network registration parameters based on required registration type:
356+
/** Gets the current network registration parameters from the network with type:
355357
* status, access technology, cell_id, lac, active_time, periodic_tau.
356358
*
357359
* @param type see RegistrationType values

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ using namespace mbed_cellular_util;
3636
// URCs should be handled fast, if you add debug traces within URC processing then you also need to increase this time
3737
#define PROCESS_URC_TIME 20
3838

39+
// Suppress logging of very big packet payloads, maxlen is approximate due to write/read are cached
40+
#define DEBUG_MAXLEN 80
41+
3942
const char *mbed::OK = "OK\r\n";
4043
const uint8_t OK_LENGTH = 4;
4144
const char *mbed::CRLF = "\r\n";
@@ -281,8 +284,8 @@ void ATHandler::process_oob()
281284
return;
282285
}
283286
lock();
284-
tr_debug("process_oob readable=%d, pos=%u, len=%u", _fileHandle->readable(), _recv_pos, _recv_len);
285287
if (_fileHandle->readable() || (_recv_pos < _recv_len)) {
288+
tr_debug("AT OoB readable %d, len %u", _fileHandle->readable(), _recv_len - _recv_pos);
286289
_current_scope = NotSet;
287290
uint32_t timeout = _at_timeout;
288291
_at_timeout = PROCESS_URC_TIME;
@@ -302,8 +305,8 @@ void ATHandler::process_oob()
302305
}
303306
}
304307
_at_timeout = timeout;
308+
tr_debug("AT OoB done");
305309
}
306-
tr_debug("process_oob exit");
307310
unlock();
308311
}
309312

@@ -355,6 +358,7 @@ bool ATHandler::fill_buffer(bool wait_for_timeout)
355358
// Reset buffer when full
356359
if (sizeof(_recv_buff) == _recv_len) {
357360
tr_error("AT overflow");
361+
debug_print(_recv_buff, _recv_len);
358362
reset_buffer();
359363
}
360364

@@ -443,15 +447,22 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
443447
return -1;
444448
}
445449

450+
bool debug_on = _debug_on;
446451
size_t read_len = 0;
447452
for (; read_len < len; read_len++) {
448453
int c = get_char();
449454
if (c == -1) {
450455
set_error(NSAPI_ERROR_DEVICE_ERROR);
456+
_debug_on = debug_on;
451457
return -1;
452458
}
453459
buf[read_len] = c;
460+
if (_debug_on && read_len >= DEBUG_MAXLEN) {
461+
debug_print("..", sizeof(".."));
462+
_debug_on = false;
463+
}
454464
}
465+
_debug_on = debug_on;
455466
return read_len;
456467
}
457468

@@ -739,13 +750,13 @@ device_err_t ATHandler::get_last_device_error() const
739750

740751
void ATHandler::set_error(nsapi_error_t err)
741752
{
753+
if (err != NSAPI_ERROR_OK) {
754+
tr_debug("AT error %d", err);
755+
}
742756
if (_last_err == NSAPI_ERROR_OK) {
743757
_last_err = err;
744758
}
745759

746-
if (_last_err != err) {
747-
tr_warn("AT error code changed from %d to %d!", _last_err, err);
748-
}
749760
}
750761

751762
int ATHandler::get_3gpp_error()
@@ -977,7 +988,7 @@ bool ATHandler::consume_to_stop_tag()
977988
return true;
978989
}
979990

980-
tr_warn("AT stop tag not found");
991+
tr_debug("AT stop tag not found");
981992
set_error(NSAPI_ERROR_DEVICE_ERROR);
982993
return false;
983994
}
@@ -1130,20 +1141,31 @@ size_t ATHandler::write(const void *data, size_t len)
11301141
fhs.fh = _fileHandle;
11311142
fhs.events = POLLOUT;
11321143
size_t write_len = 0;
1144+
bool debug_on = _debug_on;
11331145
for (; write_len < len;) {
11341146
int count = poll(&fhs, 1, poll_timeout());
11351147
if (count <= 0 || !(fhs.revents & POLLOUT)) {
11361148
set_error(NSAPI_ERROR_DEVICE_ERROR);
1149+
_debug_on = debug_on;
11371150
return 0;
11381151
}
11391152
ssize_t ret = _fileHandle->write((uint8_t *)data + write_len, len - write_len);
11401153
if (ret < 0) {
11411154
set_error(NSAPI_ERROR_DEVICE_ERROR);
1155+
_debug_on = debug_on;
11421156
return 0;
11431157
}
1144-
debug_print((char *)data + write_len, ret);
1158+
if (_debug_on && write_len < DEBUG_MAXLEN) {
1159+
if (write_len + ret < DEBUG_MAXLEN) {
1160+
debug_print((char *)data + write_len, ret);
1161+
} else {
1162+
debug_print("..", sizeof(".."));
1163+
_debug_on = false;
1164+
}
1165+
}
11451166
write_len += (size_t)ret;
11461167
}
1168+
_debug_on = debug_on;
11471169

11481170
return write_len;
11491171
}
@@ -1175,13 +1197,14 @@ bool ATHandler::check_cmd_send()
11751197

11761198
void ATHandler::flush()
11771199
{
1200+
tr_debug("AT flush");
11781201
reset_buffer();
11791202
while (fill_buffer(false)) {
11801203
reset_buffer();
11811204
}
11821205
}
11831206

1184-
void ATHandler::debug_print(char *p, int len)
1207+
void ATHandler::debug_print(const char *p, int len)
11851208
{
11861209
#if MBED_CONF_CELLULAR_DEBUG_AT
11871210
if (_debug_on) {

features/cellular/framework/AT/ATHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ class ATHandler {
524524
bool find_urc_handler(const char *prefix);
525525

526526
// print contents of a buffer to trace log
527-
void debug_print(char *p, int len);
527+
void debug_print(const char *p, int len);
528528
};
529529

530530
} // namespace mbed

0 commit comments

Comments
 (0)