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
|
||||
|
||||
namespace mbed {
|
||||
namespace mbed
|
||||
{
|
||||
|
||||
CellularConnectionFSM::CellularConnectionFSM() :
|
||||
_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),
|
||||
_at_queue(8 * EVENTS_EVENT_SIZE), _eventID(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),
|
||||
_at_queue(8 * EVENTS_EVENT_SIZE), _eventID(0)
|
||||
{
|
||||
memset(_sim_pin, 0, sizeof(_sim_pin));
|
||||
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
|
||||
|
@ -52,14 +53,14 @@ CellularConnectionFSM::CellularConnectionFSM() :
|
|||
#endif // MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY
|
||||
|
||||
// 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[2] = 4;
|
||||
_retry_timeout_array[3] = 16;
|
||||
_retry_timeout_array[4] = 32;
|
||||
_retry_timeout_array[5] = 60;
|
||||
_retry_timeout_array[6] = 120;
|
||||
_retry_timeout_array[7] = 360;
|
||||
_retry_timeout_array[3] = 8;
|
||||
_retry_timeout_array[4] = 16;
|
||||
_retry_timeout_array[5] = 32;
|
||||
_retry_timeout_array[6] = 64;
|
||||
_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[9] = TIMEOUT_NETWORK_MAX;
|
||||
_retry_array_length = MAX_RETRY_ARRAY_SIZE;
|
||||
|
@ -163,7 +164,7 @@ bool CellularConnectionFSM::open_sim()
|
|||
tr_warn("PIN required but No SIM pin provided.");
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case CellularSIM::SimStatePukNeeded:
|
||||
tr_info("SIM PUK code needed...");
|
||||
break;
|
||||
|
@ -223,19 +224,19 @@ bool CellularConnectionFSM::get_network_registration(CellularNetwork::Registrati
|
|||
switch (status) {
|
||||
case CellularNetwork::RegisteredRoaming:
|
||||
is_roaming = true;
|
||||
// fall-through
|
||||
// fall-through
|
||||
case CellularNetwork::RegisteredHomeNetwork:
|
||||
is_registered = true;
|
||||
break;
|
||||
case CellularNetwork::RegisteredSMSOnlyRoaming:
|
||||
is_roaming = true;
|
||||
// fall-through
|
||||
// fall-through
|
||||
case CellularNetwork::RegisteredSMSOnlyHome:
|
||||
tr_warn("SMS only network registration!");
|
||||
break;
|
||||
case CellularNetwork::RegisteredCSFBNotPreferredRoaming:
|
||||
is_roaming = true;
|
||||
// fall-through
|
||||
// fall-through
|
||||
case CellularNetwork::RegisteredCSFBNotPreferredHome:
|
||||
tr_warn("Not preferred network registration!");
|
||||
break;
|
||||
|
@ -304,7 +305,7 @@ bool CellularConnectionFSM::is_automatic_registering()
|
|||
nsapi_error_t CellularConnectionFSM::continue_from_state(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;
|
||||
_next_state = state;
|
||||
_retry_count = 0;
|
||||
|
@ -381,7 +382,7 @@ bool CellularConnectionFSM::device_ready()
|
|||
bool success = false;
|
||||
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
|
||||
if (!_network->set_registration_urc((CellularNetwork::RegistrationType)type, true)) {
|
||||
success = true;
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
|
@ -422,13 +423,13 @@ void CellularConnectionFSM::state_sim_pin()
|
|||
void CellularConnectionFSM::state_registering()
|
||||
{
|
||||
_cellularDevice->set_timeout(TIMEOUT_NETWORK);
|
||||
|
||||
if (is_registered()) {
|
||||
// we are already registered, go to attach
|
||||
enter_to_state(STATE_ATTACHING_NETWORK);
|
||||
} else {
|
||||
if (!is_automatic_registering()) { // when we support plmn add this : || plmn
|
||||
// automatic registering is not on, set registration and retry
|
||||
_cellularDevice->set_timeout(TIMEOUT_REGISTRATION);
|
||||
set_network_registration();
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
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) {
|
||||
_queue.cancel(_eventID);
|
||||
continue_from_state(STATE_ATTACHING_NETWORK);
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "nsapi_types.h"
|
||||
#include "Callback.h"
|
||||
|
||||
namespace mbed {
|
||||
namespace mbed
|
||||
{
|
||||
|
||||
/**
|
||||
* Class CellularPower
|
||||
|
@ -121,7 +122,7 @@ public:
|
|||
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
|
||||
* 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.
|
||||
*
|
||||
* @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_len = prefix_len;
|
||||
oob->cb = callback;
|
||||
oob->next = _oobs;
|
||||
_oobs = oob;
|
||||
|
@ -278,6 +279,7 @@ void ATHandler::process_oob()
|
|||
timer.start();
|
||||
do {
|
||||
if (match_urc()) {
|
||||
timer.reset();
|
||||
if (_fileHandle->readable() || (_recv_pos < _recv_len)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -286,8 +288,10 @@ void ATHandler::process_oob()
|
|||
// If no match found, look for CRLF and consume everything up to CRLF
|
||||
if (mem_str(_recv_buff, _recv_len, CRLF, CRLF_LENGTH)) {
|
||||
consume_to_tag(CRLF, true);
|
||||
timer.reset();
|
||||
} else {
|
||||
if (_fileHandle->readable()) {
|
||||
timer.reset();
|
||||
fill_buffer();
|
||||
} else {
|
||||
#ifdef MBED_CONF_RTOS_PRESENT
|
||||
|
@ -295,7 +299,7 @@ void ATHandler::process_oob()
|
|||
#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");
|
||||
|
||||
|
@ -316,7 +320,8 @@ void ATHandler::set_filehandle_sigio()
|
|||
void ATHandler::reset_buffer()
|
||||
{
|
||||
tr_debug("%s", __func__);
|
||||
_recv_pos = 0; _recv_len = 0;
|
||||
_recv_pos = 0;
|
||||
_recv_len = 0;
|
||||
}
|
||||
|
||||
void ATHandler::rewind_buffer()
|
||||
|
@ -607,10 +612,10 @@ bool ATHandler::match_urc()
|
|||
rewind_buffer();
|
||||
size_t prefix_len = 0;
|
||||
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 (match(oob->prefix, prefix_len)) {
|
||||
tr_debug("URC! %s", oob->prefix);
|
||||
tr_debug("URC! %s\n", oob->prefix);
|
||||
set_scope(InfoType);
|
||||
if (oob->cb) {
|
||||
oob->cb();
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
#include "Callback.h"
|
||||
#include "EventQueue.h"
|
||||
|
||||
namespace mbed {
|
||||
namespace mbed
|
||||
{
|
||||
|
||||
class FileHandle;
|
||||
|
||||
|
@ -196,6 +197,7 @@ private:
|
|||
|
||||
struct oob_t {
|
||||
const char *prefix;
|
||||
int prefix_len;
|
||||
mbed::Callback<void()> cb;
|
||||
oob_t *next;
|
||||
};
|
||||
|
@ -211,7 +213,7 @@ private:
|
|||
bool _processing;
|
||||
int32_t _ref_count;
|
||||
|
||||
//*************************************
|
||||
//*************************************
|
||||
public:
|
||||
|
||||
/** 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)
|
||||
{
|
||||
#ifdef DEVICE_READY_URC
|
||||
return _at.set_urc_handler(DEVICE_READY_URC, callback);
|
||||
#else
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
#endif // DEVICE_READY_URC
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
#define DEVICE_READY_URC "CPIN:"
|
||||
namespace mbed
|
||||
{
|
||||
|
||||
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