mirror of
https://github.com/cryptonote-social/csminer.git
synced 2024-09-11 05:35:23 +03:00
added get_miner_state to C api
This commit is contained in:
parent
7a8f9ab5d0
commit
d41d337be3
17
capi/capi.go
17
capi/capi.go
@ -37,4 +37,21 @@ func InitMiner(threads int, excludeHrStart, excludeHrEnd int) (code int, message
|
||||
return resp.Code, C.CString(resp.Message)
|
||||
}
|
||||
|
||||
//export GetMinerState
|
||||
func GetMinerState() (
|
||||
miningActivity int,
|
||||
threads int,
|
||||
recentHashrate float64,
|
||||
username *C.char,
|
||||
secondsOld int,
|
||||
lifetimeHashes int64,
|
||||
paid, owed, accumulated float64,
|
||||
timeToReward *C.char) {
|
||||
resp := minerlib.GetMiningState()
|
||||
|
||||
return resp.MiningActivity, resp.Threads, resp.RecentHashrate,
|
||||
C.CString(resp.PoolUsername), resp.SecondsOld, resp.LifetimeHashes,
|
||||
resp.Paid, resp.Owed, resp.Accumulated, C.CString(resp.TimeToReward)
|
||||
}
|
||||
|
||||
func main() {}
|
||||
|
@ -48,6 +48,7 @@ pool_login_response pool_login(const pool_login_args *args) {
|
||||
if (strlen(r.r1) > 0) {
|
||||
response.message = r.r1;
|
||||
} else {
|
||||
free((void*)r.r1);
|
||||
response.message = NULL;
|
||||
}
|
||||
return response;
|
||||
@ -88,7 +89,89 @@ init_miner_response init_miner(const init_miner_args *args) {
|
||||
if (strlen(r.r1) > 0) {
|
||||
response.message = r.r1;
|
||||
} else {
|
||||
free((void*)r.r1);
|
||||
response.message = NULL;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
typedef struct get_miner_state_response {
|
||||
// Valid values for mining_activity fall into two cateogories: MINING_PAUSED (all < 0)
|
||||
// and MINING_ACTIVE (all > 0)
|
||||
//
|
||||
// MINING_PAUSED_NO_CONNECTION = -2
|
||||
// indicates connection to pool server is lost; miner will continue trying to reconnect.
|
||||
//
|
||||
// MINING_PAUSED_SCREEN_ACTIVITY = -3
|
||||
// indicates miner is paused because the screen is active and miner is configured to mine
|
||||
// only when idle.
|
||||
//
|
||||
// MINING_PAUSED_BATTERY_POWER = -4
|
||||
// indicates miner is paused because the machine is operating on battery power.
|
||||
//
|
||||
// MINING_PAUSED_USER_OVERRIDE = -5
|
||||
// indicates miner is paused, and is in the "user focred mining pause" state.
|
||||
//
|
||||
// MINING_ACTIVE = 1
|
||||
// indicates miner is actively mining
|
||||
//
|
||||
// MINING_ACTIVE_USER_OVERRIDE = 2
|
||||
// indicates miner is actively mining, and is in "user forced active mining override" state.
|
||||
int mining_activity;
|
||||
|
||||
int threads; // number of threads actively mining
|
||||
|
||||
float recent_hashrate; // hashrate of the miner, computed over its most recent activity
|
||||
// period. This stat is always 100% up to date.
|
||||
|
||||
|
||||
// username of the miner whose pool stats appear below. Small chance this username may not match
|
||||
// the currently logged in user if a new login recently took place, so always check the username
|
||||
// matches before displaying the stats below. This value may be null (no user currently logged in)
|
||||
// in which case stats below should be ignored.
|
||||
//
|
||||
// NOTE: you must free() username
|
||||
const char* username;
|
||||
|
||||
// Stats below aremay be stale, with the seconds_old field specifying in seconds how out of
|
||||
// date they are.
|
||||
int seconds_old;
|
||||
|
||||
long lifetime_hashes; // total sum of hashes contributed to the pool under this username
|
||||
|
||||
// Amounts of $XMR paid, owed, and accumulated respectively. These floats are valid to 12 decimal
|
||||
// points. Accumulated $XMR is just an estimate of what the miner would earn should the next
|
||||
// block payout take place immediately.
|
||||
double paid;
|
||||
double owed;
|
||||
double accumulated;
|
||||
|
||||
// NOTE: you must free() time_to_reward
|
||||
const char* time_to_reward; // An estimate of the time to next reward in a pretty-printable
|
||||
// format, e.g. "3.5 days". This is just an estimate based on pool
|
||||
// hashrate and other dynamic factors
|
||||
} get_miner_state_response;
|
||||
|
||||
get_miner_state_response get_miner_state() {
|
||||
struct GetMinerState_return r = GetMinerState();
|
||||
get_miner_state_response response;
|
||||
response.mining_activity = (int)r.r0;
|
||||
response.threads = (int)r.r1;
|
||||
response.recent_hashrate = (float)r.r2;
|
||||
if (strlen(r.r3) > 0) {
|
||||
response.username = r.r3;
|
||||
response.time_to_reward = r.r9;
|
||||
} else {
|
||||
response.username = NULL;
|
||||
response.time_to_reward = NULL;
|
||||
free((void*)r.r3);
|
||||
free((void*)r.r9);
|
||||
}
|
||||
response.seconds_old = (int)r.r4;
|
||||
response.lifetime_hashes = (long)r.r5;
|
||||
response.paid = (float)r.r6;
|
||||
response.owed = (float)r.r7;
|
||||
response.accumulated = (float)r.r8;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
11
capi/test.c
11
capi/test.c
@ -63,6 +63,12 @@ int main(int argc, char* argv[]) {
|
||||
printf("Sleeping for a minute before trying another login.\n");
|
||||
sleep(60);
|
||||
|
||||
get_miner_state_response ms_resp = get_miner_state();
|
||||
printf("Hashrate was: %f\n", ms_resp.recent_hashrate);
|
||||
printf("Threads active: %d\n", ms_resp.threads);
|
||||
free((void*)ms_resp.username);
|
||||
free((void*)ms_resp.time_to_reward);
|
||||
|
||||
printf("Trying to login with a new user (donate-getmonero-org).\n");
|
||||
pl_args.username = "donate-getmonero-org";
|
||||
pl_resp = pool_login(&pl_args);
|
||||
@ -83,6 +89,11 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
printf("Sleeping for a minute before looping again.\n");
|
||||
sleep(60);
|
||||
ms_resp = get_miner_state();
|
||||
printf("Hashrate was: %f\n", ms_resp.recent_hashrate);
|
||||
printf("Threads active: %d\n", ms_resp.threads);
|
||||
free((void*)ms_resp.username);
|
||||
free((void*)ms_resp.time_to_reward);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -17,23 +17,24 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// MINING_PAUSED_NO_CONNECTION = -2
|
||||
// indicates connection to pool server is lost; miner will continue trying to reconnect.
|
||||
MINING_PAUSED_NO_CONNECTION = 2
|
||||
//
|
||||
// MINING_PAUSED_SCREEN_ACTIVITY = -3
|
||||
// indicates miner is paused because the screen is active and miner is configured to mine
|
||||
// only when idle.
|
||||
MINING_PAUSED_SCREEN_ACTIVITY = 3
|
||||
|
||||
//
|
||||
// MINING_PAUSED_BATTERY_POWER = -4
|
||||
// indicates miner is paused because the machine is operating on battery power.
|
||||
MINING_PAUSED_BATTERY_POWER = 4
|
||||
|
||||
// indicates miner is paused because of a user-initiated override
|
||||
MINING_PAUSED_USER_OVERRIDE = 5
|
||||
|
||||
//
|
||||
// MINING_PAUSED_USER_OVERRIDE = -5
|
||||
// indicates miner is paused, and is in the "user focred mining pause" state.
|
||||
//
|
||||
MINING_ACTIVE = 1
|
||||
// indicates miner is actively mining
|
||||
MINING_ACTIVE = 6
|
||||
//
|
||||
// MINING_ACTIVE_USER_OVERRIDE = 2
|
||||
|
||||
// indicates miner is actively mining because of user-initiated override
|
||||
MINING_ACTIVE_EXTERNAL_OVERRIDE = 7
|
||||
)
|
||||
|
||||
var (
|
||||
@ -290,6 +291,23 @@ func MiningLoop(jobChan <-chan *client.MultiClientJob) {
|
||||
defer crylog.Info("Mining loop terminated")
|
||||
}
|
||||
|
||||
type GetMiningStateResponse struct {
|
||||
stats.Snapshot
|
||||
MiningActivity int
|
||||
Threads int
|
||||
}
|
||||
|
||||
func GetMiningState() *GetMiningStateResponse {
|
||||
s := stats.GetSnapshot(true /*TODO: fix*/)
|
||||
configMutex.Lock()
|
||||
defer configMutex.Unlock()
|
||||
return &GetMiningStateResponse{
|
||||
Snapshot: *s,
|
||||
MiningActivity: MINING_ACTIVE,
|
||||
Threads: threads,
|
||||
}
|
||||
}
|
||||
|
||||
func printStats(isMining bool) {
|
||||
s := stats.GetSnapshot(isMining)
|
||||
crylog.Info("=====================================")
|
||||
|
Loading…
Reference in New Issue
Block a user