Пример #1
0
        private void connectToDevice(object sender, EventArgs e)
        {
            ToolStripMenuItem _sender = (ToolStripMenuItem)sender;

            string _port    = _sender.Text.Split(':')[0];
            int    _address = Int32.Parse(_sender.Text.Split(':')[1]);

            // Disconnect
            if (MySpdReader != null && MySpdReader.IsConnected)
            {
                if (MySpdReader.Disconnect())
                {
                    Logger($"{MySpdReader.PortName}:{MySpdReader.EepromAddress} disconnected");
                }

                if (!MySpdReader.IsConnected)
                {
                    // Uncheck all devices
                    ToolStripItem[] _existingDeviceItem = toolStripDeviceButton.DropDownItems.Find("FoundDevicePortAddress", false);

                    if (_existingDeviceItem.Length > 0)
                    {
                        foreach (ToolStripMenuItem toolStripItem in _existingDeviceItem)
                        {
                            toolStripItem.Checked = false;
                        }
                    }
                    //_sender.Checked = false;
                }

                // Do not reconnect if checked item was clicked
                if (MySpdReader.PortName == _port && MySpdReader.EepromAddress == _address)
                {
                    return;
                }
            }

            // Connect
            if (MySpdReader == null || !MySpdReader.IsConnected)
            {
                MySpdReader         = new Device(_port, _address);
                MySpdReader.SpdSize = Eeprom.GetSpdSize(MySpdReader);
                if (MySpdReader.Connect())
                {
                    _sender.Checked = true;
                    rt = Eeprom.GetRamType(MySpdReader);
                    Logger($"{_port}:{_address} connected ({rt})");
                }
            }
        }
Пример #2
0
        private byte[] fixCrc(byte[] input)
        {
            byte[] _spd = new byte[input.Length];

            for (int i = 0; i < _spd.Length; i++)
            {
                _spd[i] = input[i];
            }

            int[] headerStart  = new int[0];
            int   headerLength = 0;
            int   crcPosition  = 126;

            // Get DDR4 CRC data
            if (Eeprom.GetRamType(input) == RamType.DDR4)
            {
                // Read 126 bytes from headersStart positions
                headerStart  = new [] { 0, 128 };
                headerLength = 126;
            }

            // Get DDR3 CRC data
            if (Eeprom.GetRamType(input) == RamType.DDR3)
            {
                headerStart = new [] { 0 };
                // Exclude SN from CRC?
                headerLength = ((input[0] >> 7) == 1) ? 117 : 126;
            }

            // Calculate DDR3 and DDR4 CRC
            if (Eeprom.GetRamType(input) == RamType.DDR4 || Eeprom.GetRamType(input) == RamType.DDR3)
            {
                foreach (int _headerStart in headerStart)
                {
                    byte[] header = new byte[headerLength];
                    for (int i = 0; i < headerLength; i++)
                    {
                        header[i] = _spd[i + _headerStart];
                    }

                    ushort crc = Eeprom.Crc16(header);

                    byte CrcLsb = (byte)(crc & 0xff);
                    byte CrcMsb = (byte)(crc >> 8);

                    if (_spd[_headerStart + crcPosition + 0] != CrcLsb ||                     // MSB
                        _spd[_headerStart + crcPosition + 1] != CrcMsb)                       //LSB

                    {
                        _spd[_headerStart + crcPosition + 0] = CrcLsb;
                        _spd[_headerStart + crcPosition + 1] = CrcMsb;
                    }
                }
            }

            // Calculate SDR - DDR2 CRC
            else if (Eeprom.GetRamType(input) != RamType.UNKNOWN)
            {
                //headerStart = new [] { 0 };
                headerLength = 63;
                crcPosition  = 64;
                byte[] header = new byte[headerLength];

                for (int i = 0; i < headerLength; i++)
                {
                    header[i] += _spd[i];
                }

                byte crc = (byte)Eeprom.Crc(header);

                if (_spd[crcPosition - 1] != crc)
                {
                    _spd[crcPosition - 1] = crc;
                }
            }

            return(_spd);
        }
