Skip to content

Commit 8bd1d06

Browse files
author
Cruz Monrreal
authored
Merge pull request #8866 from AriParkkila/cell-cinterion-module
Cellular: Refactored GEMALTO_CINTERION_Module to GEMALTO_CINTERION
2 parents 49103d8 + d969c4f commit 8bd1d06

File tree

7 files changed

+84
-132
lines changed

7 files changed

+84
-132
lines changed

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
#include "GEMALTO_CINTERION_CellularNetwork.h"
19-
#include "GEMALTO_CINTERION_Module.h"
2019
#include "GEMALTO_CINTERION_CellularContext.h"
2120
#include "GEMALTO_CINTERION.h"
2221
#include "AT_CellularInformation.h"
@@ -28,6 +27,8 @@ using namespace events;
2827

2928
const uint16_t RESPONSE_TO_SEND_DELAY = 100; // response-to-send delay in milliseconds at bit-rate over 9600
3029

30+
GEMALTO_CINTERION::Module GEMALTO_CINTERION::_module;
31+
3132
GEMALTO_CINTERION::GEMALTO_CINTERION(FileHandle *fh) : AT_CellularDevice(fh)
3233
{
3334
}
@@ -59,10 +60,60 @@ nsapi_error_t GEMALTO_CINTERION::init_module()
5960
tr_error("Cellular model not found!");
6061
return NSAPI_ERROR_DEVICE_ERROR;
6162
}
62-
return GEMALTO_CINTERION_Module::detect_model(model);
63+
64+
if (memcmp(model, "ELS61", sizeof("ELS61") - 1) == 0) {
65+
init_module_els61();
66+
} else if (memcmp(model, "BGS2", sizeof("BGS2") - 1) == 0) {
67+
init_module_bgs2();
68+
} else if (memcmp(model, "EMS31", sizeof("EMS31") - 1) == 0) {
69+
init_module_ems31();
70+
} else {
71+
tr_error("Cinterion model unsupported %s", model);
72+
return NSAPI_ERROR_UNSUPPORTED;
73+
}
74+
tr_info("Cinterion model %s (%d)", model, _module);
75+
76+
return NSAPI_ERROR_OK;
6377
}
6478

6579
uint16_t GEMALTO_CINTERION::get_send_delay() const
6680
{
6781
return RESPONSE_TO_SEND_DELAY;
6882
}
83+
84+
GEMALTO_CINTERION::Module GEMALTO_CINTERION::get_module()
85+
{
86+
return _module;
87+
}
88+
89+
void GEMALTO_CINTERION::init_module_bgs2()
90+
{
91+
// BGS2-W_ATC_V00.100
92+
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
93+
AT_CellularBase::AT_CGSN_WITH_TYPE,
94+
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
95+
};
96+
AT_CellularBase::set_unsupported_features(unsupported_features);
97+
_module = ModuleBGS2;
98+
}
99+
100+
void GEMALTO_CINTERION::init_module_els61()
101+
{
102+
// ELS61-E2_ATC_V01.000
103+
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
104+
AT_CellularBase::AT_CGSN_WITH_TYPE,
105+
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
106+
};
107+
AT_CellularBase::set_unsupported_features(unsupported_features);
108+
_module = ModuleELS61;
109+
}
110+
111+
void GEMALTO_CINTERION::init_module_ems31()
112+
{
113+
// EMS31-US_ATC_V4.9.5
114+
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
115+
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
116+
};
117+
AT_CellularBase::set_unsupported_features(unsupported_features);
118+
_module = ModuleEMS31;
119+
}

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ class GEMALTO_CINTERION : public AT_CellularDevice {
3434
public:
3535
virtual nsapi_error_t init_module();
3636
virtual uint16_t get_send_delay() const;
37+
38+
/** Actual model of cellular module is needed to make AT command adaptation at runtime
39+
* to support many different models in one cellular driver.
40+
*/
41+
enum Module {
42+
ModuleUnknown = 0,
43+
ModuleELS61,
44+
ModuleBGS2,
45+
ModuleEMS31,
46+
};
47+
static Module get_module();
48+
49+
private:
50+
static Module _module;
51+
void init_module_bgs2();
52+
void init_module_els61();
53+
void init_module_ems31();
3754
};
3855

3956
} // namespace mbed

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
#include "GEMALTO_CINTERION_CellularContext.h"
1818
#include "GEMALTO_CINTERION_CellularStack.h"
19-
#include "GEMALTO_CINTERION_Module.h"
19+
#include "GEMALTO_CINTERION.h"
2020

