Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AT_CellularInformation.cpp Source File

AT_CellularInformation.cpp

00001 /*
00002  * Copyright (c) 2018, 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 <stdio.h>
00019 
00020 #include "AT_CellularDevice.h"
00021 #include "AT_CellularInformation.h"
00022 
00023 using namespace mbed;
00024 
00025 AT_CellularInformation::AT_CellularInformation(ATHandler &at, AT_CellularDevice &device) : _at(at), _device(device)
00026 {
00027 }
00028 
00029 AT_CellularInformation::~AT_CellularInformation()
00030 {
00031 }
00032 
00033 nsapi_error_t AT_CellularInformation::get_manufacturer(char *buf, size_t buf_size)
00034 {
00035     return get_info("AT+CGMI", buf, buf_size);
00036 }
00037 
00038 nsapi_error_t AT_CellularInformation::get_model(char *buf, size_t buf_size)
00039 {
00040     return get_info("AT+CGMM", buf, buf_size);
00041 }
00042 
00043 nsapi_error_t AT_CellularInformation::get_revision(char *buf, size_t buf_size)
00044 {
00045     return get_info("AT+CGMR", buf, buf_size);
00046 }
00047 
00048 nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_size, SerialNumberType type)
00049 {
00050     if (buf == NULL || buf_size == 0) {
00051         return NSAPI_ERROR_PARAMETER ;
00052     }
00053 
00054     if (type == SN) {
00055         return get_info("AT+CGSN", buf, buf_size);
00056     }
00057 
00058     if (!_device.get_property(AT_CellularDevice::PROPERTY_AT_CGSN_WITH_TYPE)) {
00059         return NSAPI_ERROR_UNSUPPORTED ;
00060     }
00061 
00062     return _at.at_cmd_str("+CGSN", "=", buf, buf_size, "%d", type);
00063 }
00064 
00065 nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_t buf_size)
00066 {
00067     if (buf == NULL || buf_size == 0) {
00068         return NSAPI_ERROR_PARAMETER ;
00069     }
00070     _at.lock();
00071     _at.cmd_start(cmd);
00072     _at.cmd_stop();
00073     _at.set_delimiter(0);
00074     _at.resp_start();
00075     _at.read_string(buf, buf_size);
00076     _at.resp_stop();
00077     _at.set_default_delimiter();
00078     return _at.unlock_return_error();
00079 }
00080 
00081 nsapi_error_t AT_CellularInformation::get_imsi(char *imsi, size_t buf_size)
00082 {
00083     if (imsi == NULL || buf_size == 0 || buf_size < MAX_IMSI_LENGTH + 1) {
00084         return NSAPI_ERROR_PARAMETER ;
00085     }
00086     _at.lock();
00087     _at.cmd_start_stop("+CIMI", "");
00088     _at.resp_start();
00089     _at.read_string(imsi, MAX_IMSI_LENGTH + 1);
00090     _at.resp_stop();
00091     return _at.unlock_return_error();
00092 }
00093 
00094 nsapi_error_t AT_CellularInformation::get_iccid(char *buf, size_t buf_size)
00095 {
00096     if (buf == NULL || buf_size == 0) {
00097         return NSAPI_ERROR_PARAMETER ;
00098     }
00099     return _at.at_cmd_str("+CCID", "?", buf, buf_size);
00100 }
00101 
00102 ATHandler &AT_CellularInformation::get_at_handler()
00103 {
00104     return _at;
00105 }