// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "service-fota/FotaMessages.hpp" #include "service-fota/FotaServiceAPI.hpp" #include "service-fota/ServiceFota.hpp" #include #include #include #include #include #include namespace FotaService { bool API::Configure(sys::Service *serv, const APN::Config &config) { LOG_DEBUG("FOTA - Internet Config called"); std::shared_ptr msg = std::make_shared(config); return sys::Bus::SendUnicast(std::move(msg), FotaService::Service::serviceName, serv); } bool API::Connect(sys::Service *serv) { LOG_DEBUG("FOTA - Internet connection called"); auto msg = std::make_shared(); return sys::Bus::SendUnicast(std::move(msg), FotaService::Service::serviceName, serv); } bool API::Disconnect(sys::Service *serv) { std::shared_ptr msg = std::make_shared(MessageType::FotaInternetDisconnect); return sys::Bus::SendUnicast(std::move(msg), FotaService::Service::serviceName, serv); } void API::HTTPGET(sys::Service *serv, const std::string &url) { LOG_DEBUG("HTTP GET API called"); std::shared_ptr msg = std::make_shared(); msg->url = url; msg->method = FotaService::HTTPMethod::GET; sys::Bus::SendUnicast(std::move(msg), FotaService::Service::serviceName, serv); } void API::FotaStart(sys::Service *serv, const std::string &url) { LOG_DEBUG("Fota Star: %s", url.c_str()); std::shared_ptr msg = std::make_shared(); msg->url = url; sys::Bus::SendUnicast(std::move(msg), FotaService::Service::serviceName, serv); } void API::sendRawProgress(sys::Service *serv, const std::string &rawQind) { LOG_DEBUG("Fota sending Raw progress"); std::shared_ptr msg = std::make_shared(); msg->qindRaw = rawQind; sys::Bus::SendUnicast(std::move(msg), FotaService::Service::serviceName, serv); } std::string APN::toString(APN::AuthMethod authMethod) { switch (authMethod) { case AuthMethod::NONE: return "NONE"; case AuthMethod::PAP: return "PAP"; case AuthMethod::CHAP: return "CHAP"; case AuthMethod::AUTO: return "AUTO"; } return std::to_string(static_cast(authMethod)); } std::string APN::Config::toString() const { std::ostringstream out; out << static_cast(contextId) << "," << (type == ContextType::ipv4 ? "ipv4" : "ipv4v6") << "," << apn << "," << username << "," << password << "," << APN::toString(authMethod) << "," << (activated ? "Activated" : "Deactivated") << "," << ip << ","; return out.str(); } std::string toString(HTTPErrors error) { switch (error) { case HTTPErrors::OK: return "OK"; case HTTPErrors::UnknowError: return "UnknowError"; case HTTPErrors::OpenFailed: return "OpenFailed"; case HTTPErrors::URLFailed: return "URLFailed"; case HTTPErrors::GetFailed: return "GetFailed"; } return "unknown (" + std::to_string(static_cast(error)) + ")"; } } // namespace FotaService