2121
namespace mbed {
2222

@@ -41,7 +41,7 @@ NetworkStack *GEMALTO_CINTERION_CellularContext::get_stack()
4141

4242
bool GEMALTO_CINTERION_CellularContext::stack_type_supported(nsapi_ip_stack_t requested_stack)
4343
{
44-
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelBGS2) {
44+
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleBGS2) {
4545
return (requested_stack == IPV4_STACK);
4646
}
4747
return (requested_stack == IPV4_STACK || requested_stack == IPV6_STACK);

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp

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

1818
#include "GEMALTO_CINTERION_CellularNetwork.h"
19-
#include "GEMALTO_CINTERION_Module.h"
19+
#include "GEMALTO_CINTERION.h"
2020

2121
using namespace mbed;
2222

@@ -30,10 +30,10 @@ GEMALTO_CINTERION_CellularNetwork::~GEMALTO_CINTERION_CellularNetwork()
3030

3131
AT_CellularNetwork::RegistrationMode GEMALTO_CINTERION_CellularNetwork::has_registration(RegistrationType reg_type)
3232
{
33-
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelEMS31) {
33+
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleEMS31) {
3434
return (reg_type == C_EREG) ? RegistrationModeLAC : RegistrationModeDisable;
3535
}
36-
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelBGS2) {
36+
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleBGS2) {
3737
if (reg_type == C_GREG) {
3838
return RegistrationModeEnable;
3939
}

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <cstdlib>
1919
#include "GEMALTO_CINTERION_CellularStack.h"
20-
#include "GEMALTO_CINTERION_Module.h"
20+
#include "GEMALTO_CINTERION.h"
2121
#include "CellularLog.h"
2222

2323
// 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
9191
if (urc_code == 1) { // ready
9292
if (sock->_cb) {
9393
sock->tx_ready = true;
94-
if (sock->proto == NSAPI_TCP || GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelBGS2) {
94+
if (sock->proto == NSAPI_TCP || GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleBGS2) {
9595
sock->started = true;
9696
}
9797
sock->_cb(sock->_data);
@@ -180,7 +180,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
180180
char sock_addr[sizeof("sockudp://") - 1 + NSAPI_IPv6_SIZE + sizeof("[]:12345;port=12345") - 1 + 1];
181181

182182
if (socket->proto == NSAPI_UDP) {
183-
if (GEMALTO_CINTERION_Module::get_model() != GEMALTO_CINTERION_Module::ModelBGS2) {
183+
if (GEMALTO_CINTERION::get_module() != GEMALTO_CINTERION::ModuleBGS2) {
184184
std::sprintf(sock_addr, "sockudp://%s:%u", address ? address->get_ip_address() : "", socket->localAddress.get_port());
185185
} else {
186186
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
286286
}
287287

288288
if (socket->proto == NSAPI_UDP) {
289-
if (GEMALTO_CINTERION_Module::get_model() != GEMALTO_CINTERION_Module::ModelBGS2) {
289+
if (GEMALTO_CINTERION::get_module() != GEMALTO_CINTERION::ModuleBGS2) {
290290
return socket_open_defer(socket);
291291
}
292292
}
@@ -306,7 +306,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul
306306
}
307307
}
308308

309-
if (socket->proto == NSAPI_UDP && GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelBGS2) {
309+
if (socket->proto == NSAPI_UDP && GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleBGS2) {
310310
tr_debug("Send addr %s, prev addr %s", address.get_ip_address(), socket->remoteAddress.get_ip_address());
311311
if (address != socket->remoteAddress) {
312312
if (socket->started) {
@@ -349,7 +349,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul
349349
_at.write_int(socket->id);
350350
_at.write_int(size);
351351

352-
if (GEMALTO_CINTERION_Module::get_model() != GEMALTO_CINTERION_Module::ModelBGS2) {
352+
if (GEMALTO_CINTERION::get_module() != GEMALTO_CINTERION::ModuleBGS2) {
353353
_at.write_int(0);
354354

355355
// UDP requires Udp_RemClient
@@ -466,7 +466,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
466466
}
467467

468468
// UDP Udp_RemClient
469-
if (socket->proto == NSAPI_UDP && GEMALTO_CINTERION_Module::get_model() != GEMALTO_CINTERION_Module::ModelBGS2) {
469+
if (socket->proto == NSAPI_UDP && GEMALTO_CINTERION::get_module() != GEMALTO_CINTERION::ModuleBGS2) {
470470
char ip_address[NSAPI_IPv6_SIZE + sizeof("[]:12345") - 1 + 1];
471471
int ip_len = _at.read_string(ip_address, sizeof(ip_address));
472472
if (ip_len <= 0) {
@@ -513,7 +513,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
513513
// setup internet connection profile for sockets
514514
nsapi_error_t GEMALTO_CINTERION_CellularStack::create_connection_profile(int connection_profile_id)
515515
{
516-
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelEMS31) {
516+
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleEMS31) {
517517
// EMS31 connection has only DNS settings and there is no need to modify those here for now
518518
return NSAPI_ERROR_OK;
519519
}
@@ -579,7 +579,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::create_connection_profile(int con
579579

580580
void GEMALTO_CINTERION_CellularStack::close_connection_profile(int connection_profile_id)
581581
{
582-
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelEMS31) {
582+
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleEMS31) {
583583
return;
584584
}
585585

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_Module.cpp

Lines changed: 0 additions & 69 deletions
This file was deleted.

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_Module.h

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)