Exemple #1
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 #2
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;
                }
            }
        }