Cellular: Refactored GEMALTO_CINTERION_Module to GEMALTO_CINTERION

pull/9208/head
Ari Parkkila 2018-11-26 02:14:49 -08:00 committed by Cruz Monrreal II
parent 51b0fdf23e
commit 1bbf8af7d3
7 changed files with 84 additions and 132 deletions

View File

@ -16,7 +16,6 @@
*/
#include "GEMALTO_CINTERION_CellularNetwork.h"
#include "GEMALTO_CINTERION_Module.h"
#include "GEMALTO_CINTERION_CellularContext.h"
#include "GEMALTO_CINTERION.h"
#include "AT_CellularInformation.h"
@ -28,6 +27,8 @@ using namespace events;
const uint16_t RESPONSE_TO_SEND_DELAY = 100; // response-to-send delay in milliseconds at bit-rate over 9600
GEMALTO_CINTERION::Module GEMALTO_CINTERION::_module;
GEMALTO_CINTERION::GEMALTO_CINTERION(FileHandle *fh) : AT_CellularDevice(fh)
{
}
@ -59,10 +60,60 @@ nsapi_error_t GEMALTO_CINTERION::init_module()
tr_error("Cellular model not found!");
return NSAPI_ERROR_DEVICE_ERROR;
}
return GEMALTO_CINTERION_Module::detect_model(model);
if (memcmp(model, "ELS61", sizeof("ELS61") - 1) == 0) {
init_module_els61();
} else if (memcmp(model, "BGS2", sizeof("BGS2") - 1) == 0) {
init_module_bgs2();
} else if (memcmp(model, "EMS31", sizeof("EMS31") - 1) == 0) {
init_module_ems31();
} else {
tr_error("Cinterion model unsupported %s", model);
return NSAPI_ERROR_UNSUPPORTED;
}
tr_info("Cinterion model %s (%d)", model, _module);
return NSAPI_ERROR_OK;
}
uint16_t GEMALTO_CINTERION::get_send_delay() const
{
return RESPONSE_TO_SEND_DELAY;
}
GEMALTO_CINTERION::Module GEMALTO_CINTERION::get_module()
{
return _module;
}
void GEMALTO_CINTERION::init_module_bgs2()
{
// BGS2-W_ATC_V00.100
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
};
AT_CellularBase::set_unsupported_features(unsupported_features);
_module = ModuleBGS2;
}
void GEMALTO_CINTERION::init_module_els61()
{
// ELS61-E2_ATC_V01.000
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
};
AT_CellularBase::set_unsupported_features(unsupported_features);
_module = ModuleELS61;
}
void GEMALTO_CINTERION::init_module_ems31()
{
// EMS31-US_ATC_V4.9.5
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
};
AT_CellularBase::set_unsupported_features(unsupported_features);
_module = ModuleEMS31;
}

View File

@ -34,6 +34,23 @@ protected: // AT_CellularDevice
public:
virtual nsapi_error_t init_module();
virtual uint16_t get_send_delay() const;
/** Actual model of cellular module is needed to make AT command adaptation at runtime
* to support many different models in one cellular driver.
*/
enum Module {
ModuleUnknown = 0,
ModuleELS61,
ModuleBGS2,
ModuleEMS31,
};
static Module get_module();
private:
static Module _module;
void init_module_bgs2();
void init_module_els61();
void init_module_ems31();
};
} // namespace mbed

View File

