コード例 #1
0
def get_master_crc_from_filter_crcs(input_data: [[int, int]]) -> int:
    """
    Get the master CRC from filter CRCs.

    :param input_data:  A list of [filterId, filterCRC].
    :returns:           The master CRC.
    """
    def sort_method(val):
        return val[0]

    input_data.sort(key=sort_method)

    # Check for duplicate filter IDs.
    for i in range(0, len(input_data) - 1):
        if input_data[i][0] == input_data[i + 1][0]:
            raise CrownstoneException(
                CrownstoneError.INVALID_INPUT,
                "Cannot have 2 filters with the same ID.")

    writer = BufferWriter()
    for id_and_filter_crc in input_data:
        writer.putUInt8(id_and_filter_crc[0])
        writer.putUInt32(id_and_filter_crc[1])

    return crc32(writer.getBuffer())
コード例 #2
0
 def _serialize(self, writer: BufferWriter):
     super()._serialize(writer)
     writer.putUInt8(self.adType)
     writer.putUInt32(self.mask)
コード例 #3
0
 def _serialize(self, writer: BufferWriter):
     writer.putUInt8(self.commandProtocolVersion)
     writer.putUInt16(self.masterVersion)
     writer.putUInt32(self.masterCrc)