示例#1
0
        public bool UpdateTmpAttrDict(ref Dictionary <string, DataAttr> tmpAttrDict, DataAttr dataAttr, bool dataChanged, string key)
        {
            bool success = true;

            try
            {
                if (dataChanged)
                {
                    dataAttr.DataUpdate = true;
                    tmpAttrDict.Add(key, dataAttr);
                }
                else if (m_deviceForm.attrData.attrDict.Count >= 1500)
                {
                    m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Warning, string.Format("Attribute Dictionary At Maximum {0} Elements\nData Lost\nAttrDataUtils\n", 1500));
                    success = false;
                }
                else
                {
                    m_deviceForm.attrData.attrDictAccess.WaitOne();
                    dataAttr.DataUpdate = true;
                    m_deviceForm.attrData.attrDict.Add(key, dataAttr);
                    m_deviceForm.attrData.attrDictAccess.ReleaseMutex();
                }
            }
            catch (Exception ex)
            {
                m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Attribute Dictionary Access Error\nUpdateTmpAttrDict()\n" + ex.Message + "\nAttrDataUtils\n");
                success = false;
            }
            return(success);
        }
示例#2
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;
 }
示例#3
0
 public bool UpdateAttrDictItem(DataAttr dataAttr)
 {
     bool success = true;
     m_deviceForm.attrData.attrDictAccess.WaitOne();
     if (m_deviceForm.attrData.attrDict.ContainsKey(dataAttr.Key))
     {
         m_deviceForm.attrData.attrDict[dataAttr.Key] = dataAttr;
     }
     else
     {
         m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Attribute Dictionary Update Error\nItem Does Not Exist In Dictionary\nAttrDataUtils\n"));
         success = false;
     }
     m_deviceForm.attrData.attrDictAccess.ReleaseMutex();
     return success;
 }
示例#4
0
        public bool UpdateAttrDictItem(DataAttr dataAttr)
        {
            bool success = true;

            m_deviceForm.attrData.attrDictAccess.WaitOne();
            if (m_deviceForm.attrData.attrDict.ContainsKey(dataAttr.Key))
            {
                m_deviceForm.attrData.attrDict[dataAttr.Key] = dataAttr;
            }
            else
            {
                m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Attribute Dictionary Update Error\nItem Does Not Exist In Dictionary\nAttrDataUtils\n"));
                success = false;
            }
            m_deviceForm.attrData.attrDictAccess.ReleaseMutex();
            return(success);
        }
示例#5
0
 public bool GetDataAttr(ref DataAttr dataAttr, ref bool dataChanged, string key, string funcName)
 {
     bool success = true;
     dataChanged = false;
     m_deviceForm.attrData.attrDictAccess.WaitOne();
     if (m_deviceForm.attrData.attrDict.ContainsKey(key))
     {
         try
         {
             dataAttr = m_deviceForm.attrData.attrDict[key];
             dataChanged = true;
         }
         catch (Exception ex)
         {
             string msg = "Attribute Dictionary Access Error\nGetDataAttr()\n" + funcName + "\n" + ex.Message + "\nAttrDataUtils\n";
             m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg);
             success = false;
         }
     }
     m_deviceForm.attrData.attrDictAccess.ReleaseMutex();
     return success;
 }
示例#6
0
        public bool GetDataAttr(ref DataAttr dataAttr, ref bool dataChanged, string key, string funcName)
        {
            bool success = true;

            dataChanged = false;
            m_deviceForm.attrData.attrDictAccess.WaitOne();
            if (m_deviceForm.attrData.attrDict.ContainsKey(key))
            {
                try
                {
                    dataAttr    = m_deviceForm.attrData.attrDict[key];
                    dataChanged = true;
                }
                catch (Exception ex)
                {
                    string msg = "Attribute Dictionary Access Error\nGetDataAttr()\n" + funcName + "\n" + ex.Message + "\nAttrDataUtils\n";
                    m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg);
                    success = false;
                }
            }
            m_deviceForm.attrData.attrDictAccess.ReleaseMutex();
            return(success);
        }
示例#7
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;
 }
示例#8
0
 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;
 }
示例#9
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);
        }
