Cellular: astyle fixes after introducing CellularContext class and major refactor.

pull/8579/head
Teppo Järvelin 2018-11-13 18:50:35 +02:00
parent 14f3740c13
commit 88213d3e03
6 changed files with 43 additions and 42 deletions

View File

@ -96,7 +96,7 @@ public:
typedef CellularList<pdpcontext_params_t> pdpContextList_t;
// pointer for next item when used as a linked list
CellularContext* _next;
CellularContext *_next;
protected:
// friend of CellularDevice so that it's the only way to close/delete this class.
friend class CellularDevice;
@ -217,17 +217,17 @@ protected: // Device specific implementations might need these so protected
OP_DEVICE_READY = 0,
OP_SIM_READY = 1,
OP_REGISTER = 2,
OP_ATTACH = 3 ,
OP_ATTACH = 3,
OP_CONNECT = 4,
OP_MAX = 5
};
/** Status callback function will be called on status changes on the network or CellularDevice
* by the CellularDevice.
*
* @param ev event type
* @param ptr event-type dependent reason parameter
*/
/** Status callback function will be called on status changes on the network or CellularDevice
* by the CellularDevice.
*
* @param ev event type
* @param ptr event-type dependent reason parameter
*/
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr) = 0;
// member variables needed in target override methods

View File

