Exemple #1
0
        private void ScanComplite(object sender, TiEventArgs e)
        {
            if (grdTargets.InvokeRequired)
            {
                Invoke(new MethodInvoker(delegate { ScanComplite(sender, e); }));
            }
            else
            {
                _in_scan = false;
                if (_in_test == false)
                {
                    btnScan.Enabled  = true;
                    btnStart.Enabled = true;
                    btnStop.Enabled  = true;
                }
                else
                {
                    foreach (DataGridViewRow row in grdTargets.Rows)
                    {
                        if (row.Tag == null)
                        {
                            row.Tag = 0;
                        }
                        BleDevice device = BleDevices.GetDeviceByMac(row.Cells["colMac"].Value.ToString());
                        if ((int)row.Tag > 0 || ((device != null) && (device.Connected)))
                        {
                            row.DefaultCellStyle.BackColor = Color.White;
                        }
                        else
                        {
                            row.DefaultCellStyle.BackColor = Color.OrangeRed;
                        }
                        if (csv != null)
                        {
                            string line = string.Format("{4,3},{0,8},{1,-15},{2,4},{5,12},{6,-7},{3}" /*+ Environment.NewLine*/,
                                                        row.Cells["colMAC"].Value.ToString(),
                                                        row.Cells["colDeviceName"].Value.ToString(),
                                                        row.Cells["colRSSI"].Value.ToString(),
                                                        DateTime.Now.ToString(),
                                                        (int)row.Tag,
                                                        (row.Cells["colVersion"].Value == null ? "" : row.Cells["colVersion"].Value.ToString()),
                                                        device != null ? device.Connected.ToString() : "false");
                            try
                            {
                                UpdateDeviceRssi(row.Cells["colMAC"].Value.ToString(), 0);
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex, "Failed to set RSSI to 0");
                            }
                            File.AppendAllText(CsvFilename, line + Environment.NewLine);
                            //csv.Info(line);
                        }
                        row.Tag = 0;
                    }

                    TestConnection();
                }
            }
        }
        public SoftwareUpgrade(string MacAddress, IBleCommands Ble, byte[] Image)
        {
            _status     = UPGRADE_STATUS.NOT_STARTED;
            _macAddress = MacAddress;
            _ble        = Ble;
            _image      = Image;
            BleDevices devices = new BleDevices();

            dps = devices[_macAddress];
        }
Exemple #3
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            _in_test                   = true;
            btnInit.Enabled            = false;
            btnScan.Enabled            = false;
            btnStart.Enabled           = false;
            btnStop.Enabled            = true;
            btnClear.Enabled           = false;
            chkCheckAll.Enabled        = false;
            chkCheckConnection.Enabled = false;
            //Send cancel discovery

            _checkConnection = chkCheckConnection.Checked;
            CsvFilename      = txtCsvFile.Text;

            /*
             * FileTarget target1 = LogManager.Configuration.FindTargetByName("LogFileTarget") as FileTarget;
             * NLog.Layouts.Layout logfilename = target1.FileName;*/
            FileTarget target = LogManager.Configuration.FindTargetByName("CsvFileTarget") as FileTarget;

            target.FileName = CsvFilename;

            //target1.FileName = logfilename;
            DataGridViewCheckBoxCell oCell;
            List <DataGridViewRow>   removeRows = new List <DataGridViewRow>();

            BleDevices.Clear();
            foreach (DataGridViewRow row in grdTargets.Rows)
            {
                row.Tag = 0;
                oCell   = row.Cells["colTest"] as DataGridViewCheckBoxCell;
                bool bChecked = (null != oCell && null != oCell.Value && true == (bool)oCell.Value);
                if (bChecked != true)
                {
                    removeRows.Add(row);
                }
                else
                {
                    BleDevices.Add(new BleDevice(row.Cells["colMAC"].Value.ToString(),
                                                 row.Cells["colDeviceName"].Value.ToString()));
                }
            }

            foreach (DataGridViewRow row in removeRows)
            {
                grdTargets.Rows.Remove(row);
            }
            UpdateRowCounter();
            tmrDiscover.Interval = 1000;
            tmrDiscover.Start();
        }
Exemple #4
0
        private void TestConnection()
        {
            if (_checkConnection == false)
            {
                return;
            }

            #region Disconnect the last connected device
            if (last_connected_device != null)
            {
                if (last_connected_device.Connected == true)
                {
                    _dongle.TerminateLinkRequest(last_connected_device.Handle);
                }
            }
            #endregion

            #region Connect to the next device
            next_dps_to_connect++;
            if (grdTargets.Rows.Count <= next_dps_to_connect)
            {
                next_dps_to_connect = 0;
            }

            DataGridViewRow row    = grdTargets.Rows[next_dps_to_connect];
            BleDevice       device = BleDevices.GetDeviceByMac(row.Cells["colMAC"].Value.ToString());
            last_connected_device = device;
            if (device != null)
            {
                if (!device.Connected)
                {
                    _dongle.TiConnect(device.MacBytes());
                }
            }
            #endregion
        }
