def __parse_route(self, data): """ Parses the given bytearray and returns a route. Args: data (bytearray): Bytearray with data to parse. Returns: :class:`.Route`: The route or ``None`` if not found. """ # Bytes 0 - 1: 16-bit destination address (little endian) # Byte 2: Setting byte: # * Bits 0 - 2: Route status # * Bit 3: Low-memory concentrator flag # * Bit 4: Destination is a concentrator flag # * Bit 5: Route record message should be sent prior to next transmission flag # Bytes 3 - 4: 16 bit next hop address (little endian) return Route( XBee16BitAddress.from_bytes(data[1], data[0]), XBee16BitAddress.from_bytes(data[4], data[3]), RouteStatus.get( utils.get_int_from_byte(data[2], self.__class__.__ST_FIELD_OFFSET, self.__class__.__ST_FIELD_LEN)), utils.is_bit_enabled(data[2], self.__class__.__MEM_FIELD_OFFSET), utils.is_bit_enabled(data[2], self.__class__.__M2O_FIELD_OFFSET), utils.is_bit_enabled(data[2], self.__class__.__RR_FIELD_OFFSET))
def __parse_neighbor(self, data): """ Parses the given bytearray and returns a neighbor. Args: data (bytearray): Bytearray with data to parse. Returns: :class:`.Neighbor`: The neighbor or ``None`` if not found. """ # Bytes 0 - 7: Extended PAN ID (little endian) # Bytes 8 - 15: 64-bit neighbor address (little endian) # Bytes 16 - 17: 16-bit neighbor address (little endian) # Byte 18: First setting byte: # * Bit 0 - 1: Neighbor role # * Bit 2 - 3: Receiver on when idle (indicates if the neighbor's receiver is # enabled during idle times) # * Bit 4 - 6: Relationship of this neighbor with the node # * Bit 7: Reserved # Byte 19: Second setting byte: # * Bit 0 - 1: Permit joining (indicates if the neighbor accepts join requests) # * Bit 2 - 7: Reserved # Byte 20: Depth (Tree depth of the neighbor. A value of 0 indicates the neighbor is the # coordinator) # Byte 21: LQI (The estimated link quality of data transmissions from this neighbor) x64 = XBee64BitAddress.from_bytes(*data[8:16][::-1]) x16 = XBee16BitAddress.from_bytes(data[17], data[16]) role = Role.get( utils.get_int_from_byte(data[18], self.__class__.__ROLE_FIELD_OFFSET, self.__class__.__ROLE_FIELD_LEN)) relationship = NeighborRelationship.get( utils.get_int_from_byte(data[18], self.__class__.__RELATIONSHIP_FIELD_OFFSET, self.__class__.__RELATIONSHIP_FIELD_LEN)) depth = int(data[20]) lqi = int(data[21]) if not self._xbee.is_remote(): xb = self._xbee else: xb = self._xbee.get_local_xbee_device() # Create a new remote node n_xb = RemoteZigBeeDevice(xb, x64bit_addr=x64, x16bit_addr=x16) n_xb._role = role return Neighbor(n_xb, relationship, depth, lqi)
def _parse_data(self, data): """ Override. .. seealso:: | :meth:`.__ZDOCommand._parse_data` """ # Ensure the 16-bit address received matches the address of the device x16 = XBee16BitAddress.from_bytes(data[1], data[0]) if x16 != self._xbee.get_16bit_addr(): return False # Role field: 3 bits (0, 1, 2) of the next byte role = Role.get(utils.get_int_from_byte(data[2], 0, 3)) # Complex descriptor available: next bit (3) of the same byte complex_desc_available = utils.is_bit_enabled(data[2], 3) # User descriptor available: next bit (4) of the same byte user_desc_available = utils.is_bit_enabled(data[2], 4) # Frequency band: 5 bits of the next byte freq_band = NodeDescriptorReader.__to_bits(data[3])[-5:] # MAC capabilities: next byte mac_capabilities = NodeDescriptorReader.__to_bits(data[4]) # Manufacturer code: next 2 bytes manufacturer_code = utils.bytes_to_int([data[6], data[5]]) # Maximum buffer size: next byte max_buffer_size = int(data[7]) # Maximum incoming transfer size: next 2 bytes max_in_transfer_size = utils.bytes_to_int([data[9], data[8]]) # Maximum outgoing transfer size: next 2 bytes max_out_transfer_size = utils.bytes_to_int([data[13], data[12]]) # Maximum outgoing transfer size: next byte desc_capabilities = NodeDescriptorReader.__to_bits(data[14]) self.__node_descriptor = NodeDescriptor(role, complex_desc_available, user_desc_available, freq_band, mac_capabilities, manufacturer_code, max_buffer_size, max_in_transfer_size, max_out_transfer_size, desc_capabilities) return True