Esempio n. 1
0
 private void Proto_ConnectionStateChanged(object sender, EventArgs e)
 {
     InvocationHelper.InvokeIfRequired(this, new Action(() =>
     {
         AddLineToStatus("Connection running: " + proto.IsRunning);
     }));
 }
Esempio n. 2
0
 private void HandleListDetectedDevicesProgress(byte[] data)
 {
     InvocationHelper.InvokeIfRequired(this, new Action(() =>
     {
         AddLineToStatus(String.Format("Detection progress: {0:D}%", data[0]));
     }));
 }
Esempio n. 3
0
 private void HandleRemoveAllowedResponse(MGBTCommandData cmd)
 {
     InvocationHelper.InvokeIfRequired(this, new Action(() =>
     {
         AddLineToStatus("Removed device: " + MacBytesToString(cmd.data) + ", status: " + cmd.Status);
     }));
 }
Esempio n. 4
0
        private void HandleGetClosestDevice(MGBTCommandData cmd)
        {
            if (cmd.Status == 0)
            {
                InvocationHelper.InvokeIfRequired(this, new Action(() =>
                {
                    List <MGBTDevice> devices = MGBTDevice.FromArray(cmd.data);
                    if (devices.Count > 0)
                    {
                        string riderName = "ILLEGAL";
                        string address   = MacBytesToString(devices[0].Address).ToUpperInvariant();
                        if (riderNames.ContainsKey(address))
                        {
                            riderName = riderNames[address];
                        }

                        closestDeviceLbl.Text = devices[0].ToString() + "; " + riderName;
                    }
                }));
            }
            else
            {
                InvocationHelper.InvokeIfRequired(this, new Action(() =>
                {
                    AddLineToStatus(String.Format("Error response: {0}", cmd.Status));
                }));
            }
        }
Esempio n. 5
0
        private void HandleGetCurrentTime(MGBTCommandData cmd)
        {
            try
            {
                var reader = new BinaryReader(new MemoryStream(cmd.data));

                while (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    UInt32 time     = reader.ReadUInt32();
                    byte   timeType = reader.ReadByte();

                    InvocationHelper.InvokeIfRequired(this, new Action(() =>
                    {
                        AddLineToStatus($"Got time: {time}");
                        AddLineToStatus($"Of type: {timeType}");
                    }));
                }
            }
            catch (Exception ex)
            {
                InvocationHelper.InvokeIfRequired(this, new Action(() =>
                {
                    AddLineToStatus($"Exception: {ex}");
                }));
            }
        }
Esempio n. 6
0
 private void HandleAddAllowedResponse(MGBTCommandData cmd)
 {
     InvocationHelper.InvokeIfRequired(this, new Action(() =>
     {
         AddLineToStatus("Added device: " + MacBytesToString(cmd.data) + ", status: " + cmd.Status);
         if (addingMultiple)
         {
             SendNextMultiAdd();
         }
     }));
 }
Esempio n. 7
0
        private void HandleListDetectedDevices(MGBTCommandData cmd)
        {
            switch (cmd.Status)
            {
            case 8:
                HandleListDetectedDevicesProgress(cmd.data);
                break;

            case 0:
                InvocationHelper.InvokeIfRequired(this, new Action(() =>
                {
                    AddLineToStatus("Started listing all devices");
                }));
                break;

            case 1:
                if (cmd.data.Length > 2)
                {
                    byte[] devicesData = new byte[cmd.data.Length - 2];
                    Array.Copy(cmd.data, 2, devicesData, 0, devicesData.Length);
                    if (cmd.data[0] == 0)
                    {
                        InvocationHelper.InvokeIfRequired(this, new Action(() =>
                        {
                            detectedDevicesLbx.Items.Clear();
                            HandleListDetectedDevicesDeviceData(devicesData);
                        }));
                    }
                    else
                    {
                        InvocationHelper.InvokeIfRequired(this, new Action(() =>
                        {
                            HandleListDetectedDevicesDeviceData(devicesData);
                        }));
                    }
                }
                else
                {
                    InvocationHelper.InvokeIfRequired(this, new Action(() =>
                    {
                        AddLineToStatus("Data not long enough");
                    }));
                }
                break;

            default:
                InvocationHelper.InvokeIfRequired(this, new Action(() =>
                {
                    AddLineToStatus(String.Format("Error response: {0}", cmd.Status));
                }));
                break;
            }
        }
Esempio n. 8
0
        private void HandleGetID(MGBTCommandData cmd)
        {
            try
            {
                var reader = new BinaryReader(new MemoryStream(cmd.data));

                byte   deviceType = reader.ReadByte();
                byte[] idDate     = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position));

                InvocationHelper.InvokeIfRequired(this, new Action(() =>
                {
                    AddLineToStatus($"Got type: {deviceType} with data: {BitConverter.ToString(idDate)}");
                }));
            }
            catch (Exception ex)
            {
                InvocationHelper.InvokeIfRequired(this, new Action(() =>
                {
                    AddLineToStatus($"Exception: {ex}");
                }));
            }
        }
Esempio n. 9
0
 private void HandleListAllowedDevices(MGBTCommandData cmd)
 {
     if ((cmd.data.Length > 2) && (cmd.Status == 1))
     {
         InvocationHelper.InvokeIfRequired(this, new Action(() =>
         {
             if (cmd.data[0] == 0)
             {
                 AllowedDevicesLbx.Items.Clear();
             }
             byte[] devicesData = new byte[cmd.data.Length - 2];
             Array.Copy(cmd.data, 2, devicesData, 0, devicesData.Length);
             List <MGBTDevice> devices = MGBTDevice.FromArray(devicesData);
             AllowedDevicesLbx.Items.AddRange(devices.ToArray());
         }));
     }
     else
     {
         InvocationHelper.InvokeIfRequired(this, new Action(() =>
         {
             AddLineToStatus(String.Format("Data length or error response: {0}", cmd.Status));
         }));
     }
 }
Esempio n. 10
0
        private void HandleGetLaps(MGBTCommandData cmd)
        {
            try
            {
                var           reader    = new BinaryReader(new MemoryStream(cmd.data));
                int           byteIndex = 0;
                int           time      = 0;
                int           lapIndex  = 0;
                StringBuilder lapLines  = new StringBuilder();
                while (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    byte aByte = reader.ReadByte();
                    time |= aByte << (8 * byteIndex);

                    byteIndex++;

                    if (byteIndex >= 3)
                    {
                        byteIndex = 0;
                        lapLines.AppendLine($"Got lap {lapIndex} with time {time}");
                        lapIndex++;
                    }
                }
                InvocationHelper.InvokeIfRequired(this, new Action(() =>
                {
                    AddLineToStatus(lapLines.ToString());
                }));
            }
            catch (Exception ex)
            {
                InvocationHelper.InvokeIfRequired(this, new Action(() =>
                {
                    AddLineToStatus($"Exception: {ex}");
                }));
            }
        }