summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mts/MTS_IO_TelitRadio.h4
-rw-r--r--src/MTS_IO_TelitRadio.cpp78
2 files changed, 36 insertions, 46 deletions
diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h
index b81cd7d..bd542f1 100644
--- a/include/mts/MTS_IO_TelitRadio.h
+++ b/include/mts/MTS_IO_TelitRadio.h
@@ -22,6 +22,7 @@
#define MTS_IO_TELITRADIO_H_
#include <mts/MTS_IO_CellularRadio.h>
+#include <set>
namespace MTS {
namespace IO {
@@ -54,8 +55,7 @@ namespace MTS {
private:
virtual CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk, const std::string& sLockStatus);
- static ICellularRadio::CELLULAR_MODES preferredNetwork(CELLULAR_MODES prefNetwork, int wds);
-
+ ICellularRadio::CODE wdsList(std::set<int> &wds);
};
}
}
diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp
index 5b8e55d..be31b03 100644
--- a/src/MTS_IO_TelitRadio.cpp
+++ b/src/MTS_IO_TelitRadio.cpp
@@ -631,6 +631,25 @@ ICellularRadio::CODE TelitRadio::getSimLockAttempts(int& iAttemptsPin, int& iAtt
ICellularRadio::CODE TelitRadio::getSupportedCellularModes(CELLULAR_MODES &networks) {
networks = CELLULAR_MODE_NA;
+
+ std::set<int> wds;
+ if ( TelitRadio::wdsList(wds) != SUCCESS ) {
+ return FAILURE;
+ }
+ for(const auto &it : wds) {
+ switch (it) {
+ case 12: networks = static_cast<CELLULAR_MODES>(networks | CELLULAR_MODE_2G); break;
+ case 22: networks = static_cast<CELLULAR_MODES>(networks | CELLULAR_MODE_3G); break;
+ case 28: networks = static_cast<CELLULAR_MODES>(networks | CELLULAR_MODE_4G); break;
+ case 36: networks = static_cast<CELLULAR_MODES>(networks | CELLULAR_MODE_5G); break;
+ }
+ }
+
+ return SUCCESS;
+}
+
+ICellularRadio::CODE TelitRadio::wdsList(std::set<int> &wds)
+{
std::string sCmd("AT+WS46=?");
std::string cmdResult = sendCommand(sCmd);
if (cmdResult.find("+WS46:") == std::string::npos) {
@@ -645,7 +664,6 @@ ICellularRadio::CODE TelitRadio::getSupportedCellularModes(CELLULAR_MODES &netwo
std::string s = MTS::Text::split(cmdResult, '(')[1];
s = MTS::Text::split(s, ')')[0];
std::vector<std::string>v = MTS::Text::split(s, ',');
- std::vector<int> m;
for(const auto &it : v)
{
if (it.find("-") != std::string::npos) {
@@ -656,8 +674,8 @@ ICellularRadio::CODE TelitRadio::getSupportedCellularModes(CELLULAR_MODES &netwo
return FAILURE;
}
for (int i = begin; i<=end; ++i) {
- m.push_back(i);
- if (m.size()>1024)
+ wds.insert(i);
+ if (wds.size()>1024)
break;
}
} else {
@@ -666,34 +684,34 @@ ICellularRadio::CODE TelitRadio::getSupportedCellularModes(CELLULAR_MODES &netwo
printError("AT+WS46: error parsing network mode: %s", it.c_str());
return FAILURE;
}
- m.push_back(v);
+ wds.insert(v);
}
}
- if (m.size()>1024) {
+ if (wds.size()>1024) {
printError("AT+WS46: network modes count overflow, parsing error");
return FAILURE;
}
- // Now m contains all network modes
- for(const auto &it : m) {
- networks = preferredNetwork(networks, it);
- }
-
return SUCCESS;
}
ICellularRadio::CODE TelitRadio::setCellularMode(CELLULAR_MODES networks) {
+ std::set<int> supportedWds;
+ if ( TelitRadio::wdsList(supportedWds) != SUCCESS ) {
+ return FAILURE;
+ }
+
int wds = 0;
// 3GPP TS 27.007
// https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1515
switch (static_cast<int>(networks)) {
case CELLULAR_MODE_2G : wds = 12; break;
- case CELLULAR_MODE_3G : wds = 22; break;
- case CELLULAR_MODE_2G | CELLULAR_MODE_3G | CELLULAR_MODE_4G : wds = 25; break;
- case CELLULAR_MODE_4G : wds = 28; break;
- case CELLULAR_MODE_2G | CELLULAR_MODE_3G : wds = 29; break;
- case CELLULAR_MODE_2G | CELLULAR_MODE_4G : wds = 30; break;
- case CELLULAR_MODE_3G | CELLULAR_MODE_4G : wds = 31; break;
+ case CELLULAR_MODE_3G : wds = 22; break;
+ case CELLULAR_MODE_2G | CELLULAR_MODE_3G | CELLULAR_MODE_4G : wds = 25; break;
+ case CELLULAR_MODE_4G : wds = 28; break;
+ case CELLULAR_MODE_2G | CELLULAR_MODE_3G : supportedWds.count(28) ? wds = 29 : wds = 25; break;
+ case CELLULAR_MODE_2G | CELLULAR_MODE_4G : wds = 30; break;
+ case CELLULAR_MODE_3G | CELLULAR_MODE_4G : wds = 31; break;
case CELLULAR_MODE_2G | CELLULAR_MODE_3G | CELLULAR_MODE_4G | CELLULAR_MODE_5G: wds = 35; break;
case CELLULAR_MODE_5G: wds = 36; break;
case CELLULAR_MODE_4G | CELLULAR_MODE_5G: wds = 37; break;
@@ -712,31 +730,3 @@ ICellularRadio::CODE TelitRadio::setCellularMode(CELLULAR_MODES networks) {
}
return SUCCESS;
}
-
-ICellularRadio::CELLULAR_MODES TelitRadio::preferredNetwork(CELLULAR_MODES prefNetwork, int wds)
-{
- int result = prefNetwork;
- // 3GPP TS 27.007
- // https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1515
- switch (wds) {
- case 12: result |= CELLULAR_MODE_2G; break;
- case 22: result |= CELLULAR_MODE_3G; break;
- case 25: result |= CELLULAR_MODE_2G | CELLULAR_MODE_3G | CELLULAR_MODE_4G; break;
- case 28: result |= CELLULAR_MODE_4G; break;
- case 29: result |= CELLULAR_MODE_2G | CELLULAR_MODE_3G; break;
- case 30: result |= CELLULAR_MODE_2G | CELLULAR_MODE_4G; break;
- case 31: result |= CELLULAR_MODE_3G | CELLULAR_MODE_4G; break;
- case 35: result |= CELLULAR_MODE_2G | CELLULAR_MODE_3G | CELLULAR_MODE_4G | CELLULAR_MODE_5G; break;
- case 36: result |= CELLULAR_MODE_5G; break;
- case 37: result |= CELLULAR_MODE_4G | CELLULAR_MODE_5G; break;
- case 38: result |= CELLULAR_MODE_3G | CELLULAR_MODE_4G | CELLULAR_MODE_5G; break;
- case 39: result |= CELLULAR_MODE_2G | CELLULAR_MODE_4G | CELLULAR_MODE_5G; break;
- case 40: result |= CELLULAR_MODE_3G | CELLULAR_MODE_5G; break;
- case 41: result |= CELLULAR_MODE_2G | CELLULAR_MODE_3G | CELLULAR_MODE_5G; break;
- case 42: result |= CELLULAR_MODE_2G | CELLULAR_MODE_5G; break;
- default:
- printError("AT+WS46: unhandled network mode: %d", wds);
- break;
- }
- return static_cast<CELLULAR_MODES>(result);
-}