Knight KE / Mbed OS Game_Master
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_CellularInformation.h"
00021 
00022 using namespace mbed;
00023 
00024 AT_CellularInformation::AT_CellularInformation(ATHandler &at) : AT_CellularBase(at)
00025 {
00026 }
00027 
00028 AT_CellularInformation::~AT_CellularInformation()
00029 {
00030 }
00031 
00032 nsapi_error_t AT_CellularInformation::get_manufacturer(char *buf, size_t buf_size)
00033 {
00034     return get_info("AT+CGMI", buf, buf_size);
00035 }
00036 
00037 nsapi_error_t AT_CellularInformation::get_model(char *buf, size_t buf_size)
00038 {
00039     return get_info("AT+CGMM", buf, buf_size);
00040 }
00041 
00042 nsapi_error_t AT_CellularInformation::get_revision(char *buf, size_t buf_size)
00043 {
00044     return get_info("AT+CGMR", buf, buf_size);
00045 }
00046 
00047 nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_size, SerialNumberType type)
00048 {
00049     if (type == SN) {
00050         return get_info("AT+CGSN", buf, buf_size);
00051     }
00052 
00053     if (!is_supported(AT_CGSN_WITH_TYPE)) {
00054         return NSAPI_ERROR_UNSUPPORTED ;
00055     }
00056 
00057     _at.lock();
00058     _at.cmd_start("AT+CGSN=");
00059     _at.write_int(type);
00060     _at.cmd_stop();
00061     _at.resp_start("+CGSN:");
00062     _at.read_string(buf, buf_size);
00063     _at.resp_stop();
00064     return _at.unlock_return_error();
00065 }
00066 
00067 nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_t buf_size)
00068 {
00069     _at.lock();
00070 
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 - 1);
00076     _at.resp_stop();
00077     _at.set_default_delimiter();
00078 
00079     return _at.unlock_return_error();
00080 }