示例#10
0
 private void btnWriteValue_Click(object sender, EventArgs e)
 {
     formDataAccess.WaitOne();
     if (tbValue.Text == null || tbValue.Text == string.Empty)
     {
         msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Warning, "A Value Must Be Entered To Perform A Write\n");
     }
     else
     {
         string outStr = string.Empty;
         ValueDisplay inValueDisplay = dataAttr.ValueDisplay;
         ValueDisplay outValueDisplay = ValueDisplay.Hex;
         if (lastValueDisplaySet)
             inValueDisplay = lastValueDisplay;
         if (devUtils.ConvertDisplayTypes(inValueDisplay, tbValue.Text, ref outValueDisplay, ref outStr, true))
         {
             string str = devUtils.HexStr2UserDefinedStr(outStr, SharedAppObjs.StringType.HEX);
             if (str == null || str == string.Empty)
             {
                 string msg = "Value Data Cannot Be Converted To Hex For Write Command\n";
                 msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Warning, msg);
             }
             else
             {
                 devForm.threadMgr.rspDataIn.ExtCmdStatus.ExtCmdStatusCallback = new ExtCmdStatus.ExtCmdStatusDelegate(ExtCmdStatus);
                 devForm.threadMgr.rspDataIn.AttErrorRsp.AttErrorRspCallback = new AttErrorRsp.AttErrorRspDelegate(AttErrorRsp);
                 devForm.threadMgr.rspDataIn.AttPrepareWriteRsp.AttPrepareWriteRspCallback = new AttPrepareWriteRsp.AttPrepareWriteRspDelegate(AttPrepareWriteRsp);
                 devForm.threadMgr.rspDataIn.AttExecuteWriteRsp.AttExecuteWriteRspCallback = new AttExecuteWriteRsp.AttExecuteWriteRspDelegate(AttExecuteWriteRsp);
                 HCICmds.GATTCmds.GATT_WriteLongCharValue writeLongCharValue = new HCICmds.GATTCmds.GATT_WriteLongCharValue();
                 writeLongCharValue.connHandle = dataAttr.ConnHandle;
                 writeLongCharValue.handle = dataAttr.Handle;
                 writeLongCharValue.value = str;
                 gattWriteDataAttr = dataAttr;
                 gattWriteDataAttr.Value = str;
                 int length1 = AttrData.writeLimits.MaxPacketSize >= AttrData.writeLimits.MaxNumPreparedWrites * 18 ? AttrData.writeLimits.MaxNumPreparedWrites * 18 : AttrData.writeLimits.MaxPacketSize;
                 byte[] numArray = devUtils.String2Bytes_LSBMSB(str, (byte)16);
                 if (numArray == null)
                 {
                     sendCmds.DisplayInvalidValue(writeLongCharValue.value);
                 }
                 else
                 {
                     int length2 = numArray.Length;
                     int sourceIndex = 0;
                     while (sourceIndex < numArray.Length)
                     {
                         byte[] valueData;
                         if (length2 > length1)
                         {
                             valueData = new byte[length1];
                             Array.Copy((Array)numArray, sourceIndex, (Array)valueData, 0, length1);
                         }
                         else
                         {
                             valueData = new byte[length2];
                             Array.Copy((Array)numArray, sourceIndex, (Array)valueData, 0, length2);
                         }
                         writeLongCharValue.value = string.Empty;
                         writeLongCharValue.offset = (ushort)sourceIndex;
                         if (sendCmds.SendGATT(writeLongCharValue, valueData, new SendCmds.SendCmdResult(SendCmdResult)))
                         {
                             Enabled = false;
                             int length3 = valueData.Length;
                             length2 -= valueData.Length;
                             sourceIndex += length3;
                         }
                         else
                         {
                             string msg = "GATT_WriteLongCharValue Command Failed\n";
                             if (sourceIndex > 0)
                                 msg = msg + "Multi-Part Write Sequenece Error\n" + "All Requested Data May Not Have Been Written To The Device\n";
                             if (DisplayMsgCallback != null)
                                 DisplayMsgCallback(SharedAppObjs.MsgType.Error, msg);
                             msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg);
                             ClearRspDelegates();
                             break;
                         }
                     }
                 }
             }
         }
     }
     formDataAccess.ReleaseMutex();
 }
