upsv

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UbloxATCmdParser.cpp Source File

UbloxATCmdParser.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 #ifdef TARGET_UBLOX_C030_R41XM
00018 
00019 #include "UbloxATCmdParser.h"
00020 #include "rtos/Thread.h"
00021 
00022 using namespace mbed;
00023 
00024 UbloxATCmdParser::UbloxATCmdParser(FileHandle *fh, const char *output_delimiter, int buffer_size, int timeout, bool debug) : ATCmdParser(fh, output_delimiter, buffer_size, timeout, debug)
00025 {
00026     idle_mode_disabled();
00027 }
00028 UbloxATCmdParser::~UbloxATCmdParser()
00029 {
00030 
00031 }
00032 
00033 
00034 bool UbloxATCmdParser::send(const char *command, ...)
00035 {
00036     bool status = false;
00037 
00038     if (_idle_mode_status == true) { //idle mode is active
00039         if ( _wakeup_timer.read_ms() >= 5000) { //if more than 5 secs have passed since last TX activity, wake up the modem.
00040             uint8_t retries = 3;
00041             ATCmdParser::set_timeout(1000);
00042             while(retries--) {
00043                 ATCmdParser::putc('A');
00044                 wait_ms(10); //wait a little
00045                 if ( (ATCmdParser::send("AT")) && (ATCmdParser::recv("OK")) ) { //check if modem is awake and accepting commands
00046                     status = true;
00047                     break;
00048                 }
00049             }
00050             ATCmdParser::set_timeout(_timeout);
00051             if (status == false) { //all tries failed, return false
00052                 _wakeup_timer.reset();
00053                 return status;
00054             }
00055         }
00056         _wakeup_timer.reset(); //Any activity on tx will reset the timer. Timer will expire if no activity since last 5 secs
00057     }
00058 
00059     va_list args;
00060     va_start(args, command);
00061     status = ATCmdParser::vsend(command, args);
00062     va_end(args);
00063     return status;
00064 }
00065 
00066 void UbloxATCmdParser::idle_mode_enabled()
00067 {
00068     _idle_mode_status = true;
00069     _wakeup_timer.start();
00070 }
00071 
00072 void UbloxATCmdParser::idle_mode_disabled()
00073 {
00074     _idle_mode_status = false;
00075     _wakeup_timer.stop();
00076 }
00077 
00078 bool UbloxATCmdParser::is_idle_mode_enabled()
00079 {
00080     return _idle_mode_status;
00081 }
00082 
00083 void UbloxATCmdParser::set_timeout(int timeout) {
00084     _timeout = timeout;
00085     ATCmdParser::set_timeout(timeout);
00086 }
00087 #endif /* TARGET_UBLOX_C030_R41XM */