2018-08-30 10:29:42 +00:00
|
|
|
/*
|
2018-09-14 10:10:19 +00:00
|
|
|
* Copyright (c) , Arm Limited and affiliates.
|
2018-08-30 10:29:42 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-12-03 06:47:47 +00:00
|
|
|
#include "AT_CellularDevice_stub.h"
|
2018-11-09 13:31:37 +00:00
|
|
|
#include "AT_CellularNetwork.h"
|
2018-12-03 06:47:47 +00:00
|
|
|
#include "AT_CellularContext.h"
|
2018-11-09 13:31:37 +00:00
|
|
|
#include "ATHandler.h"
|
2018-08-30 10:29:42 +00:00
|
|
|
|
2018-11-09 13:31:37 +00:00
|
|
|
const int DEFAULT_AT_TIMEOUT = 1000;
|
|
|
|
|
|
|
|
using namespace mbed;
|
|
|
|
|
2018-12-03 06:47:47 +00:00
|
|
|
int AT_CellularDevice_stub::failure_count = 0;
|
|
|
|
nsapi_error_t AT_CellularDevice_stub::nsapi_error_value = 0;
|
|
|
|
int AT_CellularDevice_stub::init_module_failure_count = 0;
|
|
|
|
int AT_CellularDevice_stub::set_pin_failure_count = 0;
|
|
|
|
int AT_CellularDevice_stub::get_sim_failure_count = 0;
|
|
|
|
bool AT_CellularDevice_stub::pin_needed = false;
|
|
|
|
|
2018-11-09 13:31:37 +00:00
|
|
|
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0),
|
2019-01-22 08:31:17 +00:00
|
|
|
_information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false)
|
2018-08-30 10:29:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AT_CellularDevice::~AT_CellularDevice()
|
|
|
|
{
|
2018-12-03 06:47:47 +00:00
|
|
|
delete _network;
|
2018-12-18 14:11:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-30 10:29:42 +00:00
|
|
|
ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
|
|
|
|
{
|
2018-12-04 10:43:36 +00:00
|
|
|
return ATHandler::get_instance(fileHandle, _queue, _default_timeout, "\r", get_send_delay(), _modem_debug_on);
|
2018-08-30 10:29:42 +00:00
|
|
|
}
|
|
|
|
|
2018-11-29 12:38:38 +00:00
|
|
|
ATHandler *AT_CellularDevice::get_at_handler()
|
2018-08-30 10:29:42 +00:00
|
|
|
{
|
2018-11-29 12:38:38 +00:00
|
|
|
return get_at_handler(NULL);
|
|
|
|
}
|
2018-08-30 10:29:42 +00:00
|
|
|
|
2018-11-29 12:38:38 +00:00
|
|
|
nsapi_error_t AT_CellularDevice::release_at_handler(ATHandler *at_handler)
|
|
|
|
{
|
2018-12-04 10:43:36 +00:00
|
|
|
if (at_handler) {
|
|
|
|
return at_handler->close();
|
|
|
|
} else {
|
|
|
|
return NSAPI_ERROR_PARAMETER;
|
|
|
|
}
|
2018-08-30 10:29:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 12:58:59 +00:00
|
|
|
CellularContext *AT_CellularDevice::create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin,
|
2018-11-16 07:40:38 +00:00
|
|
|
bool active_high, bool cp_req, bool nonip_req)
|
2018-12-04 12:58:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CellularContext *create_context(FileHandle *fh, const char *apn)
|
2018-11-09 13:31:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void delete_context(CellularContext *context)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-30 10:29:42 +00:00
|
|
|
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
|
|
|
|
{
|
2019-01-22 08:31:17 +00:00
|
|
|
_network = new AT_CellularNetwork(*ATHandler::get_instance(fh,
|
|
|
|
_queue,
|
|
|
|
_default_timeout,
|
|
|
|
"\r",
|
|
|
|
get_send_delay(),
|
|
|
|
_modem_debug_on));
|
|
|
|
return _network;
|
2018-08-30 10:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AT_CellularDevice::close_network()
|
|
|
|
{
|
2019-01-22 08:31:17 +00:00
|
|
|
delete _network;
|
|
|
|
|
|
|
|
_network = NULL;
|
2018-08-30 10:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AT_CellularDevice::close_sms()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-09 13:31:37 +00:00
|
|
|
void AT_CellularDevice::close_information()
|
2018-08-30 10:29:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-09 13:31:37 +00:00
|
|
|
CellularContext *AT_CellularDevice::get_context_list() const
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-16 07:40:38 +00:00
|
|
|
CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn, bool cp_req, bool nonip_req)
|
2018-11-09 13:31:37 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-16 07:40:38 +00:00
|
|
|
AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
|
2018-11-09 13:31:37 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AT_CellularDevice::delete_context(CellularContext *context)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at)
|
|
|
|
{
|
2019-01-22 08:31:17 +00:00
|
|
|
_network = new AT_CellularNetwork(at);
|
|
|
|
|
|
|
|
return _network;
|
2018-11-09 13:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AT_CellularDevice::set_timeout(int timeout)
|
|
|
|
{
|
|
|
|
_default_timeout = timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t AT_CellularDevice::get_send_delay() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AT_CellularDevice::modem_debug_on(bool on)
|
|
|
|
{
|
|
|
|
_modem_debug_on = on;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-28 10:36:46 +00:00
|
|
|
nsapi_error_t AT_CellularDevice::is_ready()
|
|
|
|
{
|
2018-12-03 06:47:47 +00:00
|
|
|
if (AT_CellularDevice_stub::init_module_failure_count) {
|
|
|
|
AT_CellularDevice_stub::init_module_failure_count--;
|
|
|
|
return NSAPI_ERROR_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
return AT_CellularDevice_stub::nsapi_error_value;
|
2018-11-28 10:36:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 11:42:44 +00:00
|
|
|
void AT_CellularDevice::set_ready_cb(mbed::Callback<void()> callback)
|
2018-11-28 13:00:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-28 08:57:11 +00:00
|
|
|
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
|
|
|
|
{
|
2018-11-28 13:00:35 +00:00
|
|
|
return NSAPI_ERROR_UNSUPPORTED;
|
2018-11-28 08:57:11 +00:00
|
|
|
}
|
|
|
|
|
2018-11-29 07:17:34 +00:00
|
|
|
nsapi_error_t AT_CellularDevice::init()
|
2018-08-30 10:29:42 +00:00
|
|
|
{
|
2018-12-03 06:47:47 +00:00
|
|
|
if (AT_CellularDevice_stub::init_module_failure_count) {
|
|
|
|
AT_CellularDevice_stub::init_module_failure_count--;
|
|
|
|
return NSAPI_ERROR_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
return AT_CellularDevice_stub::nsapi_error_value;
|
2018-08-30 10:29:42 +00:00
|
|
|
}
|
2018-11-28 09:04:13 +00:00
|
|
|
|
2018-11-29 08:54:27 +00:00
|
|
|
nsapi_error_t AT_CellularDevice::shutdown()
|
|
|
|
{
|
2018-12-03 06:47:47 +00:00
|
|
|
if (AT_CellularDevice_stub::init_module_failure_count) {
|
|
|
|
AT_CellularDevice_stub::init_module_failure_count--;
|
|
|
|
return NSAPI_ERROR_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
return AT_CellularDevice_stub::nsapi_error_value;
|
2018-11-29 08:54:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 09:04:13 +00:00
|
|
|
nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin)
|
|
|
|
{
|
2018-12-03 06:47:47 +00:00
|
|
|
if (AT_CellularDevice_stub::set_pin_failure_count) {
|
|
|
|
AT_CellularDevice_stub::set_pin_failure_count--;
|
|
|
|
return NSAPI_ERROR_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
return AT_CellularDevice_stub::nsapi_error_value;
|
2018-11-28 09:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state)
|
|
|
|
{
|
2018-12-03 06:47:47 +00:00
|
|
|
if (AT_CellularDevice_stub::get_sim_failure_count) {
|
|
|
|
AT_CellularDevice_stub::get_sim_failure_count--;
|
|
|
|
return NSAPI_ERROR_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AT_CellularDevice_stub::pin_needed) {
|
|
|
|
AT_CellularDevice_stub::pin_needed = false;
|
|
|
|
state = SimStatePinNeeded;
|
|
|
|
} else {
|
|
|
|
state = SimStateReady;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AT_CellularDevice_stub::nsapi_error_value;
|
2018-11-28 09:04:13 +00:00
|
|
|
}
|
2018-12-20 13:48:31 +00:00
|
|
|
|
2019-01-15 10:57:58 +00:00
|
|
|
nsapi_error_t AT_CellularDevice::hard_power_on()
|
2018-12-20 13:48:31 +00:00
|
|
|
{
|
2019-01-15 10:57:58 +00:00
|
|
|
return NSAPI_ERROR_OK;
|
2018-12-20 13:48:31 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 10:57:58 +00:00
|
|
|
nsapi_error_t AT_CellularDevice::hard_power_off()
|
2018-12-20 13:48:31 +00:00
|
|
|
{
|
2019-01-15 10:57:58 +00:00
|
|
|
return NSAPI_ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsapi_error_t AT_CellularDevice::soft_power_on()
|
|
|
|
{
|
|
|
|
return NSAPI_ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsapi_error_t AT_CellularDevice::soft_power_off()
|
|
|
|
{
|
|
|
|
return NSAPI_ERROR_OK;
|
2018-12-20 13:48:31 +00:00
|
|
|
}
|