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.
ATHandler_stub.cpp
00001 /* 00002 * Copyright (c) , 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 00018 #include <ctype.h> 00019 #include "nsapi_types.h" 00020 #include "ATHandler.h" 00021 #include "EventQueue.h" 00022 #include "ATHandler_stub.h" 00023 00024 using namespace mbed; 00025 using namespace events; 00026 00027 #include "CellularLog.h" 00028 00029 const int DEFAULT_AT_TIMEOUT = 1000; // at default timeout in milliseconds 00030 00031 nsapi_error_t ATHandler_stub::nsapi_error_value = 0; 00032 uint8_t ATHandler_stub::nsapi_error_ok_counter = 0; 00033 int ATHandler_stub::int_value = -1; 00034 int ATHandler_stub::ref_count = 0; 00035 int ATHandler_stub::timeout = 0; 00036 bool ATHandler_stub::default_timeout = 0; 00037 bool ATHandler_stub::debug_on = 0; 00038 ssize_t ATHandler_stub::ssize_value = 0; 00039 const char *ATHandler_stub::read_string_value = NULL; 00040 size_t ATHandler_stub::size_value = 0; 00041 size_t ATHandler_stub::return_given_size = false; 00042 bool ATHandler_stub::bool_value = false; 00043 uint8_t ATHandler_stub::uint8_value = 0; 00044 FileHandle_stub *ATHandler_stub::fh_value = NULL; 00045 device_err_t ATHandler_stub::device_err_value; 00046 Callback<void()> ATHandler_stub::callback = NULL; 00047 bool ATHandler_stub::call_immediately = false; 00048 uint8_t ATHandler_stub::resp_info_true_counter = false; 00049 uint8_t ATHandler_stub::info_elem_true_counter = false; 00050 int ATHandler_stub::int_valid_count_table[kRead_int_table_size]; 00051 int ATHandler_stub::int_count = kRead_int_table_size; 00052 00053 int ATHandler_stub::read_string_index = kRead_string_table_size; 00054 const char *ATHandler_stub::read_string_table[kRead_string_table_size]; 00055 int ATHandler_stub::resp_stop_success_count = kResp_stop_count_default; 00056 00057 ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay) : 00058 _nextATHandler(0), 00059 _fileHandle(fh), 00060 _queue(queue) 00061 { 00062 ATHandler_stub::ref_count = 1; 00063 } 00064 00065 void ATHandler::set_debug(bool debug_on) 00066 { 00067 ATHandler_stub::debug_on = debug_on; 00068 } 00069 00070 ATHandler::~ATHandler() 00071 { 00072 ATHandler_stub::ref_count = kATHandler_destructor_ref_ount; 00073 } 00074 00075 void ATHandler::inc_ref_count() 00076 { 00077 ATHandler_stub::ref_count++; 00078 } 00079 00080 void ATHandler::dec_ref_count() 00081 { 00082 ATHandler_stub::ref_count--; 00083 } 00084 00085 int ATHandler::get_ref_count() 00086 { 00087 return ATHandler_stub::ref_count; 00088 } 00089 00090 FileHandle *ATHandler::get_file_handle() 00091 { 00092 return ATHandler_stub::fh_value; 00093 } 00094 00095 void ATHandler::set_file_handle(FileHandle *fh) 00096 { 00097 } 00098 00099 nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb) 00100 { 00101 ATHandler_stub::callback = cb; 00102 if (ATHandler_stub::call_immediately) { 00103 cb(); 00104 } 00105 return ATHandler_stub::nsapi_error_value; 00106 } 00107 00108 void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback<void()> callback) 00109 { 00110 } 00111 00112 nsapi_error_t ATHandler::get_last_error() const 00113 { 00114 if (ATHandler_stub::nsapi_error_ok_counter) { 00115 ATHandler_stub::nsapi_error_ok_counter--; 00116 return NSAPI_ERROR_OK ; 00117 } 00118 return ATHandler_stub::nsapi_error_value; 00119 } 00120 00121 void ATHandler::lock() 00122 { 00123 } 00124 00125 void ATHandler::unlock() 00126 { 00127 } 00128 00129 nsapi_error_t ATHandler::unlock_return_error() 00130 { 00131 return ATHandler_stub::nsapi_error_value; 00132 } 00133 00134 void ATHandler::set_at_timeout(uint32_t timeout_milliseconds, bool default_timeout) 00135 { 00136 ATHandler_stub::timeout = timeout_milliseconds; 00137 ATHandler_stub::default_timeout = default_timeout; 00138 } 00139 00140 void ATHandler::restore_at_timeout() 00141 { 00142 } 00143 00144 void ATHandler::process_oob() 00145 { 00146 } 00147 00148 void ATHandler::clear_error() 00149 { 00150 ATHandler_stub::nsapi_error_ok_counter++; 00151 } 00152 00153 void ATHandler::skip_param(uint32_t count) 00154 { 00155 00156 } 00157 00158 void ATHandler::skip_param(ssize_t len, uint32_t count) 00159 { 00160 } 00161 00162 ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len) 00163 { 00164 return ATHandler_stub::ssize_value; 00165 } 00166 00167 ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag) 00168 { 00169 00170 if (ATHandler_stub::read_string_index == kRead_string_table_size) { 00171 if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) { 00172 memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value + 1); 00173 } 00174 return ATHandler_stub::ssize_value; 00175 } 00176 00177 ATHandler_stub::read_string_index--; 00178 if (ATHandler_stub::read_string_index >= 0) { 00179 const char *tmp = ATHandler_stub::read_string_table[ATHandler_stub::read_string_index]; 00180 ssize_t len = strlen(tmp); 00181 memcpy(buf, tmp, len + 1); 00182 return len; 00183 } 00184 00185 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR ; 00186 return -1; 00187 } 00188 00189 int32_t ATHandler::read_int() 00190 { 00191 if (ATHandler_stub::nsapi_error_value != NSAPI_ERROR_OK ) { 00192 return -1; 00193 } 00194 00195 if (ATHandler_stub::int_count == kRead_int_table_size) { 00196 return ATHandler_stub::int_value; 00197 } 00198 00199 //printf("ATHandler_stub::int_count: %d", ATHandler_stub::int_count); 00200 ATHandler_stub::int_count--; 00201 if (ATHandler_stub::int_count < kRead_int_table_size && ATHandler_stub::int_count >= 0) { 00202 return ATHandler_stub::int_valid_count_table[ATHandler_stub::int_count]; 00203 } 00204 00205 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR ; 00206 return -1; 00207 } 00208 00209 void ATHandler::set_delimiter(char delimiter) 00210 { 00211 } 00212 00213 void ATHandler::set_default_delimiter() 00214 { 00215 } 00216 00217 void ATHandler::set_stop_tag(const char *stop_tag_seq) 00218 { 00219 } 00220 00221 int ATHandler::get_3gpp_error() 00222 { 00223 return ATHandler_stub::int_value; 00224 } 00225 00226 void ATHandler::resp_start(const char *prefix, bool stop) 00227 { 00228 } 00229 00230 bool ATHandler::info_resp() 00231 { 00232 if (ATHandler_stub::resp_info_true_counter) { 00233 ATHandler_stub::resp_info_true_counter--; 00234 return true; 00235 } 00236 return ATHandler_stub::bool_value; 00237 } 00238 00239 bool ATHandler::info_elem(char start_tag) 00240 { 00241 if (ATHandler_stub::info_elem_true_counter) { 00242 ATHandler_stub::info_elem_true_counter--; 00243 return true; 00244 } 00245 return ATHandler_stub::bool_value; 00246 } 00247 00248 bool ATHandler::consume_to_stop_tag() 00249 { 00250 return ATHandler_stub::bool_value; 00251 } 00252 00253 void ATHandler::resp_stop() 00254 { 00255 if (ATHandler_stub::resp_stop_success_count > 0) { 00256 ATHandler_stub::resp_stop_success_count--; 00257 return; 00258 } 00259 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR ; 00260 } 00261 00262 void ATHandler::cmd_start(const char *cmd) 00263 { 00264 } 00265 00266 void ATHandler::write_int(int32_t param) 00267 { 00268 } 00269 00270 void ATHandler::write_string(const char *param, bool useQuotations) 00271 { 00272 } 00273 00274 size_t ATHandler::write_bytes(const uint8_t *param, size_t len) 00275 { 00276 if (ATHandler_stub::return_given_size) { 00277 return len; 00278 } 00279 return ATHandler_stub::size_value; 00280 } 00281 00282 void ATHandler::cmd_stop() 00283 { 00284 } 00285 00286 device_err_t ATHandler::get_last_device_error() const 00287 { 00288 return ATHandler_stub::device_err_value; 00289 } 00290 00291 void ATHandler::flush() 00292 { 00293 00294 }
Generated on Tue Aug 9 2022 00:37:03 by
1.7.2