GetAttrKey() public method

public GetAttrKey ( ushort connHandle, ushort handle ) : string
connHandle ushort
handle ushort
return string
        public bool GetATT_HandleValueNotification(HCIReplies hciReplies, ref bool dataFound)
        {
            dataFound = false;
            bool success;

            if (success = rspHdlrsUtils.CheckValidResponse(hciReplies))
            {
                HCIReplies.HCI_LE_ExtEvent hciLeExtEvent = hciReplies.HciLeExtEvent;
                HCIReplies.HCI_LE_ExtEvent.ATT_HandleValueNotification valueNotification = hciLeExtEvent.AttHandleValueNotification;
                HCIReplies.LE_ExtEventHeader leExtEventHeader = hciLeExtEvent.Header;
                if (valueNotification != null)
                {
                    dataFound = true;
                    switch (leExtEventHeader.EventStatus)
                    {
                    case (byte)0:
                        if (valueNotification.Value != null)
                        {
                            Dictionary <string, DataAttr> tmpAttrDict = new Dictionary <string, DataAttr>();
                            string   attrKey     = attrUuidUtils.GetAttrKey(valueNotification.AttMsgHdr.ConnHandle, valueNotification.Handle);
                            DataAttr dataAttr    = new DataAttr();
                            bool     dataChanged = false;
                            if (!attrDataUtils.GetDataAttr(ref dataAttr, ref dataChanged, attrKey, "AttHandleValueNotification"))
                            {
                                success = false;
                                break;
                            }
                            else
                            {
                                dataAttr.Key        = attrKey;
                                dataAttr.ConnHandle = valueNotification.AttMsgHdr.ConnHandle;
                                dataAttr.Handle     = valueNotification.Handle;
                                dataAttr.Value      = valueNotification.Value;
                                if (!attrDataUtils.UpdateTmpAttrDict(ref tmpAttrDict, dataAttr, dataChanged, attrKey))
                                {
                                    success = false;
                                    break;
                                }
                                else if (!attrDataUtils.UpdateAttrDict(tmpAttrDict))
                                {
                                    success = false;
                                    break;
                                }
                                else
                                {
                                    SendRspCallback(hciReplies, true);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            break;
                        }

                    default:
                        success = rspHdlrsUtils.UnexpectedRspEventStatus(hciReplies, "AttHandleValueNotification");
                        break;
                    }
                }
            }
            if (!success && dataFound)
            {
                SendRspCallback(hciReplies, false);
            }
            return(success);
        }
Beispiel #2
0
        public bool GetATT_FindInfoRsp(HCIReplies hciReplies, ref bool dataFound)
        {
            dataFound = false;
            bool success;

            if (success = rspHdlrsUtils.CheckValidResponse(hciReplies))
            {
                HCIReplies.HCI_LE_ExtEvent hciLeExtEvent = hciReplies.HciLeExtEvent;
                HCIReplies.HCI_LE_ExtEvent.ATT_FindInfoRsp attFindInfoRsp = hciLeExtEvent.AttFindInfoRsp;
                HCIReplies.LE_ExtEventHeader leExtEventHeader             = hciLeExtEvent.Header;
                if (attFindInfoRsp != null)
                {
                    dataFound = true;
                    switch (leExtEventHeader.EventStatus)
                    {
                    case (byte)0:
                        if (attFindInfoRsp.HandleData != null)
                        {
                            Dictionary <string, DataAttr> tmpAttrDict = new Dictionary <string, DataAttr>();
                            foreach (HCIReplies.HandleData handleData in attFindInfoRsp.HandleData)
                            {
                                string   attrKey     = m_attrUuidUtils.GetAttrKey(attFindInfoRsp.AttMsgHdr.ConnHandle, handleData.Handle);
                                DataAttr dataAttr    = new DataAttr();
                                bool     dataChanged = false;
                                if (!m_attrDataUtils.GetDataAttr(ref dataAttr, ref dataChanged, attrKey, "AttFindInfoRsp"))
                                {
                                    success = false;
                                    break;
                                }
                                else
                                {
                                    dataAttr.Key          = attrKey;
                                    dataAttr.ConnHandle   = attFindInfoRsp.AttMsgHdr.ConnHandle;
                                    dataAttr.Handle       = handleData.Handle;
                                    dataAttr.Uuid         = m_deviceFormUtils.UnloadColonData(handleData.Data, false);
                                    dataAttr.UuidHex      = m_dataUtils.GetStringFromBytes(handleData.Data, true);
                                    dataAttr.IndentLevel  = m_attrUuidUtils.GetIndentLevel(dataAttr.UuidHex);
                                    dataAttr.UuidDesc     = m_attrUuidUtils.GetUuidDesc(dataAttr.UuidHex);
                                    dataAttr.ValueDesc    = m_attrUuidUtils.GetUuidValueDesc(dataAttr.UuidHex);
                                    dataAttr.ForeColor    = m_attrUuidUtils.GetForegroundColor(dataAttr.UuidHex);
                                    dataAttr.BackColor    = m_attrUuidUtils.GetBackgroundColor(dataAttr.UuidHex);
                                    dataAttr.ValueDisplay = m_attrUuidUtils.GetValueDsp(dataAttr.UuidHex);
                                    dataAttr.ValueEdit    = m_attrUuidUtils.GetValueEdit(dataAttr.UuidHex);
                                    if (m_deviceForm.attrData.sendAutoCmds || hciReplies.CmdType == TxDataOut.CmdTypes.DiscUuidAndValues)
                                    {
                                        m_sendCmds.SendGATT(new HCICmds.GATTCmds.GATT_ReadLongCharValue()
                                        {
                                            connHandle = dataAttr.ConnHandle,
                                            handle     = dataAttr.Handle
                                        }, TxDataOut.CmdTypes.DiscUuidAndValues, (SendCmds.SendCmdResult)null);
                                    }
                                    if (!m_attrDataUtils.UpdateTmpAttrDict(ref tmpAttrDict, dataAttr, dataChanged, attrKey))
                                    {
                                        success = false;
                                        break;
                                    }
                                }
                            }
                            if (!m_attrDataUtils.UpdateAttrDict(tmpAttrDict))
                            {
                                success = false;
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }

                    case (byte)23:
                    case (byte)26:
                        SendRspCallback(hciReplies, true);
                        break;

                    default:
                        success = rspHdlrsUtils.UnexpectedRspEventStatus(hciReplies, "AttFindInfoRsp");
                        break;
                    }
                }
            }
            if (!success && dataFound)
            {
                SendRspCallback(hciReplies, false);
            }
            return(success);
        }
Beispiel #3
0
        public bool GetATT_ReadByGrpTypeRsp(HCIReplies hciReplies, ref bool dataFound)
        {
            dataFound = false;
            bool flag = rspHdlrsUtils.CheckValidResponse(hciReplies);

            if (flag)
            {
                HCIReplies.HCI_LE_ExtEvent hciLeExtEvent = hciReplies.HciLeExtEvent;
                HCIReplies.HCI_LE_ExtEvent.ATT_ReadByGrpTypeRsp readByGrpTypeRsp = hciLeExtEvent.AttReadByGrpTypeRsp;
                HCIReplies.LE_ExtEventHeader leExtEventHeader = hciLeExtEvent.Header;
                if (readByGrpTypeRsp != null)
                {
                    dataFound = true;
                    switch (leExtEventHeader.EventStatus)
                    {
                    case 0:
                        if (readByGrpTypeRsp.HandleData != null)
                        {
                            Dictionary <string, DataAttr> tmpAttrDict = new Dictionary <string, DataAttr>();
                            foreach (HCIReplies.HandleHandleData handleHandleData in readByGrpTypeRsp.HandleData)
                            {
                                string   attrKey1     = attrUuidUtils.GetAttrKey(readByGrpTypeRsp.AttMsgHdr.ConnHandle, handleHandleData.Handle1);
                                DataAttr dataAttr1    = new DataAttr();
                                bool     dataChanged1 = false;
                                if (!attrDataUtils.GetDataAttr(ref dataAttr1, ref dataChanged1, attrKey1, "AttReadByGrpTypeRsp"))
                                {
                                    flag = false;
                                    break;
                                }

                                dataAttr1.Key        = attrKey1;
                                dataAttr1.ConnHandle = readByGrpTypeRsp.AttMsgHdr.ConnHandle;
                                dataAttr1.Handle     = handleHandleData.Handle1;
                                dataAttr1.Value      = devUtils.UnloadColonData(handleHandleData.Data, false);
                                if (!attrDataUtils.UpdateTmpAttrDict(ref tmpAttrDict, dataAttr1, dataChanged1, attrKey1))
                                {
                                    flag = false;
                                    break;
                                }

                                if (handleHandleData.Handle2 != ushort.MaxValue)
                                {
                                    if ((int)handleHandleData.Handle2 - (int)handleHandleData.Handle1 <= 0)
                                    {
                                        flag = false;
                                        break;
                                    }
                                    for (int index = handleHandleData.Handle1 + 1; index <= handleHandleData.Handle2; ++index)
                                    {
                                        string   attrKey2     = attrUuidUtils.GetAttrKey(readByGrpTypeRsp.AttMsgHdr.ConnHandle, (ushort)index);
                                        DataAttr dataAttr2    = new DataAttr();
                                        bool     dataChanged2 = false;
                                        if (!attrDataUtils.GetDataAttr(ref dataAttr2, ref dataChanged2, attrKey2, "AttReadByGrpTypeRsp"))
                                        {
                                            flag = false;
                                            break;
                                        }
                                        dataAttr2.Key        = attrKey2;
                                        dataAttr2.ConnHandle = readByGrpTypeRsp.AttMsgHdr.ConnHandle;
                                        dataAttr2.Handle     = (ushort)index;
                                        if (devForm.attrData.sendAutoCmds)
                                        {
                                            sendCmds.SendGATT(new HCICmds.GATTCmds.GATT_ReadLongCharValue()
                                            {
                                                connHandle = dataAttr2.ConnHandle,
                                                handle     = dataAttr2.Handle
                                            }, TxDataOut.CmdTypes.DiscUuidAndValues, null);
                                        }
                                        if (!attrDataUtils.UpdateTmpAttrDict(ref tmpAttrDict, dataAttr2, dataChanged2, attrKey2))
                                        {
                                            flag = false;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            if (!attrDataUtils.UpdateAttrDict(tmpAttrDict))
                            {
                                flag = false;
                            }
                        }
                        break;

                    case 23:
                    case 26:
                        SendRspCallback(hciReplies, true);
                        break;

                    default:
                        flag = rspHdlrsUtils.UnexpectedRspEventStatus(hciReplies, "AttReadByGrpTypeRsp");
                        break;
                    }
                }
            }
            if (!flag && dataFound)
            {
                SendRspCallback(hciReplies, false);
            }
            return(flag);
        }
Beispiel #4
0
        public bool GetATT_FindByTypeValueRsp(HCIReplies hciReplies, ref bool dataFound)
        {
            dataFound = false;
            bool flag;

            if (flag = rspHdlrsUtils.CheckValidResponse(hciReplies))
            {
                HCIReplies.HCI_LE_ExtEvent hciLeExtEvent = hciReplies.HciLeExtEvent;
                HCIReplies.HCI_LE_ExtEvent.ATT_FindByTypeValueRsp findByTypeValueRsp = hciLeExtEvent.AttFindByTypeValueRsp;
                HCIReplies.LE_ExtEventHeader leExtEventHeader = hciLeExtEvent.Header;
                if (findByTypeValueRsp != null)
                {
                    dataFound = true;
                    switch (leExtEventHeader.EventStatus)
                    {
                    case (byte)0:
                        if (findByTypeValueRsp.Handle != null)
                        {
                            Dictionary <string, DataAttr> tmpAttrDict = new Dictionary <string, DataAttr>();
                            foreach (ushort handle in findByTypeValueRsp.Handle)
                            {
                                string   attrKey     = attrUuidUtils.GetAttrKey(findByTypeValueRsp.AttMsgHdr.ConnHandle, handle);
                                DataAttr dataAttr    = new DataAttr();
                                bool     dataChanged = false;
                                if (!attrDataUtils.GetDataAttr(ref dataAttr, ref dataChanged, attrKey, "AttFindByTypeValueRsp"))
                                {
                                    flag = false;
                                    break;
                                }
                                else
                                {
                                    dataAttr.Key        = attrKey;
                                    dataAttr.ConnHandle = findByTypeValueRsp.AttMsgHdr.ConnHandle;
                                    dataAttr.Handle     = handle;
                                    if (!attrDataUtils.UpdateTmpAttrDict(ref tmpAttrDict, dataAttr, dataChanged, attrKey))
                                    {
                                        flag = false;
                                        break;
                                    }
                                }
                            }
                            if (!attrDataUtils.UpdateAttrDict(tmpAttrDict))
                            {
                                flag = false;
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }

                    case (byte)23:
                    case (byte)26:
                        SendRspCallback(hciReplies, true);
                        break;

                    default:
                        flag = rspHdlrsUtils.UnexpectedRspEventStatus(hciReplies, "AttFindByTypeValueRsp");
                        break;
                    }
                }
            }
            if (!flag && dataFound)
            {
                SendRspCallback(hciReplies, false);
            }
            return(flag);
        }
Beispiel #5
0
        public bool GetATT_ReadByTypeRsp(HCIReplies hciReplies, ref bool dataFound)
        {
            dataFound = false;
            bool flag = rspHdlrsUtils.CheckValidResponse(hciReplies);

            if (flag)
            {
                HCIReplies.HCI_LE_ExtEvent hciLeExtEvent = hciReplies.HciLeExtEvent;
                HCIReplies.HCI_LE_ExtEvent.ATT_ReadByTypeRsp attReadByTypeRsp = hciLeExtEvent.AttReadByTypeRsp;
                HCIReplies.LE_ExtEventHeader leExtEventHeader = hciLeExtEvent.Header;
                if (attReadByTypeRsp != null)
                {
                    dataFound = true;
                    switch (leExtEventHeader.EventStatus)
                    {
                    case 0:
                        if (attReadByTypeRsp.HandleData != null)
                        {
                            Dictionary <string, DataAttr> tmpAttrDict = new Dictionary <string, DataAttr>();
                            foreach (HCIReplies.HandleData handleData in attReadByTypeRsp.HandleData)
                            {
                                string   attrKey     = attrUuidUtils.GetAttrKey(attReadByTypeRsp.AttMsgHdr.ConnHandle, handleData.Handle);
                                DataAttr dataAttr    = new DataAttr();
                                bool     dataChanged = false;
                                if (!attrDataUtils.GetDataAttr(ref dataAttr, ref dataChanged, attrKey, "AttReadByTypeRsp"))
                                {
                                    flag = false;
                                    break;
                                }
                                dataAttr.Key        = attrKey;
                                dataAttr.ConnHandle = attReadByTypeRsp.AttMsgHdr.ConnHandle;
                                dataAttr.Handle     = handleData.Handle;
                                dataAttr.Value      = devUtils.UnloadColonData(handleData.Data, false);
                                if (!attrDataUtils.UpdateTmpAttrDict(ref tmpAttrDict, dataAttr, dataChanged, attrKey))
                                {
                                    flag = false;
                                    break;
                                }
                            }
                            if (!attrDataUtils.UpdateAttrDict(tmpAttrDict))
                            {
                                flag = false;
                            }
                        }
                        break;

                    case 23:
                    case 26:
                        SendRspCallback(hciReplies, true);
                        break;

                    default:
                        flag = rspHdlrsUtils.UnexpectedRspEventStatus(hciReplies, "AttReadByTypeRsp");
                        break;
                    }
                }
            }
            if (!flag && dataFound)
            {
                SendRspCallback(hciReplies, false);
            }
            return(flag);
        }
Beispiel #6
0
        public bool GetATT_ReadBlobRsp(HCIReplies hciReplies, ref bool dataFound)
        {
            dataFound = false;
            bool flag;

            if (flag = rspHdlrsUtils.CheckValidResponse(hciReplies))
            {
                HCIReplies.HCI_LE_ExtEvent hciLeExtEvent = hciReplies.HciLeExtEvent;
                HCIReplies.HCI_LE_ExtEvent.ATT_ReadBlobRsp attReadBlobRsp = hciLeExtEvent.AttReadBlobRsp;
                HCIReplies.LE_ExtEventHeader leExtEventHeader             = hciLeExtEvent.Header;
                if (attReadBlobRsp != null)
                {
                    dataFound = true;
                    switch (leExtEventHeader.EventStatus)
                    {
                    case 0:
                        if (attReadBlobRsp.Data != null)
                        {
                            int    length = attReadBlobRsp.Data.Length;
                            byte[] data   = attReadBlobRsp.Data;
                            if (length > 0)
                            {
                                if (readBlobData == null)
                                {
                                    readBlobData = new byte[length];
                                    readBlobData = data;
                                }
                                else
                                {
                                    byte[] bytes = readBlobData;
                                    readBlobData = new byte[bytes.Length + length];
                                    Array.Copy(bytes, 0, readBlobData, 0, bytes.Length);
                                    Array.Copy(data, 0, readBlobData, bytes.Length, data.Length);
                                }
                                if (hciReplies.ObjTag != null)
                                {
                                    readBlobHandle      = (ushort)hciReplies.ObjTag;
                                    readBlobHandleValid = true;
                                    break;
                                }
                                else
                                {
                                    readBlobHandle      = 0;
                                    readBlobHandleValid = false;
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }

                    case 23:
                        SendRspCallback(hciReplies, true);
                        break;

                    case 26:
                        if (readBlobData != null && readBlobHandleValid)
                        {
                            Dictionary <string, DataAttr> tmpAttrDict = new Dictionary <string, DataAttr>();
                            string   attrKey1     = attrUuidUtils.GetAttrKey(attReadBlobRsp.AttMsgHdr.ConnHandle, readBlobHandle);
                            DataAttr dataAttr1    = new DataAttr();
                            bool     dataChanged1 = false;
                            if (!attrDataUtils.GetDataAttr(ref dataAttr1, ref dataChanged1, attrKey1, "AttReadBlobRsp"))
                            {
                                flag = false;
                                break;
                            }

                            dataAttr1.Key        = attrKey1;
                            dataAttr1.ConnHandle = attReadBlobRsp.AttMsgHdr.ConnHandle;
                            dataAttr1.Handle     = readBlobHandle;
                            dataAttr1.Value      = devUtils.UnloadColonData(readBlobData, false);
                            if (!attrDataUtils.UpdateTmpAttrDict(ref tmpAttrDict, dataAttr1, dataChanged1, attrKey1))
                            {
                                flag = false;
                                break;
                            }

                            string[] delimiterStrs = new string[2] {
                                " ", ":"
                            };
                            byte[] uuid = dataUtils.GetHexBytes(dataAttr1.Uuid, delimiterStrs);
                            if (uuid != null &&
                                uuid.Length > 1 &&
                                uuid[0] == 3 &&
                                uuid[1] == 40 &&
                                dataAttr1.Value.Length > 0)
                            {
                                byte[] value = dataUtils.GetHexBytes(dataAttr1.Value, delimiterStrs);
                                if (value.Length > 0)
                                {
                                    int  index   = 0;
                                    bool dataErr = false;
                                    dataAttr1.Properties = dataUtils.Unload8Bits(value, ref index, ref dataErr);
                                    if (dataAttr1.Properties == 0)
                                    {
                                        dataAttr1.PropertiesStr = string.Empty;
                                    }
                                    else
                                    {
                                        dataAttr1.PropertiesStr = devUtils.GetGattCharProperties(dataAttr1.Properties, true) + " 0x" + dataAttr1.Properties.ToString("X2");
                                        if (value.Length >= 5)
                                        {
                                            ushort   handle       = dataUtils.Unload16Bits(value, ref index, ref dataErr, false);
                                            ushort   connHandle   = attReadBlobRsp.AttMsgHdr.ConnHandle;
                                            string   attrKey2     = attrUuidUtils.GetAttrKey(connHandle, handle);
                                            DataAttr dataAttr2    = new DataAttr();
                                            bool     dataChanged2 = false;
                                            if (!attrDataUtils.GetDataAttr(ref dataAttr2, ref dataChanged2, attrKey2, "AttReadBlobRsp"))
                                            {
                                                flag = false;
                                                break;
                                            }

                                            dataAttr2.Key        = attrKey2;
                                            dataAttr2.ConnHandle = connHandle;
                                            dataAttr2.Handle     = handle;
                                            int    dataLength = value.Length - index;
                                            byte[] destData   = new byte[dataLength];
                                            dataUtils.UnloadDataBytes(value, dataLength, ref index, ref destData, ref dataErr);
                                            dataAttr2.Uuid          = devUtils.UnloadColonData(destData, false);
                                            dataAttr2.UuidHex       = dataUtils.GetStringFromBytes(destData, true);
                                            dataAttr2.Properties    = dataAttr1.Properties;
                                            dataAttr2.PropertiesStr = dataAttr1.PropertiesStr;
                                            dataAttr2.IndentLevel   = attrUuidUtils.GetIndentLevel(dataAttr2.UuidHex);
                                            dataAttr2.UuidDesc      = attrUuidUtils.GetUuidDesc(dataAttr2.UuidHex);
                                            dataAttr2.ValueDesc     = attrUuidUtils.GetUuidValueDesc(dataAttr2.UuidHex);
                                            dataAttr2.ForeColor     = attrUuidUtils.GetForegroundColor(dataAttr2.UuidHex);
                                            dataAttr2.BackColor     = attrUuidUtils.GetBackgroundColor(dataAttr2.UuidHex);
                                            dataAttr2.ValueDisplay  = attrUuidUtils.GetValueDsp(dataAttr2.UuidHex);
                                            dataAttr2.ValueEdit     = attrUuidUtils.GetValueEdit(dataAttr2.UuidHex);
                                            if (!attrDataUtils.UpdateTmpAttrDict(ref tmpAttrDict, dataAttr2, dataChanged2, attrKey2))
                                            {
                                                flag = false;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            if (!attrDataUtils.UpdateAttrDict(tmpAttrDict))
                            {
                                flag = false;
                                break;
                            }
                        }
                        readBlobData   = null;
                        readBlobHandle = 0;
                        SendRspCallback(hciReplies, true);
                        break;

                    default:
                        flag = rspHdlrsUtils.UnexpectedRspEventStatus(hciReplies, "AttReadBlobRsp");
                        break;
                    }
                }
            }
            if (!flag && dataFound)
            {
                readBlobData   = null;
                readBlobHandle = 0;
                SendRspCallback(hciReplies, false);
            }
            return(flag);
        }