示例#11
0
        public void LoadData(string dataKey)
        {
            if (InvokeRequired)
            {
                try
                {
                    Invoke((Delegate)new AttrDataItemForm.LoadDataDelegate(LoadData), dataKey);
                }
                catch { }
            }
            else
            {
                formDataAccess.WaitOne();
                key = dataKey;
                dataAttr = new DataAttr();
                bool dataChanged = false;
                if (attrDataUtils.GetDataAttr(ref dataAttr, ref dataChanged, key, "LoadData"))
                {
                    if (dataChanged)
                    {
                        tbConnHnd.Text = "0x" + dataAttr.ConnHandle.ToString("X4");
                        tbHandle.Text = "0x" + dataAttr.Handle.ToString("X4");
                        if (dataAttr.UuidHex != string.Empty && dataAttr.UuidHex != null)
                            tbUuid.Text = "0x" + dataAttr.UuidHex;
                        tbUuidDesc.Text = dataAttr.UuidDesc;
                        string outStr = string.Empty;
                        if (lastValueDisplaySet)
                        {
                            devUtils.ConvertDisplayTypes(ValueDisplay.Hex, dataAttr.Value, ref lastValueDisplay, ref outStr, false);
                        }
                        else
                        {
                            devUtils.ConvertDisplayTypes(ValueDisplay.Hex, dataAttr.Value, ref dataAttr.ValueDisplay, ref outStr, false);
                            lastValueDisplay = dataAttr.ValueDisplay;
                            lastValueDisplaySet = true;
                            cbDataType.SelectedIndex = (int)lastValueDisplay;
                        }
                        tbValue.Text = outStr;
                        tbValueDesc.Text = dataAttr.ValueDesc;
                        tbProperties.Text = dataAttr.PropertiesStr;
                        bool flag = false;
                        if (dataAttr.PropertiesStr != null && dataAttr.PropertiesStr != string.Empty)
                        {
                            flag = true;
                            Color green = Color.Green;
                            Color red = Color.Red;

                            if ((dataAttr.Properties & 0x01) == 0x01)
                                lblBroadcast.ForeColor = green;
                            else
                                lblBroadcast.ForeColor = red;

                            if ((dataAttr.Properties & 0x02) == 0x02)
                                lblRead.ForeColor = green;
                            else
                                lblRead.ForeColor = red;

                            if ((dataAttr.Properties & 0x04) == 0x04)
                                lblWriteWithoutResponse.ForeColor = green;
                            else
                                lblWriteWithoutResponse.ForeColor = red;

                            if ((dataAttr.Properties & 0x08) == 0x08)
                                lblWrite.ForeColor = green;
                            else
                                lblWrite.ForeColor = red;

                            if ((dataAttr.Properties & 0x10) == 0x10)
                                lblNotify.ForeColor = green;
                            else
                                lblNotify.ForeColor = red;

                            if ((dataAttr.Properties & 0x20) == 0x20)
                                lblIndicate.ForeColor = green;
                            else
                                lblIndicate.ForeColor = red;

                            if ((dataAttr.Properties & 0x40) == 0x40)
                                lblAuthenticatedSignedWrites.ForeColor = green;
                            else
                                lblAuthenticatedSignedWrites.ForeColor = red;

                            if ((dataAttr.Properties & 0x80) == 0x80)
                                lblExtendedProperties.ForeColor = green;
                            else
                                lblExtendedProperties.ForeColor = red;
                        }
                        gbProperties.Enabled = flag;
                        tbProperties.Enabled = flag;
                        lblProperties.Enabled = flag;
                        lblBroadcast.Enabled = flag;
                        lblRead.Enabled = flag;
                        lblWriteWithoutResponse.Enabled = flag;
                        lblWrite.Enabled = flag;
                        lblNotify.Enabled = flag;
                        lblIndicate.Enabled = flag;
                        lblAuthenticatedSignedWrites.Enabled = flag;
                        lblExtendedProperties.Enabled = flag;
                    }
                    if (dataAttr.ValueEdit == ValueEdit.ReadOnly)
                    {
                        btnWriteValue.Enabled = false;
                        tbValue.ReadOnly = true;
                    }
                    else
                    {
                        btnWriteValue.Enabled = true;
                        tbValue.ReadOnly = false;
                    }
                    if (!lastValueDisplaySet)
                        cbDataType.SelectedIndex = (int)dataAttr.ValueDisplay;
                }
                formDataAccess.ReleaseMutex();
            }
        }
