Skip to content

Cellular: changed support features to CellularProperty array. #9050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,19 @@ class my_base : public AT_CellularBase {
}
bool check_not_supported()
{
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = {
0, // AT_CGSN_WITH_TYPE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for the comments

1, // AT_CGDATA
1 // AT_CGAUTH
};
set_unsupported_features(unsupported_features);
return is_supported(AT_CGSN_WITH_TYPE);
}

bool check_supported()
{
set_unsupported_features(NULL);
return is_supported(AT_CGSN_WITH_TYPE);
set_cellular_properties(cellular_properties);
return get_property(AT_CGSN_WITH_TYPE);
}

bool check_supported_not_found()
bool check_supported()
{
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
};
set_unsupported_features(unsupported_features);
return is_supported(SUPPORTED_FEATURE_END_MARK);
return get_property(AT_CGDATA);
}
};

Expand Down Expand Up @@ -109,19 +100,19 @@ TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_device_error)
ATHandler_stub::device_err_value.errCode = 0;
}

TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_unsupported_features)
TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_cellular_properties)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularBase at(ah);

static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = {
0, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
1 // AT_CGAUTH
};

at.set_unsupported_features(unsupported_features);
at.set_cellular_properties(cellular_properties);
}

TEST_F(TestAT_CellularBase, test_AT_CellularBase_is_supported)
Expand All @@ -131,7 +122,6 @@ TEST_F(TestAT_CellularBase, test_AT_CellularBase_is_supported)
ATHandler ah(&fh, eq, 0, ",");
my_base my_at(ah);

EXPECT_TRUE(true == my_at.check_supported());
EXPECT_TRUE(true == my_at.check_supported_not_found());
EXPECT_TRUE(false == my_at.check_not_supported());
EXPECT_EQ(true, my_at.check_supported());
EXPECT_EQ(false, my_at.check_not_supported());
}
4 changes: 1 addition & 3 deletions UNITTESTS/stubs/AT_CellularBase_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
*/

#include "nsapi_types.h"
#include "AT_CellularBase.h"
#include "AT_CellularBase_stub.h"


using namespace mbed;

ATHandler *AT_CellularBase_stub::handler_value = NULL;
Expand All @@ -42,7 +40,7 @@ device_err_t AT_CellularBase::get_device_error() const
return AT_CellularBase_stub::device_err_value;
}

bool AT_CellularBase::is_supported(SupportedFeature feature)
intptr_t AT_CellularBase::get_property(CellularProperty key)
{
return AT_CellularBase_stub::supported_bool;
}
2 changes: 1 addition & 1 deletion UNITTESTS/stubs/AT_CellularBase_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "ATHandler.h"
#include "AT_CellularBase.h"

namespace AT_CellularBase_stub {
extern mbed::ATHandler *handler_value;
Expand Down
26 changes: 10 additions & 16 deletions features/cellular/framework/AT/AT_CellularBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,19 @@ device_err_t AT_CellularBase::get_device_error() const
return _at.get_last_device_error();
}

AT_CellularBase::SupportedFeature const *AT_CellularBase::_unsupported_features;
const intptr_t *AT_CellularBase::_property_array;

void AT_CellularBase::set_unsupported_features(const SupportedFeature *unsupported_features)
void AT_CellularBase::set_cellular_properties(const intptr_t *property_array)
{
_unsupported_features = unsupported_features;
}

