private List <byte[]> ConfigureDriveForWebPageUploadAndGenerateArrayBuffer(int firmwareVersion, string motorIP, byte[] fileByteArray) { const int headerLength = 4; int length = fileByteArray.Count(); string output = new NetworkTools.TimedWebClient { Timeout = WebRequestTimeoutMs }.DownloadString("http://" + motorIP + "/getData.cgi?clear"); byte[] fileByteArrayWithHeader = new byte[length + headerLength]; // reserve 1MB fileByteArray.CopyTo(fileByteArrayWithHeader, headerLength); // Add web page length to first 4 bytes fileByteArrayWithHeader[3] = (byte)((length >> 24) & 0xFF); fileByteArrayWithHeader[2] = (byte)((length >> 16) & 0xFF); fileByteArrayWithHeader[1] = (byte)((length >> 8) & 0xFF); fileByteArrayWithHeader[0] = (byte)(length & 0xFF); Array.Resize(ref fileByteArrayWithHeader, length + headerLength); return(ComposeArrayBufferToSend(firmwareVersion, 0, fileByteArrayWithHeader)); }
private void UpdateProgressBar(object sender, EventArgs ev) { // Check if all update tasks are completed bool allTasksCompleted = true; foreach (Task t in _updateTasks) { if (!t.IsCompleted) { allTasksCompleted = false; } } if (allTasksCompleted && _updateStarted) { _updateTasks.Clear(); _updateStarted = false; // Re discover drives lock (_locker) { _oldCountOfHDrives = 0; _foundHdrives.Clear(); _buttonVisibility = false; _hdriveSearcher.DetectHDrives(); } } if (_foundHdrives.Count != _oldCountOfHDrives) { dataGridView.Rows.Clear(); foreach (HDriveInformation.HDriveData e in _foundHdrives) { bool error = false; // Check if bootLoader is active if (e.FwVersion == 0) { try { string errorTxt = new NetworkTools.TimedWebClient { Timeout = WebRequestTimeoutMs }.DownloadString("http://" + e.Ip.ToString() + "/getData.cgi?txt"); if (errorTxt.Contains("crash") || errorTxt.Contains("not to work") || errorTxt.Contains("reset")) { error = true; } } catch (Exception err) { _debugConsoleText = err.ToString() + debugConsole; } } var row0 = new object[] { e.Ip.ToString(), e.Mac.ToString(), e.SerialNumber.ToString(), e.FwVersion.ToString(), e.GuiVersion.ToString(), e.BootLoaderVersion.ToString(), e.AppId.ToString(), e.Progress }; dataGridView.Rows.Add(row0); if (error) { dataGridView.Rows[dataGridView.Rows.Count - 1].DefaultCellStyle.BackColor = Color.Red; // your color settings } dataGridView.Invalidate(); } _oldCountOfHDrives = _foundHdrives.Count; } foreach (HDriveInformation.HDriveData dt in _updatedHDrives) { int rowIndex = GetRowIndexFromIp(dt.Ip); if (rowIndex >= 0) { dataGridView.Rows[rowIndex].Cells[7].Value = dt.Progress; } } _radialProgressbar1 = _hdriveSearcher.PingSweep.ProgressBarValue1; _radialProgressbar2 = _hdriveSearcher.PingSweep.ProgressBarValue2; // progressBar_fwUpdate.Value = progressBarValue; statusLabel.Text = _statusLabelText; debugConsole.Text = _debugConsoleText; btn_upload_webpage.Enabled = _buttonVisibility; btn_FW_Update.Enabled = _buttonVisibility; btn_refresh.Enabled = _buttonVisibility; btn_refreshHDriveData.Enabled = _buttonVisibility; dataGridView.Visible = _gridViewVisibility; Invalidate(); }