Cellular: Move power on/off to device and remove CellularPower

pull/9472/head
Ari Parkkila 2018-12-18 06:11:52 -08:00
parent 55b54f7c97
commit 139d506a24
44 changed files with 154 additions and 1066 deletions

View File

@ -27,7 +27,6 @@ set(unittest-test-sources
stubs/AT_CellularDevice_stub.cpp
stubs/AT_CellularStack_stub.cpp
stubs/AT_CellularNetwork_stub.cpp
stubs/AT_CellularPower_stub.cpp
stubs/CellularDevice_stub.cpp
stubs/CellularStateMachine_stub.cpp
stubs/equeue_stub.c

View File

@ -58,19 +58,18 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
EXPECT_TRUE(dev.open_information(&fh3));
ATHandler_stub::fh_value = &fh1;
EXPECT_TRUE(dev.open_power(&fh1)); // AT fh1 ref count 3
ATHandler_stub::fh_value = NULL;
AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 4
EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 5
ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 6
EXPECT_TRUE(at->get_ref_count() == 6);
delete dev2; // AT fh1 2 refs deleted -> ref count 4
EXPECT_TRUE(at->get_ref_count() == 4);
AT_CellularDevice dev3(&fh1); // AT fh1 ref count 5
EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 4
EXPECT_TRUE(ATHandler_stub::ref_count == 4);
AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 3
EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 4
ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 5
EXPECT_TRUE(at->get_ref_count() == 5);
delete dev2; // AT fh1 2 refs deleted -> ref count 3
EXPECT_TRUE(at->get_ref_count() == 3);
AT_CellularDevice dev3(&fh1); // AT fh1 ref count 4
EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 3
EXPECT_TRUE(ATHandler_stub::ref_count == 3);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
@ -99,19 +98,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
EXPECT_TRUE(sms1 == sms);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power)
{
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
CellularPower *pwr = dev.open_power(NULL);
CellularPower *pwr1 = dev.open_power(&fh1);
EXPECT_TRUE(pwr);
EXPECT_TRUE(pwr1);
EXPECT_TRUE(pwr1 == pwr);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
{
FileHandle_stub fh1;
@ -151,19 +137,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power)
{
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
EXPECT_TRUE(dev.open_power(&fh1));
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
EXPECT_TRUE(ATHandler_stub::ref_count == 2);
dev.close_power();
EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
{
FileHandle_stub fh1;

View File

@ -28,7 +28,6 @@ set(unittest-test-sources
stubs/AT_CellularNetwork_stub.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularSMS_stub.cpp
stubs/AT_CellularPower_stub.cpp
stubs/AT_CellularInformation_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/AT_CellularBase_stub.cpp

View File

@ -1,76 +0,0 @@
/*
* 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 "gtest/gtest.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "AT_CellularPower.h"
#include "FileHandle_stub.h"
#include "ATHandler_stub.h"
using namespace mbed;
using namespace events;
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularPower : public testing::Test {
protected:
void SetUp() {
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
}
void TearDown() {
}
};
// *INDENT-ON*
TEST_F(TestAT_CellularPower, Create)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower *pow = new AT_CellularPower(at);
EXPECT_TRUE(pow != NULL);
delete pow;
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_on)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.on());
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_off)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.off());
}

View File

@ -1,28 +0,0 @@
####################
# UNIT TESTS
####################
# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/frameworks/mbed-client-randlib/mbed-client-randlib
)
# Source files
set(unittest-sources
../features/cellular/framework/AT/AT_CellularPower.cpp
)
# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -20,7 +20,6 @@
#include "CellularDevice.h"
#include "AT_CellularDevice_stub.h"
#include "FileHandle_stub.h"
#include "AT_CellularPower_stub.h"
#include "AT_CellularNetwork_stub.h"
#include "myCellularDevice.h"
#include "Thread_stub.h"
@ -48,7 +47,6 @@ protected:
void SetUp()
{
Thread_stub::osStatus_value = osOK;
AT_CellularPower_stub::fail_counter = 0;
}
void TearDown()
@ -268,8 +266,6 @@ TEST_F(TestCellularStateMachine, test_stop)
equeue_stub.void_ptr = &ptr;
equeue_stub.call_cb_immediately = true;
AT_CellularPower_stub::fail_counter = 1;
ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_power_on());
ut.stop(); // thread and power are created, now stop will delete them
@ -281,7 +277,6 @@ TEST_F(TestCellularStateMachine, test_stop)
ASSERT_EQ(NSAPI_ERROR_OK, err);
ut.set_cellular_callback(&cellular_callback);
AT_CellularPower_stub::fail_counter = 1;
ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready());
@ -316,7 +311,6 @@ TEST_F(TestCellularStateMachine, test_run_to_state)
equeue_stub.call_cb_immediately = true;
ut.set_cellular_callback(&cellular_callback);
AT_CellularPower_stub::fail_counter = 0;
ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_power_on());
UT_CellularState current_state;
@ -326,7 +320,6 @@ TEST_F(TestCellularStateMachine, test_run_to_state)
ASSERT_EQ(UT_STATE_POWER_ON, target_state);
ut.reset();
AT_CellularPower_stub::set_at_fail_counter = 1;
ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready());
(void)ut.get_current_status(current_state, target_state);
ASSERT_EQ(UT_STATE_DEVICE_READY, current_state);
@ -334,21 +327,18 @@ TEST_F(TestCellularStateMachine, test_run_to_state)
ut.ready_urc_cb();
ut.reset();
AT_CellularPower_stub::fail_counter = 1;
ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready());
(void)ut.get_current_status(current_state, target_state);
ASSERT_EQ(UT_STATE_DEVICE_READY, current_state);
ASSERT_EQ(UT_STATE_DEVICE_READY, target_state);
ut.reset();
AT_CellularPower_stub::fail_counter = 2;
ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready());
(void)ut.get_current_status(current_state, target_state);
ASSERT_EQ(UT_STATE_DEVICE_READY, current_state);
ASSERT_EQ(UT_STATE_DEVICE_READY, target_state);
ut.reset();
AT_CellularPower_stub::fail_counter = 3;
ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_ready());
(void)ut.get_current_status(current_state, target_state);
ASSERT_EQ(UT_STATE_DEVICE_READY, current_state);
@ -356,7 +346,6 @@ TEST_F(TestCellularStateMachine, test_run_to_state)
ut.reset();
AT_CellularDevice_stub::init_module_failure_count = 1;
AT_CellularPower_stub::fail_counter = 0;
AT_CellularNetwork_stub::set_registration_urc_fail_counter = 4;
ASSERT_EQ(NSAPI_ERROR_OK, ut.run_to_device_sim_ready());
(void) ut.get_current_status(current_state, target_state);

View File

@ -28,7 +28,6 @@ set(unittest-test-sources
stubs/SerialBase_stub.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularNetwork_stub.cpp
stubs/AT_CellularPower_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/AT_CellularContext_stub.cpp
stubs/AT_CellularDevice_stub.cpp

View File

@ -17,7 +17,6 @@
#include "AT_CellularDevice_stub.h"
#include "AT_CellularNetwork.h"
#include "AT_CellularPower.h"
#include "AT_CellularContext.h"
#include "ATHandler.h"
@ -34,7 +33,7 @@ int AT_CellularDevice_stub::get_sim_failure_count = 0;
bool AT_CellularDevice_stub::pin_needed = false;
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0),
_power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
_information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
_modem_debug_on(false)
{
}
@ -42,7 +41,16 @@ AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _netw
AT_CellularDevice::~AT_CellularDevice()
{
delete _network;
delete _power;
}
nsapi_error_t AT_CellularDevice::power_on()
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t AT_CellularDevice::power_off()
{
return NSAPI_ERROR_UNSUPPORTED;
}
ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
@ -87,11 +95,6 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
return NULL;
}
CellularPower *AT_CellularDevice::open_power(FileHandle *fh)
{
return new AT_CellularPower(*ATHandler::get_instance(fh, _queue, _default_timeout, "\r", get_send_delay(), _modem_debug_on));
}
CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)
{
return NULL;
@ -105,10 +108,6 @@ void AT_CellularDevice::close_sms()
{
}
void AT_CellularDevice::close_power()
{
}
void AT_CellularDevice::close_information()
{
}
@ -142,11 +141,6 @@ AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at)
return NULL;
}
AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at)
{
return NULL;
}
AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at)
{
return NULL;

View File

@ -1,53 +0,0 @@
/*
* Copyright (c) , 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 "AT_CellularPower_stub.h"
#include "CellularUtil.h"
#include "CellularLog.h"
using namespace mbed_cellular_util;
using namespace mbed;
nsapi_error_t AT_CellularPower_stub::nsapi_error_value = 0;
int AT_CellularPower_stub::fail_counter = 0;
int AT_CellularPower_stub::set_at_fail_counter = 0;
AT_CellularPower::AT_CellularPower(ATHandler &at) : AT_CellularBase(at)
{
}
AT_CellularPower::~AT_CellularPower()
{
}
nsapi_error_t AT_CellularPower::on()
{
if (AT_CellularPower_stub::fail_counter) {
AT_CellularPower_stub::fail_counter--;
return NSAPI_ERROR_DEVICE_ERROR;
}
return AT_CellularPower_stub::nsapi_error_value;
}
nsapi_error_t AT_CellularPower::off()
{
if (AT_CellularPower_stub::fail_counter) {
AT_CellularPower_stub::fail_counter--;
return NSAPI_ERROR_DEVICE_ERROR;
}
return AT_CellularPower_stub::nsapi_error_value;
}

View File

@ -1,28 +0,0 @@
/*
* 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 AT_CELLULARPOWER_STUB_H_
#define AT_CELLULARPOWER_STUB_H_
#include "AT_CellularPower.h"
namespace AT_CellularPower_stub {
extern nsapi_error_t nsapi_error_value;
extern int fail_counter;
extern int set_at_fail_counter;
}
#endif /* AT_CELLULARPOWER_STUB_H_ */

View File

@ -30,7 +30,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
return NULL;
}
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0),
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
{
}

View File

@ -27,7 +27,6 @@ using namespace events;
namespace mbed {
class CellularPower;
class CellularSMS;
class CellularInformation;
class CellularContext;
@ -80,12 +79,17 @@ public:
return _network;
}
virtual CellularSMS *open_sms(FileHandle *fh = NULL)
nsapi_error_t power_on()
{
return NULL;
return NSAPI_ERROR_UNSUPPORTED;
}
virtual CellularPower *open_power(FileHandle *fh = NULL)
nsapi_error_t power_off()
{
return NSAPI_ERROR_UNSUPPORTED;
}
virtual CellularSMS *open_sms(FileHandle *fh = NULL)
{
return NULL;
}
@ -102,8 +106,6 @@ public:
virtual void close_sms() {}
virtual void close_power() {}
virtual void close_information() {}
virtual void set_timeout(int timeout) {}

View File

@ -74,10 +74,6 @@ static void open_close_interfaces()
TEST_ASSERT(info != NULL);
device->close_information();
CellularPower *power = device->open_power(&cellular_serial);
TEST_ASSERT(power != NULL);
device->close_power();
CellularSMS *sms = device->open_sms(&cellular_serial);
TEST_ASSERT(sms != NULL);
device->close_sms();

View File

@ -1,117 +0,0 @@
/*
* 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.
*/
#if !defined(MBED_CONF_NSAPI_PRESENT)
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
#endif
#include "CellularUtil.h" // for CELLULAR_ helper macros
#include "CellularTargets.h"
#ifndef CELLULAR_DEVICE
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
#endif
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
#endif
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "mbed.h"
#include "AT_CellularPower.h"
#include "CellularDevice.h"
#include "../../cellular_tests_common.h"
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
#define NETWORK_TIMEOUT (180*1000)
static CellularDevice *cellular_device;
static void urc_callback()
{
}
static void wait_for_power(CellularPower *pwr)
{
cellular_device->set_ready_cb(&urc_callback);
int sanity_count = 0;
nsapi_error_t err = cellular_device->init();
while (err != NSAPI_ERROR_OK) {
sanity_count++;
wait(1);
TEST_ASSERT(sanity_count < 40);
err = cellular_device->init();
}
TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK);
cellular_device->set_ready_cb(0);
}
static void test_power_interface()
{
const char *devi = CELLULAR_STRINGIFY(CELLULAR_DEVICE);
cellular_device = CellularDevice::get_default_instance();
cellular_device->set_timeout(9000);
CellularPower *pwr = cellular_device->open_power();
TEST_ASSERT(pwr != NULL);
nsapi_error_t err = pwr->on();
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
wait_for_power(pwr);
err = pwr->off();
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
}
using namespace utest::v1;
static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{
greentea_case_failure_abort_handler(source, reason);
return STATUS_ABORT;
}
static Case cases[] = {
Case("CellularPower test interface", test_power_interface, greentea_failure_handler)
};
static utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10 * 60, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
static Specification specification(test_setup, cases);
int main()
{
#if MBED_CONF_MBED_TRACE_ENABLE
trace_open();
#endif
int ret = Harness::run(specification);
#if MBED_CONF_MBED_TRACE_ENABLE
trace_close();
#endif
return ret;
}

View File

@ -169,9 +169,9 @@ public: // from NetworkInterface
/** Start the interface
*
* Powers on the device and does the initializations for communication with the modem.
* Initializes the modem for communication.
* By default, this API is synchronous. API can be set to asynchronous with method set_blocking(...).
* In synchronous and asynchronous mode, the application can get result in from callback, which is set with
* In synchronous and asynchronous mode application can get result in from callback which is set with
* attach(...)
*
* @return NSAPI_ERROR_OK on success

View File

@ -26,7 +26,6 @@
namespace mbed {
class CellularPower;
class CellularSMS;
class CellularInformation;
class CellularNetwork;
@ -75,6 +74,24 @@ public:
*/
virtual ~CellularDevice();
/** Set cellular device power on.
*
* @post init must be called after power_on to setup module
*
* @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_UNSUPPORTED if there is no implementation
*/
virtual nsapi_error_t power_on() = 0;
/** Set cellular device power off.
*
* @pre shutdown must be called before power_down to quit cellular network
*
* @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_UNSUPPORTED if there is no implementation
*/
virtual nsapi_error_t power_off() = 0;
/** Open the SIM card by setting the pin code for SIM.
*
* @param sim_pin PIN for the SIM card
@ -160,7 +177,7 @@ public:
/** Start the interface
*
* Powers on the device and does the initializations for communication with the modem.
* Initializes the modem for communication.
* API is asynchronous. Application can get results from CellularContext callback, which is set
* with attach(...), or callback, which is set by attach(...), in this class.
*
@ -231,14 +248,6 @@ public:
*/
virtual CellularSMS *open_sms(FileHandle *fh = NULL) = 0;
/** Create new CellularPower interface.
*
* @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
* file handle is used.
* @return New instance of interface CellularPower.
*/
virtual CellularPower *open_power(FileHandle *fh = NULL) = 0;
/** Create new CellularInformation interface.
*
* @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
@ -255,10 +264,6 @@ public:
*/
virtual void close_sms() = 0;
/** Closes the opened CellularPower by deleting the CellularPower instance.
*/
virtual void close_power() = 0;
/** Closes the opened CellularInformation by deleting the CellularInformation instance.
*/
virtual void close_information() = 0;
@ -361,7 +366,6 @@ protected:
int _network_ref_count;
int _sms_ref_count;
int _power_ref_count;
int _info_ref_count;
FileHandle *_fh;
events::EventQueue _queue;

View File

@ -1,64 +0,0 @@
/*
* Copyright (c) 2017, 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 CELLULAR_API_CELLULARPOWER_H_
#define CELLULAR_API_CELLULARPOWER_H_
#include "nsapi_types.h"
#include "Callback.h"
namespace mbed {
/**
* Class CellularPower
*
* An interface that provides power handling functions for modem/module.
*/
class CellularPower {
protected:
// friend of CellularDevice so that it's the only way to close/delete this class.
friend class CellularDevice;
/**
* virtual Destructor
*/
virtual ~CellularPower() {}
public:
/** Set cellular device power on. Default implementation is empty.
* Device power on/off is modem/board specific behavior and must be done on inherited class if needed.
* Power on is done by toggling power pin/button.
*
* @remark init must be called to initialize cellular device
*
* @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
*/
virtual nsapi_error_t on() = 0;
/** Set cellular device power off. Default implementation is empty.
* Device power on/off is modem/board specific behavior and must be done on inherited class if needed.
* Power off is done by toggling power pin/button.
*
* @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
*/
virtual nsapi_error_t off() = 0;
};
} // namespace mbed
#endif /* CELLULAR_API_CELLULARPOWER_H_ */

