コード例 #1
0
        protected override void SendCommand(byte[] cmd)
        {
            base.SendCommand(cmd);

            LogHelper.DebugConsoleLog(string.Format("Device {0} getting: {1}", this.Name, HexConversionHelper.ConvertToHexString(cmd)), ConsoleColor.Cyan);

            Thread.Sleep(commandWaitTime);
        }
コード例 #2
0
        private bool ProcessResponsePacket(byte[] response)
        {
            // Check for the response header
            if (response[0] == 0x55 && response[3] == 0x00)
            {
                if (response[1] == 0x20) // LTC nonce
                {
                    if (_currentWork != null)
                    {
                        int taskId = (int)(((long)response[11] << 24) | ((long)response[10] << 16) | ((long)response[9] << 8) | (long)response[8]);

                        if (taskId >= _currentTaskId)
                        {
                            long   nonce       = ((long)response[4] << 24) | ((long)response[5] << 16) | ((long)response[6] << 8) | (long)response[7];
                            string nonceString = string.Format("{0:X8}", nonce);

                            if (this.ValidateNonce(nonceString))
                            {
                                this.SubmitWork(_currentWork, nonceString);
                            }
                            else
                            {
                                this.OnInvalidNonce(_currentWork);
                            }

                            if (LogHelper.ShouldDisplay(LogVerbosity.Verbose))
                            {
                                LogHelper.ConsoleLog(string.Format("Device {0} submitting {1} for job {2}.", this.Name, nonceString, this._currentWork.JobId), ConsoleColor.DarkCyan, LogVerbosity.Verbose);
                            }
                        }
                        else
                        {
                            LogHelper.DebugConsoleLogError(string.Format("Device {0} discarding share with old task ID. Got {1}. Expected {2}.", this.Name, taskId, _currentTaskId));
                        }
                    }
                }
                else if (response[1] == 0xAA && response[2] == 0xC0)
                {
                    // Interaction Response
                    // TODO

                    LogHelper.DebugConsoleLog(string.Format("Got response from {0}: {1}", this.Name, HexConversionHelper.ConvertToHexString(response).Substring(0, 24)));
                }

                return(true);
            }

            return(false);
        }
コード例 #3
0
        private void SendWork(IPoolWork work, long startingNonce = 0)
        {
            try
            {
                if (work != null)
                {
                    timesNonZero = 0;

                    int    diffCode = 0xFFFF / work.Diff;
                    byte[] cmd      = _commandPacket;

                    cmd[3] = (byte)diffCode;
                    cmd[2] = (byte)(diffCode >> 8);

                    int offset = 4;

                    // Starting nonce
                    cmd[offset]     = (byte)startingNonce;
                    cmd[offset + 1] = (byte)(startingNonce >> 8);
                    cmd[offset + 2] = (byte)(startingNonce >> 16);
                    cmd[offset + 3] = (byte)(startingNonce >> 24);
                    offset         += 4;

                    byte[] headerBytes = work.Header.Reverse().ToArray();
                    headerBytes.CopyTo(cmd, offset);

                    LogHelper.DebugConsoleLog(string.Format("{0} getting: {1}", this.Name, HexConversionHelper.ConvertToHexString(cmd)));

                    LogHelper.DebugLogToFile(string.Format("{0} getting: {1}", this.Name, HexConversionHelper.ConvertToHexString(cmd)), deviceLogFile);

                    // Send work to the miner
                    this.currentWork = work;
                    this.usbPort.DiscardInBuffer();

                    this.SendCommand(cmd);
                }
            }
            catch (Exception e)
            {
                LogHelper.LogError(e);

                throw e;
            }
        }