Skip to content

Commit 44365bc

Browse files
author
Ari Parkkila
committed
Cellular: Added AT+CCID and AT+CGSN
1 parent 799ba08 commit 44365bc

File tree

6 files changed

+79
-25
lines changed

6 files changed

+79
-25
lines changed

features/cellular/framework/API/CellularInformation.h

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ namespace mbed {
2828
*
2929
* An abstract interface that provides information about cellular device.
3030
*/
31-
class CellularInformation
32-
{
31+
class CellularInformation {
3332
protected:
3433
// friend of CellularDevice so that it's the only way to close/delete this class.
3534
friend class CellularDevice;
@@ -41,27 +40,42 @@ class CellularInformation
4140
public:
4241
/** Request manufacturer identification of cellular device
4342
*
44-
* @param buf manufacturer identification
43+
* @param buf manufacturer identification as zero terminated string
4544
* @param buf_size max length of manufacturer identification is 2048 characters
46-
* @return on success read character count, on failure negative error code
45+
* @return zero on success, on failure negative error code
4746
*/
48-
virtual nsapi_size_or_error_t get_manufacturer(char *buf, size_t buf_size) = 0;
47+
virtual nsapi_error_t get_manufacturer(char *buf, size_t buf_size) = 0;
4948

5049
/** Request model identification of cellular device
5150
*
52-
* @param buf model identification
51+
* @param buf model identification as zero terminated string
5352
* @param buf_size max length of model identification is 2048 characters
54-
* @return on success read character count, on failure negative error code
53+
* @return zero on success, on failure negative error code
5554
*/
56-
virtual nsapi_size_or_error_t get_model(char *buf, size_t buf_size) = 0;
55+
virtual nsapi_error_t get_model(char *buf, size_t buf_size) = 0;
5756

5857
/** Request revision identification of cellular device
5958
*
60-
* @param buf revision identification
59+
* @param buf revision identification as zero terminated string
6160
* @param buf_size max length of revision identification is 2048 characters
62-
* @return on success read character count, on failure negative error code
61+
* @return zero on success, on failure negative error code
6362
*/
64-
virtual nsapi_size_or_error_t get_revision(char *buf, size_t buf_size) = 0;
63+
virtual nsapi_error_t get_revision(char *buf, size_t buf_size) = 0;
64+
65+
/** Request serial number identification of cellular device
66+
*
67+
* @param buf serial number as zero terminated string
68+
* @param buf_size max length of serial number is 2048 characters
69+
* @param type serial number type to read
70+
* @return zero on success, on failure negative error code
71+
*/
72+
enum SerialNumberType {
73+
SN = 0,
74+
IMEI = 1,
75+
IMEISV = 2,
76+
SVN = 3
77+
};
78+
virtual nsapi_size_or_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type) = 0;
6579
};
6680

6781
} // namespace mbed

features/cellular/framework/API/CellularSIM.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@
1818
#ifndef CELLULAR_SIM_H_
1919
#define CELLULAR_SIM_H_
2020

21+
#include <stddef.h>
22+
2123
#include "nsapi_types.h"
2224

2325
namespace mbed {
2426

2527
const int MAX_SIM_READY_WAITING_TIME = 30;
2628
const int MAX_IMSI_LENGTH = 15;
29+
const int MAX_ICCID_LENGTH = 20 + 1; // +1 for zero termination
2730
/**
2831
* Class CellularSIM
2932
*
3033
* An abstract interface for SIM card handling.
3134
*/
32-
class CellularSIM
33-
{
35+
class CellularSIM {
3436
protected:
3537
// friend of CellularDevice so that it's the only way to close/delete this class.
3638
friend class CellularDevice;
@@ -84,7 +86,15 @@ class CellularSIM
8486
* @param imsi preallocated char* which after successful request contains imsi
8587
* @return zero on success
8688
*/
87-
virtual nsapi_error_t get_imsi(char* imsi) = 0;
89+
virtual nsapi_error_t get_imsi(char *imsi) = 0;
90+
91+
/** Get serial number from the SIM card
92+
*
93+
* @param buf SIM ICCID as zero terminated string
94+
* @param buf_size max length of SIM ICCID is MAX_ICCID_LENGTH
95+
* @return zero on success, on failure negative error code
96+
*/
97+
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size) = 0;
8898
};
8999

90100
} // namespace mbed

