GetLastActiveTime() public method

Get DateTime when miner sent UDP status packet.
public GetLastActiveTime ( ) : System.DateTime
return System.DateTime
Exemplo n.º 1
0
        public APIData GetSummary()
        {
            string  resp;
            string  aname = null;
            APIData ad    = new APIData();

            if (AlgoNameIs("daggerhashimoto"))
            {
                try
                {
                    FillAlgorithm("daggerhashimoto", ref ad);
                    if (ER.GetIsRunning() && ER.GetDAGprogress() != 100 && ER.GetSpeed() < 1)
                    {
                        ad.AlgorithmName = "Creating DAG " + ER.GetDAGprogress().ToString() + "%";
                        aname            = "Creating DAG File";
                        ad.Speed         = 0;
                    }
                    else
                    {
                        double time = 10;
                        if (ER.GetIsRunning())
                        {
                            time = 30;
                        }
                        if ((DateTime.Now.Subtract(ER.GetLastActiveTime())).TotalSeconds > time)
                        {
                            Helpers.ConsolePrint(MinerDeviceName, "ethminer is not running.. restarting..");
                            Restart();
                            return(null);
                        }

                        ad.Speed = ER.GetSpeed() * 1000 * 1000;
                    }
                }
                catch (Exception e)
                {
                    Helpers.ConsolePrint(MinerDeviceName, "GetSummary: " + e.Message);
                    return(null);
                }
            }
            else
            {
                resp = GetAPIData(APIPort, "summary");
                if (resp == null)
                {
                    return(null);
                }

                try
                {
                    string[] resps;

                    if (!MinerDeviceName.Equals("AMD_OpenCL"))
                    {
                        resps = resp.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < resps.Length; i++)
                        {
                            string[] optval = resps[i].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
                            }
                        }
                    }
                    else
                    {
                        // Checks if all the GPUs are Alive first
                        string resp2 = GetAPIData(APIPort, "devs");
                        if (resp2 == null)
                        {
                            return(null);
                        }

                        string[] checkGPUStatus = resp2.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                        for (int i = 1; i < checkGPUStatus.Length - 1; i++)
                        {
                            if (!checkGPUStatus[i].Contains("Status=Alive"))
                            {
                                Helpers.ConsolePrint(MinerDeviceName, "GPU " + i + ": Sick/Dead/NoStart/Initialising/Disabled/Rejecting/Unknown");
                                return(null);
                            }
                        }

                        resps = resp.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                        if (resps[1].Contains("SUMMARY"))
                        {
                            string[] data = resps[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                            // Get miner's current total speed
                            string[] speed = data[4].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                            // Get miner's current total MH
                            double total_mh = Double.Parse(data[18].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries)[1], new CultureInfo("en-US"));

                            ad.Speed = Double.Parse(speed[1]) * 1000;

                            aname = SupportedAlgorithms[CurrentAlgo].MinerName;

                            if (total_mh <= PreviousTotalMH)
                            {
                                Helpers.ConsolePrint(MinerDeviceName, "SGMiner might be stuck as no new hashes are being produced");
                                Helpers.ConsolePrint(MinerDeviceName, "Prev Total MH: " + PreviousTotalMH + " .. Current Total MH: " + total_mh);
                                return(null);
                            }

                            PreviousTotalMH = total_mh;
                        }
                        else
                        {
                            ad.Speed = 0;
                        }
                    }
                }
                catch
                {
                    return(null);
                }

                FillAlgorithm(aname, ref ad);
            }

            return(ad);
        }