mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: Added AT+CCID and AT+CGSN
parent
799ba08017
commit
44365bccd0
|
@ -28,8 +28,7 @@ namespace mbed {
|
|||
*
|
||||
* An abstract interface that provides information about cellular device.
|
||||
*/
|
||||
class CellularInformation
|
||||
{
|
||||
class CellularInformation {
|
||||
protected:
|
||||
// friend of CellularDevice so that it's the only way to close/delete this class.
|
||||
friend class CellularDevice;
|
||||
|
@ -41,27 +40,42 @@ protected:
|
|||
public:
|
||||
/** Request manufacturer identification of cellular device
|
||||
*
|
||||
* @param buf manufacturer identification
|
||||
* @param buf manufacturer identification as zero terminated string
|
||||
* @param buf_size max length of manufacturer identification is 2048 characters
|
||||
* @return on success read character count, on failure negative error code
|
||||
* @return zero on success, on failure negative error code
|
||||
*/
|
||||
virtual nsapi_size_or_error_t get_manufacturer(char *buf, size_t buf_size) = 0;
|
||||
virtual nsapi_error_t get_manufacturer(char *buf, size_t buf_size) = 0;
|
||||
|
||||
/** Request model identification of cellular device
|
||||
*
|
||||
* @param buf model identification
|
||||
* @param buf model identification as zero terminated string
|
||||
* @param buf_size max length of model identification is 2048 characters
|
||||
* @return on success read character count, on failure negative error code
|
||||
* @return zero on success, on failure negative error code
|
||||
*/
|
||||
virtual nsapi_size_or_error_t get_model(char *buf, size_t buf_size) = 0;
|
||||
virtual nsapi_error_t get_model(char *buf, size_t buf_size) = 0;
|
||||
|
||||
/** Request revision identification of cellular device
|
||||
*
|
||||
* @param buf revision identification
|
||||
* @param buf revision identification as zero terminated string
|
||||
* @param buf_size max length of revision identification is 2048 characters
|
||||
* @return on success read character count, on failure negative error code
|
||||
* @return zero on success, on failure negative error code
|
||||
*/
|
||||
virtual nsapi_size_or_error_t get_revision(char *buf, size_t buf_size) = 0;
|
||||
virtual nsapi_error_t get_revision(char *buf, size_t buf_size) = 0;
|
||||
|
||||
/** Request serial number identification of cellular device
|
||||
*
|
||||
* @param buf serial number as zero terminated string
|
||||
* @param buf_size max length of serial number is 2048 characters
|
||||
* @param type serial number type to read
|
||||
* @return zero on success, on failure negative error code
|
||||
*/
|
||||
enum SerialNumberType {
|
||||
SN = 0,
|
||||
IMEI = 1,
|
||||
IMEISV = 2,
|
||||
SVN = 3
|
||||
};
|
||||
virtual nsapi_size_or_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type) = 0;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
@ -18,19 +18,21 @@
|
|||
#ifndef CELLULAR_SIM_H_
|
||||
#define CELLULAR_SIM_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "nsapi_types.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
const int MAX_SIM_READY_WAITING_TIME = 30;
|
||||
const int MAX_IMSI_LENGTH = 15;
|
||||
const int MAX_ICCID_LENGTH = 20 + 1; // +1 for zero termination
|
||||
/**
|
||||
* Class CellularSIM
|
||||
*
|
||||
* An abstract interface for SIM card handling.
|
||||
*/
|
||||
class CellularSIM
|
||||
{
|
||||
class CellularSIM {
|
||||
protected:
|
||||
// friend of CellularDevice so that it's the only way to close/delete this class.
|
||||
friend class CellularDevice;
|
||||
|
@ -84,7 +86,15 @@ public:
|
|||
* @param imsi preallocated char* which after successful request contains imsi
|
||||
* @return zero on success
|
||||
*/
|
||||
virtual nsapi_error_t get_imsi(char* imsi) = 0;
|
||||
virtual nsapi_error_t get_imsi(char *imsi) = 0;
|
||||
|
||||
/** Get serial number from the SIM card
|
||||
*
|
||||
* @param buf SIM ICCID as zero terminated string
|
||||
* @param buf_size max length of SIM ICCID is MAX_ICCID_LENGTH
|
||||
* @return zero on success, on failure negative error code
|
||||
*/
|
||||
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size) = 0;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "AT_CellularInformation.h"
|
||||
|
||||
using namespace mbed;
|
||||
|
@ -42,6 +44,21 @@ nsapi_error_t AT_CellularInformation::get_revision(char *buf, size_t buf_size)
|
|||
return get_info("AT+CGMR", buf, buf_size);
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_size, SerialNumberType type)
|
||||
{
|
||||
if (type == SN) {
|
||||
return get_info("AT+CGSN", buf, buf_size);
|
||||
}
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CGSN=");
|
||||
_at.write_int(type);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+CGSN:");
|
||||
_at.read_string(buf, buf_size);
|
||||
_at.resp_stop();
|
||||
return _at.unlock_return_error();
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_t buf_size)
|
||||
{
|
||||
_at.lock();
|
||||
|
@ -50,7 +67,7 @@ nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_
|
|||
_at.cmd_stop();
|
||||
_at.set_delimiter(0);
|
||||
_at.resp_start();
|
||||
_at.read_string(buf, buf_size-1);
|
||||
_at.read_string(buf, buf_size - 1);
|
||||
_at.resp_stop();
|
||||
_at.set_default_delimiter();
|
||||
|
||||
|
|
|
@ -28,25 +28,26 @@ namespace mbed {
|
|||
*
|
||||
* Class that provides information about cellular device.
|
||||
*/
|
||||
class AT_CellularInformation : public CellularInformation, public AT_CellularBase
|
||||
{
|
||||
class AT_CellularInformation : public CellularInformation, public AT_CellularBase {
|
||||
public:
|
||||
AT_CellularInformation(ATHandler &atHandler);
|
||||
virtual ~AT_CellularInformation();
|
||||
|
||||
public:
|
||||
virtual nsapi_size_or_error_t get_manufacturer(char *buf, size_t buf_size);
|
||||
virtual nsapi_error_t get_manufacturer(char *buf, size_t buf_size);
|
||||
|
||||
virtual nsapi_size_or_error_t get_model(char *buf, size_t buf_size);
|
||||
virtual nsapi_error_t get_model(char *buf, size_t buf_size);
|
||||
|
||||
virtual nsapi_size_or_error_t get_revision(char *buf, size_t buf_size);
|
||||
virtual nsapi_error_t get_revision(char *buf, size_t buf_size);
|
||||
|
||||
virtual nsapi_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type);
|
||||
|
||||
protected:
|
||||
/** Request information text from cellular device
|
||||
*
|
||||
* @param cmd 3gpp command string
|
||||
* @param buf manufacturer identification
|
||||
* @param buf_size max length of manufacturer identification is 2048 characters
|
||||
* @param buf buffer for response
|
||||
* @param buf_size buffer size
|
||||
* @return on success read character count, on failure negative error code
|
||||
*/
|
||||
nsapi_error_t get_info(const char *cmd, char *buf, size_t buf_size);
|
||||
|
|
|
@ -147,3 +147,14 @@ nsapi_error_t AT_CellularSIM::get_imsi(char *imsi)
|
|||
_at.resp_stop();
|
||||
return _at.unlock_return_error();
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularSIM::get_iccid(char *buf, size_t buf_size)
|
||||
{
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CCID?");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+CCID:");
|
||||
_at.read_string(buf, buf_size);
|
||||
_at.resp_stop();
|
||||
return _at.unlock_return_error();
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ namespace mbed {
|
|||
*
|
||||
* Class for SIM card handling.
|
||||
*/
|
||||
class AT_CellularSIM : public CellularSIM, public AT_CellularBase
|
||||
{
|
||||
class AT_CellularSIM : public CellularSIM, public AT_CellularBase {
|
||||
|
||||
public:
|
||||
AT_CellularSIM(ATHandler &atHandler);
|
||||
|
@ -44,7 +43,9 @@ public:
|
|||
|
||||
virtual nsapi_error_t get_sim_state(SimState &state);
|
||||
|
||||
virtual nsapi_error_t get_imsi(char* imsi);
|
||||
virtual nsapi_error_t get_imsi(char *imsi);
|
||||
|
||||
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
|
Loading…
Reference in New Issue