Exemple #5
0
        public void analyzePacket(TiCommand Replay)
        {
            if (Replay.type == TiCommand.TI_PROTOCOL_EVENT_TYPE_MESSAGE)
            {
                switch (Replay.eventOpCode)
                {
                case TI_PROTOCOL_EVENT_OPCODE_INIT_SUCCESS:
                {
                    HCI_ExtentionCommandStatus h = new HCI_ExtentionCommandStatus(Replay.data);
                    GetParam(GAP_ParamId.TGAP_CONN_EST_INT_MIN);
                    Thread.Sleep(200);
                    GetParam(GAP_ParamId.TGAP_CONN_EST_INT_MAX);
                    Thread.Sleep(200);
                    GetParam(GAP_ParamId.TGAP_CONN_EST_LATENCY);
                    Thread.Sleep(200);
                    init_success = true;
                    if (OnHardwareInitComplite != null)
                    {
                        OnHardwareInitComplite(this, new TiEventArgs());
                    }
                }
                break;

                case TI_PROTOCOL_EVENT_OPCODE_ESTABLISH_LINK:
                {
                    EstablishLink l1 = new EstablishLink(Replay.data);
                    CommandReplyed = true;
                    BleDevice dps = BleDevices.GetDeviceByMac(l1.MacAddress.ToString());
                    if (dps != null)
                    {
                        dps.Handle    = l1.ConnectionHandle;
                        dps.Connected = true;
                        //ReadCharValueByHandle(l1.ConnectionHandle, 0x1f); //type 0x2803
                    }
                    device_connected = true;
                    OnLinkEstablished(this, new TiEventArgs(l1.MacAddress, "TI_PROTOCOL_EVENT_OPCODE_ESTABLISH_LINK"));
                }
                break;

                case ATT_HANDLE_VALUE_NOTIFICATION:
                    HandleValueNotification l = new HandleValueNotification(Replay.data);
                    NextBlock      = l.NextBlock;
                    CommandReplyed = true;
                    break;

                case TI_PROTOCOL_EVENT_OPCODE_TERMINATED_LINK:
                {
                    TerminateLink terminateLink = new TerminateLink(Replay.data);
                    CommandReplyed = true;
                    if (terminateLink.Status == 0)
                    {
                        List <BleDevice> deviceList = BleDevices.GetDevices();
                        foreach (BleDevice dps in deviceList)
                        {
                            if (dps.Handle == terminateLink.ConnectionHandle)
                            {
                                dps.Handle    = 0xFFFF;
                                dps.Connected = false;
                                OnLinkTerminated(this, new TiEventArgs(dps.MacAddress, "TI_PROTOCOL_EVENT_OPCODE_TERMINATED_LINK"));
                            }
                        }
                    }
                    device_disconnected = true;
                }
                break;

                case TI_PROTOCOL_EVENT_OPCODE_COMMAND_STATUS:
                {
                    HCI_ExtentionCommandStatus r = new HCI_ExtentionCommandStatus(Replay.data);
                    if (r.Status == 0)
                    {
                        CommandReplyed = true;
                    }
                }
                break;

                case TI_PROTOCOL_EVENT_OPCODE_SCAN_COMPLIRE:
                    DeviceDiscoveryDone scan_complite = new DeviceDiscoveryDone(Replay.data);
                    OnSerchComplite(this, new TiEventArgs(null, "TI_PROTOCOL_EVENT_OPCODE_SCAN_COMPLIRE"));
                    break;

                case TI_PROTOCOL_EVENT_OPCODE_SCAN_DEVICE:
                    DeviceInformation scan_device = new DeviceInformation(Replay.data);
                    CommandReplyed = true;
                    if ((scan_device.Name != null) && (scan_device.Name.Length > 0))
                    {
                        if (BleDevices.Add(new BleDevice(scan_device.MacAddress, scan_device.Name)))
                        {
                            if (_gui != null)
                            {
                                _gui.AddDevice(scan_device.MacAddress, scan_device.Name, scan_device.RSSI);
                            }
                        }
                        else
                        {
                            _gui.UpdateDevice(scan_device.MacAddress, scan_device.Name, scan_device.RSSI);
                        }
                    }
                    else
                    {
                        _gui.UpdateDeviceRssi(scan_device.MacAddress, scan_device.RSSI);
                    }
                    break;

                case ATT_READ_RESPONSE:
                    ReadRsp read_response = new ReadRsp(Replay.data);
                    CommandReplyed = true;
                    break;

                case ATT_WRITE_RESPONSE:
                    WriteRsp write_response = new WriteRsp(Replay.data);
                    CommandReplyed = true;
                    if (write_response.Status == 0)
                    {
                        WriteResponse = true;
                    }
                    break;

                case ATT_ERROR_RESPONSE:

                    ErrorRsp error_response = new ErrorRsp(Replay.data);
                    CommandReplyed = true;
                    break;
                }
            }
        }
Exemple #6
0
 private void btnClear_Click(object sender, EventArgs e)
 {
     grdTargets.Rows.Clear();
     BleDevices.Clear();
     UpdateRowCounter();
 }