@ -99,7 +99,7 @@ public:
*
* @param plmn plmn used when registering to cellular network
*/
void set_plmn(const char* plmn);
void set_plmn(const char *plmn);
/** Start the interface
*
@ -260,7 +260,7 @@ private:
CellularNetwork *_nw;
char _sim_pin[MAX_PIN_SIZE + 1];
char _plmn[MAX_PLMN_SIZE +1];
char _plmn[MAX_PLMN_SIZE + 1];
PlatformMutex _mutex;
};

View File

@ -22,16 +22,17 @@
#include "nsapi_types.h"
struct cell_callback_data_t {
nsapi_error_t error; /* possible error code */
int status_data; /* cellular_event_status related enum or other info in int format. Check cellular_event_status comments.*/
bool final_try; /* This flag is true if state machine is used and this was the last try. State machine does goes to idle. */
nsapi_error_t error; /* possible error code */
int status_data; /* cellular_event_status related enum or other info in int format. Check cellular_event_status comments.*/
bool final_try; /* This flag is true if state machine is used and this was the last try. State machine does goes to idle. */
cell_callback_data_t() {
error = NSAPI_ERROR_OK;
status_data = -1;
final_try = false;
}
};
cell_callback_data_t()
{
error = NSAPI_ERROR_OK;
status_data = -1;
final_try = false;
}
};
/**
* Cellular specific event changes.

View File

@ -36,7 +36,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
#if DEVICE_SERIAL_FC
if (MDMRTS != NC && MDMCTS != NC) {
tr_info("_USING flow control, MDMRTS: %d MDMCTS: %d",MDMRTS, MDMCTS);
tr_info("_USING flow control, MDMRTS: %d MDMCTS: %d", MDMRTS, MDMCTS);
serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
}
#endif
@ -50,8 +50,8 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
}
#endif // CELLULAR_DEVICE
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),_power_ref_count(0), _sim_ref_count(0),
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0),
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
{
set_sim_pin(NULL);
set_plmn(NULL);
@ -87,7 +87,7 @@ void CellularDevice::set_sim_pin(const char *sim_pin)
}
}
void CellularDevice::set_plmn(const char* plmn)
void CellularDevice::set_plmn(const char *plmn)
{
if (plmn) {
strncpy(_plmn, plmn, sizeof(_plmn));
@ -156,7 +156,7 @@ nsapi_error_t CellularDevice::start_state_machine(CellularStateMachine::Cellular
void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
{
if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) {
cell_callback_data_t* ptr_data = (cell_callback_data_t*)ptr;
cell_callback_data_t *ptr_data = (cell_callback_data_t *)ptr;
tr_debug("Device: network_callback called with event: %d, err: %d, data: %d", ev, ptr_data->error, ptr_data->status_data);
cellular_connection_status_t cell_ev = (cellular_connection_status_t)ev;
if (cell_ev == CellularRegistrationStatusChanged && _state_machine) {
@ -174,7 +174,7 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
_state_machine->set_plmn(_plmn);
}
} else if (cell_ev == CellularSIMStatusChanged && ptr_data->error == NSAPI_ERROR_OK &&
ptr_data->status_data == CellularSIM::SimStatePinNeeded) {
ptr_data->status_data == CellularSIM::SimStatePinNeeded) {
if (strlen(_sim_pin)) {
_state_machine->set_sim_pin(_sim_pin);
}

View File

@ -44,11 +44,11 @@ const int STM_STOPPED = -99;
namespace mbed {
CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue) :
_cellularDevice(device), _state(STATE_INIT), _next_state(_state), _target_state(_state),
_event_status_cb(0), _network(0), _power(0), _sim(0), _queue(queue), _queue_thread(0), _sim_pin(0),
_retry_count(0), _event_timeout(-1), _event_id(-1), _plmn(0), _command_success(false),
_plmn_network_found(false), _is_retry(false), _cb_data(), _current_event(NSAPI_EVENT_CONNECTION_STATUS_CHANGE),
_active_context(false)
_cellularDevice(device), _state(STATE_INIT), _next_state(_state), _target_state(_state),
_event_status_cb(0), _network(0), _power(0), _sim(0), _queue(queue), _queue_thread(0), _sim_pin(0),
_retry_count(0), _event_timeout(-1), _event_id(-1), _plmn(0), _command_success(false),
_plmn_network_found(false), _is_retry(false), _cb_data(), _current_event(NSAPI_EVENT_CONNECTION_STATUS_CHANGE),
_active_context(false)
{
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
_start_time = 0;
@ -157,7 +157,7 @@ bool CellularStateMachine::open_sim()
// report current state so callback can set sim pin if needed
if (_event_status_cb) {
_cb_data.status_data = state;
_event_status_cb((nsapi_event_t)CellularSIMStatusChanged, (intptr_t )&_cb_data);
_event_status_cb((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&_cb_data);
}
if (state == CellularSIM::SimStatePinNeeded) {
@ -197,7 +197,7 @@ bool CellularStateMachine::is_registered()
}
bool CellularStateMachine::get_network_registration(CellularNetwork::RegistrationType type,
CellularNetwork::RegistrationStatus &status, bool &is_registered)
CellularNetwork::RegistrationStatus &status, bool &is_registered)
{
is_registered = false;
bool is_roaming = false;
@ -255,7 +255,7 @@ void CellularStateMachine::report_failure(const char *msg)
_event_id = -1;
if (_event_status_cb) {
_cb_data.final_try = true;
_event_status_cb(_current_event, (intptr_t )&_cb_data);
_event_status_cb(_current_event, (intptr_t)&_cb_data);
}
tr_error("Target state %s was not reached. Returning from state: %s", get_state_string(_target_state), get_state_string(_state));
@ -379,7 +379,7 @@ bool CellularStateMachine::device_ready()
return false;
}
if (_event_status_cb) {
_event_status_cb((nsapi_event_t)CellularDeviceReady, (intptr_t )&_cb_data);
_event_status_cb((nsapi_event_t)CellularDeviceReady, (intptr_t)&_cb_data);
}
_power->remove_device_ready_urc_cb(mbed::callback(this, &CellularStateMachine::ready_urc_cb));
_cellularDevice.close_power();
@ -493,7 +493,7 @@ void CellularStateMachine::state_attaching()
_sim = NULL;
if (_event_status_cb) {
_cb_data.status_data = CellularNetwork::Attached;
_event_status_cb(_current_event, (intptr_t )&_cb_data);
_event_status_cb(_current_event, (intptr_t)&_cb_data);
}
} else {
retry_state_or_fail();
@ -527,29 +527,29 @@ nsapi_error_t CellularStateMachine::run_to_state(CellularStateMachine::CellularS
_mutex.unlock();
return NSAPI_ERROR_NO_MEMORY;
}
_mutex.unlock();
_mutex.unlock();
return NSAPI_ERROR_OK;
}
void CellularStateMachine::pre_event(CellularState state)
{
tr_debug("CellularStateMachine::pre_event, state: %s, _target_state: %s, _event_id: %d", get_state_string(state), get_state_string(_target_state), _event_id);
if (_target_state < state) {
if (_target_state < state) {
// new wanted state will not be achieved with current _target_state so update it
_target_state = state;
} else {
// wanted state is already / will be achieved, return without launching new event
return;
}
// if _event_id is -1 it means that new event is not going to be launched so we must launch new event
// if _event_id is -1 it means that new event is not going to be launched so we must launch new event
if (_event_id == -1) {
if (!_cb_data.final_try) {
// update next state so that we don't continue from previous state if state machine was paused and then started again.
// but only if earlier try did not finish to failure, then we must continue from that state
_state = _next_state;
}
enter_to_state(_next_state);
_event_id = _queue.call_in(0, this, &CellularStateMachine::event);
enter_to_state(_next_state);
_event_id = _queue.call_in(0, this, &CellularStateMachine::event);
if (!_event_id) {
_event_id = -1;
report_failure("Failed to call queue.");
@ -655,7 +655,7 @@ void CellularStateMachine::set_cellular_callback(mbed::Callback<void(nsapi_event
void CellularStateMachine::cellular_event_changed(nsapi_event_t ev, intptr_t ptr)
{
cell_callback_data_t *data = (cell_callback_data_t*)ptr;
cell_callback_data_t *data = (cell_callback_data_t *)ptr;
if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) {
tr_debug("FSM: cellular_event_changed called with event: %d, err: %d, data: %d _state: %s", ev, data->error, data->status_data, get_state_string(_state));
} else {

View File

@ -23,7 +23,7 @@
#include "PlatformMutex.h"
namespace rtos {
class Thread;
class Thread;
}
namespace mbed {