View File

@ -19,7 +19,6 @@
#include "AT_CellularDevice.h"
#include "AT_CellularInformation.h"
#include "AT_CellularNetwork.h"
#include "AT_CellularPower.h"
#include "AT_CellularSMS.h"
#include "AT_CellularContext.h"
#include "AT_CellularStack.h"
@ -36,7 +35,7 @@ using namespace mbed;
const int MAX_SIM_RESPONSE_LENGTH = 16;
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0),
_power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
_information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
_modem_debug_on(false)
{
MBED_ASSERT(fh);
@ -51,12 +50,10 @@ AT_CellularDevice::~AT_CellularDevice()
// make sure that all is deleted even if somewhere close was not called and reference counting is messed up.
_network_ref_count = 1;
_sms_ref_count = 1;
_power_ref_count = 1;
_info_ref_count = 1;
close_network();
close_sms();
close_power();
close_information();
AT_CellularContext *curr = _context_list;
@ -72,6 +69,16 @@ AT_CellularDevice::~AT_CellularDevice()
release_at_handler(_at);
}
nsapi_error_t AT_CellularDevice::power_on()
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t AT_CellularDevice::power_off()
{
return NSAPI_ERROR_UNSUPPORTED;
}
// each parser is associated with one filehandle (that is UART)
ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
{
@ -250,15 +257,6 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
return _sms;
}
CellularPower *AT_CellularDevice::open_power(FileHandle *fh)
{
if (!_power) {
_power = open_power_impl(*get_at_handler(fh));
}
_power_ref_count++;
return _power;
}
CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)
{
if (!_information) {
@ -278,11 +276,6 @@ AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at)
return new AT_CellularSMS(at);
}
AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at)
{
return new AT_CellularPower(at);
}
AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at)
{
return new AT_CellularInformation(at);
@ -314,19 +307,6 @@ void AT_CellularDevice::close_sms()
}
}
void AT_CellularDevice::close_power()
{
if (_power) {
_power_ref_count--;
if (_power_ref_count == 0) {
ATHandler *atHandler = &_power->get_at_handler();
delete _power;
_power = NULL;
release_at_handler(atHandler);
}
}
}
void AT_CellularDevice::close_information()
{
if (_information) {

View File

@ -25,7 +25,6 @@ namespace mbed {
class ATHandler;
class AT_CellularInformation;
class AT_CellularNetwork;
class AT_CellularPower;
class AT_CellularSMS;
class AT_CellularContext;
@ -40,6 +39,10 @@ public:
AT_CellularDevice(FileHandle *fh);
virtual ~AT_CellularDevice();
virtual nsapi_error_t power_on();
virtual nsapi_error_t power_off();
virtual nsapi_error_t set_pin(const char *sim_pin);
virtual nsapi_error_t get_sim_state(SimState &state);
@ -54,16 +57,12 @@ public:
virtual CellularSMS *open_sms(FileHandle *fh = NULL);
virtual CellularPower *open_power(FileHandle *fh = NULL);
virtual CellularInformation *open_information(FileHandle *fh = NULL);
virtual void close_network();
virtual void close_sms();
virtual void close_power();
virtual void close_information();
virtual void set_timeout(int timeout);
@ -119,13 +118,6 @@ public:
*/
virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
/** Create new instance of AT_CellularPower or if overridden, modem specific implementation.
*
* @param at ATHandler reference for communication with the modem.
* @return new instance of class AT_CellularPower
*/
virtual AT_CellularPower *open_power_impl(ATHandler &at);
/** Create new instance of AT_CellularInformation or if overridden, modem specific implementation.
*
* @param at ATHandler reference for communication with the modem.
@ -137,7 +129,6 @@ public:
AT_CellularNetwork *_network;
AT_CellularSMS *_sms;
AT_CellularPower *_power;
AT_CellularInformation *_information;
AT_CellularContext *_context_list;
int _default_timeout;

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2017, 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 "AT_CellularPower.h"
#include "CellularUtil.h"
#include "CellularLog.h"
#include "CellularTargets.h"
#include "nsapi_types.h"
using namespace mbed_cellular_util;
using namespace mbed;
AT_CellularPower::AT_CellularPower(ATHandler &at) : AT_CellularBase(at)
{
}
AT_CellularPower::~AT_CellularPower()
{
}
nsapi_error_t AT_CellularPower::on()
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t AT_CellularPower::off()
{
return NSAPI_ERROR_UNSUPPORTED;
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (c) 2017, 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 AT_CELLULAR_POWER_H_
#define AT_CELLULAR_POWER_H_
#include "CellularPower.h"
#include "AT_CellularBase.h"
namespace mbed {
/**
* Class AT_CellularPower
*
* Class that provides power handling functions for modem/module.
*/
class AT_CellularPower : public CellularPower, public AT_CellularBase {
public:
AT_CellularPower(ATHandler &atHandler);
virtual ~AT_CellularPower();
public:
virtual nsapi_error_t on();
virtual nsapi_error_t off();
};
} // namespace mbed
#endif /* AT_CELLULAR_POWER_H_ */

View File

@ -48,7 +48,7 @@ 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),
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0)
{
MBED_ASSERT(fh);

View File

@ -17,7 +17,6 @@
#include "CellularStateMachine.h"
#include "CellularDevice.h"
#include "CellularPower.h"
#include "CellularLog.h"
#include "Thread.h"
#include "UARTSerial.h"
@ -46,7 +45,7 @@ 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), _queue(queue), _queue_thread(0), _sim_pin(0),
_event_status_cb(0), _network(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),
_network_status(0)
@ -101,10 +100,6 @@ void CellularStateMachine::stop()
reset();
_event_id = STM_STOPPED;
if (_power) {
_cellularDevice.close_power();
_power = NULL;
}
if (_network) {
_cellularDevice.close_network();
@ -114,10 +109,10 @@ void CellularStateMachine::stop()
bool CellularStateMachine::power_on()
{
_cb_data.error = _power->on();
_cb_data.error = _cellularDevice.power_on();
if (_cb_data.error != NSAPI_ERROR_OK && _cb_data.error != NSAPI_ERROR_UNSUPPORTED) {
tr_warn("Power on failed. Try to power off/on.");
_cb_data.error = _power->off();
_cb_data.error = _cellularDevice.power_off();
if (_cb_data.error != NSAPI_ERROR_OK && _cb_data.error != NSAPI_ERROR_UNSUPPORTED) {
tr_error("Power off failed!");
}
@ -337,9 +332,6 @@ void CellularStateMachine::state_init()
{
_cellularDevice.set_timeout(TIMEOUT_POWER_ON);
tr_info("Start connecting (timeout %d s)", TIMEOUT_POWER_ON / 1000);
if (!_power) {
_power = _cellularDevice.open_power();
}
_cb_data.error = _cellularDevice.is_ready();
if (_cb_data.error != NSAPI_ERROR_OK) {
_event_timeout = _start_time;
@ -386,8 +378,6 @@ bool CellularStateMachine::device_ready()
_event_status_cb((nsapi_event_t)CellularDeviceReady, (intptr_t)&_cb_data);
}
_cellularDevice.set_ready_cb(0);
_cellularDevice.close_power();
_power = NULL;
return true;
}

View File

@ -28,7 +28,6 @@ class Thread;
namespace mbed {
class CellularPower;
class CellularDevice;
const int RETRY_ARRAY_SIZE = 10;
@ -167,7 +166,6 @@ private:
Callback<void(nsapi_event_t, intptr_t)> _event_status_cb;
CellularNetwork *_network;
CellularPower *_power;
events::EventQueue &_queue;
rtos::Thread *_queue_thread;

View File

@ -15,9 +15,10 @@
* limitations under the License.
*/
#include "onboard_modem_api.h"
#include "SARA4_PPP.h"
#include "SARA4_PPP_CellularNetwork.h"
#include "SARA4_PPP_CellularPower.h"
using namespace mbed;
using namespace events;
@ -48,8 +49,19 @@ AT_CellularNetwork *SARA4_PPP::open_network_impl(ATHandler &at)
return new SARA4_PPP_CellularNetwork(at);
}
AT_CellularPower *SARA4_PPP::open_power_impl(ATHandler &at)
nsapi_error_t SARA4_PPP::power_on()
{
return new SARA4_PPP_CellularPower(at);
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}
nsapi_error_t SARA4_PPP::power_off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}

View File

@ -30,7 +30,8 @@ public:
public: // CellularDevice
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
virtual AT_CellularPower *open_power_impl(ATHandler &at);
virtual nsapi_error_t power_on();
virtual nsapi_error_t power_off();
};
} // namespace mbed

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2017, 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 "SARA4_PPP_CellularPower.h"
#include "onboard_modem_api.h"
using namespace mbed;
SARA4_PPP_CellularPower::SARA4_PPP_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
{
}
SARA4_PPP_CellularPower::~SARA4_PPP_CellularPower()
{
}
nsapi_error_t SARA4_PPP_CellularPower::on()
{
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}
nsapi_error_t SARA4_PPP_CellularPower::off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2017, 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 SARA4_PPP_CELLULARPOWER_H_
#define SARA4_PPP_CELLULARPOWER_H_
#include "AT_CellularPower.h"
namespace mbed {
class SARA4_PPP_CellularPower : public AT_CellularPower {
public:
SARA4_PPP_CellularPower(ATHandler &atHandler);
virtual ~SARA4_PPP_CellularPower();
public: //from CellularPower
virtual nsapi_error_t on();
virtual nsapi_error_t off();
};
} // namespace mbed
#endif // SARA4_PPP_CELLULARPOWER_H_

