Cellular logging to use mbed_trace

pull/6082/head
Ari Parkkila 2018-02-19 12:44:24 +02:00
parent 331a27df63
commit f2613a6154
19 changed files with 144 additions and 264 deletions

View File

@ -21,39 +21,39 @@ using namespace mbed;
static bool wait_register()
{
log_info("Try registering to network...");
tr_info("Try registering to network...");
if (network->set_registration() != NSAPI_ERROR_OK) {
log_error("Network registration request failed.");
tr_error("Network registration request failed.");
return false;
}
CellularNetwork::RegistrationStatus status;
for (int i=0; i<180; i++) {
log_info("Register to network %d...", i);
tr_info("Register to network %d...", i);
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
if (network->get_registration_status((CellularNetwork::RegistrationType)type, status) == NSAPI_ERROR_OK) {
log_info("status %d...", status);
tr_info("status %d...", status);
switch (status) {
case CellularNetwork::RegisteredRoaming:
// fall-through
case CellularNetwork::RegisteredHomeNetwork:
log_info("Registered to network.");
tr_info("Registered to network.");
return true;
case CellularNetwork::RegisteredSMSOnlyRoaming:
// fall-through
case CellularNetwork::RegisteredSMSOnlyHome:
log_warn("SMS only network registration!");
tr_warn("SMS only network registration!");
return true;
case CellularNetwork::RegisteredCSFBNotPreferredRoaming:
// fall-through
case CellularNetwork::RegisteredCSFBNotPreferredHome:
log_warn("Not preferred network registration!");
tr_warn("Not preferred network registration!");
return true;
case CellularNetwork::AttachedEmergencyOnly:
log_warn("Emergency only network registration!");
tr_warn("Emergency only network registration!");
return true;
case CellularNetwork::RegistrationDenied:
log_warn("Network registration denied!");
tr_warn("Network registration denied!");
wait(i);
break;
case CellularNetwork::NotRegistered:
@ -71,9 +71,9 @@ static bool wait_register()
void test_attach()
{
log_info("Register to network.");
tr_info("Register to network.");
TEST_ASSERT(wait_register());
log_info("Attach to network.");
tr_info("Attach to network.");
nsapi_error_t err = network->set_attach();
TEST_ASSERT(!err);
CellularNetwork::AttachStatus status;
@ -91,7 +91,7 @@ void test_get_ip_address()
{
const char *ip = network->get_ip_address();
TEST_ASSERT(ip && ip[0]);
log_info("IP: %s\r\n", ip);
tr_info("IP: %s\r\n", ip);
}
void test_disconnect()

View File

@ -30,7 +30,7 @@ static bool start_cellular_at(CellularPower *pwr)
if (err != NSAPI_ERROR_OK && err != NSAPI_ERROR_UNSUPPORTED) {
return false;
}
log_info("Wait for cellular device 180 seconds...");
tr_info("Wait for cellular device 180 seconds...");
for (int i = 0; i < 180; i++) {
if (pwr->set_at_mode() == NSAPI_ERROR_OK) {
return true;
@ -44,7 +44,7 @@ void test_create_power()
{
TEST_ASSERT(start_cellular_at(pwr));
log_info("Cellular device is ready!");
tr_info("Cellular device is ready!");
}
// TODO: tests still missing for off, sleep, opt_power_save_mode, opt_receive_period

View File

@ -26,7 +26,7 @@ void test_get_sim_state()
{
wait(1);
CellularSIM::SimState state = CellularSIM::SimStateUnknown;
log_info("Wait SIM for 180 seconds...");
tr_info("Wait SIM for 180 seconds...");
for (int i = 0; i < 180; i++) {
CellularSIM::SimState tmp_state;
if ((sim->get_sim_state(tmp_state) == NSAPI_ERROR_OK) && tmp_state != CellularSIM::SimStateUnknown) {

View File

@ -54,7 +54,7 @@ void test_socket_send_receive_blocking()
// Send to echo server
while (send_tries <= max_send_tries) {
log_info("ONE!!!");
tr_info("ONE!!!");
send_count = socket.sendto(SERVER_IP_ADDR, SERVER_UDP_PORT, send_buffer, sizeof(send_buffer));
TEST_ASSERT_MESSAGE(send_count == sizeof(send_buffer), "Sent count doesnt match sent buffer!");
send_tries++;
@ -65,7 +65,7 @@ void test_socket_send_receive_blocking()
// 2 tries. First recv attempt should be blocked and wait for a max 5 seconds for socket read flag
int recv_tries = 2;
while (recv_tries >= 0) {
log_info("RECV!!!");
tr_info("RECV!!!");
receive_count = socket.recvfrom(&address, receive_buffer, sizeof(receive_buffer));
if (receive_count > 0) {
break;

View File

@ -28,8 +28,6 @@
using namespace mbed;
using namespace events;
uint32_t mbed::cellular_log_time = 0;
void conn_stat_cb(nsapi_error_t error)
{

View File

@ -28,8 +28,6 @@
using namespace mbed;
using namespace events;
uint32_t mbed::cellular_log_time = 0;
Test_AT_CellularSIM::Test_AT_CellularSIM()
{
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;

View File

@ -28,8 +28,6 @@
using namespace mbed;
using namespace events;
uint32_t mbed::cellular_log_time = 0;
Test_AT_CellularSMS::Test_AT_CellularSMS()
{
ATHandler_stub::return_given_size = false;

View File

@ -29,8 +29,6 @@
using namespace mbed;
using namespace events;
uint32_t mbed::cellular_log_time = 0;
class MyStack : public AT_CellularStack {
public:
bool bool_value;

View File

@ -30,8 +30,6 @@
using namespace mbed;
using namespace events;
uint32_t mbed::cellular_log_time = 0;
void urc_callback()
{
}

View File

@ -62,7 +62,7 @@ nsapi_error_t CellularConnectionUtil::init()
at_queue.chain(&_queue);
log_info("init done...");
tr_info("init done...");
return NSAPI_ERROR_OK;
}
@ -77,10 +77,10 @@ bool CellularConnectionUtil::open_power(FileHandle *fh)
nsapi_error_t err = _power->on();
if (err != NSAPI_ERROR_OK && err != NSAPI_ERROR_UNSUPPORTED) {
log_warn("Cellular start failed. Power off/on.");
tr_warn("Cellular start failed. Power off/on.");
err = _power->off();
if (err != NSAPI_ERROR_OK && err != NSAPI_ERROR_UNSUPPORTED) {
log_error("Cellular power down failed!");
tr_error("Cellular power down failed!");
}
return false;
}
@ -107,14 +107,14 @@ bool CellularConnectionUtil::open_sim()
// wait until SIM is readable
// here you could add wait(secs) if you know start delay of your SIM
while (sim->get_sim_state(state) != NSAPI_ERROR_OK || state == CellularSIM::SimStateUnknown) {
log_debug("Waiting for SIM (state %d)...", state);
tr_debug("Waiting for SIM (state %d)...", state);
return false;
}
if (state == CellularSIM::SimStatePinNeeded) {
log_info("SIM pin required, entering pin: %s", _sim_pin);
tr_info("SIM pin required, entering pin: %s", _sim_pin);
err = sim->set_pin(_sim_pin);
if (err) {
log_error("SIM pin set failed with: %d, bailing out...", err);
tr_error("SIM pin set failed with: %d, bailing out...", err);
return false;
}
// here you could add wait(secs) if you know delay of changing PIN on your SIM
@ -122,13 +122,13 @@ bool CellularConnectionUtil::open_sim()
if (sim->get_sim_state(state) == NSAPI_ERROR_OK && state == CellularSIM::SimStateReady) {
break;
}
log_debug("SIM state: %d", state);
tr_debug("SIM state: %d", state);
return false;
}
}
return state == CellularSIM::SimStateReady;
} else {
log_info("Continue without SIM.");
tr_info("Continue without SIM.");
return true;
}
}
@ -138,13 +138,13 @@ void CellularConnectionUtil::device_ready()
CellularInformation *info = _cellularDevice->open_information(_serial);
if (info->get_manufacturer(device_info_buf, sizeof(device_info_buf)) == NSAPI_ERROR_OK) {
log_info("Cellular device manufacturer: %s", device_info_buf);
tr_info("Cellular device manufacturer: %s", device_info_buf);
}
if (info->get_model(device_info_buf, sizeof(device_info_buf)) == NSAPI_ERROR_OK) {
log_info("Cellular device model: %s", device_info_buf);
tr_info("Cellular device model: %s", device_info_buf);
}
if (info->get_revision(device_info_buf, sizeof(device_info_buf)) == NSAPI_ERROR_OK) {
log_info("Cellular device revision: %s", device_info_buf);
tr_info("Cellular device revision: %s", device_info_buf);
}
}
@ -159,7 +159,7 @@ bool CellularConnectionUtil::open_network()
bool CellularConnectionUtil::set_network_registration(char *plmn)
{
if (_network->set_registration(plmn) != NSAPI_ERROR_OK) {
log_error("Failed to set network registration.");
tr_error("Failed to set network registration.");
return false;
}
return true;
@ -173,7 +173,7 @@ bool CellularConnectionUtil::get_network_registration(CellularNetwork::Registrat
nsapi_error_t err = _network->get_registration_status(type, status);
if (err != NSAPI_ERROR_OK) {
if (err != NSAPI_ERROR_UNSUPPORTED) {
log_warn("Get network registration failed (type %d)!", type);
tr_warn("Get network registration failed (type %d)!", type);
}
return false;
}
@ -188,16 +188,16 @@ bool CellularConnectionUtil::get_network_registration(CellularNetwork::Registrat
is_roaming = true;
// fall-through
case CellularNetwork::RegisteredSMSOnlyHome:
log_warn("SMS only network registration!");
tr_warn("SMS only network registration!");
break;
case CellularNetwork::RegisteredCSFBNotPreferredRoaming:
is_roaming = true;
// fall-through
case CellularNetwork::RegisteredCSFBNotPreferredHome:
log_warn("Not preferred network registration!");
tr_warn("Not preferred network registration!");
break;
case CellularNetwork::AttachedEmergencyOnly:
log_warn("Emergency only network registration!");
tr_warn("Emergency only network registration!");
break;
case CellularNetwork::RegistrationDenied:
case CellularNetwork::NotRegistered:
@ -208,7 +208,7 @@ bool CellularConnectionUtil::get_network_registration(CellularNetwork::Registrat
}
if (is_roaming) {
log_warn("Roaming cellular network!");
tr_warn("Roaming cellular network!");
}
return true;
@ -234,7 +234,7 @@ bool CellularConnectionUtil::set_attach_network()
void CellularConnectionUtil::report_failure(const char* msg)
{
log_error("Cellular network failed: %s", msg);
tr_error("Cellular network failed: %s", msg);
if (_status_callback) {
_status_callback(_state, _next_state);
}
@ -261,13 +261,13 @@ void CellularConnectionUtil::event()
switch (_state) {
case STATE_POWER_ON:
cellularDevice.set_timeout(TIMEOUT_POWER_ON);
log_info("Cellular power ON (timeout %d ms)", TIMEOUT_POWER_ON);
tr_info("Cellular power ON (timeout %d ms)", TIMEOUT_POWER_ON);
if (open_power(_serial)) {
_next_state = STATE_DEVICE_READY;
} else {
static int retry_count;
if (++retry_count <= 10) {
log_warn("Power ON retry %d", retry_count);
tr_warn("Power ON retry %d", retry_count);
event_timeout = 1000;
} else {
report_failure("Power");
@ -278,12 +278,12 @@ void CellularConnectionUtil::event()
case STATE_DEVICE_READY:
cellularDevice.set_timeout(TIMEOUT_POWER_ON);
if (_power->set_at_mode() == NSAPI_ERROR_OK) {
log_info("Cellular device ready");
tr_info("Cellular device ready");
_next_state = STATE_START_CELLULAR;
device_ready();
} else {
static int retry_count = 0;
log_info("Waiting for cellular device (retry %d/10, timeout %d ms)", retry_count, TIMEOUT_POWER_ON);
tr_info("Waiting for cellular device (retry %d/10, timeout %d ms)", retry_count, TIMEOUT_POWER_ON);
if (++retry_count <= 10) {
event_timeout = 1000;
} else {
@ -294,20 +294,20 @@ void CellularConnectionUtil::event()
break;
case STATE_START_CELLULAR:
cellularDevice.set_timeout(TIMEOUT_NETWORK);
log_info("Start cellular (timeout %d ms)", TIMEOUT_NETWORK);
tr_info("Start cellular (timeout %d ms)", TIMEOUT_NETWORK);
open_network();
_next_state = STATE_SIM_PIN;
break;
case STATE_SIM_PIN:
cellularDevice.set_timeout(TIMEOUT_SIM_PIN);
log_info("Start cellular (timeout %d ms)", TIMEOUT_SIM_PIN);
tr_info("Start cellular (timeout %d ms)", TIMEOUT_SIM_PIN);
if (open_sim()) {
_next_state = STATE_REGISTERING_NETWORK;
log_info("Check for network registration");
tr_info("Check for network registration");
} else {
static int retry_count;
if (++retry_count <= 10) {
log_warn("Waiting for SIM %d", retry_count);
tr_warn("Waiting for SIM %d", retry_count);
event_timeout = 1000;
} else {
report_failure("Entering SIM PIN");
@ -322,27 +322,27 @@ void CellularConnectionUtil::event()
_next_state = STATE_REGISTER_NETWORK;
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
if (get_network_registration((CellularNetwork::RegistrationType)type, status, is_registered)) {
log_debug("get_network_registration: type=%d, status=%d", type, status);
tr_debug("get_network_registration: type=%d, status=%d", type, status);
if (is_registered) {
log_info("Registered to cellular network (type %d, status %d)", type, status);
tr_info("Registered to cellular network (type %d, status %d)", type, status);
_next_state = STATE_ATTACH_NETWORK;
log_info("Check cellular network attach state");
tr_info("Check cellular network attach state");
break;
} else {
if (status == CellularNetwork::RegistrationDenied) {
static int backoff_timeout = 1;
log_warn("Network registration denied (type %d)! Retry after %d seconds.", type, backoff_timeout);
tr_warn("Network registration denied (type %d)! Retry after %d seconds.", type, backoff_timeout);
event_timeout = backoff_timeout * 1000;
backoff_timeout *= 2;
break;
} else if (status != CellularNetwork::NotRegistered) {
static int retry_count;
if (++retry_count <= 180) {
log_info("Waiting for registration %d/180 (type %d, status %d)", retry_count, type, status);
tr_info("Waiting for registration %d/180 (type %d, status %d)", retry_count, type, status);
event_timeout = 1*1000;
_next_state = STATE_REGISTERING_NETWORK;
} else {
log_info("Start cellular registration");
tr_info("Start cellular registration");
_next_state = STATE_REGISTER_NETWORK;
retry_count = 0;
break;
@ -356,7 +356,7 @@ void CellularConnectionUtil::event()
break;
case STATE_REGISTER_NETWORK:
cellularDevice.set_timeout(TIMEOUT_REGISTRATION);
log_info("Register to cellular network (timeout %d ms)", TIMEOUT_REGISTRATION);
tr_info("Register to cellular network (timeout %d ms)", TIMEOUT_REGISTRATION);
if (set_network_registration()) {
_next_state = STATE_REGISTERING_NETWORK;
} else {
@ -384,17 +384,17 @@ void CellularConnectionUtil::event()
break;
case STATE_ATTACH_NETWORK:
cellularDevice.set_timeout(TIMEOUT_NETWORK);
log_info("Attach to cellular network (timeout %d ms)", TIMEOUT_NETWORK);
tr_info("Attach to cellular network (timeout %d ms)", TIMEOUT_NETWORK);
if (set_attach_network()) {
_next_state = STATE_ATTACHING_NETWORK;
log_info("Cellular network attaching");
tr_info("Cellular network attaching");
} else {
event_timeout = 0;
}
break;
case STATE_CONNECT_NETWORK:
cellularDevice.set_timeout(TIMEOUT_NETWORK);
log_info("Connect to cellular network (timeout %d ms)", TIMEOUT_NETWORK);
tr_info("Connect to cellular network (timeout %d ms)", TIMEOUT_NETWORK);
err = _network->connect();
if (!err) {
_next_state = STATE_CONNECTED;
@ -405,7 +405,7 @@ void CellularConnectionUtil::event()
break;
case STATE_CONNECTED:
cellularDevice.set_timeout(TIMEOUT_NETWORK);
log_debug("Cellular ready! (timeout %d ms)", TIMEOUT_NETWORK);
tr_debug("Cellular ready! (timeout %d ms)", TIMEOUT_NETWORK);
if (_status_callback) {
if (!_status_callback(_state, _next_state)) {
return;
@ -419,7 +419,7 @@ void CellularConnectionUtil::event()
if (_next_state != _state || event_timeout >= 0) {
if (_next_state != _state) {
log_info("Cellular state from %d to %d", _state, _next_state);
tr_info("Cellular state from %d to %d", _state, _next_state);
if (_status_callback) {
if (!_status_callback(_state, _next_state)) {
return;
@ -429,13 +429,13 @@ void CellularConnectionUtil::event()
if (event_timeout == 0) {
static int retry_count = 0;
if (++retry_count <= 3) {
log_info("Cellular event retry %d", retry_count);
tr_info("Cellular event retry %d", retry_count);
} else {
report_failure("Cellular connection failed!");
return;
}
} else {
log_info("Cellular event in %d milliseconds", event_timeout);
tr_info("Cellular event in %d milliseconds", event_timeout);
}
}
_state = _next_state;
@ -451,8 +451,8 @@ void CellularConnectionUtil::event()
nsapi_error_t CellularConnectionUtil::start_dispatch()
{
log_info("CellularConnectionUtil::start");
log_info("Create cellular thread");
tr_info("CellularConnectionUtil::start");
tr_info("Create cellular thread");
MBED_ASSERT(!_queue_thread);
@ -466,13 +466,13 @@ nsapi_error_t CellularConnectionUtil::start_dispatch()
return NSAPI_ERROR_NO_MEMORY;
}
log_info("CellularConnectionUtil::started");
tr_info("CellularConnectionUtil::started");
return NSAPI_ERROR_OK;
}
void CellularConnectionUtil::stop()
{
log_info("CellularConnectionUtil::stop");
tr_info("CellularConnectionUtil::stop");
_cellularDevice->close_power();
_cellularDevice->close_network();
if (_queue_thread) {

View File

@ -38,7 +38,7 @@ static UARTSerial cellularSerial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERI
bool EasyCellularConnection::cellular_status(int state, int next_state)
{
log_info("cellular_status %d=>%d", state, next_state);
tr_info("cellular_status %d=>%d", state, next_state);
if (_target_state == state) {
if (state == CellularConnectionUtil::STATE_CONNECTED) {
_is_connected = true;
@ -56,7 +56,7 @@ bool EasyCellularConnection::cellular_status(int state, int next_state)
EasyCellularConnection::EasyCellularConnection() : _is_connected(false), _target_state(CellularConnectionUtil::STATE_POWER_ON)
{
log_info("EasyCellularConnection()");
tr_info("EasyCellularConnection()");
}
EasyCellularConnection::~EasyCellularConnection()
@ -66,8 +66,6 @@ EasyCellularConnection::~EasyCellularConnection()
nsapi_error_t EasyCellularConnection::init()
{
log_init(STDIO_UART_TX, STDIO_UART_RX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
#if defined (MDMRTS) && defined (MDMCTS)
cellularSerial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
#endif
@ -89,7 +87,7 @@ void EasyCellularConnection::set_credentials(const char *apn, const char *uname,
if (network) {
network->set_credentials(apn, uname, pwd);
} else {
log_error("NO Network...");
tr_error("NO Network...");
}
}
@ -112,7 +110,7 @@ nsapi_error_t EasyCellularConnection::connect()
if (err == NSAPI_ERROR_OK) {
int ret_wait = cellularSemaphore.wait(10*60*1000); // cellular network searching may take several minutes
if (ret_wait != 1) {
log_info("No cellular connection");
tr_info("No cellular connection");
err = NSAPI_ERROR_NO_CONNECTION;
}
}

View File

@ -228,7 +228,7 @@ void ATHandler::restore_at_timeout()
void ATHandler::process_oob()
{
lock();
log_debug("process_oob %d", (_fileHandle->readable() || (_recv_pos < _recv_len)));
tr_debug("process_oob %d", (_fileHandle->readable() || (_recv_pos < _recv_len)));
if (_fileHandle->readable() || (_recv_pos < _recv_len)) {
_current_scope = NotSet;
Timer timer;
@ -254,7 +254,7 @@ void ATHandler::process_oob()
}
} while (timer.read_ms() < 20); // URC's are very short so 20ms should be enough
}
log_debug("process_oob exit");
tr_debug("process_oob exit");
flush(); // consume anything that could not be handled
@ -272,13 +272,13 @@ void ATHandler::set_filehandle_sigio()
void ATHandler::reset_buffer()
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
_recv_pos = 0; _recv_len = 0;
}
void ATHandler::rewind_buffer()
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (_recv_pos > 0 && _recv_len >= _recv_pos) {
_recv_len -= _recv_pos;
// move what is not read to beginning of buffer
@ -290,7 +290,7 @@ void ATHandler::rewind_buffer()
// we are always expecting to receive something so there is wait timeout
void ATHandler::fill_buffer()
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
// Reset buffer when full
if (sizeof(_recv_buff) == _recv_len) {
reset_buffer();
@ -309,7 +309,7 @@ void ATHandler::fill_buffer()
at_debug("\n----------readable----------\n");
return;
} else if (len != -EAGAIN && len != 0) {
log_warn("%s error: %d while reading", __func__, len);
tr_warn("%s error: %d while reading", __func__, len);
break;
}
#ifdef MBED_CONF_RTOS_PRESENT
@ -318,29 +318,29 @@ void ATHandler::fill_buffer()
} while ((uint32_t)timer.read_ms() < _at_timeout);
set_error(NSAPI_ERROR_DEVICE_ERROR);
log_error("AT TIMEOUT, scope: %d timeout: %d", _current_scope, _at_timeout);
tr_error("AT TIMEOUT, scope: %d timeout: %lu", _current_scope, _at_timeout);
}
int ATHandler::get_char()
{
if (_recv_pos == _recv_len) {
log_debug("%s", __func__);
tr_debug("%s", __func__);
reset_buffer(); // try to read as much as possible
fill_buffer();
if (get_last_error()) {
log_debug("%s: -1", __func__);
tr_debug("%s: -1", __func__);
return -1; // timeout to read
}
}
log_debug("%s: %c", __func__, _recv_buff[_recv_pos]);
tr_debug("%s: %c", __func__, _recv_buff[_recv_pos]);
return _recv_buff[_recv_pos++];
}
void ATHandler::skip_param(uint32_t count)
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (_last_err || !_stop_tag || _stop_tag->found) {
return;
}
@ -370,7 +370,7 @@ void ATHandler::skip_param(uint32_t count)
void ATHandler::skip_param(ssize_t len, uint32_t count)
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (_last_err || !_stop_tag || _stop_tag->found) {
return;
}
@ -391,7 +391,7 @@ void ATHandler::skip_param(ssize_t len, uint32_t count)
ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (_last_err) {
return -1;
}
@ -410,7 +410,7 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
at_debug("\n----------buff:----------\n");
for (size_t i = _recv_pos; i < _recv_len; i++) {
at_debug("%c", _recv_buff[i]);
@ -463,7 +463,7 @@ ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
int32_t ATHandler::read_int()
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (_last_err || !_stop_tag || _stop_tag->found) {
return -1;
@ -507,7 +507,7 @@ void ATHandler::set_stop_tag(const char *stop_tag_seq)
void ATHandler::set_scope(ScopeType scope_type)
{
log_debug("%s: %d", __func__, scope_type);
tr_debug("%s: %d", __func__, scope_type);
if (_current_scope != scope_type) {
_current_scope = scope_type;
switch (_current_scope) {
@ -536,7 +536,7 @@ void ATHandler::set_scope(ScopeType scope_type)
// should match from recv_pos?
bool ATHandler::match(const char* str, size_t size)
{
log_debug("%s: %s", __func__, str);
tr_debug("%s: %s", __func__, str);
rewind_buffer();
if ((_recv_len - _recv_pos) < size) {
@ -553,14 +553,14 @@ bool ATHandler::match(const char* str, size_t size)
bool ATHandler::match_urc()
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
rewind_buffer();
size_t prefix_len = 0;
for (struct oob_t *oob = _oobs; oob; oob = oob->next) {
prefix_len = strlen(oob->prefix);
if (_recv_len >= prefix_len) {
if (match(oob->prefix, prefix_len)) {
log_debug("URC!");
tr_debug("URC!");
set_scope(InfoType);
if (oob->cb) {
oob->cb();
@ -575,7 +575,7 @@ bool ATHandler::match_urc()
bool ATHandler::match_error()
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (match(CME_ERROR, CME_ERROR_LENGTH)) {
at_error(true, DeviceErrorTypeErrorCME);
@ -616,7 +616,7 @@ void ATHandler::set_error(nsapi_error_t err)
}
if (_last_err != err) {
log_warn("AT error code changed from %d to %d!", _last_err, err);
tr_warn("AT error code changed from %d to %d!", _last_err, err);
}
}
@ -638,7 +638,7 @@ void ATHandler::set_3gpp_error(int err, DeviceErrorType error_type)
for (size_t i = 0; i<sizeof(map_3gpp_errors)/sizeof(map_3gpp_errors[0]); i++) {
if (map_3gpp_errors[i][0] == err) {
_last_3gpp_error = map_3gpp_errors[i][1];
log_debug("AT3GPP error code %d", get_3gpp_error());
tr_debug("AT3GPP error code %d", get_3gpp_error());
break;
}
}
@ -657,9 +657,9 @@ void ATHandler::at_error(bool error_code_expected, DeviceErrorType error_type)
set_3gpp_error(err, error_type);
_last_at_err.errCode = err;
_last_at_err.errType = error_type;
log_debug("ATHandler ERROR: %d", err);
tr_debug("ATHandler ERROR: %d", err);
} else {
log_debug("ATHandler ERROR reading failed");
tr_debug("ATHandler ERROR reading failed");
}
}
@ -668,7 +668,7 @@ void ATHandler::at_error(bool error_code_expected, DeviceErrorType error_type)
void ATHandler::resp(const char *prefix, bool check_urc)
{
log_debug("%s: %s", __func__, prefix);
tr_debug("%s: %s", __func__, prefix);
at_debug("\n----------buff:----------\n");
for (size_t i = _recv_pos; i < _recv_len; i++) {
@ -727,7 +727,7 @@ void ATHandler::resp(const char *prefix, bool check_urc)
void ATHandler::resp_start(const char *prefix, bool stop)
{
log_debug("%s: %s", __func__, prefix);
tr_debug("%s: %s", __func__, prefix);
if (_last_err) {
return;
@ -757,7 +757,7 @@ void ATHandler::resp_start(const char *prefix, bool stop)
// check urc because of error as urc
bool ATHandler::info_resp()
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (_last_err || _resp_stop.found) {
return false;
}
@ -788,7 +788,7 @@ bool ATHandler::info_resp()
bool ATHandler::info_elem(char start_tag)
{
log_debug("%s: %c", __func__, start_tag);
tr_debug("%s: %c", __func__, start_tag);
if (_last_err) {
return false;
}
@ -814,7 +814,7 @@ bool ATHandler::info_elem(char start_tag)
bool ATHandler::consume_char(char ch)
{
log_debug("%s: %c", __func__, ch);
tr_debug("%s: %c", __func__, ch);
int read_char = get_char();
// If we read something else than ch, recover it
if (read_char != ch && read_char != -1) {
@ -826,7 +826,7 @@ bool ATHandler::consume_char(char ch)
bool ATHandler::consume_to_tag(const char *tag, bool consume_tag)
{
log_debug("%s: %s", __func__, tag);
tr_debug("%s: %s", __func__, tag);
size_t match_pos = 0;
while (true) {
@ -845,13 +845,13 @@ bool ATHandler::consume_to_tag(const char *tag, bool consume_tag)
match_pos = 0;
}
}
log_error("consume_to_tag not found");
tr_error("consume_to_tag not found");
return false;
}
bool ATHandler::consume_to_stop_tag()
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (!_stop_tag || (_stop_tag && _stop_tag->found) || _error_found) {
return true;
@ -861,7 +861,7 @@ bool ATHandler::consume_to_stop_tag()
return true;
}
log_error("consume_to_stop_tag not found");
tr_error("consume_to_stop_tag not found");
set_error(NSAPI_ERROR_DEVICE_ERROR);
return false;
}
@ -872,7 +872,7 @@ void ATHandler::resp_stop()
{
// Do not return on error so that we can consume whatever there is in the buffer
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (_current_scope == ElemType) {
information_response_element_stop();
@ -896,7 +896,7 @@ void ATHandler::resp_stop()
void ATHandler::information_response_stop()
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (consume_to_stop_tag()) {
set_scope(RespType);
}
@ -904,7 +904,7 @@ void ATHandler::information_response_stop()
void ATHandler::information_response_element_stop()
{
log_debug("%s", __func__);
tr_debug("%s", __func__);
if (consume_to_stop_tag()) {
set_scope(InfoType);
}
@ -936,7 +936,7 @@ const char* ATHandler::mem_str(const char* dest, size_t dest_len, const char* sr
void ATHandler::cmd_start(const char* cmd)
{
log_debug("AT> %s", cmd);
tr_debug("AT> %s", cmd);
if (_last_err != NSAPI_ERROR_OK) {
return;

View File

@ -30,7 +30,7 @@ AT_CellularMultiplexer::~AT_CellularMultiplexer()
nsapi_error_t AT_CellularMultiplexer::multiplexer_mode_start()
{
log_info("multiplexer_mode_start()");
tr_info("multiplexer_mode_start()");
_at.lock();

View File

@ -48,7 +48,7 @@ AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(a
#ifdef MBED_CONF_APP_CELLULAR_APN
strncpy(_apn, MBED_CONF_APP_CELLULAR_APN, MAX_ACCESSPOINT_NAME_LENGTH);
log_debug("Using APN [%s] from json", _apn);
tr_debug("Using APN [%s] from json", _apn);
#endif
}
@ -108,7 +108,7 @@ nsapi_error_t AT_CellularNetwork::connect()
nsapi_error_t err = set_context_to_be_activated();
if (err != NSAPI_ERROR_OK) {
_at.unlock();
log_error("Failed to activate network context!");
tr_error("Failed to activate network context!");
_connect_status = NSAPI_STATUS_DISCONNECTED;
if (_connection_status_cb) {
@ -121,7 +121,7 @@ nsapi_error_t AT_CellularNetwork::connect()
err = open_data_channel();
if (err != NSAPI_ERROR_OK) {
_at.unlock();
log_error("Failed to open data channel!");
tr_error("Failed to open data channel!");
_connect_status = NSAPI_STATUS_DISCONNECTED;
if (_connection_status_cb) {
@ -148,14 +148,14 @@ nsapi_error_t AT_CellularNetwork::open_data_channel()
//old way: _at.send("ATD*99***%d#", _cid) && _at.recv("CONNECT");
nsapi_error_t err = NSAPI_ERROR_NO_CONNECTION;
#if NSAPI_PPP_AVAILABLE
log_info("Open data channel in PPP mode");
tr_info("Open data channel in PPP mode");
_at.cmd_start("AT+CGDATA=\"PPP\",");
_at.write_int(_cid);
_at.cmd_stop();
_at.resp_start("CONNECT", true);
if (_at.get_last_error()) {
log_warn("Failed to CONNECT");
tr_warn("Failed to CONNECT");
}
/* Initialize PPP
* mbed_ppp_init() is a blocking call, it will block until
@ -182,7 +182,7 @@ nsapi_error_t AT_CellularNetwork::open_data_channel()
_at.resp_stop();
if (!is_context_active) {
log_info("Activate PDP context");
tr_info("Activate PDP context");
_at.cmd_start("AT+CGACT=1,");
_at.write_int(_cid);
_at.cmd_stop();
@ -399,7 +399,7 @@ bool AT_CellularNetwork::get_context(nsapi_ip_stack_t requested_stack)
strncpy(_apn, apn, MAX_ACCESSPOINT_NAME_LENGTH);
}
log_debug("Context id %d", _cid);
tr_debug("Context id %d", _cid);
return true;
}
@ -446,18 +446,18 @@ nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn)
nsapi_error_t ret = set_registration_urc(false);
if (ret) {
log_error("Setting registration URC failed!");
tr_error("Setting registration URC failed!");
_at.clear_error(); // allow temporary failures here
}
if (!plmn) {
log_debug("Automatic network registration");
tr_debug("Automatic network registration");
_at.cmd_start("AT+COPS=0");
_at.cmd_stop();
_at.resp_start();
_at.resp_stop();
} else {
log_debug("Manual network registration to %s", plmn);
tr_debug("Manual network registration to %s", plmn);
_at.cmd_start("AT+COPS=4,2,");
_at.write_string(plmn);
_at.cmd_stop();
@ -525,12 +525,12 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
if (lac_read) {
_lac = hex_str_to_int(lac_string, LAC_LENGTH);
log_debug("lac %s %d", lac_string, _lac );
tr_debug("lac %s %d", lac_string, _lac );
}
if (cell_id_read) {
_cell_id = hex_str_to_int(cell_id_string, CELL_ID_LENGTH);
log_debug("cell_id %s %d", cell_id_string, _cell_id );
tr_debug("cell_id %s %d", cell_id_string, _cell_id );
}
return ret;
@ -563,7 +563,7 @@ nsapi_error_t AT_CellularNetwork::set_attach(int timeout)
int attached_state = _at.read_int();
_at.resp_stop();
if (attached_state != 1) {
log_debug("Network attach");
tr_debug("Network attach");
_at.cmd_start("AT+CGATT=1");
_at.cmd_stop();
_at.resp_start();
@ -776,7 +776,7 @@ nsapi_error_t AT_CellularNetwork::get_rate_control(
int next_element = _at.read_int();
if (next_element >= 0) {
reports = (RateControlExceptionReports)next_element;
log_debug("reports %d",reports);
tr_debug("reports %d",reports);
next_element = _at.read_int();
} else {
comma_found = false;
@ -784,7 +784,7 @@ nsapi_error_t AT_CellularNetwork::get_rate_control(
if (comma_found && next_element >= 0) {
timeUnit = (RateControlUplinkTimeUnit)next_element;
log_debug("time %d",timeUnit);
tr_debug("time %d",timeUnit);
next_element = _at.read_int();
} else {
comma_found = false;
@ -792,7 +792,7 @@ nsapi_error_t AT_CellularNetwork::get_rate_control(
if (comma_found && next_element >= 0) {
uplinkRate = next_element;
log_debug("rate %d",uplinkRate);
tr_debug("rate %d",uplinkRate);
}
}
_at.resp_stop();
@ -828,7 +828,7 @@ nsapi_error_t AT_CellularNetwork::get_pdpcontext_params(pdpContextList_t& params
while (_at.info_resp()) { // response can be zero or many +CGDCONT lines
params = params_list.add_new();
if (!params) {
log_warn("Could not allocate new pdpcontext_params_t");
tr_warn("Could not allocate new pdpcontext_params_t");
params_list.delete_all();
_at.resp_stop();
free(temp);

View File

@ -203,7 +203,7 @@ nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int activ
if (_at.get_last_error() != NSAPI_ERROR_OK) {
log_warn("Power save mode not enabled!");
tr_warn("Power save mode not enabled!");
} else {
// network may not agree with power save options but
// that should be fine as timeout is not longer than requested

View File

@ -48,11 +48,11 @@ nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state)
state = SimStatePukNeeded;
} else {
simstr[len] = '\0';
log_error("Unknown SIM state %s", simstr);
tr_error("Unknown SIM state %s", simstr);
state = SimStateUnknown;
}
} else {
log_warn("SIM not readable.");
tr_warn("SIM not readable.");
state = SimStateUnknown; // SIM may not be ready yet or +CPIN may be unsupported command
}
_at.resp_stop();

View File

@ -187,26 +187,26 @@ AT_CellularSMS::~AT_CellularSMS()
void AT_CellularSMS::cmt_urc()
{
log_debug("CMT_URC called");
tr_debug("CMT_URC called");
//+CMT: <oa>,[<alpha>],<scts>[,<tooa>,<fo>,<pid>,<dcs>,<sca>,<tosca>,<length>]<CR><LF><data>
_at.consume_to_stop_tag();
// call user defined callback function
if (_cb) {
_cb();
} else {
log_warn("cmt_urc, no user defined callback for receiving sms!");
tr_warn("cmt_urc, no user defined callback for receiving sms!");
}
}
void AT_CellularSMS::cmti_urc()
{
//+CMTI: <mem>,<index>,
log_debug("CMTI_URC called");
tr_debug("CMTI_URC called");
// call user defined callback function
if (_cb) {
_cb();
} else {
log_warn("cmti_urc, no user defined callback for receiving sms!");
tr_warn("cmti_urc, no user defined callback for receiving sms!");
}
}
@ -718,7 +718,7 @@ nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t* sms, char* buf, char*
}
}
else {
log_warn("NOT all concatenated parts were received...");
tr_warn("NOT all concatenated parts were received...");
index = SMS_ERROR_MULTIPART_ALL_PARTS_NOT_READ;
}
@ -743,7 +743,7 @@ nsapi_size_or_error_t AT_CellularSMS::get_sms(char* buf, uint16_t len, char* pho
if (info) {
if (info->msg_size+1 > len) { // +1 for '\0'
log_warn("Given buf too small, len is: %d but is must be: %d", len, info->msg_size);
tr_warn("Given buf too small, len is: %d but is must be: %d", len, info->msg_size);
if (buf_size) {
*buf_size = info->msg_size;
}
@ -978,7 +978,7 @@ nsapi_size_or_error_t AT_CellularSMS::read_pdu_payload(const char* pdu, int sche
// 8bit scheme so just convert hexstring to charstring
return hex_str_to_char_str(pdu, strlen(pdu), msg);
} else {
log_error("Received unsupported data coding scheme: 0x%02x", scheme);
tr_error("Received unsupported data coding scheme: 0x%02x", scheme);
return NSAPI_ERROR_UNSUPPORTED;
}
}

View File

@ -1,67 +0,0 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdarg.h>
#include <stddef.h>
#include "CellularLog.h"
#include "us_ticker_api.h"
#include "serial_api.h"
#include "rtos/Mutex.h"
extern serial_t stdio_uart;
extern int stdio_uart_inited;
namespace mbed {
uint32_t cellular_log_time = us_ticker_read() / 1000L;
/**
* Local mutex object for synchronization
*/
static rtos::Mutex mutex;
/**
* Lock provided for serial printing used by trace library
*/
static void serial_lock()
{
mutex.lock();
}
/**
* Releasing lock provided for serial printing used by trace library
*/
static void serial_unlock()
{
mutex.unlock();
}
void log_init(PinName tx, PinName rx, int baud)
{
#ifdef FEATURE_COMMON_PAL
mbed_trace_mutex_wait_function_set(serial_lock);
mbed_trace_mutex_release_function_set(serial_unlock);
mbed_trace_init();
#else
serial_init(&stdio_uart, tx, rx);
serial_baud(&stdio_uart, baud);
stdio_uart_inited = 1;
#endif
log_info("\r\n\r\n**************************************");
log_info("Hellular says Cellular Hello!");
log_info("Build time %s %s", __DATE__, __TIME__);
}
} // namespace mbed

View File

@ -18,65 +18,24 @@
#ifndef CELLULAR_LOG_H_
#define CELLULAR_LOG_H_
#include <inttypes.h>
#ifdef FEATURE_COMMON_PAL
#include <stdarg.h>
#endif // FEATURE_COMMON_PAL
#include "PinNames.h"
#include "us_ticker_api.h"
#include "mbed_debug.h"
namespace mbed {
/** this print is some deep information for debug purpose */
#define TRACE_LEVEL_DEBUG 0x10
/** Info print, for general purpose prints */
#define TRACE_LEVEL_INFO 0x08
/** warning prints, which shouldn't causes any huge problems */
#define TRACE_LEVEL_WARN 0x04
/** Error prints, which causes probably problems, e.g. out of mem. */
#define TRACE_LEVEL_ERROR 0x02
/** special level for cmdline. Behaviours like "plain mode" */
#define TRACE_LEVEL_CMD 0x01
#define TRACE_GROUP "cellular"
#ifndef MBED_TRACE_MAX_LEVEL
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_ERROR
#if defined(HAVE_DEBUG) && !defined(FEA_TRACE_SUPPORT)
#define FEA_TRACE_SUPPORT
#endif
#ifdef FEATURE_COMMON_PAL
#if defined(FEATURE_COMMON_PAL)
#include "mbed-trace/mbed_trace.h"
#define log_debug tr_debug
#define log_info tr_info
#define log_warn tr_warn
#define log_error tr_error
#else
extern uint32_t cellular_log_time;
#if (MBED_TRACE_MAX_LEVEL >= TRACE_LEVEL_DEBUG)
#define log_debug(format, ...) do { debug("DEBUG" " [" TRACE_GROUP " %ums] " format "\r\n", (us_ticker_read()-cellular_log_time) / 1000L, ## __VA_ARGS__); } while (0)
#else
#define log_debug(...)
#endif
#if (MBED_TRACE_MAX_LEVEL >= TRACE_LEVEL_INFO)
#define log_info(format, ...) do { debug("INFO" " [" TRACE_GROUP " %ums] " format "\r\n", (us_ticker_read()-cellular_log_time) / 1000L, ## __VA_ARGS__); } while (0)
#else
#define log_info(...)
#endif
#if (MBED_TRACE_MAX_LEVEL >= TRACE_LEVEL_WARN)
#define log_warn(format, ...) do { debug("WARN" " [" TRACE_GROUP " %ums] " format "\r\n", (us_ticker_read()-cellular_log_time) / 1000L, ## __VA_ARGS__); } while (0)
#else
#define log_warn(...)
#endif
#if (MBED_TRACE_MAX_LEVEL >= TRACE_LEVEL_ERROR)
#define log_error(format, ...) do { debug("ERROR" " [" TRACE_GROUP " %ums] " format "\r\n", (us_ticker_read()-cellular_log_time) / 1000L, ## __VA_ARGS__); } while (0)
#else
#define log_error(...)
#endif
#endif
#ifndef TRACE_GROUP
#define TRACE_GROUP "cellular"
#endif // TRACE_GROUP
extern void log_init(PinName tx, PinName rx, int baud);
#else
} // namespace mbed
#define tr_debug(...) (void(0))
#define tr_info(...) (void(0))
#define tr_error(...) (void(0))
#define tr_warn(...) (void(0))
#endif // FEATURE_COMMON_PAL
#endif // CELLULAR_LOG_H_