示例#12
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);
        }
示例#13
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);
        }
示例#14
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;
        }
示例#15
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);
        }
示例#16
0
 private void lvAttributes_MouseDoubleClick()
 {
     if (dataUpdating)
         return;
     formDataAccess.WaitOne();
     ListView.SelectedListViewItemCollection selectedItems = lvAttributes.SelectedItems;
     if (selectedItems.Count > 0)
     {
         string text = selectedItems[0].Text;
         DataAttr dataAttr = new DataAttr();
         bool dataChanged = false;
         if (attrDataUtils.GetDataAttr(ref dataAttr, ref dataChanged, text, "lvAttributes_DoubleClick") && dataChanged)
         {
             AttrDataItemForm attrDataItemForm = new AttrDataItemForm(devForm);
             attrDataItemForm.DisplayMsgCallback = DisplayMsgCallback;
             attrDataItemForm.AttrDataItemChangedCallback = new AttrDataItemForm.AttrDataItemChangedDelegate(RspDataInChanged);
             attrDataItemForm.LoadData(text);
             int num = (int)attrDataItemForm.ShowDialog();
         }
     }
     formDataAccess.ReleaseMutex();
 }
示例#17
0
 public bool UpdateTmpAttrDict(ref Dictionary<string, DataAttr> tmpAttrDict, DataAttr dataAttr, bool dataChanged, string key)
 {
     bool success = true;
     try
     {
         if (dataChanged)
         {
             dataAttr.DataUpdate = true;
             tmpAttrDict.Add(key, dataAttr);
         }
         else if (m_deviceForm.attrData.attrDict.Count >= 1500)
         {
             m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Warning, string.Format("Attribute Dictionary At Maximum {0} Elements\nData Lost\nAttrDataUtils\n", 1500));
             success = false;
         }
         else
         {
             m_deviceForm.attrData.attrDictAccess.WaitOne();
             dataAttr.DataUpdate = true;
             m_deviceForm.attrData.attrDict.Add(key, dataAttr);
             m_deviceForm.attrData.attrDictAccess.ReleaseMutex();
         }
     }
     catch (Exception ex)
     {
         m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Attribute Dictionary Access Error\nUpdateTmpAttrDict()\n" + ex.Message + "\nAttrDataUtils\n");
         success = false;
     }
     return success;
 }
示例#18
0
 private bool ReadSelectedValue()
 {
     bool flag = true;
     ListView.SelectedListViewItemCollection selectedItems = lvAttributes.SelectedItems;
     if (selectedItems.Count > 0)
     {
         string text = selectedItems[0].Text;
         DataAttr dataAttr = new DataAttr();
         bool dataChanged = false;
         if (attrDataUtils.GetDataAttr(ref dataAttr, ref dataChanged, text, "lvAttributes_Click") && dataChanged)
         {
             devForm.threadMgr.rspDataIn.ExtCmdStatus.ExtCmdStatusCallback = new ExtCmdStatus.ExtCmdStatusDelegate(ExtCmdStatus);
             devForm.threadMgr.rspDataIn.AttErrorRsp.AttErrorRspCallback = new AttErrorRsp.AttErrorRspDelegate(AttErrorRsp);
             devForm.threadMgr.rspDataIn.AttReadBlobRsp.AttReadBlobRspCallback = new AttReadBlobRsp.AttReadBlobRspDelegate(AttReadBlobRsp);
             if (sendCmds.SendGATT(new HCICmds.GATTCmds.GATT_ReadLongCharValue()
             {
                 connHandle = dataAttr.ConnHandle,
                 handle = dataAttr.Handle
             }, TxDataOut.CmdTypes.General, new SendCmds.SendCmdResult(SendCmdResult)))
                 Enabled = false;
             else
                 ClearRspDelegates();
         }
     }
     return flag;
 }
示例#19
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;
        }
示例#20
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);
        }
        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);
        }
示例#22
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;
 }