public static CidPacket ReadAttributesRequest( DiscoverAttributesResponse resp) { byte[] u8Mode = new byte[] { resp.Payload[0] }; byte[] manufacturerCode = BitHelpers.GetBytes(resp.ManufacturerCode); byte[] dstAdd = BitHelpers.GetBytes(resp.SourceAddress); byte[] dstEpt = new byte[] { resp.SourceEndpoint }; byte[] clstrID = BitHelpers.GetBytes((ushort)resp.ClusterID); byte[] cmdId = new byte[] { 0 }; byte[] attrbs = new byte[] { resp.AttributeCount }; byte[] attrList = new byte[2 * resp.AttributeCount]; for (int i = 0; i < resp.AttributeCount; i++) { byte[] id = new byte[] { 0x00, 0x00 }; // BitHelpers.GetBytes(resp.ClusterID); attrList[i * 2] = id[0]; attrList[i * 2 + 1] = id[1]; } IEnumerable <byte> data = null; if (resp.IsManufacturerSpecific) { data = Merge(new byte[][] { u8Mode, manufacturerCode, dstAdd, dstEpt, clstrID, cmdId, attrbs, attrList }); } else { data = Merge(new byte[][] { u8Mode, dstAdd, dstEpt, clstrID, cmdId, attrbs, attrList }); } return(new CidPacket(new byte[] { 0x00, 0x30 }, data.ToArray())); }
/// <summary> /// The Discover Attributes Response /// /// The discover attributes response command is generated in response to a discover /// attributes command. /// /// @param discoveryComplete {@link bool} Discovery Complete /// @param attributeInformation {@link List<AttributeInformation>} Attribute Information /// @return the Task<CommandResult> command result Task /// </summary> public Task <CommandResult> DiscoverAttributesResponse(bool discoveryComplete, List <AttributeInformation> attributeInformation) { DiscoverAttributesResponse command = new DiscoverAttributesResponse(); // Set the fields command.DiscoveryComplete = discoveryComplete; command.AttributeInformation = attributeInformation; return(Send(command)); }
/** * Discovers the list of attributes supported by the cluster on the remote device. * <p> * If the discovery has already been completed, and rediscover is false, then the future will complete immediately * and the user can use existing results. Normally there should not be a need to set rediscover to true. * <p> * This method returns a future to a boolean. Upon success the caller should call {@link #getSupportedAttributes()} * to get the list of supported attributes. * * @param rediscover true to perform a discovery even if it was previously completed * @return {@link Future} returning a {@link Boolean} */ public Task <bool> DiscoverAttributes(bool rediscover) { return(Task.Run(() => { // Synchronise the request to avoid multiple simultaneous requests to this update the list on this // cluster which would cause errors consolidating the responses lock (_supportedAttributes) { // If we don't want to rediscover, and we already have the list of attributes, then return if (!rediscover && !(_supportedAttributes == null || _supportedAttributes.Count == 0)) { return true; } ushort index = 0; bool complete = false; List <AttributeInformation> attributes = new List <AttributeInformation>(); do { DiscoverAttributesCommand command = new DiscoverAttributesCommand(); command.ClusterId = _clusterId; command.DestinationAddress = _zigbeeEndpoint.GetEndpointAddress(); command.StartAttributeIdentifier = index; command.MaximumAttributeIdentifiers = 10; CommandResult result = Send(command).Result; if (result.IsError()) { return false; } DiscoverAttributesResponse response = (DiscoverAttributesResponse)result.GetResponse(); complete = response.DiscoveryComplete; if (response.AttributeInformation != null) { attributes.AddRange(response.AttributeInformation); index = (ushort)(attributes.Max().Identifier + 1); } } while (!complete); _supportedAttributes.Clear(); foreach (AttributeInformation attribute in attributes) { _supportedAttributes.Add(attribute.Identifier); } } return true; })); }
public static CidPacket ReadAttributesRequest( DiscoverAttributesResponse resp) { byte[] u8Mode = new byte[] { resp.Payload[0] }; byte[] manufacturerCode = BitHelpers.GetBytes(resp.ManufacturerCode); byte[] dstAdd = BitHelpers.GetBytes(resp.SourceAddress); byte[] dstEpt = new byte[] { resp.SourceEndpoint }; byte[] clstrID = BitHelpers.GetBytes((ushort)resp.ClusterID); byte[] cmdId = new byte[] { 0 }; byte[] attrbs = new byte[] { resp.AttributeCount }; byte[] attrList = new byte[2 * resp.AttributeCount]; for (int i = 0; i < resp.AttributeCount; i++) { byte[] id = new byte[] { 0x00, 0x00 }; // BitHelpers.GetBytes(resp.ClusterID); attrList[i * 2] = id[0]; attrList[i * 2 + 1] = id[1]; } IEnumerable<byte> data = null; if (resp.IsManufacturerSpecific) { data = Merge(new byte[][] { u8Mode, manufacturerCode, dstAdd, dstEpt, clstrID, cmdId, attrbs, attrList }); } else { data = Merge(new byte[][] { u8Mode, dstAdd, dstEpt, clstrID, cmdId, attrbs, attrList }); } return new CidPacket(new byte[] { 0x00, 0x30 }, data.ToArray()); }