Exemplo n.º 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())
Exemplo n.º 2
0
 def getPowerSamplesRequestPacket(samplesType, index):
     buffer = BufferWriter()
     buffer.putUInt8(samplesType)
     buffer.putUInt8(index)
     data = buffer.getBuffer()
     return ControlPacket(
         ControlType.GET_POWER_SAMPLES).loadByteArray(data).serialize()
 def serialize(self):
     writer = BufferWriter()
     writer.putUInt8(self.type)
     writer.putUInt8(self.flags)
     writer.putUInt8(self.timeout_or_transmissions)
     writer.putUInt8(len(self.crownstoneIds))
     for stoneId in self.crownstoneIds:
         writer.putUInt8(stoneId)
     writer.putBytes(self.payload)
     return writer.getBuffer()
Exemplo n.º 4
0
 def toBuffer(self, data=None) -> list:
     if isinstance(data, BufferWriter):
         writer = data
         self._toBuffer(writer)
         buf = writer.getBuffer()
         return buf
     else:
         writer = BufferWriter()
         self._toBuffer(writer)
         buf = writer.getBuffer()
         if data is None:
             return buf
         else:
             data.extend(buf)
             return data
 def serialize(self):
     writer = BufferWriter()
     writer.putUInt8(self.crownstoneId)
     writer.putUInt8(self.state)
     return writer.getBuffer()
 def serialize(self):
     writer = BufferWriter()
     writer.putUInt8(len(self.packets))
     for stonePacket in self.packets:
         writer.putBytes(stonePacket.serialize())
     return writer.getBuffer()