Skip to content

Commit 7d006f6

Browse files
author
Ari Parkkila
committed
Cellular: Target support for AT+CCID and AT+CGSN
1 parent 44365bc commit 7d006f6

File tree

10 files changed

+163
-16
lines changed

10 files changed

+163
-16
lines changed

features/cellular/framework/API/CellularInformation.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ class CellularInformation {
7070
* @return zero on success, on failure negative error code
7171
*/
7272
enum SerialNumberType {
73-
SN = 0,
74-
IMEI = 1,
75-
IMEISV = 2,
76-
SVN = 3
73+
SN = 0, // Serial Number
74+
IMEI = 1, // International Mobile station Equipment Identity
75+
IMEISV = 2, // IMEI and Software Version number
76+
SVN = 3 // Software Version Number
7777
};
78-
virtual nsapi_size_or_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type) = 0;
78+
virtual nsapi_size_or_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type = SN) = 0;
7979
};
8080

8181
} // namespace mbed

features/cellular/framework/AT/AT_CellularBase.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
*/
1717

1818
#include "AT_CellularBase.h"
19+
#include "CellularLog.h"
1920

2021
using namespace mbed;
2122

22-
AT_CellularBase::AT_CellularBase(ATHandler& at) : _at(at)
23+
AT_CellularBase::AT_CellularBase(ATHandler &at) : _at(at)
2324
{
24-
2525
}
2626

27-
ATHandler& AT_CellularBase::get_at_handler()
27+
ATHandler &AT_CellularBase::get_at_handler()
2828
{
2929
return _at;
3030
}
@@ -34,3 +34,25 @@ device_err_t AT_CellularBase::get_device_error() const
3434
return _at.get_last_device_error();
3535
}
3636

37+
AT_CellularBase::SupportedFeature const *AT_CellularBase::_unsupported_features;
38+
39+
void AT_CellularBase::set_unsupported_features(const SupportedFeature *unsupported_features)
40+
{
41+
_unsupported_features = unsupported_features;
42+
}
43+
44+
bool AT_CellularBase::is_supported(SupportedFeature feature)
45+
{
46+
if (!_unsupported_features) {
47+
return true;
48+
}
49+
50+
for (int i = 0; _unsupported_features[i] != SUPPORTED_FEATURE_END_MARK; i++) {
51+
if (_unsupported_features[i] == feature) {
52+
tr_debug("Unsupported feature (%d)", (int)feature);
53+
return false;
54+
}
55+
}
56+
57+
return true;
58+
}

features/cellular/framework/AT/AT_CellularBase.h

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ namespace mbed {
2626
*
2727
* A base class for AT-classes.
2828
*/
29-
class AT_CellularBase
30-
{
29+
class AT_CellularBase {
3130
public:
32-
AT_CellularBase(ATHandler& at);
31+
AT_CellularBase(ATHandler &at);
3332

3433
/** Getter for at handler. Common method for all AT-classes.
3534
*
3635
* @return reference to ATHandler
3736
*/
38-
ATHandler& get_at_handler();
37+
ATHandler &get_at_handler();
3938

4039
/** Gets the device error that happened when using AT commands/responses. This is at error
4140
* returned by the device. Returned CME/CMS errors can be found from 3gpp documents 27007 and 27005.
@@ -44,8 +43,28 @@ class AT_CellularBase
4443
*/
4544
device_err_t get_device_error() const;
4645

46+
/** Cellular module need to define an array of unsupported features if any,
47+
* by default all features are supported.
48+
*
49+
* @param features Array of type SupportedFeature with last element FEATURE_END_MARK
50+
*/
51+
enum SupportedFeature {
52+
AT_CGSN_WITH_TYPE, // AT+CGSN without type is likely always supported similar to AT+GSN
53+
SUPPORTED_FEATURE_END_MARK // must be last element in the array of features
54+
};
55+
static void set_unsupported_features(const SupportedFeature *unsupported_features);
56+
4757
protected:
48-
ATHandler& _at;
58+
ATHandler &_at;
59+
60+
/** Check if some functionality is supported by a cellular module. For example,
61+
* most of standard AT commands are optional and not implemented by all cellular modules.
62+
*
63+
* @param feature check for feature to support
64+
* @return true on supported, otherwise false
65+
*/
66+
static const SupportedFeature *_unsupported_features;
67+
static bool is_supported(SupportedFeature feature);
4968
};
5069

5170
} // namespace mbed

features/cellular/framework/AT/AT_CellularInformation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_si
4949
if (type == SN) {
5050
return get_info("AT+CGSN", buf, buf_size);
5151
}
52+
53+
if (!is_supported(AT_CGSN_WITH_TYPE)) {
54+
return NSAPI_ERROR_UNSUPPORTED;
55+
}
56+
5257
_at.lock();
5358
_at.cmd_start("AT+CGSN=");
5459
_at.write_int(type);

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ nsapi_error_t QUECTEL_BC95_CellularSIM::get_sim_state(SimState &state)
4747
return _at.unlock_return_error();
4848
}
4949

