mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: async FSM updates
parent
84b445f51c
commit
6072407ec9
|
@ -36,12 +36,13 @@
|
||||||
|
|
||||||
#define RETRY_COUNT_DEFAULT 3
|
#define RETRY_COUNT_DEFAULT 3
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed
|
||||||
|
{
|
||||||
|
|
||||||
CellularConnectionFSM::CellularConnectionFSM() :
|
CellularConnectionFSM::CellularConnectionFSM() :
|
||||||
_serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _event_status_cb(0), _network(0), _power(0), _sim(0),
|
_serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _event_status_cb(0), _network(0), _power(0), _sim(0),
|
||||||
_queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _cellularDevice(0), _retry_count(0), _event_timeout(-1),
|
_queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _cellularDevice(0), _retry_count(0), _event_timeout(-1),
|
||||||
_at_queue(8 * EVENTS_EVENT_SIZE), _eventID(0)
|
_at_queue(8 * EVENTS_EVENT_SIZE), _eventID(0)
|
||||||
{
|
{
|
||||||
memset(_sim_pin, 0, sizeof(_sim_pin));
|
memset(_sim_pin, 0, sizeof(_sim_pin));
|
||||||
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
|
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
|
||||||
|
@ -52,14 +53,14 @@ CellularConnectionFSM::CellularConnectionFSM() :
|
||||||
#endif // MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY
|
#endif // MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY
|
||||||
|
|
||||||
// set initial retry values in seconds
|
// set initial retry values in seconds
|
||||||
_retry_timeout_array[0] = 1;
|
_retry_timeout_array[0] = 1; // double time on each retry in order to keep network happy
|
||||||
_retry_timeout_array[1] = 2;
|
_retry_timeout_array[1] = 2;
|
||||||
_retry_timeout_array[2] = 4;
|
_retry_timeout_array[2] = 4;
|
||||||
_retry_timeout_array[3] = 16;
|
_retry_timeout_array[3] = 8;
|
||||||
_retry_timeout_array[4] = 32;
|
_retry_timeout_array[4] = 16;
|
||||||
_retry_timeout_array[5] = 60;
|
_retry_timeout_array[5] = 32;
|
||||||
_retry_timeout_array[6] = 120;
|
_retry_timeout_array[6] = 64;
|
||||||
_retry_timeout_array[7] = 360;
|
_retry_timeout_array[7] = 128; // if around two minutes was not enough then let's wait much longer
|
||||||
_retry_timeout_array[8] = 600;
|
_retry_timeout_array[8] = 600;
|
||||||
_retry_timeout_array[9] = TIMEOUT_NETWORK_MAX;
|
_retry_timeout_array[9] = TIMEOUT_NETWORK_MAX;
|
||||||
_retry_array_length = MAX_RETRY_ARRAY_SIZE;
|
_retry_array_length = MAX_RETRY_ARRAY_SIZE;
|
||||||
|
@ -163,7 +164,7 @@ bool CellularConnectionFSM::open_sim()
|
||||||
tr_warn("PIN required but No SIM pin provided.");
|
tr_warn("PIN required but No SIM pin provided.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CellularSIM::SimStatePukNeeded:
|
case CellularSIM::SimStatePukNeeded:
|
||||||
tr_info("SIM PUK code needed...");
|
tr_info("SIM PUK code needed...");
|
||||||
break;
|
break;
|
||||||
|
@ -223,19 +224,19 @@ bool CellularConnectionFSM::get_network_registration(CellularNetwork::Registrati
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case CellularNetwork::RegisteredRoaming:
|
case CellularNetwork::RegisteredRoaming:
|
||||||
is_roaming = true;
|
is_roaming = true;
|
||||||
// fall-through
|
// fall-through
|
||||||
case CellularNetwork::RegisteredHomeNetwork:
|
case CellularNetwork::RegisteredHomeNetwork:
|
||||||
is_registered = true;
|
is_registered = true;
|
||||||
break;
|
break;
|
||||||
case CellularNetwork::RegisteredSMSOnlyRoaming:
|
case CellularNetwork::RegisteredSMSOnlyRoaming:
|
||||||
is_roaming = true;
|
is_roaming = true;
|
||||||
// fall-through
|
// fall-through
|
||||||
case CellularNetwork::RegisteredSMSOnlyHome:
|
case CellularNetwork::RegisteredSMSOnlyHome:
|
||||||
tr_warn("SMS only network registration!");
|
tr_warn("SMS only network registration!");
|
||||||
break;
|
break;
|
||||||
case CellularNetwork::RegisteredCSFBNotPreferredRoaming:
|
case CellularNetwork::RegisteredCSFBNotPreferredRoaming:
|
||||||
is_roaming = true;
|
is_roaming = true;
|
||||||
// fall-through
|
// fall-through
|
||||||
case CellularNetwork::RegisteredCSFBNotPreferredHome:
|
case CellularNetwork::RegisteredCSFBNotPreferredHome:
|
||||||
tr_warn("Not preferred network registration!");
|
tr_warn("Not preferred network registration!");
|
||||||
break;
|
break;
|
||||||
|
@ -304,7 +305,7 @@ bool CellularConnectionFSM::is_automatic_registering()
|
||||||
nsapi_error_t CellularConnectionFSM::continue_from_state(CellularState state)
|
nsapi_error_t CellularConnectionFSM::continue_from_state(CellularState state)
|
||||||
{
|
{
|
||||||
tr_info("Continue state from %s to %s", get_state_string((CellularConnectionFSM::CellularState)_state),
|
tr_info("Continue state from %s to %s", get_state_string((CellularConnectionFSM::CellularState)_state),
|
||||||
get_state_string((CellularConnectionFSM::CellularState)state));
|
get_state_string((CellularConnectionFSM::CellularState)state));
|
||||||
_state = state;
|
_state = state;
|
||||||
_next_state = state;
|
_next_state = state;
|
||||||
_retry_count = 0;
|
_retry_count = 0;
|
||||||
|
@ -381,7 +382,7 @@ bool CellularConnectionFSM::device_ready()
|
||||||
bool success = false;
|
bool success = false;
|
||||||
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
|
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
|
||||||
if (!_network->set_registration_urc((CellularNetwork::RegistrationType)type, true)) {
|
if (!_network->set_registration_urc((CellularNetwork::RegistrationType)type, true)) {
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
@ -422,13 +423,13 @@ void CellularConnectionFSM::state_sim_pin()
|
||||||
void CellularConnectionFSM::state_registering()
|
void CellularConnectionFSM::state_registering()
|
||||||
{
|
{
|
||||||
_cellularDevice->set_timeout(TIMEOUT_NETWORK);
|
_cellularDevice->set_timeout(TIMEOUT_NETWORK);
|
||||||
|
|
||||||
if (is_registered()) {
|
if (is_registered()) {
|
||||||
// we are already registered, go to attach
|
// we are already registered, go to attach
|
||||||
enter_to_state(STATE_ATTACHING_NETWORK);
|
enter_to_state(STATE_ATTACHING_NETWORK);
|
||||||
} else {
|
} else {
|
||||||
if (!is_automatic_registering()) { // when we support plmn add this : || plmn
|
if (!is_automatic_registering()) { // when we support plmn add this : || plmn
|
||||||
// automatic registering is not on, set registration and retry
|
// automatic registering is not on, set registration and retry
|
||||||
|
_cellularDevice->set_timeout(TIMEOUT_REGISTRATION);
|
||||||
set_network_registration();
|
set_network_registration();
|
||||||
}
|
}
|
||||||
retry_state_or_fail();
|
retry_state_or_fail();
|
||||||
|
@ -566,7 +567,7 @@ void CellularConnectionFSM::attach(mbed::Callback<void(nsapi_event_t, intptr_t)>
|
||||||
void CellularConnectionFSM::network_callback(nsapi_event_t ev, intptr_t ptr)
|
void CellularConnectionFSM::network_callback(nsapi_event_t ev, intptr_t ptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
tr_debug("FSM: network_callback called with event: %d, intptr: %d", ev, ptr);
|
tr_info("FSM: network_callback called with event: %d, intptr: %d", ev, ptr);
|
||||||
if ((cellular_connection_status_t)ev == CellularRegistrationStatusChanged && ptr == CellularNetwork::RegisteredHomeNetwork && _state == STATE_REGISTERING_NETWORK) {
|
if ((cellular_connection_status_t)ev == CellularRegistrationStatusChanged && ptr == CellularNetwork::RegisteredHomeNetwork && _state == STATE_REGISTERING_NETWORK) {
|
||||||
_queue.cancel(_eventID);
|
_queue.cancel(_eventID);
|
||||||
continue_from_state(STATE_ATTACHING_NETWORK);
|
continue_from_state(STATE_ATTACHING_NETWORK);
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
#include "nsapi_types.h"
|
#include "nsapi_types.h"
|
||||||
#include "Callback.h"
|
#include "Callback.h"
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CellularPower
|
* Class CellularPower
|
||||||
|
@ -121,7 +122,7 @@ public:
|
||||||
virtual nsapi_error_t opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) = 0;
|
virtual nsapi_error_t opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) = 0;
|
||||||
|
|
||||||
/** Set URC callback function for device specific ready urc. URC is defined in device specific
|
/** Set URC callback function for device specific ready urc. URC is defined in device specific
|
||||||
* header (for example in QUECTEL_BG96.h). Used in startup sequence to listen when device is ready
|
* power API. Used in startup sequence to listen when device is ready
|
||||||
* for using at commands and possible sim.
|
* for using at commands and possible sim.
|
||||||
*
|
*
|
||||||
* @param callback Callback function called when urc received
|
* @param callback Callback function called when urc received
|
||||||
|
|
|
@ -174,6 +174,7 @@ nsapi_error_t ATHandler::set_urc_handler(const char *prefix, mbed::Callback<void
|
||||||
}
|
}
|
||||||
|
|
||||||
oob->prefix = prefix;
|
oob->prefix = prefix;
|
||||||
|
oob->prefix_len = prefix_len;
|
||||||
oob->cb = callback;
|
oob->cb = callback;
|
||||||
oob->next = _oobs;
|
oob->next = _oobs;
|
||||||
_oobs = oob;
|
_oobs = oob;
|
||||||
|
@ -278,6 +279,7 @@ void ATHandler::process_oob()
|
||||||
timer.start();
|
timer.start();
|
||||||
do {
|
do {
|
||||||
if (match_urc()) {
|
if (match_urc()) {
|
||||||
|
timer.reset();
|
||||||
if (_fileHandle->readable() || (_recv_pos < _recv_len)) {
|
if (_fileHandle->readable() || (_recv_pos < _recv_len)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -286,8 +288,10 @@ void ATHandler::process_oob()
|
||||||
// If no match found, look for CRLF and consume everything up to CRLF
|
// If no match found, look for CRLF and consume everything up to CRLF
|
||||||
if (mem_str(_recv_buff, _recv_len, CRLF, CRLF_LENGTH)) {
|
if (mem_str(_recv_buff, _recv_len, CRLF, CRLF_LENGTH)) {
|
||||||
consume_to_tag(CRLF, true);
|
consume_to_tag(CRLF, true);
|
||||||
|
timer.reset();
|
||||||
} else {
|
} else {
|
||||||
if (_fileHandle->readable()) {
|
if (_fileHandle->readable()) {
|
||||||
|
timer.reset();
|
||||||
fill_buffer();
|
fill_buffer();
|
||||||
} else {
|
} else {
|
||||||
#ifdef MBED_CONF_RTOS_PRESENT
|
#ifdef MBED_CONF_RTOS_PRESENT
|
||||||
|
@ -295,7 +299,7 @@ void ATHandler::process_oob()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (timer.read_ms() < 20); // URC's are very short so 20ms should be enough
|
} while (timer.read_ms() < 100); // URC's are very short
|
||||||
}
|
}
|
||||||
tr_debug("process_oob exit");
|
tr_debug("process_oob exit");
|
||||||
|
|
||||||
|
@ -316,7 +320,8 @@ void ATHandler::set_filehandle_sigio()
|
||||||
void ATHandler::reset_buffer()
|
void ATHandler::reset_buffer()
|
||||||
{
|
{
|
||||||
tr_debug("%s", __func__);
|
tr_debug("%s", __func__);
|
||||||
_recv_pos = 0; _recv_len = 0;
|
_recv_pos = 0;
|
||||||
|
_recv_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATHandler::rewind_buffer()
|
void ATHandler::rewind_buffer()
|
||||||
|
@ -607,10 +612,10 @@ bool ATHandler::match_urc()
|
||||||
rewind_buffer();
|
rewind_buffer();
|
||||||
size_t prefix_len = 0;
|
size_t prefix_len = 0;
|
||||||
for (struct oob_t *oob = _oobs; oob; oob = oob->next) {
|
for (struct oob_t *oob = _oobs; oob; oob = oob->next) {
|
||||||
prefix_len = strlen(oob->prefix);
|
prefix_len = oob->prefix_len;
|
||||||
if (_recv_len >= prefix_len) {
|
if (_recv_len >= prefix_len) {
|
||||||
if (match(oob->prefix, prefix_len)) {
|
if (match(oob->prefix, prefix_len)) {
|
||||||
tr_debug("URC! %s", oob->prefix);
|
tr_debug("URC! %s\n", oob->prefix);
|
||||||
set_scope(InfoType);
|
set_scope(InfoType);
|
||||||
if (oob->cb) {
|
if (oob->cb) {
|
||||||
oob->cb();
|
oob->cb();
|
||||||
|
|
|
@ -29,7 +29,8 @@
|
||||||
#include "Callback.h"
|
#include "Callback.h"
|
||||||
#include "EventQueue.h"
|
#include "EventQueue.h"
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed
|
||||||
|
{
|
||||||
|
|
||||||
class FileHandle;
|
class FileHandle;
|
||||||
|
|
||||||
|
@ -196,6 +197,7 @@ private:
|
||||||
|
|
||||||
struct oob_t {
|
struct oob_t {
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
|
int prefix_len;
|
||||||
mbed::Callback<void()> cb;
|
mbed::Callback<void()> cb;
|
||||||
oob_t *next;
|
oob_t *next;
|
||||||
};
|
};
|
||||||
|
@ -211,7 +213,7 @@ private:
|
||||||
bool _processing;
|
bool _processing;
|
||||||
int32_t _ref_count;
|
int32_t _ref_count;
|
||||||
|
|
||||||
//*************************************
|
//*************************************
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Starts the command writing by clearing the last error and writing the given command.
|
/** Starts the command writing by clearing the last error and writing the given command.
|
||||||
|
|
|
@ -236,16 +236,9 @@ nsapi_error_t AT_CellularPower::opt_receive_period(int mode, EDRXAccessTechnolog
|
||||||
|
|
||||||
nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
|
nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
|
||||||
{
|
{
|
||||||
#ifdef DEVICE_READY_URC
|
|
||||||
return _at.set_urc_handler(DEVICE_READY_URC, callback);
|
|
||||||
#else
|
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
#endif // DEVICE_READY_URC
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
|
void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
|
||||||
{
|
{
|
||||||
#ifdef DEVICE_READY_URC
|
|
||||||
_at.remove_urc_handler(DEVICE_READY_URC, callback);
|
|
||||||
#endif // DEVICE_READY_URC
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,8 @@
|
||||||
|
|
||||||
#include "AT_CellularDevice.h"
|
#include "AT_CellularDevice.h"
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed
|
||||||
|
{
|
||||||
#define DEVICE_READY_URC "CPIN:"
|
|
||||||
|
|
||||||
class QUECTEL_BG96 : public AT_CellularDevice
|
class QUECTEL_BG96 : public AT_CellularDevice
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018, 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 "QUECTEL_BG96_CellularPower.h"
|
||||||
|
|
||||||
|
#define DEVICE_READY_URC "CPIN:"
|
||||||
|
|
||||||
|
using namespace mbed;
|
||||||
|
|
||||||
|
QUECTEL_BG96_CellularPower::QUECTEL_BG96_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
nsapi_error_t QUECTEL_BG96_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
|
||||||
|
{
|
||||||
|
return _at.set_urc_handler(DEVICE_READY_URC, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QUECTEL_BG96_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
|
||||||
|
{
|
||||||
|
_at.remove_urc_handler(DEVICE_READY_URC, callback);
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef QUECTEL_BG96_CELLULAR_POWER_H_
|
||||||
|
#define QUECTEL_BG96_CELLULAR_POWER_H_
|
||||||
|
|
||||||
|
#include "AT_CellularPower.h"
|
||||||
|
|
||||||
|
namespace mbed
|
||||||
|
{
|
||||||
|
|
||||||
|
class QUECTEL_BG96_CellularPower : public AT_CellularPower
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QUECTEL_BG96_CellularPower(ATHandler &atHandler);
|
||||||
|
virtual ~QUECTEL_BG96_CellularPower();
|
||||||
|
|
||||||
|
public: //from CellularPower
|
||||||
|
virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback);
|
||||||
|
virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace mbed
|
||||||
|
|
||||||
|
#endif // QUECTEL_BG96_CELLULAR_POWER_H_
|
Loading…
Reference in New Issue