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); }
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); }