M module-cellular/at/response.hpp => module-cellular/at/response.hpp +35 -0
@@ 56,6 56,13 @@ namespace at
CDMA = 100
};
+ enum class NameFormat
+ {
+ Long = 0,
+ Short = 1,
+ Numeric = 2
+ };
+
class Operator
{
public:
@@ 64,6 71,34 @@ namespace at
std::string longName;
std::string numericName;
std::optional<cops::AccessTechnology> technology = std::nullopt;
+
+ std::string getNameByFormat(NameFormat format)
+ {
+ switch (format) {
+ case NameFormat::Long:
+ return longName;
+ case NameFormat::Short:
+ return shortName;
+ case NameFormat::Numeric:
+ return numericName;
+ }
+ return {};
+ }
+
+ void setNameByFormat(NameFormat format, const std::string &name)
+ {
+ switch (format) {
+ case NameFormat::Long:
+ longName = name;
+ break;
+ case NameFormat::Short:
+ shortName = name;
+ break;
+ case NameFormat::Numeric:
+ numericName = name;
+ break;
+ }
+ }
};
} // namespace cops
M module-services/service-cellular/CellularServiceAPI.cpp => module-services/service-cellular/CellularServiceAPI.cpp +15 -0
@@ 119,6 119,21 @@ void CellularServiceAPI::StartOperatorsScan(sys::Service *serv, bool fullInfo)
sys::Bus::SendUnicast(msg, ServiceCellular::serviceName, serv);
}
+void CellularServiceAPI::SetOperatorAutoSelect(sys::Service *serv)
+{
+ auto msg = std::make_shared<CellularSetOperatorAutoSelectMessage>();
+ sys::Bus::SendUnicast(msg, ServiceCellular::serviceName, serv);
+}
+
+void CellularServiceAPI::SetOperator(sys::Service *serv,
+ at::response::cops::CopsMode mode,
+ at::response::cops::NameFormat format,
+ const std::string &name)
+{
+ auto msg = std::make_shared<CellularSetOperatorMessage>(mode, format, name);
+ sys::Bus::SendUnicast(msg, ServiceCellular::serviceName, serv);
+}
+
bool CellularServiceAPI::SelectAntenna(sys::Service *serv, bsp::cellular::antenna antenna)
{
auto msg = std::make_shared<CellularAntennaRequestMessage>(MessageType::CellularSelectAntenna);
M module-services/service-cellular/NetworkSettings.cpp => module-services/service-cellular/NetworkSettings.cpp +28 -0
@@ 54,3 54,31 @@ std::vector<std::string> NetworkSettings::scanOperators(bool fullInfoList)
return operatorNames;
}
+
+bool NetworkSettings::setOperatorAutoSelect()
+{
+ auto channel = cellularService.cmux->get(TS0710::Channel::Commands);
+ if (!channel) {
+ return false;
+ }
+
+ at::Cmd buildCmd =
+ at::factory(at::AT::COPS) + "=" + utils::to_string(static_cast<int>(at::response::cops::CopsMode::Automatic));
+ auto resp = channel->cmd(buildCmd);
+ return (resp.code == at::Result::Code::OK);
+}
+bool NetworkSettings::setOperator(at::response::cops::CopsMode mode,
+ at::response::cops::NameFormat format,
+ const std::string &name)
+{
+ auto channel = cellularService.cmux->get(TS0710::Channel::Commands);
+ if (!channel) {
+ return false;
+ }
+
+ at::Cmd buildCmd = at::factory(at::AT::COPS) + "=" + utils::to_string(static_cast<int>(mode)) + "," +
+ utils::to_string(static_cast<int>(format)) + ",\"" + name + "\"";
+
+ auto resp = channel->cmd(buildCmd);
+ return (resp.code == at::Result::Code::OK);
+}
M module-services/service-cellular/NetworkSettings.hpp => module-services/service-cellular/NetworkSettings.hpp +3 -0
@@ 25,6 25,9 @@ class NetworkSettings
*/
std::vector<std::string> scanOperators(bool fullInfoList = false);
+ bool setOperatorAutoSelect();
+ bool setOperator(at::response::cops::CopsMode mode, at::response::cops::NameFormat format, const std::string &name);
+
private:
ServiceCellular &cellularService;
};
M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +18 -0
@@ 2100,3 2100,21 @@ std::shared_ptr<CellularGetActiveContextsResponse> ServiceCellular::handleCellul
{
return std::make_shared<CellularGetActiveContextsResponse>(packetData->getActiveContexts());
}
+
+std::shared_ptr<CellularSetOperatorAutoSelectResponse> ServiceCellular::handleCellularSetOperatorAutoSelect(
+ CellularSetOperatorAutoSelectMessage *msg)
+{
+ LOG_INFO("CellularSetOperatorAutoSelect handled");
+
+ NetworkSettings networkSettings(*this);
+ return std::make_shared<CellularSetOperatorAutoSelectResponse>(networkSettings.setOperatorAutoSelect());
+}
+
+std::shared_ptr<CellularSetOperatorResponse> ServiceCellular::handleCellularSetOperator(CellularSetOperatorMessage *msg)
+{
+ LOG_INFO("CellularSetOperatorAutoSelect handled");
+
+ NetworkSettings networkSettings(*this);
+ return std::make_shared<CellularSetOperatorResponse>(
+ networkSettings.setOperator(msg->getMode(), msg->getFormat(), msg->getName()));
+}
M module-services/service-cellular/service-cellular/CellularMessage.hpp => module-services/service-cellular/service-cellular/CellularMessage.hpp +52 -0
@@ 14,6 14,8 @@
#include <utf8/UTF8.hpp>
#include <SimState.hpp>
+#include <response.hpp>
+
#include <memory>
#include <string>
@@ 86,6 88,41 @@ class CellularNotificationMessage : public CellularMessage
std::string data;
};
+class CellularSetOperatorAutoSelectMessage : public sys::Message
+{
+ public:
+ CellularSetOperatorAutoSelectMessage()
+ {}
+};
+
+class CellularSetOperatorMessage : public sys::Message
+{
+ at::response::cops::CopsMode mode;
+ at::response::cops::NameFormat format;
+ const std::string name;
+
+ public:
+ explicit CellularSetOperatorMessage(at::response::cops::CopsMode mode,
+ at::response::cops::NameFormat format,
+ std::string name)
+ : mode(mode), format(format), name(std::move(name))
+ {}
+
+ at::response::cops::CopsMode getMode() const noexcept
+ {
+ return mode;
+ }
+ at::response::cops::NameFormat getFormat() const noexcept
+ {
+ return format;
+ }
+
+ std::string getName() const
+ {
+ return name;
+ }
+};
+
class CellularStartOperatorsScanMessage : public CellularMessage
{
bool fullInfo = false;
@@ 622,6 659,21 @@ class CellularMMIPushMessage : public CellularMMIDataMessage, public app::manage
sender, app::manager::actions::ShowMMIPush, std::make_unique<app::manager::actions::MMIParams>(params));
}
};
+
+class CellularSetOperatorAutoSelectResponse : public CellularResponseMessage
+{
+ public:
+ explicit CellularSetOperatorAutoSelectResponse(bool ret) : CellularResponseMessage(ret)
+ {}
+};
+
+class CellularSetOperatorResponse : public CellularResponseMessage
+{
+ public:
+ explicit CellularSetOperatorResponse(bool ret) : CellularResponseMessage(ret)
+ {}
+};
+
namespace cellular
{
M module-services/service-cellular/service-cellular/CellularServiceAPI.hpp => module-services/service-cellular/service-cellular/CellularServiceAPI.hpp +7 -0
@@ 50,6 50,13 @@ namespace CellularServiceAPI
*
*/
void StartOperatorsScan(sys::Service *serv, bool fullInfo = false);
+
+ void SetOperatorAutoSelect(sys::Service *serv);
+ void SetOperator(sys::Service *serv,
+ at::response::cops::CopsMode mode,
+ at::response::cops::NameFormat format,
+ const std::string &name);
+
/*
* @brief It calls service-cellulat to switch antenna
* @param serv pointer to caller service.
M module-services/service-cellular/service-cellular/ServiceCellular.hpp => module-services/service-cellular/service-cellular/ServiceCellular.hpp +3 -1
@@ 269,9 269,11 @@ class ServiceCellular : public sys::Service
std::shared_ptr<cellular::RawCommandRespAsync> handleCellularStartOperatorsScan(
CellularStartOperatorsScanMessage *msg);
-
+ std::shared_ptr<CellularSetOperatorAutoSelectResponse> handleCellularSetOperatorAutoSelect(
+ CellularSetOperatorAutoSelectMessage *msg);
std::shared_ptr<CellularGetAPNResponse> handleCellularGetAPNMessage(CellularGetAPNMessage *msg);
std::shared_ptr<CellularSetAPNResponse> handleCellularSetAPNMessage(CellularSetAPNMessage *msg);
+ std::shared_ptr<CellularSetOperatorResponse> handleCellularSetOperator(CellularSetOperatorMessage *msg);
std::shared_ptr<CellularSetDataTransferResponse> handleCellularSetDataTransferMessage(
CellularSetDataTransferMessage *msg);
std::shared_ptr<CellularGetDataTransferResponse> handleCellularGetDataTransferMessage(