View File

@ -15,8 +15,8 @@
* limitations under the License.
*/
#include "onboard_modem_api.h"
#include "QUECTEL_UG96.h"
#include "QUECTEL_UG96_CellularPower.h"
#include "QUECTEL_UG96_CellularContext.h"
#include "AT_CellularNetwork.h"
@ -48,9 +48,21 @@ QUECTEL_UG96::~QUECTEL_UG96()
{
}
AT_CellularPower *QUECTEL_UG96::open_power_impl(ATHandler &at)
nsapi_error_t QUECTEL_UG96::power_on()
{
return new QUECTEL_UG96_CellularPower(at);
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}
nsapi_error_t QUECTEL_UG96::power_off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}
AT_CellularContext *QUECTEL_UG96::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)

View File

@ -36,7 +36,8 @@ public:
virtual ~QUECTEL_UG96();
protected: // AT_CellularDevice
virtual AT_CellularPower *open_power_impl(ATHandler &at);
virtual nsapi_error_t power_on();
virtual nsapi_error_t power_off();
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
public: // NetworkInterface

View File

@ -1,49 +0,0 @@
/*
* 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_UG96_CellularPower.h"
#include "onboard_modem_api.h"
using namespace mbed;
QUECTEL_UG96_CellularPower::QUECTEL_UG96_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
{
}
QUECTEL_UG96_CellularPower::~QUECTEL_UG96_CellularPower()
{
}
nsapi_error_t QUECTEL_UG96_CellularPower::on()
{
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}
nsapi_error_t QUECTEL_UG96_CellularPower::off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}

View File

@ -1,39 +0,0 @@
/*
* 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_UG96_CELLULARPOWER_H_
#define QUECTEL_UG96_CELLULARPOWER_H_
#include "AT_CellularPower.h"
namespace mbed {
class QUECTEL_UG96_CellularPower : public AT_CellularPower {
public:
QUECTEL_UG96_CellularPower(ATHandler &atHandler);
virtual ~QUECTEL_UG96_CellularPower();
public: //from CellularPower
virtual nsapi_error_t on();
virtual nsapi_error_t off();
};
} // namespace mbed
#endif // QUECTEL_UG96_CELLULARPOWER_H_

View File

@ -15,8 +15,8 @@
* limitations under the License.
*/
#include "onboard_modem_api.h"
#include "TELIT_HE910.h"
#include "TELIT_HE910_CellularPower.h"
#include "AT_CellularNetwork.h"
using namespace mbed;
@ -43,9 +43,21 @@ TELIT_HE910::~TELIT_HE910()
{
}
AT_CellularPower *TELIT_HE910::open_power_impl(ATHandler &at)
nsapi_error_t TELIT_HE910::power_on()
{
return new TELIT_HE910_CellularPower(at);
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}
nsapi_error_t TELIT_HE910::power_off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}
uint16_t TELIT_HE910::get_send_delay() const

