Esempio n. 1
0
        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            switch ((ColumnIndex)e.ColumnIndex)
            {
            case ColumnIndex.Device:
                break;

            default:
                e.Cancel = true;
                return;
            }

            DataGridViewRow row = dataGridView1.Rows[e.RowIndex];

            ConnectionRow connectionRow = row.Tag as ConnectionRow;

            deviceNameEditOriginalValue = row.Cells[(int)ColumnIndex.Device].Value.ToString();

            row.Cells[(int)ColumnIndex.Device].Value = connectionRow.Connection.Settings.DeviceInformation.DeviceName.Value;
        }
Esempio n. 2
0
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            switch ((ColumnIndex)e.ColumnIndex)
            {
            case ColumnIndex.Device:
                break;

            default:
                return;
            }

            DataGridViewRow row = dataGridView1.Rows[e.RowIndex];

            ConnectionRow connectionRow = row.Tag as ConnectionRow;

            string newValue = row.Cells[(int)ColumnIndex.Device].Value.ToString();

            if (newValue.Equals(deviceNameEditOriginalValue) == true)
            {
                return;
            }

            connectionRow.Connection.Settings.DeviceName.Value = newValue;

            this.WriteSettings(connectionsRows, true, new[] { connectionRow.Connection.Settings.DeviceName });
        }
Esempio n. 3
0
        private void SelectSynchronisationMaster(ConnectionRow selectedConnectionRow)
        {
            this.SetSettingValueOnAllDevices(connectionsRows.Select(connectionRowItem => connectionRowItem.Connection.Settings.SynchronisationMasterEnabled), false);

            selectedConnectionRow.Connection.Settings.SynchronisationMasterEnabled.Value = true;

            this.WriteSettings(connectionsRows, true, connectionsRows.Select(connectionRowItem => connectionRowItem.Connection.Settings.SynchronisationMasterEnabled));

            foreach (ConnectionRow connectionRow in connectionsRows)
            {
                connectionRow.Cells[(int)ColumnIndex.Master] =
                    connectionRow.Connection.Settings.SynchronisationMasterEnabled.HasRemoteValue == true &&
                    connectionRow.Connection.Settings.SynchronisationMasterEnabled.RemoteValue == true;
            }
        }
Esempio n. 4
0
        private void SetSynchronisationMasterTime()
        {
            try
            {
                ConnectionRow synchronisationMasterRow = SynchronisationMasterRow;

                this.SendCommand(synchronisationMasterRow, true, Command.Time, OscTimeTag.Now);

                this.SendCommand(
                    (from connectionRow in connectionsRows
                     where connectionRow != synchronisationMasterRow
                     select connectionRow).ToList(),
                    true,
                    Command.Time, new OscTimeTag(0));
            }
            catch (Exception ex)
            {
                this.InvokeShowError(ex.Message);
            }
        }
