Added modem_debug_on to cellular device

pull/6082/head
Ari Parkkila 2018-02-27 09:22:31 +02:00
parent a95d376820
commit 164e8fb717
5 changed files with 56 additions and 15 deletions

View File

@ -32,7 +32,8 @@
#include "APN_db.h" #include "APN_db.h"
#endif //MBED_CONF_APP_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP #endif //MBED_CONF_APP_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
namespace mbed { namespace mbed
{
bool EasyCellularConnection::cellular_status(int state, int next_state) bool EasyCellularConnection::cellular_status(int state, int next_state)
{ {
@ -45,17 +46,16 @@ bool EasyCellularConnection::cellular_status(int state, int next_state)
} }
MBED_ASSERT(_cellularSemaphore.release() == osOK); MBED_ASSERT(_cellularSemaphore.release() == osOK);
return false; return false;
} } else {
else {
_is_connected = false; _is_connected = false;
} }
return true; return true;
} }
EasyCellularConnection::EasyCellularConnection() : _is_connected(false), _is_initialized(false), EasyCellularConnection::EasyCellularConnection() : _is_connected(false), _is_initialized(false),
_target_state(CellularConnectionUtil::STATE_POWER_ON), _target_state(CellularConnectionUtil::STATE_POWER_ON),
_cellularSerial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE), _cellularSerial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE),
_cellularSemaphore(0), _cellularConnectionUtil(), _credentials_err(NSAPI_ERROR_OK) _cellularSemaphore(0), _cellularConnectionUtil(), _credentials_err(NSAPI_ERROR_OK)
{ {
#if MBED_CONF_APP_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP #if MBED_CONF_APP_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
_credentials_set = false; _credentials_set = false;
@ -78,7 +78,7 @@ nsapi_error_t EasyCellularConnection::init()
_cellularConnectionUtil.set_serial(&_cellularSerial); _cellularConnectionUtil.set_serial(&_cellularSerial);
_cellularConnectionUtil.set_callback(callback(this, &EasyCellularConnection::cellular_status)); _cellularConnectionUtil.set_callback(callback(this, &EasyCellularConnection::cellular_status));
err = _cellularConnectionUtil.init(); err = _cellularConnectionUtil.init();
if (err == NSAPI_ERROR_OK) { if (err == NSAPI_ERROR_OK) {
err = _cellularConnectionUtil.start_dispatch(); err = _cellularConnectionUtil.start_dispatch();
@ -259,6 +259,14 @@ void EasyCellularConnection::attach(mbed::Callback<void(nsapi_event_t, intptr_t)
} }
} }
void EasyCellularConnection::modem_debug_on(bool on)
{
CellularDevice *dev =_cellularConnectionUtil.get_device();
if (dev) {
dev->modem_debug_on(on);
}
}
NetworkStack *EasyCellularConnection::get_stack() NetworkStack *EasyCellularConnection::get_stack()
{ {
return _cellularConnectionUtil.get_stack(); return _cellularConnectionUtil.get_stack();

View File

@ -23,13 +23,15 @@
#include "netsocket/CellularBase.h" #include "netsocket/CellularBase.h"
namespace mbed { namespace mbed
{
/** EasyCellularConnection class /** EasyCellularConnection class
* *
* Simplified adapter for cellular connection * Simplified adapter for cellular connection
*/ */
class EasyCellularConnection: public CellularBase { class EasyCellularConnection: public CellularBase
{
public: public:
EasyCellularConnection(); EasyCellularConnection();
@ -117,6 +119,12 @@ public:
*/ */
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
/** Turn modem debug traces on
*
* @param on set true to enable debug traces
*/
void modem_debug_on(bool on);
protected: protected:
/** Provide access to the NetworkStack object /** Provide access to the NetworkStack object

View File

@ -28,7 +28,8 @@
#include "CellularInformation.h" #include "CellularInformation.h"
#include "NetworkStack.h" #include "NetworkStack.h"
namespace mbed { namespace mbed
{
/** /**
* Class CellularDevice * Class CellularDevice
@ -115,7 +116,13 @@ public:
* @param timeout milliseconds to wait response from modem * @param timeout milliseconds to wait response from modem
*/ */
virtual void set_timeout(int timeout) = 0; virtual void set_timeout(int timeout) = 0;
/** Turn modem debug traces on
*
* @param on set true to enable debug traces
*/
virtual void modem_debug_on(bool on) = 0;
/** Get network stack. /** Get network stack.
* *
* @return network stack * @return network stack

View File

@ -23,7 +23,8 @@ using namespace mbed;
#define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds #define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds
AT_CellularDevice::AT_CellularDevice(EventQueue &queue) : AT_CellularDevice::AT_CellularDevice(EventQueue &queue) :
_atHandlers(0), _network(0), _sms(0), _sim(0), _power(0), _multiplexer(0), _information(0), _queue(queue), _default_timeout(DEFAULT_AT_TIMEOUT) _atHandlers(0), _network(0), _sms(0), _sim(0), _power(0), _multiplexer(0), _information(0), _queue(queue),
_default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false)
{ {
} }
@ -62,6 +63,9 @@ ATHandler* AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
atHandler = new ATHandler(fileHandle, _queue, _default_timeout, "\r"); atHandler = new ATHandler(fileHandle, _queue, _default_timeout, "\r");
if (atHandler) { if (atHandler) {
if (_modem_debug_on) {
atHandler->enable_debug(_modem_debug_on);
}
atHandler->_nextATHandler = _atHandlers; atHandler->_nextATHandler = _atHandlers;
_atHandlers = atHandler; _atHandlers = atHandler;
} }
@ -83,8 +87,7 @@ void AT_CellularDevice::release_at_handler(ATHandler* at_handler)
if (atHandler == at_handler) { if (atHandler == at_handler) {
if (prev == NULL) { if (prev == NULL) {
_atHandlers = _atHandlers->_nextATHandler; _atHandlers = _atHandlers->_nextATHandler;
} } else {
else {
prev->_nextATHandler = atHandler->_nextATHandler; prev->_nextATHandler = atHandler->_nextATHandler;
} }
delete atHandler; delete atHandler;
@ -247,6 +250,17 @@ void AT_CellularDevice::set_timeout(int timeout)
} }
} }
void AT_CellularDevice::modem_debug_on(bool on)
{
_modem_debug_on = on;
ATHandler *atHandler = _atHandlers;
while (atHandler) {
atHandler->enable_debug(_modem_debug_on);
atHandler = atHandler->_nextATHandler;
}
}
NetworkStack *AT_CellularDevice::get_stack() NetworkStack *AT_CellularDevice::get_stack()
{ {
if (!_network) { if (!_network) {

View File

@ -29,7 +29,8 @@
#include "ATHandler.h" #include "ATHandler.h"
namespace mbed { namespace mbed
{
/** /**
* Class AT_CellularDevice * Class AT_CellularDevice
@ -81,6 +82,8 @@ public: // CellularDevice
virtual void set_timeout(int timeout); virtual void set_timeout(int timeout);
virtual void modem_debug_on(bool on);
virtual NetworkStack *get_stack(); virtual NetworkStack *get_stack();
protected: protected:
@ -94,6 +97,7 @@ protected:
protected: protected:
events::EventQueue &_queue; events::EventQueue &_queue;
int _default_timeout; int _default_timeout;
bool _modem_debug_on;
}; };
} // namespace mbed } // namespace mbed