bool AT_CellularBase::is_supported(SupportedFeature feature)
{
if (!_unsupported_features) {
return true;
if (!property_array) {
tr_warning("trying to set an empty cellular property array");
return;
}

for (int i = 0; _unsupported_features[i] != SUPPORTED_FEATURE_END_MARK; i++) {
if (_unsupported_features[i] == feature) {
tr_debug("Unsupported feature (%d)", (int)feature);
return false;
}
}
_property_array = property_array;
}

return true;
intptr_t AT_CellularBase::get_property(CellularProperty key)
{
return _property_array[key];
}
33 changes: 17 additions & 16 deletions features/cellular/framework/AT/AT_CellularBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,31 @@ class AT_CellularBase {
*/
device_err_t get_device_error() const;

/** Cellular module need to define an array of unsupported features if any,
* by default all features are supported.
enum CellularProperty {
AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN.
AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***<cid>#
AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported
CELLULAR_PROPERTY_MAX
};

/** Cellular module need to define an array of cellular properties which defines module supported property values.
*
* @param features Array of type SupportedFeature with last element FEATURE_END_MARK
* @param property_array array of module properties
*/
enum SupportedFeature {
AT_CGSN_WITH_TYPE, // AT+CGSN without type is likely always supported similar to AT+GSN
AT_CGDATA, // alternative is to support only ATD*99***<cid>#
AT_CGAUTH, // APN authentication AT commands supported
SUPPORTED_FEATURE_END_MARK // must be last element in the array of features
};
static void set_unsupported_features(const SupportedFeature *unsupported_features);
static void set_cellular_properties(const intptr_t *property_array);

protected:

static const intptr_t *_property_array;

ATHandler &_at;

/** Check if some functionality is supported by a cellular module. For example,
* most of standard AT commands are optional and not implemented by all cellular modules.
/** Get value for the given key.
*
* @param feature check for feature to support
* @return true on supported, otherwise false
* @param key key for value to be fetched
* @return property value for the given key. Value type is defined in enum CellularProperty
*/
static const SupportedFeature *_unsupported_features;
static bool is_supported(SupportedFeature feature);
static intptr_t get_property(CellularProperty key);
};

} // namespace mbed
Expand Down
4 changes: 2 additions & 2 deletions features/cellular/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ nsapi_error_t AT_CellularContext::do_user_authentication()
{
// if user has defined user name and password we need to call CGAUTH before activating or modifying context
if (_pwd && _uname) {
if (!is_supported(AT_CGAUTH)) {
if (!get_property(AT_CGAUTH)) {
return NSAPI_ERROR_UNSUPPORTED;
}
_at.cmd_start("AT+CGAUTH=");
Expand Down Expand Up @@ -572,7 +572,7 @@ void AT_CellularContext::do_connect()
nsapi_error_t AT_CellularContext::open_data_channel()
{
tr_info("CellularContext PPP connect");
if (is_supported(AT_CGDATA)) {
if (get_property(AT_CGDATA)) {
_at.cmd_start("AT+CGDATA=\"PPP\",");
_at.write_int(_cid);
} else {
Expand Down
2 changes: 1 addition & 1 deletion features/cellular/framework/AT/AT_CellularInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_si
return get_info("AT+CGSN", buf, buf_size);
}

if (!is_supported(AT_CGSN_WITH_TYPE)) {
if (!get_property(AT_CGSN_WITH_TYPE)) {
return NSAPI_ERROR_UNSUPPORTED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,39 @@
using namespace mbed;

// unsupported features as per ELS61-E2_ATC_V01.000
static const AT_CellularBase::SupportedFeature unsupported_features_els61[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties_els61[AT_CellularBase::CELLULAR_PROPERTY_MAX] = {
0, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
1 // AT_CGAUTH
};

// unsupported features as per BGS2-W_ATC_V00.100
static const AT_CellularBase::SupportedFeature unsupported_features_bgs2[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
};

// unsupported features as per EMS31-US_ATC_V4.9.5
static const AT_CellularBase::SupportedFeature unsupported_features_ems31[] = {
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties_bgs2[AT_CellularBase::CELLULAR_PROPERTY_MAX] = {
0, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
1 // AT_CGAUTH
};

GEMALTO_CINTERION_Module::Model GEMALTO_CINTERION_Module::_model;

nsapi_error_t GEMALTO_CINTERION_Module::detect_model(const char *model)
{
static const AT_CellularBase::SupportedFeature *unsupported_features;
static const intptr_t *cellular_properties;
if (memcmp(model, "ELS61", sizeof("ELS61") - 1) == 0) {
_model = ModelELS61;
unsupported_features = unsupported_features_els61;
cellular_properties = cellular_properties_els61;
} else if (memcmp(model, "BGS2", sizeof("BGS2") - 1) == 0) {
_model = ModelBGS2;
unsupported_features = unsupported_features_bgs2;
cellular_properties = cellular_properties_bgs2;
} else if (memcmp(model, "EMS31", sizeof("EMS31") - 1) == 0) {
_model = ModelEMS31;
unsupported_features = unsupported_features_ems31;
cellular_properties = NULL;
} else {
tr_error("Cinterion model unsupported %s", model);
return NSAPI_ERROR_UNSUPPORTED;
}
tr_info("Cinterion model %s (%d)", model, _model);
AT_CellularBase::set_unsupported_features(unsupported_features);
AT_CellularBase::set_cellular_properties(cellular_properties);
return NSAPI_ERROR_OK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
using namespace mbed;
using namespace events;

static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::AT_CGDATA,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = {
0, // AT_CGSN_WITH_TYPE
0, // AT_CGDATA
1 // AT_CGAUTH
};

SARA4_PPP::SARA4_PPP(FileHandle *fh) : AT_CellularDevice(fh)
{
AT_CellularBase::set_unsupported_features(unsupported_features);
AT_CellularBase::set_cellular_properties(cellular_properties);
}

SARA4_PPP::~SARA4_PPP()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
using namespace events;
using namespace mbed;

static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGAUTH, // BC95_AT_Commands_Manual_V1.9
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = {
1, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
0 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9
};

QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh)
{
AT_CellularBase::set_unsupported_features(unsupported_features);
AT_CellularBase::set_cellular_properties(cellular_properties);
}

QUECTEL_BC95::~QUECTEL_BC95()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ using namespace events;
#define MAX_STARTUP_TRIALS 5
#define MAX_RESET_TRIALS 5

static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = {
0, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
1 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9
};

QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh) : AT_CellularDevice(fh)
{
AT_CellularBase::set_unsupported_features(unsupported_features);
AT_CellularBase::set_cellular_properties(cellular_properties);
}

QUECTEL_BG96::~QUECTEL_BG96()
Expand Down
10 changes: 5 additions & 5 deletions features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
using namespace mbed;
using namespace events;

static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE, // HE910/UE910/UL865/UE866 AT Commands Reference Guide Rev. 11-2006-10-14
AT_CellularBase::AT_CGAUTH, // HE910/UE910/UL865/UE866 AT Commands Reference Guide Rev. 11-2006-10-14
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = {
0, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
0 // AT_CGAUTH
};

TELIT_HE910::TELIT_HE910(FileHandle *fh) : AT_CellularDevice(fh)
{
AT_CellularBase::set_unsupported_features(unsupported_features);
AT_CellularBase::set_cellular_properties(cellular_properties);
}

TELIT_HE910::~TELIT_HE910()
Expand Down
9 changes: 5 additions & 4 deletions features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ using namespace mbed;
using namespace events;

#ifdef TARGET_UBLOX_C030_R410M
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = {
0, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
1 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9
};
#endif

UBLOX_AT::UBLOX_AT(FileHandle *fh) : AT_CellularDevice(fh)
{
#ifdef TARGET_UBLOX_C030_R410M
AT_CellularBase::set_unsupported_features(unsupported_features);
AT_CellularBase::set_cellular_properties(cellular_properties);
#endif
}

Expand Down
9 changes: 5 additions & 4 deletions features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ using namespace mbed;
using namespace events;

#ifdef TARGET_UBLOX_C027
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties[AT_CellularBase::CELLULAR_PROPERTY_MAX] = {
0, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
1 // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9
};
#endif

UBLOX_PPP::UBLOX_PPP(FileHandle *fh) : AT_CellularDevice(fh)
{
#ifdef TARGET_UBLOX_C027
AT_CellularBase::set_unsupported_features(unsupported_features);
AT_CellularBase::set_cellular_properties(cellular_properties);
#endif
}

Expand Down