Esempio n. 5
0
        private void OnSyncMessage(OscMessage message)
        {
            if (message.Count != 1)
            {
                return;
            }

            if ((message[0] is OscTimeTag) == false)
            {
                return;
            }

            ConnectionRow synchronisationMasterRow = SynchronisationMasterRow;

            synchronisationMasterTimeTimeStamp = DateTime.UtcNow;

            DateTime synchronisationMasterTime = ((OscTimeTag)message[0]).ToDataTime();

            Invoke(new MethodInvoker(() =>
            {
                synchronisationMasterTimeLabel.Text = string.Format(synchronisationMasterTimeLabel.Tag.ToString(), NgimuApi.Helper.DateTimeToString(synchronisationMasterTime, false));
            }));

            if (synchronisationMasterRow == null)
            {
                return;
            }

            if (Equals(((UdpConnectionInfo)synchronisationMasterRow.Connection.ConnectionInfo).SendIPAddress, message.Origin.Address) == false ||
                message.Origin.Port != SynchronisationMasterPort)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendLine("More than one synchronisation master is sending on the network.");

                //this.InvokeShowError(sb.ToString());

                sb.AppendLine();
                sb.Append("Click OK to configure the first device as the synchronisation master.");

                Invoke(new MethodInvoker(() =>
                {
                    switch (this.ShowError(sb.ToString(), MessageBoxButtons.OKCancel))
                    {
                    case DialogResult.OK:
                        SelectSynchronisationMaster(connectionsRows[0]);
                        break;

                    case DialogResult.Cancel:
                        DisconnectAll();
                        return;

                    default:
                        break;
                    }
                }));

                // destroy and recreate the sync master listener to clear out any junk messages that might have backed up when waiting for user input
                synchronisationMasterListener?.Dispose();
                CreateSynchronisationMasterListener();

                return;
            }

            if (synchronisationMasterTimeConfirmedByUser == true)
            {
                return;
            }

            if (synchronisationMasterTime < DateTime.Now.AddSeconds(-30) || synchronisationMasterTime > DateTime.Now.AddSeconds(30))
            {
                synchronisationMasterTimeConfirmedByUser = true;

                StringBuilder sb = new StringBuilder();

                sb.AppendLine("Synchronisation master time does not match computer time.");
                sb.AppendLine();
                sb.Append("Set synchronisation master time now?");

                if (this.InvokeShowWarning(sb.ToString(), MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Invoke(new MethodInvoker(SetSynchronisationMasterTime));
                }
            }
        }
