Exemplo n.º 1
0
 protected void StartCoolDownTimerChecker()
 {
     if (ConfigManager.GeneralConfig.CoolDownCheckEnabled)
     {
         Helpers.ConsolePrint(MinerTag(), ProcessTag() + " Starting cooldown checker");
         if (_cooldownCheckTimer != null && _cooldownCheckTimer.Enabled)
         {
             _cooldownCheckTimer.Stop();
         }
         // cool down init
         _cooldownCheckTimer = new Timer()
         {
             Interval = MinCooldownTimeInMilliseconds
         };
         _cooldownCheckTimer.Elapsed += MinerCoolingCheck_Tick;
         _cooldownCheckTimer.Start();
         _currentCooldownTimeInSeconds     = MinCooldownTimeInMilliseconds;
         _currentCooldownTimeInSecondsLeft = _currentCooldownTimeInSeconds;
     }
     else
     {
         Helpers.ConsolePrint(MinerTag(), "Cooldown checker disabled");
     }
     CurrentMinerReadStatus = MinerApiReadStatus.NONE;
 }
Exemplo n.º 2
0
        protected async Task <ApiData> GetSummaryCpuAsync(string method = "", bool overrideLoop = false)
        {
            var ad = new ApiData(MiningSetup.CurrentAlgorithmType);

            try
            {
                CurrentMinerReadStatus = MinerApiReadStatus.WAIT;
                var dataToSend = GetHttpRequestNhmAgentStrin(method);
                var respStr    = await GetApiDataAsync(ApiPort, dataToSend);

                if (string.IsNullOrEmpty(respStr))
                {
                    CurrentMinerReadStatus = MinerApiReadStatus.NETWORK_EXCEPTION;
                    throw new Exception("Response is empty!");
                }
                if (respStr.IndexOf("HTTP/1.1 200 OK") > -1)
                {
                    respStr = respStr.Substring(respStr.IndexOf(HttpHeaderDelimiter) + HttpHeaderDelimiter.Length);
                }
                else
                {
                    throw new Exception("Response not HTTP formed! " + respStr);
                }

                dynamic resp = JsonConvert.DeserializeObject(respStr);

                if (resp != null)
                {
                    JArray totals = resp.hashrate.total;
                    foreach (var total in totals)
                    {
                        if (total.Value <string>() == null)
                        {
                            continue;
                        }
                        ad.Speed = total.Value <double>();
                        break;
                    }
                    if (ad.Speed == 0)
                    {
                        CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
                    }
                    else
                    {
                        CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;
                    }
                }
                else
                {
                    throw new Exception($"Response does not contain speed data: {respStr.Trim()}");
                }
            }
            catch (Exception ex)
            {
                Helpers.ConsolePrint(MinerTag(), ex.Message);
            }

            return(ad);
        }
Exemplo n.º 3
0
 /// <summary>
 /// decrement time for half current half time, if less then min ammend
 /// </summary>
 private void CoolDown()
 {
     if (_currentCooldownTimeInSeconds > MinCooldownTimeInMilliseconds)
     {
         _currentCooldownTimeInSeconds = MinCooldownTimeInMilliseconds;
         Helpers.ConsolePrint(MinerTag(), $"{ProcessTag()} Reseting cool time = {MinCooldownTimeInMilliseconds} ms");
         CurrentMinerReadStatus = MinerApiReadStatus.NONE;
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// increment time for half current half time, if more then max set restart
 /// </summary>
 private void CoolUp()
 {
     _currentCooldownTimeInSeconds *= 2;
     Helpers.ConsolePrint(MinerTag(), $"{ProcessTag()} Cooling UP, cool time is {_currentCooldownTimeInSeconds} ms");
     if (_currentCooldownTimeInSeconds > _maxCooldownTimeInMilliseconds)
     {
         CurrentMinerReadStatus = MinerApiReadStatus.RESTART;
         Helpers.ConsolePrint(MinerTag(), ProcessTag() + " MAX cool time exceeded. RESTARTING");
         Restart();
     }
 }
Exemplo n.º 5
0
        protected async Task <ApiData> GetSummaryCpuCcminerAsync()
        {
            // TODO aname
            string aname = null;
            var    ad    = new ApiData(MiningSetup.CurrentAlgorithmType);

            var dataToSend = GetHttpRequestNhmAgentStrin("summary");

            var resp = await GetApiDataAsync(ApiPort, dataToSend);

            if (resp == null)
            {
                Helpers.ConsolePrint(MinerTag(), ProcessTag() + " summary is null");
                CurrentMinerReadStatus = MinerApiReadStatus.NONE;
                return(null);
            }

            try
            {
                var resps = resp.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var res in resps)
                {
                    var optval = res.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (optval.Length != 2)
                    {
                        continue;
                    }
                    if (optval[0] == "ALGO")
                    {
                        aname = optval[1];
                    }
                    else if (optval[0] == "KHS")
                    {
                        ad.Speed = double.Parse(optval[1], CultureInfo.InvariantCulture) * 1000; // HPS
                    }
                }
            }
            catch
            {
                Helpers.ConsolePrint(MinerTag(), ProcessTag() + " Could not read data from API bind port");
                CurrentMinerReadStatus = MinerApiReadStatus.NONE;
                return(null);
            }

            CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;
            // check if speed zero
            if (ad.Speed == 0)
            {
                CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
            }

            return(ad);
        }
Exemplo n.º 6
0
        protected void ScheduleRestart(int ms)
        {
            var restartInMs = ConfigManager.GeneralConfig.MinerRestartDelayMS > ms ? ConfigManager.GeneralConfig.MinerRestartDelayMS : ms;

            Helpers.ConsolePrint(MinerTag(), ProcessTag() + $" Miner_Exited Will restart in {restartInMs} ms");
            if (ConfigManager.GeneralConfig.CoolDownCheckEnabled)
            {
                CurrentMinerReadStatus            = MinerApiReadStatus.RESTART;
                _needsRestart                     = true;
                _currentCooldownTimeInSecondsLeft = restartInMs;
            }
            else
            {
                // directly restart since cooldown checker not running
                Thread.Sleep(restartInMs);
                Restart();
            }
        }