ctr_Repair/trunk/NetworkUpdater/sources/common/Util.cpp
N2614 84aac69652 バッテリ残量をptmから取得するよう変更。cfg:sを使うよう変更
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@797 385bec56-5757-e545-9c3a-d8741f4650f1
2014-05-02 02:11:11 +00:00

279 lines
6.0 KiB
C++

/*---------------------------------------------------------------------------*
Project: Horizon
File: Util.cpp
Copyright (C)2010-2011 Nintendo Co., Ltd. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Rev$
*---------------------------------------------------------------------------*/
#include <cctype>
#include <nn.h>
#include <nn/ptm/CTR/ptm_ApiSysmenu.h>
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
#include <nn/fs/CTR/MPCore/fs_ApiIntegrityVerificationSeed.h>
#include <nn/fs/fs_ApiSysSaveData.h>
#include <nn/cfg/CTR/cfg_Api.h>
#include <nn/cfg/CTR/cfg_ApiInit.h>
#include <nn/cfg/CTR/cfg_ApiSys.h>
#include <nn/friends.h>
#include <nn/friends/CTR/friends_ApiPrivate.h>
#include <nn/ps.h>
#include <nn/drivers/mcu/CTR/driverMcuRegisterMap.h>
#include <nn/ac.h>
#include <nn/ac/private/ac.h>
#include <nn/ac/CTR/private/ac_InternalApi.h>
#include <nn/ac/CTR/private/ac_NetworkSetting.h>
#include <nn/nwm/CTR/nwm_ExtAPI.h>
#include <nn/nwm/CTR/nwm_ExtHwAPI.h>
#include "Util.h"
#include "FileName.h"
#include "CommonLogger.h"
#include "HeapManager.h"
namespace common
{
Util::Util() :
m_BatteryRemain(100)
{
}
Util::~Util()
{
}
void Util::InitializeForBackup()
{
Initialize();
}
void Util::InitializeForRestore()
{
Initialize();
}
void Util::Initialize()
{
nn::Result result;
// リージョンの取得
m_Region = nn::cfg::CTR::GetRegion();
// バージョンの取得
common::GetSystemVersion(&m_VerData, m_Region);
// nwmの初期化
nn::nwm::InitializeExtControl();
}
void Util::FinalizeForBackup()
{
Finalize();
}
void Util::FinalizeForRestore()
{
nn::friends::detail::Finalize();
}
void Util::Finalize()
{
nn::nwm::FinalizeExtControl();
}
void Util::SetWifiOn()
{
COMMON_LOGGER_RESULT_IF_FAILED(
nn::nwm::Ext::SetWifiOn());
}
void Util::SetWifiOff()
{
COMMON_LOGGER_RESULT_IF_FAILED(
nn::nwm::Ext::SetWifiOff());
}
// 無線状態を取得する
bool Util::IsWifiOn()
{
return nn::nwm::IsWifiOn();
}
bool Util::IsAdapterConnected()
{
return nn::ptm::CTR::GetAdapterState() == nn::ptm::CTR::ADAPTERSTATE_CONNECTED;
}
bool Util::IsBatteryLower()
{
nn::ptm::CTR::BatteryLevel level = nn::ptm::CTR::GetBatteryLevel();
if(level == nn::ptm::CTR::BATTERYLEVEL_0 ||
level == nn::ptm::CTR::BATTERYLEVEL_1 ||
level == nn::ptm::CTR::BATTERYLEVEL_2)
{
return true;
}
else
{
return false;
}
}
u8 Util::GetCupMajorVersion()
{
return m_VerData.cup.majorVersion;
}
u8 Util::GetCupMinorVersion()
{
return m_VerData.cup.minorVersion;
}
u8 Util::GetCupMicroVersion()
{
return m_VerData.cup.microVersion;
}
u8 Util::GetNupVersion()
{
return m_VerData.nup.majorVersion;
}
nn::Handle Util::GetMcuHandle()
{
return m_McuSession;
}
u32 Util::GetBatteryRemain()
{
nn::ptm::CTR::BatteryLevel level = nn::ptm::CTR::GetBatteryLevel();
if(level == nn::ptm::CTR::BATTERYLEVEL_0)
{
return 0;
}
else if(level == nn::ptm::CTR::BATTERYLEVEL_1)
{
return 5;
}
else if(level == nn::ptm::CTR::BATTERYLEVEL_2)
{
return 10;
}
else if(level == nn::ptm::CTR::BATTERYLEVEL_3)
{
return 30;
}
else if(level == nn::ptm::CTR::BATTERYLEVEL_4)
{
return 60;
}
else if(level == nn::ptm::CTR::BATTERYLEVEL_5)
{
return 100;
}
return 100;
}
nn::cfg::CTR::CfgRegionCode Util::GetRegion()
{
return m_Region;
}
const char* Util::GetRegionCodeA3()
{
return nn::cfg::GetRegionCodeA3(m_Region);
}
void Util::GetVersionData(common::VerDef* version)
{
*version = m_VerData;
}
u32 Util::GetRenderTarget(u32 target, bool flip)
{
if(flip)
{
if(target == NN_GX_DISPLAY0)
{
return NN_GX_DISPLAY1;
}
else
{
return NN_GX_DISPLAY0;
}
}
else
{
return target;
}
}
nn::Result PrintNetworkSetting()
{
nn::Result result;
nn::ac::NetworkSetting networkSetting;
result = nn::ac::LoadNetworkSetting(0, networkSetting);
COMMON_LOGGER("SSID: %s\n", networkSetting.wireless.essidSecurity.ssid);
COMMON_LOGGER("DNS : %d.%d.%d.%d\n",
networkSetting.ip.dns[0][0], networkSetting.ip.dns[0][1],
networkSetting.ip.dns[0][2], networkSetting.ip.dns[0][3]);
return result;
}
nn::Result InitializeNetwork(void)
{
nn::Result result;
nn::ac::Config config;
// 未初期化の時だけ初期化する
if(!nn::ac::IsInitializedInternal())
{
result = nn::ac::InitializeInternal();
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
}
// 接続要求用のパラメータを作成
result = nn::ac::CreateDefaultConfig(&config);
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
// デバッグ用に接続テストを無効化
nn::ac::DebugSetNetworkArea(&config, nn::ac::NETWORK_AREA_LAN);
// 接続要求を発行
result = nn::ac::ConnectWithoutEula(config);
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
return nn::ResultSuccess();
}
nn::Result FinalizeNetwork(void)
{
nn::Result result;
// 接続要求用のパラメータを作成
result = nn::ac::Close();
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
result = nn::ac::FinalizeInternal();
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
return nn::ResultSuccess();
}
}