Esempio n. 1
0
        private void timPeridic_Tick(object sender, EventArgs e)
        {
            if (bglib.IsBusy())
            {
                tsLabelScan.Text = "Busy";
            }
            else
            {
                tsLabelScan.Text = "Ready";
            }

            if (mFrmPairKey.PairYes)
            {
                byte[] cmd = bglib.BLECommandSMPasskeyEntry(c_BleDev.ConnHandle, mFrmPairKey.PairKey);
                bglib.SendCommand(comDev, cmd);
                mFrmPairKey.PairYes = false;
            }
            switch (c_BleDev.State)
            {
            case GhpBle.ACTTION_IDLE:
                tsProcessBar.Value = 0;
                break;

            case GhpBle.ACTTION_SCAN_PRIMSRV:
                tsProcessBar.Value = (tsProcessBar.Value + 20) % 120;
                break;

            case GhpBle.ACTTION_SCAN_PRIMSRV_DONE://服务项扫描完毕,添加到树表中;
            {
                tsProcessBar.Value = 100;
                tvSrvTree.Nodes.Clear();
                foreach (CPrimService srv in c_BleDev.m_PrimSrvList)
                {
                    TreeNode srvNode = new TreeNode();
                    if (srv.Description == null)
                    {
                        srvNode.Text = srv.UUID;
                    }
                    else
                    {
                        srvNode.Text = srv.Description;
                    }
                    srvNode.Tag         = srv.UUID;
                    srvNode.ToolTipText = "UUID= " + srv.UUID;
                    tvSrvTree.Nodes.Add(srvNode);
                }
                c_BleDev.State = GhpBle.ACTTION_IDLE;
            }
            break;

            case GhpBle.ACTTION_SCAN_ATTRIB:
                tsProcessBar.Value = (tsProcessBar.Value + 20) % 120;
                break;

            case GhpBle.ACTTION_SCAN_ATTRIB_DONE://添加属性列表
            {
                tsProcessBar.Value = 100;
                if (tvSrvTree.SelectedNode != null && tvSrvTree.SelectedNode.Level == 0)
                {
                    if (tvSrvTree.SelectedNode.Nodes.Count == 0)
                    {
                        foreach (CAttribute attr in c_BleDev.CurrentPrimSrv.AttrList)
                        {
                            TreeNode attNode = new TreeNode();
                            if (attr.AttName == null)
                            {
                                attNode.Text = attr.AttUUID;
                            }
                            else
                            {
                                attNode.Text = attr.AttName;
                            }
                            attNode.Tag         = attr.AttUUID;
                            attNode.ToolTipText = "UUID= " + attr.AttUUID;
                            tvSrvTree.SelectedNode.Nodes.Add(attNode);
                        }
                    }
                }
                c_BleDev.State = GhpBle.ACTTION_IDLE;
            }
            break;
            }
        }