@ -16,7 +16,7 @@
*/
#include "GEMALTO_CINTERION_CellularContext.h"
#include "GEMALTO_CINTERION_CellularStack.h"
#include "GEMALTO_CINTERION_Module.h"
#include "GEMALTO_CINTERION.h"
namespace mbed {
@ -41,7 +41,7 @@ NetworkStack *GEMALTO_CINTERION_CellularContext::get_stack()
bool GEMALTO_CINTERION_CellularContext::stack_type_supported(nsapi_ip_stack_t requested_stack)
{
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelBGS2) {
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleBGS2) {
return (requested_stack == IPV4_STACK);
}
return (requested_stack == IPV4_STACK || requested_stack == IPV6_STACK);

View File

@ -16,7 +16,7 @@
*/
#include "GEMALTO_CINTERION_CellularNetwork.h"
#include "GEMALTO_CINTERION_Module.h"
#include "GEMALTO_CINTERION.h"
using namespace mbed;
@ -30,10 +30,10 @@ GEMALTO_CINTERION_CellularNetwork::~GEMALTO_CINTERION_CellularNetwork()
AT_CellularNetwork::RegistrationMode GEMALTO_CINTERION_CellularNetwork::has_registration(RegistrationType reg_type)
{
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelEMS31) {
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleEMS31) {
return (reg_type == C_EREG) ? RegistrationModeLAC : RegistrationModeDisable;
}
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelBGS2) {
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleBGS2) {
if (reg_type == C_GREG) {
return RegistrationModeEnable;
}

View File

@ -17,7 +17,7 @@
#include <cstdlib>
#include "GEMALTO_CINTERION_CellularStack.h"
#include "GEMALTO_CINTERION_Module.h"
#include "GEMALTO_CINTERION.h"
#include "CellularLog.h"
// defines as per ELS61-E2_ATC_V01.000 and BGS2-W_ATC_V00.100
@ -91,7 +91,7 @@ void GEMALTO_CINTERION_CellularStack::sisw_urc_handler(int sock_id, int urc_code
if (urc_code == 1) { // ready
if (sock->_cb) {
sock->tx_ready = true;
if (sock->proto == NSAPI_TCP || GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelBGS2) {
if (sock->proto == NSAPI_TCP || GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleBGS2) {
sock->started = true;
}
sock->_cb(sock->_data);
@ -180,7 +180,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
char sock_addr[sizeof("sockudp://") - 1 + NSAPI_IPv6_SIZE + sizeof("[]:12345;port=12345") - 1 + 1];
if (socket->proto == NSAPI_UDP) {
if (GEMALTO_CINTERION_Module::get_model() != GEMALTO_CINTERION_Module::ModelBGS2) {
if (GEMALTO_CINTERION::get_module() != GEMALTO_CINTERION::ModuleBGS2) {
std::sprintf(sock_addr, "sockudp://%s:%u", address ? address->get_ip_address() : "", socket->localAddress.get_port());
} else {
std::sprintf(sock_addr, "sockudp://%s:%u;port=%u", address->get_ip_address(), address->get_port(), socket->localAddress.get_port());
@ -286,7 +286,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::create_socket_impl(CellularSocket
}
if (socket->proto == NSAPI_UDP) {
if (GEMALTO_CINTERION_Module::get_model() != GEMALTO_CINTERION_Module::ModelBGS2) {
if (GEMALTO_CINTERION::get_module() != GEMALTO_CINTERION::ModuleBGS2) {
return socket_open_defer(socket);
}
}
@ -306,7 +306,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul
}
}
if (socket->proto == NSAPI_UDP && GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelBGS2) {
if (socket->proto == NSAPI_UDP && GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleBGS2) {
tr_debug("Send addr %s, prev addr %s", address.get_ip_address(), socket->remoteAddress.get_ip_address());
if (address != socket->remoteAddress) {
if (socket->started) {
@ -349,7 +349,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul
_at.write_int(socket->id);
_at.write_int(size);
if (GEMALTO_CINTERION_Module::get_model() != GEMALTO_CINTERION_Module::ModelBGS2) {
if (GEMALTO_CINTERION::get_module() != GEMALTO_CINTERION::ModuleBGS2) {
_at.write_int(0);
// UDP requires Udp_RemClient
@ -466,7 +466,7 @@ sisr_retry:
}
// UDP Udp_RemClient
if (socket->proto == NSAPI_UDP && GEMALTO_CINTERION_Module::get_model() != GEMALTO_CINTERION_Module::ModelBGS2) {
if (socket->proto == NSAPI_UDP && GEMALTO_CINTERION::get_module() != GEMALTO_CINTERION::ModuleBGS2) {
char ip_address[NSAPI_IPv6_SIZE + sizeof("[]:12345") - 1 + 1];
int ip_len = _at.read_string(ip_address, sizeof(ip_address));
if (ip_len <= 0) {
@ -513,7 +513,7 @@ sisr_retry:
// setup internet connection profile for sockets
nsapi_error_t GEMALTO_CINTERION_CellularStack::create_connection_profile(int connection_profile_id)
{
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelEMS31) {
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleEMS31) {
// EMS31 connection has only DNS settings and there is no need to modify those here for now
return NSAPI_ERROR_OK;
}
@ -579,7 +579,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::create_connection_profile(int con
void GEMALTO_CINTERION_CellularStack::close_connection_profile(int connection_profile_id)
{
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelEMS31) {
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleEMS31) {
return;
}

View File

@ -1,69 +0,0 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string.h>
#include "AT_CellularBase.h"
#include "GEMALTO_CINTERION_Module.h"
#include "CellularLog.h"
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
};
// 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
};
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;
if (memcmp(model, "ELS61", sizeof("ELS61") - 1) == 0) {
_model = ModelELS61;
unsupported_features = unsupported_features_els61;
} else if (memcmp(model, "BGS2", sizeof("BGS2") - 1) == 0) {
_model = ModelBGS2;
unsupported_features = unsupported_features_bgs2;
} else if (memcmp(model, "EMS31", sizeof("EMS31") - 1) == 0) {
_model = ModelEMS31;
unsupported_features = unsupported_features_ems31;
} 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);
return NSAPI_ERROR_OK;
}
GEMALTO_CINTERION_Module::Model GEMALTO_CINTERION_Module::get_model()
{
return _model;
}

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GEMALTO_CINTERION_MODULE_H_
#define GEMALTO_CINTERION_MODULE_H_
#include "nsapi_types.h"
namespace mbed {
class FileHandle;
class GEMALTO_CINTERION_Module {
public:
/** Actual model of cellular module is needed to make AT command adaptation at runtime
* to support many different models in one cellular driver.
*/
enum Model {
ModelUnknown = 0,
ModelELS61,
ModelBGS2,
ModelEMS31,
};
static nsapi_error_t detect_model(const char *model);
static Model get_model();
private:
static Model _model;
};
} // namespace mbed
#endif // GEMALTO_CINTERION_MODULE_H_