View File

@ -31,7 +31,8 @@ public:
virtual ~TELIT_HE910();
protected: // AT_CellularDevice
virtual AT_CellularPower *open_power_impl(ATHandler &at);
virtual nsapi_error_t power_on();
virtual nsapi_error_t power_off();
virtual uint16_t get_send_delay() const;
virtual nsapi_error_t init();
};

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2017, 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 "TELIT_HE910_CellularPower.h"
// for modem powering up&down
#include "onboard_modem_api.h"
using namespace mbed;
TELIT_HE910_CellularPower::TELIT_HE910_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
{
}
TELIT_HE910_CellularPower::~TELIT_HE910_CellularPower()
{
}
nsapi_error_t TELIT_HE910_CellularPower::on()
{
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}
nsapi_error_t TELIT_HE910_CellularPower::off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2017, 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 TELIT_HE910_CELLULAR_POWER_H_
#define TELIT_HE910_CELLULAR_POWER_H_
#include "AT_CellularPower.h"
namespace mbed {
class TELIT_HE910_CellularPower : public AT_CellularPower {
public:
TELIT_HE910_CellularPower(ATHandler &atHandler);
virtual ~TELIT_HE910_CellularPower();
public: //from CellularPower
virtual nsapi_error_t on();
virtual nsapi_error_t off();
};
} // namespace mbed
#endif // TELIT_HE910_CELLULAR_POWER_H_

