Skip to content

Commit b1aa399

Browse files
authored
Merge pull request arduino#571 from Rocketct/master
added API to allows to set the Modem's bands
2 parents 216b2e4 + 4a8fa79 commit b1aa399

File tree

4 files changed

+135
-4
lines changed

4 files changed

+135
-4
lines changed

libraries/GSM/examples/GSMClient/GSMClient.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ char pass[] = SECRET_PASSWORD;
1111
const char server[] = "www.example.com";
1212
const char* ip_address;
1313
int port = 80;
14-
1514
GSMClient client;
1615

1716
void setup() {
1817
Serial.begin(115200);
1918
while(!Serial) {}
2019
Serial.println("Starting Carrier Network registration");
21-
if(!GSM.begin(pin, apn, username, pass, CATNB)){
20+
if(!GSM.begin(pin, apn, username, pass, CATNB, BAND_20 | BAND_19)){
2221
Serial.println("The board was not able to register to the network...");
2322
// do nothing forevermore:
2423
while(1);

libraries/GSM/src/GSM.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mbed::CellularDevice *mbed::CellularDevice::get_default_instance()
2626
return &device;
2727
}
2828

29-
int arduino::GSMClass::begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat, bool restart) {
29+
int arduino::GSMClass::begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat, uint32_t band, bool restart) {
3030

3131
if(restart || isCmuxEnable()) {
3232
pinMode(PJ_10, OUTPUT);
@@ -69,9 +69,11 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
6969
_username = username;
7070
_password = password;
7171
_rat = rat;
72+
_band = (FrequencyBand) band;
7273
_context->set_credentials(apn, username, password);
7374

7475
_context->set_access_technology(rat);
76+
_context->set_band(_band);
7577

7678
int connect_status = NSAPI_ERROR_AUTH_FAILURE;
7779
uint8_t retryCount = 0;

libraries/GSM/src/GSM.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class GSMClass : public MbedSocketClass {
6969
*
7070
* return: 0 in case of success, negative number in case of failure
7171
*/
72-
int begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat = CATNB, bool restart = true);
72+
int begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat = CATNB, uint32_t band = BAND_20, bool restart = true);
7373

7474
/*
7575
* Disconnect from the network
@@ -104,6 +104,7 @@ class GSMClass : public MbedSocketClass {
104104
const char* _password = nullptr;
105105
bool _cmuxGSMenable = _CMUX_ENABLE;
106106
RadioAccessTechnologyType _rat;
107+
FrequencyBand _band;
107108
NetworkInterface* gsm_if = nullptr;
108109
mbed::CellularContext* _context = nullptr;
109110
mbed::CellularDevice* _device = nullptr;
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
From d258aa3cec48ecd5c0e625e6f60368353be833d4 Mon Sep 17 00:00:00 2001
2+
From: Riccardo <r.rizzo@arduino.cc>
3+
Date: Thu, 3 Nov 2022 12:05:21 +0100
4+
Subject: [PATCH 184/185] Cellular: add API to set Modem bands
5+
6+
---
7+
.../cellular/framework/API/CellularContext.h | 19 +++++++++++++++++++
8+
.../framework/AT/AT_CellularContext.h | 2 ++
9+
.../framework/AT/AT_CellularContext.cpp | 15 ++++++++++++---
10+
3 files changed, 33 insertions(+), 3 deletions(-)
11+
12+
diff --git a/connectivity/cellular/include/cellular/framework/API/CellularContext.h b/connectivity/cellular/include/cellular/framework/API/CellularContext.h
13+
index 1061d5d926..325f93db4b 100644
14+
--- a/connectivity/cellular/include/cellular/framework/API/CellularContext.h
15+
+++ b/connectivity/cellular/include/cellular/framework/API/CellularContext.h
16+
@@ -35,6 +35,24 @@ enum RadioAccessTechnologyType {
17+
CATNB = 8
18+
};
19+
20+
+enum FrequencyBand {
21+
+ BAND_1 = 0x01,
22+
+ BAND_2 = 0x02,
23+
+ BAND_3 = 0x04,
24+
+ BAND_4 = 0x08,
25+
+ BAND_5 = 0x10,
26+
+ BAND_8 = 0x80,
27+
+ BAND_12 = 0x800,
28+
+ BAND_13 = 0x1000,
29+
+ BAND_18 = 0x20000,
30+
+ BAND_19 = 0x40000,
31+
+ BAND_20 = 0x80000,
32+
+ BAND_25 = 0x1000000,
33+
+ BAND_26 = 0x2000000,
34+
+ BAND_28 = 0x8000000
35+
+};
36+
+
37+
+
38+
namespace mbed {
39+
40+
/**
41+
@@ -160,6 +178,7 @@ public: // from NetworkInterface
42+
const char *pwd = 0) = 0;
43+
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0) = 0;
44+
virtual void set_access_technology(RadioAccessTechnologyType rat = CATM1) = 0;
45+
+ virtual void set_band(FrequencyBand band = BAND_20) = 0;
46+
virtual bool is_connected() = 0;
47+
48+
/** Same as NetworkInterface::get_default_instance()
49+
diff --git a/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h b/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h
50+
index 0eb83531b0..eb3bf5afdd 100644
51+
--- a/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h
52+
+++ b/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h
53+
@@ -48,6 +48,7 @@ public:
54+
const char *pwd = 0);
55+
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0);
56+
virtual void set_access_technology(RadioAccessTechnologyType rat = CATM1);
57+
+ virtual void set_band(FrequencyBand band = BAND_20);
58+
59+
// from CellularContext
60+
virtual nsapi_error_t get_pdpcontext_params(pdpContextList_t &params_list);
61+
@@ -135,6 +136,7 @@ private:
62+
PinName _dcd_pin;
63+
bool _active_high;
64+
RadioAccessTechnologyType _rat;
65+
+ FrequencyBand _band;
66+
67+
protected:
68+
char _found_apn[MAX_APN_LENGTH];
69+
diff --git a/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp b/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp
70+
index 620af5ac76..087846e9b5 100644
71+
--- a/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp
72+
+++ b/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp
73+
@@ -48,7 +48,7 @@ using namespace rtos;
74+
using namespace std::chrono_literals;
75+
76+
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
77+
- _current_op(OP_INVALID), _dcd_pin(NC), _active_high(false), _rat(CATM1), _cp_req(cp_req), _is_connected(false), _at(at)
78+
+ _current_op(OP_INVALID), _dcd_pin(NC), _active_high(false), _rat(CATM1), _band(BAND_20), _cp_req(cp_req), _is_connected(false), _at(at)
79+
{
80+
tr_info("New CellularContext %s (%p)", apn ? apn : "", this);
81+
_nonip_req = nonip_req;
82+
@@ -284,6 +284,11 @@ void AT_CellularContext::set_access_technology(RadioAccessTechnologyType rat)
83+
_rat = rat;
84+
}
85+
86+
+void AT_CellularContext::set_band(FrequencyBand band)
87+
+{
88+
+ _band = band;
89+
+}
90+
+
91+
// PDP Context handling
92+
void AT_CellularContext::delete_current_context()
93+
{
94+
@@ -440,11 +445,14 @@ bool AT_CellularContext::set_new_context(int cid)
95+
96+
void AT_CellularContext::enable_access_technology()
97+
{
98+
+ char *buffer = new char [8];
99+
+ memset(buffer, 0, 8);
100+
+ sprintf(buffer,"%08X", _band);
101+
switch (_rat)
102+
{
103+
case CATM1:
104+
_at.at_cmd_discard("^SXRAT", "=","%d", _rat);
105+
- _at.cmd_start_stop("^SCFG", "=","%s%d", "Radio/Band/CatM",80000);
106+
+ _at.cmd_start_stop("^SCFG", "=","%s%s", "Radio/Band/CatM",buffer);
107+
_at.resp_start("^SCFG");
108+
_at.cmd_start_stop("^SCFG", "=","%s%d%d", "Radio/Band/CatNB",0,0);
109+
_at.resp_start("^SCFG");
110+
@@ -452,7 +460,7 @@ void AT_CellularContext::enable_access_technology()
111+
112+
case CATNB:
113+
_at.at_cmd_discard("^SXRAT", "=","%d", _rat);
114+
- _at.cmd_start_stop("^SCFG", "=","%s%d", "Radio/Band/CatNB",80000);
115+
+ _at.cmd_start_stop("^SCFG", "=","%s%s", "Radio/Band/CatNB",buffer);
116+
_at.resp_start("^SCFG");
117+
_at.cmd_start_stop("^SCFG", "=","%s%d%d", "Radio/Band/CatM",0,0);
118+
_at.resp_start("^SCFG");
119+
@@ -464,6 +472,7 @@ void AT_CellularContext::enable_access_technology()
120+
121+
_at.cmd_start_stop("^SCFG", "=", "%s%s", "Tcp/withURCs", "on");
122+
_at.resp_start("^SCFG");
123+
+ free(buffer);
124+
125+
}
126+
127+
--
128+
2.38.1
129+

0 commit comments

Comments
 (0)