Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 25:e67d3d9d2e7e, committed 2019-05-29
- Comitter:
- wajahat.abbas@u-blox.com
- Date:
- Wed May 29 12:39:28 2019 +0500
- Parent:
- 24:e26a6ab0dd75
- Commit message:
- Added support for +UPSV (idle mode) for C030_R412M
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UbloxATCmdParser.cpp Wed May 29 12:39:28 2019 +0500 @@ -0,0 +1,87 @@ +/* + * 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. + */ +#ifdef TARGET_UBLOX_C030_R41XM + +#include "UbloxATCmdParser.h" +#include "rtos/Thread.h" + +using namespace mbed; + +UbloxATCmdParser::UbloxATCmdParser(FileHandle *fh, const char *output_delimiter, int buffer_size, int timeout, bool debug) : ATCmdParser(fh, output_delimiter, buffer_size, timeout, debug) +{ + idle_mode_disabled(); +} +UbloxATCmdParser::~UbloxATCmdParser() +{ + +} + + +bool UbloxATCmdParser::send(const char *command, ...) +{ + bool status = false; + + if (_idle_mode_status == true) { //idle mode is active + if ( _wakeup_timer.read_ms() >= 5000) { //if more than 5 secs have passed since last TX activity, wake up the modem. + uint8_t retries = 3; + ATCmdParser::set_timeout(1000); + while(retries--) { + ATCmdParser::putc('A'); + wait_ms(10); //wait a little + if ( (ATCmdParser::send("AT")) && (ATCmdParser::recv("OK")) ) { //check if modem is awake and accepting commands + status = true; + break; + } + } + ATCmdParser::set_timeout(_timeout); + if (status == false) { //all tries failed, return false + _wakeup_timer.reset(); + return status; + } + } + _wakeup_timer.reset(); //Any activity on tx will reset the timer. Timer will expire if no activity since last 5 secs + } + + va_list args; + va_start(args, command); + status = ATCmdParser::vsend(command, args); + va_end(args); + return status; +} + +void UbloxATCmdParser::idle_mode_enabled() +{ + _idle_mode_status = true; + _wakeup_timer.start(); +} + +void UbloxATCmdParser::idle_mode_disabled() +{ + _idle_mode_status = false; + _wakeup_timer.stop(); +} + +bool UbloxATCmdParser::is_idle_mode_enabled() +{ + return _idle_mode_status; +} + +void UbloxATCmdParser::set_timeout(int timeout) { + _timeout = timeout; + ATCmdParser::set_timeout(timeout); +} +#endif /* TARGET_UBLOX_C030_R41XM */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UbloxATCmdParser.h Wed May 29 12:39:28 2019 +0500 @@ -0,0 +1,58 @@ +/* + * 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. + */ +#ifdef TARGET_UBLOX_C030_R41XM +#ifndef UBLOXATCMDPARSER_H_ +#define UBLOXATCMDPARSER_H_ + +#include "ATCmdParser.h" +#include "mbed.h" + +namespace mbed { + +/** + * Class UbloxATCmdParser + * + */ +class UbloxATCmdParser : public ATCmdParser +{ +public: + UbloxATCmdParser(FileHandle *fh, const char *output_delimiter = "\r", + int buffer_size = 256, int timeout = 8000, bool debug = false); + ~UbloxATCmdParser(); + + bool send(const char *command, ...) MBED_PRINTF_METHOD(1,2); + + void set_timeout(int timeout); + + bool is_idle_mode_enabled(); + + void idle_mode_enabled(); + + void idle_mode_disabled(); + +private: + bool _idle_mode_status; + Timer _wakeup_timer; + int _timeout; +}; + + +} // namespace mbed + +#endif +#endif +
--- a/UbloxCellularBase.cpp Tue May 28 15:39:51 2019 +0500 +++ b/UbloxCellularBase.cpp Wed May 29 12:39:28 2019 +0500 @@ -532,8 +532,13 @@ _fh = new UARTSerial(tx, rx, baud); // Set up the AT parser +#ifdef TARGET_UBLOX_C030_R41XM + _at = new UbloxATCmdParser(_fh, OUTPUT_ENTER_KEY, AT_PARSER_BUFFER_SIZE, + _at_timeout, _debug_trace_on); +#else _at = new ATCmdParser(_fh, OUTPUT_ENTER_KEY, AT_PARSER_BUFFER_SIZE, _at_timeout, _debug_trace_on); +#endif // Error cases, out of band handling _at->oob("ERROR", callback(this, &UbloxCellularBase::parser_abort_cb)); @@ -813,6 +818,11 @@ set_power_saving_mode(0, 0); } #endif +#ifdef TARGET_UBLOX_C030_R41XM + if (_at->is_idle_mode_enabled() == false) { + set_idle_mode(false); //disable idle mode at start up + } +#endif if (set_device_identity(&_dev_info.dev) && // Set up device identity device_init(_dev_info.dev)) {// Initialise this device // Get the integrated circuit ID of the SIM @@ -1296,7 +1306,57 @@ UNLOCK(); return return_val; } +// Enable or Disable the UPSV power saving mode +bool UbloxCellularBase::set_idle_mode(bool enable) +{ +#ifdef TARGET_UBLOX_C030_R412M + if (_psm_status == true && enable == true) { + return false; + } #endif + + bool success = false; + LOCK(); + + MBED_ASSERT(_at != NULL); + + if (_at->send("AT+UPSV=%d", enable ? 4 : 0) && _at->recv("OK")) { + if (enable == true) { + _at->idle_mode_enabled(); + } + else { + _at->idle_mode_disabled(); + } + success = true; + } + + UNLOCK(); + return success; +} + +bool UbloxCellularBase::get_idle_mode(int *status) +{ + bool return_val = false; + + if (status == NULL) { + return false; + } + + LOCK(); + MBED_ASSERT(_at != NULL); + + if ( (_at->send("AT+UPSV?") && _at->recv("+UPSV: %d", status) && _at->recv("OK")) ) { + if (*status == 4) { + *status = 1; + } + return_val = true; + } + + UNLOCK(); + return return_val; +} +#endif + #ifdef TARGET_UBLOX_C030_R412M bool UbloxCellularBase::get_power_saving_mode(int *status, int *periodic_time, int *active_time) { @@ -1305,6 +1365,10 @@ int value, multiplier; bool return_val; + if (status == NULL || periodic_time == NULL || active_time == NULL) { + return false; + } + LOCK(); //+UCPSMS:1,,,"01000011","01000011" if (_at->send("AT+UCPSMS?") && _at->recv("+UCPSMS:%d,,,\"%8c\",\"%8c\"\n", status, pt_encoded, at_encoded)) { @@ -1405,6 +1469,9 @@ bool UbloxCellularBase::set_power_saving_mode(int periodic_time, int active_time) { + if (_at->is_idle_mode_enabled() == true && periodic_time != 0 && active_time != 0 ) { + return false; + } bool return_val = false; LOCK();
--- a/UbloxCellularBase.h Tue May 28 15:39:51 2019 +0500 +++ b/UbloxCellularBase.h Wed May 29 12:39:28 2019 +0500 @@ -18,7 +18,7 @@ #include "mbed.h" #include "mbed_toolchain.h" // for MBED_DEPRECATED -#include "ATCmdParser.h" +#include "ubloxATCmdParser.h" #include "FileHandle.h" /********************************************************************** @@ -253,6 +253,23 @@ * @return true if operation was successful, false if there was an error */ bool get_mno_profile(int *profile); + + /** Enable or disable the UPSV Power Saving Mode. + * + * @param idle_mode_value 1: enable idle mode + * 0: disable idle mode + * @return true if successful, otherwise false. + */ + bool set_idle_mode(bool enable = false); + + /** Queries the modem for idle mode status. + * + * @param status pointer to variable that can hold the value for idle mode status + * 1: enabled + * 0: disabled + * @return true if successful, otherwise false. + */ + bool get_idle_mode(int *status); #endif /** Set Radio Access Technology on modem. @@ -458,7 +475,11 @@ /** Point to the instance of the AT parser in use. */ +#ifdef TARGET_UBLOX_C030_R41XM + UbloxATCmdParser *_at; +#else ATCmdParser *_at; +#endif /** The current AT parser timeout value. */