View File

@ -15,9 +15,9 @@
* limitations under the License.
*/
#include "onboard_modem_api.h"
#include "UBLOX_AT.h"
#include "UBLOX_AT_CellularNetwork.h"
#include "UBLOX_AT_CellularPower.h"
#include "UBLOX_AT_CellularContext.h"
using namespace mbed;
@ -64,9 +64,21 @@ AT_CellularNetwork *UBLOX_AT::open_network_impl(ATHandler &at)
return new UBLOX_AT_CellularNetwork(at);
}
AT_CellularPower *UBLOX_AT::open_power_impl(ATHandler &at)
nsapi_error_t UBLOX_AT::power_on()
{
return new UBLOX_AT_CellularPower(at);
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}
nsapi_error_t UBLOX_AT::power_off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}
AT_CellularContext *UBLOX_AT::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)

View File

@ -28,8 +28,9 @@ public:
virtual ~UBLOX_AT();
protected: // AT_CellularDevice
virtual nsapi_error_t power_on();
virtual nsapi_error_t power_off();
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
virtual AT_CellularPower *open_power_impl(ATHandler &at);
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
public: // NetworkInterface
void handle_urc(FileHandle *fh);

View File

@ -1,47 +0,0 @@
/*
* 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 "UBLOX_AT_CellularPower.h"
#include "onboard_modem_api.h"
using namespace mbed;
UBLOX_AT_CellularPower::UBLOX_AT_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
{
}
UBLOX_AT_CellularPower::~UBLOX_AT_CellularPower()
{
}
nsapi_error_t UBLOX_AT_CellularPower::on()
{
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}
nsapi_error_t UBLOX_AT_CellularPower::off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}

View File

@ -1,39 +0,0 @@
/*
* 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 UBLOX_AT_CELLULARPOWER_H_
#define UBLOX_AT_CELLULARPOWER_H_
#include "AT_CellularPower.h"
namespace mbed {
class UBLOX_AT_CellularPower : public AT_CellularPower {
public:
UBLOX_AT_CellularPower(ATHandler &atHandler);
virtual ~UBLOX_AT_CellularPower();
public: //from CellularPower
virtual nsapi_error_t on();
virtual nsapi_error_t off();
};
} // namespace mbed
#endif // UBLOX_AT_CELLULARPOWER_H_

View File

@ -15,8 +15,8 @@
* limitations under the License.
*/
#include "onboard_modem_api.h"
#include "UBLOX_PPP.h"
#include "UBLOX_PPP_CellularPower.h"
#include "AT_CellularNetwork.h"
using namespace mbed;
@ -57,7 +57,19 @@ UBLOX_PPP::~UBLOX_PPP()
{
}
AT_CellularPower *UBLOX_PPP::open_power_impl(ATHandler &at)
nsapi_error_t UBLOX_PPP::power_on()
{
return new UBLOX_PPP_CellularPower(at);
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}
nsapi_error_t UBLOX_PPP::power_off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}

