BTool.SendCmds.SendGAP C# (CSharp) Méthode

SendGAP() public méthode

public SendGAP ( HCICmds cmd ) : bool
cmd HCICmds
Résultat bool
        public bool SendGAP(HCICmds.GAPCmds.GAP_DeviceInit cmd)
        {
            bool success = true;
            try
            {
                byte[] s_IRK = m_deviceFormUtils.String2Bytes_LSBMSB(cmd.irk, 16);
                if (s_IRK == null)
                {
                    m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Invalid IRK Value Entry '{0}'\nFormat Is 00:00....\n", cmd.irk));
                    return false;
                }

                byte[] s_CSRK = m_deviceFormUtils.String2Bytes_LSBMSB(cmd.csrk, 16);
                if (s_CSRK == null)
                {
                    m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Invalid CSRK Value Entry '{0}'\nFormat Is 00:00....\n", cmd.csrk));
                    return false;
                }

                byte dataLength = (byte)(cmd.dataLength + s_IRK.Length + s_CSRK.Length);
                byte[] data = new byte[dataLength + 4];
                int index = 0;
                bool dataErr = false;
                if (m_deviceFormUtils.LoadMsgHeader(ref data, ref index, 1, cmd.opCodeValue, dataLength))
                {
                    byte bits = 0;
                    if (cmd.broadcasterProfileRole == HCICmds.GAP_EnableDisable.Enable)
                        bits |= 1;
                    if (cmd.observerProfileRole == HCICmds.GAP_EnableDisable.Enable)
                        bits |= 2;
                    if (cmd.peripheralProfileRole == HCICmds.GAP_EnableDisable.Enable)
                        bits |= 4;
                    if (cmd.centralProfileRole == HCICmds.GAP_EnableDisable.Enable)
                        bits |= 8;
                    if (!m_dataUtils.Load8Bits(ref data, ref index, bits, ref dataErr)
                    && !m_dataUtils.Load8Bits(ref data, ref index, cmd.maxScanResponses, ref dataErr))
                    {
                        if (s_IRK.Length == 16)
                        {
                            if (!m_dataUtils.LoadDataBytes(ref data, ref index, s_IRK, ref dataErr))
                            {
                                if (s_CSRK.Length == 16)
                                {
                                    if (!m_dataUtils.LoadDataBytes(ref data, ref index, s_CSRK, ref dataErr)
                                    && !m_dataUtils.Load32Bits(ref data, ref index, cmd.signCounter, ref dataErr, false))
                                        TransmitCmd(cmd.cmdName, cmd.opCodeValue, data);
                                }
                                else
                                {
                                    m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Invalid CSRK Data Length = {0:D} \nLength must be {1:D}\n", s_CSRK.Length, 16));
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Invalid IRK Data Length = {0:D} \nLength must be {1:D}\n", s_IRK.Length, 16));
                            return false;
                        }
                    }
                }
                if (dataErr)
                    success = HandleDataError(cmd.cmdName);
            }
            catch (Exception ex)
            {
                success = HandleException(cmd.cmdName, ex.Message);
            }
            return success;
        }