diff --git a/coapthon/defines.py b/coapthon/defines.py index 09fff43..172d058 100644 --- a/coapthon/defines.py +++ b/coapthon/defines.py @@ -125,7 +125,7 @@ class OptionRegistry(object): LOCATION_QUERY = OptionItem(20,"Location-Query",STRING, True, None) BLOCK2 = OptionItem(23, "Block2", INTEGER, False, None) BLOCK1 = OptionItem(27, "Block1", INTEGER, False, None) - SIZE2 = OptionItem(28, "Size2", INTEGER, False, None) + SIZE2 = OptionItem(28, "Size2", INTEGER, False, 0) PROXY_URI = OptionItem(35, "Proxy-Uri", STRING, False, None) PROXY_SCHEME = OptionItem(39, "Proxy-Schema", STRING, False, None) SIZE1 = OptionItem(60, "Size1", INTEGER, False, None) diff --git a/coapthon/layers/blocklayer.py b/coapthon/layers/blocklayer.py index 1980764..cc7bec1 100644 --- a/coapthon/layers/blocklayer.py +++ b/coapthon/layers/blocklayer.py @@ -233,6 +233,7 @@ class BlockLayer(object): self._block2_receive[key_token] = BlockItem(byte, num, m, size) + # correct m m = 0 if ((num * size) + size) > len(transaction.response.payload) else 1 # add size2 if requested or if payload is bigger than one datagram @@ -240,6 +241,7 @@ class BlockLayer(object): if (transaction.request.size2 is not None and transaction.request.size2 == 0) or \ (transaction.response.payload is not None and len(transaction.response.payload) > defines.MAX_PAYLOAD): transaction.response.size2 = len(transaction.response.payload) + transaction.response.payload = transaction.response.payload[byte:byte + size] del transaction.response.block2 transaction.response.block2 = (num, m, size) diff --git a/coapthon/messages/message.py b/coapthon/messages/message.py index d8159f9..98e4a76 100644 --- a/coapthon/messages/message.py +++ b/coapthon/messages/message.py @@ -645,8 +645,7 @@ class Message(object): Delete the Block2 option. """ self.del_option_by_number(defines.OptionRegistry.BLOCK2.number) - - @property + def size1(self): value = None for option in self.options: @@ -667,14 +666,24 @@ class Message(object): @property def size2(self): + """ + Get the Size2 option. + + :return: the Size2 value + """ value = None for option in self.options: if option.number == defines.OptionRegistry.SIZE2.number: - value = option.value if option.value is not None else 0 + value = option.value return value @size2.setter def size2(self, value): + """ + Set the Size2 option. + + :param value: the Block2 value + """ option = Option() option.number = defines.OptionRegistry.SIZE2.number option.value = value @@ -682,6 +691,9 @@ class Message(object): @size2.deleter def size2(self): + """ + Delete the Size2 option. + """ self.del_option_by_number(defines.OptionRegistry.SIZE2.number) @property