50+
// According to BC95_AT_Commands_Manual_V1.9
51+
nsapi_error_t QUECTEL_BC95_CellularSIM::get_iccid(char *buf, size_t buf_size)
52+
{
53+
_at.lock();
54+
_at.cmd_start("AT+NCCID?");
55+
_at.cmd_stop();
56+
_at.resp_start("+NCCID:");
57+
_at.read_string(buf, buf_size);
58+
_at.resp_stop();
59+
return _at.unlock_return_error();
60+
}

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
namespace mbed {
2424

25-
class QUECTEL_BC95_CellularSIM : public AT_CellularSIM
26-
{
25+
class QUECTEL_BC95_CellularSIM : public AT_CellularSIM {
2726
public:
2827
QUECTEL_BC95_CellularSIM(ATHandler &atHandler);
2928
virtual ~QUECTEL_BC95_CellularSIM();
3029

3130
public: //from CellularSIM
3231
virtual nsapi_error_t get_sim_state(SimState &state);
32+
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
3333
};
3434

3535
} // namespace mbed

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ using namespace events;
2929
#define MAX_STARTUP_TRIALS 5
3030
#define MAX_RESET_TRIALS 5
3131

32+
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
33+
AT_CellularBase::AT_CGSN_WITH_TYPE,
34+
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
35+
};
36+
3237
QUECTEL_BG96::QUECTEL_BG96(EventQueue &queue) : AT_CellularDevice(queue)
3338
{
39+
AT_CellularBase::set_unsupported_features(unsupported_features);
3440
}
3541

3642
QUECTEL_BG96::~QUECTEL_BG96()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "QUECTEL_BG96_CellularSIM.h"
19+
#include "CellularLog.h"
20+
21+
using namespace mbed;
22+
23+
QUECTEL_BG96_CellularSIM::QUECTEL_BG96_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler)
24+
{
25+
26+
}
27+
28+
QUECTEL_BG96_CellularSIM::~QUECTEL_BG96_CellularSIM()
29+
{
30+
31+
}
32+
33+
// According to BG96_AT_Commands_Manual_V2.0
34+
nsapi_error_t QUECTEL_BG96_CellularSIM::get_iccid(char *buf, size_t buf_size)
35+
{
36+
_at.lock();
37+
_at.cmd_start("AT+QCCID");
38+
_at.cmd_stop();
39+
_at.resp_start("+QCCID:");
40+
_at.read_string(buf, buf_size);
41+
_at.resp_stop();
42+
return _at.unlock_return_error();
43+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef QUECTEL_BG96_CELLULAR_SIM_H_
19+
#define QUECTEL_BG96_CELLULAR_SIM_H_
20+
21+
#include "AT_CellularSIM.h"
22+
23+
namespace mbed {
24+
25+
class QUECTEL_BG96_CellularSIM : public AT_CellularSIM {
26+
public:
27+
QUECTEL_BG96_CellularSIM(ATHandler &atHandler);
28+
virtual ~QUECTEL_BG96_CellularSIM();
29+
30+
public: //from CellularSIM
31+
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
32+
};
33+
34+
} // namespace mbed
35+
36+
#endif // QUECTEL_BG96_CELLULAR_SIM_H_

features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222
using namespace mbed;
2323
using namespace events;
2424

25+
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
26+
AT_CellularBase::AT_CGSN_WITH_TYPE, // HE910/UE910/UL865/UE866 AT Commands Reference Guide Rev. 11-2006-10-14
27+
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
28+
};
29+
2530
TELIT_HE910::TELIT_HE910(EventQueue &queue) : AT_CellularDevice(queue)
2631
{
27-
32+
AT_CellularBase::set_unsupported_features(unsupported_features);
2833
}
2934

3035
TELIT_HE910::~TELIT_HE910()

0 commit comments

Comments
 (0)