forked from drkskwlkr/NiceHashMinerLegacy
-
Notifications
You must be signed in to change notification settings - Fork 18
/
GroupMiner.cs
125 lines (114 loc) · 4.64 KB
/
GroupMiner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using NiceHashMiner.Configs;
using System.Collections.Generic;
using NiceHashMinerLegacy.Common.Enums;
using System;
using System.Linq;
namespace NiceHashMiner.Miners.Grouping
{
public class GroupMiner
{
public Miner Miner { get; protected set; }
public string DevicesInfoString { get; }
public AlgorithmType AlgorithmType { get; }
public AlgorithmType DualAlgorithmType { get; }
// for now used only for dagger identification AMD or NVIDIA
public DeviceType DeviceType { get; }
public double CurrentRate { get; set; }
public double PowerRate { get; set; }
public string Key { get; }
public List<int> DevIndexes { get; }
public double TotalPower { get; }
public DateTime StartMinerTime { get; set; }
// , string miningLocation, string btcAdress, string worker
public GroupMiner(List<MiningPair> miningPairs, string key)
{
AlgorithmType = AlgorithmType.NONE;
DualAlgorithmType = AlgorithmType.NONE;
DevicesInfoString = "N/A";
CurrentRate = 0;
PowerRate = 0;
Key = key;
StartMinerTime = new DateTime(0);
if (miningPairs.Count > 0)
{
// sort pairs by device id
miningPairs.Sort((a, b) => a.Device.ID - b.Device.ID);
// init name scope and IDs
{
DeviceType deviceType = new DeviceType();
var deviceNames = new List<string>();
int MaxDevices = 0;
DevIndexes = new List<int>();
foreach (var pair in miningPairs.OrderBy(pair => pair.Device.IDByBus))
{
deviceType = pair.Device.DeviceType;
deviceNames.Add(pair.Device.NameCount);
DevIndexes.Add(pair.Device.Index);
MaxDevices = Math.Max(MaxDevices, deviceNames.Count);
//TotalPower += pair.Device.PowerUsage;
TotalPower += pair.Algorithm.PowerUsage;
}
if (MaxDevices >= 6)
{
if (deviceType == DeviceType.AMD)
{
DevicesInfoString = "AMD GPU " + ("{ " + string.Join(", ", deviceNames) + " }").Replace("GPU", "");
}
if (deviceType == DeviceType.NVIDIA)
{
DevicesInfoString = "NVIDIA GPU " + ("{ " + string.Join(", ", deviceNames) + " }").Replace("GPU", "");
}
if (deviceType == DeviceType.CPU)
{
DevicesInfoString = "CPU " + ("{ " + string.Join(", ", deviceNames) + " }").Replace("CPU", "");
}
} else
{
DevicesInfoString = ("{ " + string.Join(", ", deviceNames) + " }");
}
}
// init miner
{
var mPair = miningPairs[0];
DeviceType = mPair.Device.DeviceType;
Miner = MinerFactory.CreateMiner(mPair.Device, mPair.Algorithm);
if (Miner != null)
{
Miner.InitMiningSetup(new MiningSetup(miningPairs));
AlgorithmType = mPair.Algorithm.NiceHashID;
DualAlgorithmType = mPair.Algorithm.DualNiceHashID;
//StartMinerTime = DateTime.Now;
}
}
}
}
public void Stop()
{
if (Miner != null && Miner.IsRunning)
{
Miner.Stop();
// wait before going on
System.Threading.Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);
}
CurrentRate = 0;
PowerRate = 0;
}
public void End()
{
Miner?.End();
CurrentRate = 0;
PowerRate = 0;
}
public void Start(string miningLocation, string btcAdress, string worker)
{
if (Miner.IsRunning)
{
return;
}
// Wait before new start
System.Threading.Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);
var locationUrl = Globals.GetLocationUrl(AlgorithmType, miningLocation, Miner.ConectionType);
Miner.Start(locationUrl, btcAdress, worker);
}
}
}