features/cellular/framework/AT/AT_CellularInformation.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include <stdio.h>
19+
1820
#include "AT_CellularInformation.h"
1921

2022
using namespace mbed;
@@ -42,6 +44,21 @@ nsapi_error_t AT_CellularInformation::get_revision(char *buf, size_t buf_size)
4244
return get_info("AT+CGMR", buf, buf_size);
4345
}
4446

47+
nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_size, SerialNumberType type)
48+
{
49+
if (type == SN) {
50+
return get_info("AT+CGSN", buf, buf_size);
51+
}
52+
_at.lock();
53+
_at.cmd_start("AT+CGSN=");
54+
_at.write_int(type);
55+
_at.cmd_stop();
56+
_at.resp_start("+CGSN:");
57+
_at.read_string(buf, buf_size);
58+
_at.resp_stop();
59+
return _at.unlock_return_error();
60+
}
61+
4562
nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_t buf_size)
4663
{
4764
_at.lock();
@@ -50,7 +67,7 @@ nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_
5067
_at.cmd_stop();
5168
_at.set_delimiter(0);
5269
_at.resp_start();
53-
_at.read_string(buf, buf_size-1);
70+
_at.read_string(buf, buf_size - 1);
5471
_at.resp_stop();
5572
_at.set_default_delimiter();
5673

features/cellular/framework/AT/AT_CellularInformation.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,26 @@ namespace mbed {
2828
*
2929
* Class that provides information about cellular device.
3030
*/
31-
class AT_CellularInformation : public CellularInformation, public AT_CellularBase
32-
{
31+
class AT_CellularInformation : public CellularInformation, public AT_CellularBase {
3332
public:
3433
AT_CellularInformation(ATHandler &atHandler);
3534
virtual ~AT_CellularInformation();
3635

3736
public:
38-
virtual nsapi_size_or_error_t get_manufacturer(char *buf, size_t buf_size);
37+
virtual nsapi_error_t get_manufacturer(char *buf, size_t buf_size);
3938

40-
virtual nsapi_size_or_error_t get_model(char *buf, size_t buf_size);
39+
virtual nsapi_error_t get_model(char *buf, size_t buf_size);
4140

42-
virtual nsapi_size_or_error_t get_revision(char *buf, size_t buf_size);
41+
virtual nsapi_error_t get_revision(char *buf, size_t buf_size);
42+
43+
virtual nsapi_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type);
4344

4445
protected:
4546
/** Request information text from cellular device
4647
*
4748
* @param cmd 3gpp command string
48-
* @param buf manufacturer identification
49-
* @param buf_size max length of manufacturer identification is 2048 characters
49+
* @param buf buffer for response
50+
* @param buf_size buffer size
5051
* @return on success read character count, on failure negative error code
5152
*/
5253
nsapi_error_t get_info(const char *cmd, char *buf, size_t buf_size);

features/cellular/framework/AT/AT_CellularSIM.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,14 @@ nsapi_error_t AT_CellularSIM::get_imsi(char *imsi)
147147
_at.resp_stop();
148148
return _at.unlock_return_error();
149149
}
150+
151+
nsapi_error_t AT_CellularSIM::get_iccid(char *buf, size_t buf_size)
152+
{
153+
_at.lock();
154+
_at.cmd_start("AT+CCID?");
155+
_at.cmd_stop();
156+
_at.resp_start("+CCID:");
157+
_at.read_string(buf, buf_size);
158+
_at.resp_stop();
159+
return _at.unlock_return_error();
160+
}

features/cellular/framework/AT/AT_CellularSIM.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ namespace mbed {
2828
*
2929
* Class for SIM card handling.
3030
*/
31-
class AT_CellularSIM : public CellularSIM, public AT_CellularBase
32-
{
31+
class AT_CellularSIM : public CellularSIM, public AT_CellularBase {
3332

3433
public:
3534
AT_CellularSIM(ATHandler &atHandler);
@@ -44,7 +43,9 @@ class AT_CellularSIM : public CellularSIM, public AT_CellularBase
4443

4544
virtual nsapi_error_t get_sim_state(SimState &state);
4645

47-
virtual nsapi_error_t get_imsi(char* imsi);
46+
virtual nsapi_error_t get_imsi(char *imsi);
47+
48+
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
4849
};
4950

5051
} // namespace mbed

0 commit comments

Comments
 (0)