|
| 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 ¶ms_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