def _serialize(self, writer: BufferWriter):
        writer.putUInt8(self.itemCount)
        writer.putUInt8(self.itemSize)

        self.items.sort()
        for item in self.items:
            writer.putBytes(item)
 def _serialize(self, writer: BufferWriter):
     writer.putUInt8(self.commandProtocolVersion)
     writer.putUInt8(self.filterId)
     writer.putUInt16(self.chunkStartIndex)
     writer.putUInt16(self.totalSize)
     writer.putUInt16(self.chunkSize)
     writer.putBytes(self.chunk)
Example #3
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())
Example #4
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()
 def serialize(self):
     writer = BufferWriter()
     writer.putUInt8(len(self.packets))
     for stonePacket in self.packets:
         writer.putBytes(stonePacket.serialize())
     return writer.getBuffer()
Example #7
0
	def _serialize(self, writer: BufferWriter):
		writer.putUInt8(self.major)
		writer.putUInt8(self.minor)
 def _serialize(self, writer: BufferWriter):
     writer.putUInt8(self.protocol)
     writer.putUInt8(self.appIndex)
 def _serialize(self, writer: BufferWriter):
     writer.putUInt8(self.type)
     self.flags.serialize(writer)
     writer.putUInt8(self.profileId)
     self.filterInput.serialize(writer)
     self.filterOutput.serialize(writer)
 def _serialize(self, writer: BufferWriter):
     super()._serialize(writer)
     writer.putUInt8(self.adType)
     writer.putUInt32(self.mask)
 def _serialize(self, writer: BufferWriter):
     writer.putUInt8(self.type)
 def _serialize(self, writer: BufferWriter):
     writer.putUInt8(self.commandProtocolVersion)
     writer.putUInt16(self.masterVersion)
     writer.putUInt32(self.masterCrc)
 def _serialize(self, writer: BufferWriter):
     writer.putUInt8(self.commandProtocolVersion)
     writer.putUInt8(self.filterId)
 def _serialize(self, writer: BufferWriter):
     writer.putUInt8(self.outFormat)
     if self.inFormat is not None:
         self.inFormat.serialize(writer)
 def serialize(self):
     writer = BufferWriter()
     writer.putUInt8(self.crownstoneId)
     writer.putUInt8(self.state)
     return writer.getBuffer()
	def _toBuffer(self, writer: BufferWriter):
		writer.putUInt8(self.protocol)
		writer.putUInt8(self.appIndex)
Example #17
0
 def _toBuffer(self, writer: BufferWriter):
     writer.putUInt8(self.major)
     writer.putUInt8(self.minor)
 def _serialize(self, writer: BufferWriter):
     self._calc_bitmask()
     writer.putUInt8(self.bitmask)