View File

@ -28,7 +28,8 @@ public:
virtual ~UBLOX_PPP();
protected: // AT_CellularDevice
virtual AT_CellularPower *open_power_impl(ATHandler &at);
virtual nsapi_error_t power_on();
virtual nsapi_error_t power_off();
};
} // namespace mbed

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2017, 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 "UBLOX_PPP_CellularPower.h"
#include "onboard_modem_api.h"
using namespace mbed;
UBLOX_PPP_CellularPower::UBLOX_PPP_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
{
}
UBLOX_PPP_CellularPower::~UBLOX_PPP_CellularPower()
{
}
nsapi_error_t UBLOX_PPP_CellularPower::on()
{
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}
nsapi_error_t UBLOX_PPP_CellularPower::off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2017, 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 UBLOX_PPP_CELLULARPOWER_H_
#define UBLOX_PPP_CELLULARPOWER_H_
#include "AT_CellularPower.h"
namespace mbed {
class UBLOX_PPP_CellularPower : public AT_CellularPower {
public:
UBLOX_PPP_CellularPower(ATHandler &atHandler);
virtual ~UBLOX_PPP_CellularPower();
public: //from CellularPower
virtual nsapi_error_t on();
virtual nsapi_error_t off();
};
} // namespace mbed
#endif // UBLOX_PPP_CELLULARPOWER_H_