Esempio n. 6
0
        private void searchForConnectionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            disconnectAllToolStripMenuItem_Click(sender, e);

            DialogResult result;

            using (SearchingForConnectionsDialog searchDialog = new SearchingForConnectionsDialog()
            {
                ConnectionSearchType = ConnectionSearchTypes.Udp,
                AllowMultipleConnections = true
            })
            {
                if (searchDialog.ShowDialog(this) == DialogResult.Cancel)
                {
                    return;
                }

                List <Connection> newConnections;

                result = ConnectToAllDevices(searchDialog.ConnectionSearchResults, out newConnections);

                foreach (Connection connection in newConnections)
                {
                    ConnectionRow connectionRow = new ConnectionRow();

                    connectionRow.Connection = connection;

                    connectionsRows.Add(connectionRow);

                    dataLogger?.ActiveConnections.Add(connection);
                    sendRates?.ActiveConnections.Add(connectionRow);

                    connection.Message += Connection_Message;

                    object[]   cells      = new object[Enum.GetNames(typeof(ColumnIndex)).Length];
                    DateTime[] timestamps = new DateTime[cells.Length];

                    StringBuilder nameBuilder = new StringBuilder();

                    nameBuilder.AppendLine(connection.Settings.DeviceInformation.DeviceName.Value);
                    nameBuilder.AppendLine(connection.Settings.DeviceInformation.SerialNumber.Value);

                    cells[(int)ColumnIndex.Device] = nameBuilder.ToString().Trim();

                    cells[(int)ColumnIndex.Master]           = connectionRow.Connection.Settings.SynchronisationMasterEnabled.Value;
                    cells[(int)ColumnIndex.MessagesReceived] = "Unknown";
                    cells[(int)ColumnIndex.MessagesSent]     = "Unknown";
                    cells[(int)ColumnIndex.Battery]          = new DataGridViewProgressValue()
                    {
                        Value = 0, Text = "Unknown"
                    };
                    cells[(int)ColumnIndex.Signal] = new DataGridViewProgressValue()
                    {
                        Value = 0, Text = "Unknown"
                    };
                    cells[(int)ColumnIndex.Identify] = "Identify";

                    timestamps[(int)ColumnIndex.Device]           = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.Master]           = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.MessagesReceived] = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.MessagesSent]     = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.Battery]          = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.Signal]           = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.Identify]         = DateTime.UtcNow;

                    connectionRow.Timestamps = timestamps;
                    connectionRow.Cells      = cells;
                    connectionRow.Row        = dataGridView1.Rows[dataGridView1.Rows.Add(cells)];
                    connectionRow.Row.Tag    = connectionRow;

                    connectionRow.Information = new IconInfo()
                    {
                        Image = icons[(int)ConnectionIcon.Information], Message = "", MessageIcon = MessageBoxIcon.Information, Visible = false
                    };
                    connectionRow.Warning = new IconInfo()
                    {
                        Image = icons[(int)ConnectionIcon.Warning], Message = "", MessageIcon = MessageBoxIcon.Warning, Visible = false
                    };
                    connectionRow.Error = new IconInfo()
                    {
                        Image = icons[(int)ConnectionIcon.Error], Message = "", MessageIcon = MessageBoxIcon.Error, Visible = false
                    };

                    (connectionRow.Row.Cells[(int)ColumnIndex.Device] as TextAndIconCell).Add(connectionRow.Information);
                    (connectionRow.Row.Cells[(int)ColumnIndex.Device] as TextAndIconCell).Add(connectionRow.Warning);
                    (connectionRow.Row.Cells[(int)ColumnIndex.Device] as TextAndIconCell).Add(connectionRow.Error);

                    connectionRow.Connection.DeviceError.Received += (s, args) =>
                    {
                        StringBuilder stringBuilder = new StringBuilder();

                        stringBuilder.AppendLine("Error message received:");
                        stringBuilder.AppendLine();
                        stringBuilder.AppendLine(connectionRow.Connection.DeviceError.Message);

                        connectionRow.SetInformation(stringBuilder.ToString());
                    };

                    connectionRow.Connection.Battery.Received += (s, arg) =>
                    {
                        string text = String.Format("{0}%" + Environment.NewLine, connectionRow.Connection.Battery.Percentage.ToString("F0", CultureInfo.InvariantCulture));

                        if (connectionRow.Connection.Battery.IsChargerConnected == true)
                        {
                            text += String.IsNullOrEmpty(connectionRow.Connection.Battery.ChargerState) == false ? connectionRow.Connection.Battery.ChargerState : String.Empty;
                        }
                        else
                        {
                            text += NgimuApi.Helper.TimeSpanToString(connectionRow.Connection.Battery.TimeToEmpty, TimeSpanStringFormat.Shorthand) + " remaining";
                        }

                        connectionRow.Timestamps[(int)ColumnIndex.Battery] = DateTime.UtcNow;
                        connectionRow.Cells[(int)ColumnIndex.Battery]      = new DataGridViewProgressValue()
                        {
                            Value = (int)connectionRow.Connection.Battery.Percentage, Text = text
                        };
                    };

                    connectionRow.Connection.Rssi.Received += (s, arg) =>
                    {
                        string text = String.Format("{0}%" + Environment.NewLine, connectionRow.Connection.Rssi.Percentage.ToString("F0", CultureInfo.InvariantCulture));
                        text += connectionRow.Connection.Rssi.Power.ToString("F2", CultureInfo.InvariantCulture) + " dBm";

                        connectionRow.Timestamps[(int)ColumnIndex.Signal] = DateTime.UtcNow;
                        connectionRow.Cells[(int)ColumnIndex.Signal]      = new DataGridViewProgressValue()
                        {
                            Value = (int)connectionRow.Connection.Rssi.Percentage, Text = text
                        };
                    };
                }
            }

            sendRates?.UpdateColumns();
            dataLogger?.UpdateConnections();

            if (result == DialogResult.Cancel)
            {
                DisconnectAll();
                return;
            }

            if (connectionsRows.Count == 0)
            {
                DisconnectAll();
                return;
            }

            sendCommandToolStripMenuItem.Enabled = true;

            SetTitle();

            VerifyConfiguration();

            CreateSynchronisationMasterListener();

            ApplySort();
        }