Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers power.cpp Source File

power.cpp

00001 /*
00002  * Copyright (c) 2017, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #include "CellularTests.h"
00018 
00019 #ifdef CELLULAR_DEVICE
00020 
00021 using namespace mbed;
00022 
00023 static bool start_cellular_at(CellularPower *pwr)
00024 {
00025     nsapi_error_t err = pwr->off();
00026     if (err != NSAPI_ERROR_OK  && err != NSAPI_ERROR_UNSUPPORTED ) {
00027         return false;
00028     }
00029     err = pwr->on();
00030     if (err != NSAPI_ERROR_OK  && err != NSAPI_ERROR_UNSUPPORTED ) {
00031         return false;
00032     }
00033     tr_info("Wait for cellular device 180 seconds...");
00034     for (int i = 0; i < 180; i++) {
00035         if (pwr->set_at_mode() == NSAPI_ERROR_OK ) {
00036             return true;
00037         }
00038         wait(1);
00039     }
00040     return false;
00041 }
00042 
00043 void test_create_power()
00044 {
00045     TEST_ASSERT(start_cellular_at(pwr));
00046 
00047     tr_info("Cellular device is ready!");
00048 }
00049 
00050 // TODO: tests still missing for off, sleep, opt_power_save_mode, opt_receive_period
00051 
00052 #endif // CELLULAR_DEVICE