Пример #3
0
        private void timerInterfaceUpdater_Tick(object sender, EventArgs e)
        {
            // Enable or disable EEPROM toolbar buttons and menus depending on device state
            bool _deviceConnectionEstablished = MySpdReader != null && MySpdReader.IsConnected;
            bool _eepromWriteable             = _deviceConnectionEstablished && SpdContents.Length != 0;
            bool _progressBarActive           = statusProgressBar.Value == statusProgressBar.Minimum || statusProgressBar.Value == statusProgressBar.Maximum;

            readEeprom_button.Enabled           = _deviceConnectionEstablished && _progressBarActive;
            readToolStripMenuItem.Enabled       = _deviceConnectionEstablished && _progressBarActive;
            disconnectToolStripMenuItem.Enabled = _deviceConnectionEstablished;
            testToolStripMenuItem.Enabled       = _deviceConnectionEstablished;
            clearToolStripMenuItem.Enabled      = _deviceConnectionEstablished && _progressBarActive && rt == RamType.DDR4;
            enableToolStripMenuItem.Enabled     = _deviceConnectionEstablished && _progressBarActive && rt == RamType.DDR4;
            enableRswpButton.Enabled            = _deviceConnectionEstablished && _progressBarActive && rt == RamType.DDR4;
            clearRswpButton.Enabled             = _deviceConnectionEstablished && _progressBarActive && rt == RamType.DDR4;
            writeEeprom_button.Enabled          = _eepromWriteable && _progressBarActive;
            writeToolStripMenuItem.Enabled      = _eepromWriteable && _progressBarActive;
            refreshToolStripMenuItem.Enabled    = !_deviceConnectionEstablished;

            // Enable or disable file operations
            bool _spdLoaded = SpdContents.Length != 0;

            toolSaveFile_button.Enabled = _spdLoaded;
            //crcDropdownMenu.Enabled        = toolSaveFile_button.Enabled;
            saveToolStripMenuItem.Enabled    = _spdLoaded;
            saveasToolStripMenuItem.Enabled  = _spdLoaded;
            copyHexToolStripMenuItem.Enabled = _spdLoaded;

            // CRC status
            if (_spdLoaded && (Eeprom.GetRamType(SpdContents) != RamType.UNKNOWN))
            {
                statusBarCrcStatus.Visible      = statusProgressBar.Value == statusProgressBar.Maximum;
                statusBarCrcStatus.Text         = (crcValidChecksum) ? "CRC OK" : "CRC Error";
                statusBarCrcStatus.ForeColor    = (crcValidChecksum) ? Color.FromArgb(128, 255, 128) : Color.White;
                statusBarCrcStatus.BackColor    = (crcValidChecksum) ? Color.FromArgb(255, 0, 64, 0) : Color.FromArgb(192, 255, 0, 0);
                fixCrcToolStripMenuItem.Enabled = !crcValidChecksum && _spdLoaded;
            }
            else
            {
                // Hide CRC status for non DDR4 RAM
                statusBarCrcStatus.Visible = false;
            }

            // RAM type
            if (_spdLoaded)
            {
                toolStripStatusRamType.Text    = $"{Eeprom.GetRamType(SpdContents)}";              //, {Eeprom.GetModuleModelName(SpdContents)}
                toolStripStatusRamType.Visible = true;
            }

            // Status progress bar (hide when value is 0 or maximum)
            //statusProgressBar.Visible = (statusProgressBar.Value > 0 && statusProgressBar.Value < statusProgressBar.Maximum);
            statusProgressBar.Visible = !_progressBarActive;

            // Connection Status
            statusBarConnectionStatus.Enabled   = _deviceConnectionEstablished;
            statusBarConnectionStatus.ForeColor = (_deviceConnectionEstablished) ? Color.Navy : SystemColors.Control;
            statusBarConnectionStatus.Text      = (_deviceConnectionEstablished) ? $"Connected to {MySpdReader.PortName}:{MySpdReader.EepromAddress}" : "Not connected";
            toolStripDeviceButton.Text          = (_deviceConnectionEstablished) ? $"{MySpdReader.PortName}:{MySpdReader.EepromAddress}" : "Device";

            // Toolbar device button
            toolStripDeviceButton.Text        = (_deviceConnectionEstablished) ? $"{MySpdReader.PortName}:{MySpdReader.EepromAddress}" : "Device";
            toolStripDeviceButton.ToolTipText = (_deviceConnectionEstablished) ? $"Connected to {MySpdReader.PortName}:{MySpdReader.EepromAddress}" : "Select device port and address";

            // Split container looks
            splitContainerViewer.Panel1.MinimumSize = labelTopOffsetHex.GetPreferredSize(new Size());
            if (splitContainerViewer.SplitterDistance < splitContainerViewer.Panel1.MinimumSize.Width)
            {
                splitContainerViewer.SplitterDistance = splitContainerViewer.Panel1.MinimumSize.Width;
            }
            splitContainerViewer.Panel2.MinimumSize = labelTopOffsetAscii.GetPreferredSize(new Size());
            if (splitContainerViewer.SplitterDistance > splitContainerViewer.Panel1.MinimumSize.Width + splitContainerViewer.Panel2.MinimumSize.Width)
            {
                splitContainerViewer.SplitterDistance = splitContainerViewer.Panel1.MinimumSize.Width + splitContainerViewer.Panel2.MinimumSize.Width;
            }

            // Main tab label
            if (currentFileName != "" && tabPageMain.Text != Path.GetFileName(currentFileName))
            {
                //tabPageMain.Text = Path.GetFileName(currentFileName);
            }

            // Main tab color
            //if (tabControlMain.SelectedTab == tabPageMain) {
            //	tabPageMain.ForeColor = SystemColors.ControlText;
            //}

            // Disable Save log button if log is empty
            buttonSaveLog.Enabled = loggerBox.Items.Count > 0;

            // ASCII textbox size to match ascii offset box width
            //Size asciiBoxSize = textBoxAscii.Size;
            //asciiBoxSize.Width = labelTopOffsetAscii.Size.Width;
        }