Added mining on battery setting

This commit is contained in:
SChernykh 2020-07-22 20:12:16 +02:00
parent 5bc89fdc8b
commit 299b180b28
10 changed files with 95 additions and 18 deletions

View file

@ -54,6 +54,8 @@ public:
static inline const char *userAgent() { return m_userAgent; }
static bool isOnBatteryPower();
private:
static char *createUserAgent();

View file

@ -29,6 +29,7 @@
#include <sys/resource.h>
#include <uv.h>
#include <thread>
#include <fstream>
#include "base/kernel/Platform.h"
@ -107,3 +108,18 @@ void xmrig::Platform::setThreadPriority(int priority)
setpriority(PRIO_PROCESS, 0, prio);
}
bool xmrig::Platform::isOnBatteryPower()
{
for (int i = 0; i <= 1; ++i) {
char buf[64];
snprintf(buf, 64, "/sys/class/power_supply/BAT%d/status", i);
std::ifstream f(buf);
if (f.is_open()) {
std::string status;
f >> status;
return (status == "Discharging");
}
}
return false;
}

View file

@ -38,6 +38,7 @@
#include <unistd.h>
#include <uv.h>
#include <thread>
#include <fstream>
#include "base/kernel/Platform.h"
@ -146,3 +147,19 @@ void xmrig::Platform::setThreadPriority(int priority)
}
# endif
}
bool xmrig::Platform::isOnBatteryPower()
{
for (int i = 0; i <= 1; ++i) {
char buf[64];
snprintf(buf, 64, "/sys/class/power_supply/BAT%d/status", i);
std::ifstream f(buf);
if (f.is_open()) {
std::string status;
f >> status;
return (status == "Discharging");
}
}
return false;
}

View file

@ -157,3 +157,12 @@ void xmrig::Platform::setThreadPriority(int priority)
SetThreadPriority(GetCurrentThread(), prio);
}
bool xmrig::Platform::isOnBatteryPower()
{
SYSTEM_POWER_STATUS st;
if (GetSystemPowerStatus(&st)) {
return (st.ACLineStatus == 0);
}
return false;
}

View file

@ -67,6 +67,7 @@ const char *BaseConfig::kTitle = "title";
const char *BaseConfig::kUserAgent = "user-agent";
const char *BaseConfig::kVerbose = "verbose";
const char *BaseConfig::kWatch = "watch";
const char *BaseConfig::kMineOnBattery = "mine-on-battery";
#ifdef XMRIG_FEATURE_TLS
@ -85,15 +86,16 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
return false;
}
m_autoSave = reader.getBool(kAutosave, m_autoSave);
m_background = reader.getBool(kBackground, m_background);
m_dryRun = reader.getBool(kDryRun, m_dryRun);
m_syslog = reader.getBool(kSyslog, m_syslog);
m_watch = reader.getBool(kWatch, m_watch);
m_logFile = reader.getString(kLogFile);
m_userAgent = reader.getString(kUserAgent);
m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U);
m_title = reader.getValue(kTitle);
m_autoSave = reader.getBool(kAutosave, m_autoSave);
m_background = reader.getBool(kBackground, m_background);
m_dryRun = reader.getBool(kDryRun, m_dryRun);
m_syslog = reader.getBool(kSyslog, m_syslog);
m_watch = reader.getBool(kWatch, m_watch);
m_mineOnBattery = reader.getBool(kMineOnBattery, m_mineOnBattery);
m_logFile = reader.getString(kLogFile);
m_userAgent = reader.getString(kUserAgent);
m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U);
m_title = reader.getValue(kTitle);
# ifdef XMRIG_FEATURE_TLS
m_tls = reader.getValue(kTls);

View file

@ -61,6 +61,7 @@ public:
static const char *kUserAgent;
static const char *kVerbose;
static const char *kWatch;
static const char* kMineOnBattery;
# ifdef XMRIG_FEATURE_TLS
static const char *kTls;
@ -80,6 +81,7 @@ public:
inline const String &apiWorkerId() const { return m_apiWorkerId; }
inline const Title &title() const { return m_title; }
inline uint32_t printTime() const { return m_printTime; }
inline bool mineOnBattery() const { return m_mineOnBattery; }
# ifdef XMRIG_FEATURE_TLS
inline const TlsConfig &tls() const { return m_tls; }
@ -95,12 +97,13 @@ public:
void printVersions();
protected:
bool m_autoSave = true;
bool m_background = false;
bool m_dryRun = false;
bool m_syslog = false;
bool m_upgrade = false;
bool m_watch = true;
bool m_autoSave = true;
bool m_background = false;
bool m_dryRun = false;
bool m_syslog = false;
bool m_upgrade = false;
bool m_watch = true;
bool m_mineOnBattery = true;
Http m_http;
Pools m_pools;
String m_apiId;